2019-09-25 15:52:58 +00:00
|
|
|
use crate::{
|
|
|
|
comp,
|
|
|
|
effect::Effect,
|
|
|
|
terrain::{Block, BlockKind},
|
|
|
|
};
|
2019-10-09 19:28:05 +00:00
|
|
|
use rand::prelude::*;
|
2019-07-26 21:01:41 +00:00
|
|
|
use specs::{Component, FlaggedStorage};
|
2019-07-29 19:54:48 +00:00
|
|
|
use specs_idvs::IDVStorage;
|
2019-05-18 16:46:14 +00:00
|
|
|
|
2019-08-27 19:56:46 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2019-07-29 13:44:16 +00:00
|
|
|
pub enum Tool {
|
2019-10-09 19:28:05 +00:00
|
|
|
Dagger,
|
|
|
|
Shield,
|
2019-06-28 23:42:51 +00:00
|
|
|
Sword,
|
|
|
|
Axe,
|
|
|
|
Hammer,
|
|
|
|
Bow,
|
|
|
|
Staff,
|
|
|
|
}
|
2019-07-29 13:44:16 +00:00
|
|
|
|
|
|
|
impl Tool {
|
|
|
|
pub fn name(&self) -> &'static str {
|
|
|
|
match self {
|
2019-10-09 19:28:05 +00:00
|
|
|
Tool::Dagger => "Dagger",
|
|
|
|
Tool::Shield => "Shield",
|
|
|
|
Tool::Sword => "Sword",
|
|
|
|
Tool::Axe => "Axe",
|
|
|
|
Tool::Hammer => "Hammer",
|
|
|
|
Tool::Bow => "Bow",
|
|
|
|
Tool::Staff => "Staff",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn description(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
Tool::Dagger => "A basic kitchen knife.",
|
|
|
|
Tool::Shield => {
|
|
|
|
"This shield belonged to many adventurers.\n\
|
|
|
|
Now it's yours.\n\
|
|
|
|
NOT YET AVAILABLE."
|
|
|
|
}
|
|
|
|
Tool::Sword => "When closing one eye it's nearly like it wasn't rusty at all!",
|
|
|
|
Tool::Axe => {
|
|
|
|
"It has a name written on it.\n\
|
|
|
|
Sounds dwarvish."
|
|
|
|
}
|
|
|
|
Tool::Hammer => "Use with caution around nails.",
|
|
|
|
Tool::Bow => "An old but sturdy hunting bow.",
|
|
|
|
Tool::Staff => {
|
|
|
|
"A carved stick.\n\
|
|
|
|
The wood smells like magic.\n\
|
|
|
|
NOT YET AVAILABLE."
|
|
|
|
}
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const ALL_TOOLS: [Tool; 7] = [
|
2019-10-09 19:28:05 +00:00
|
|
|
Tool::Dagger,
|
|
|
|
Tool::Shield,
|
2019-07-29 13:44:16 +00:00
|
|
|
Tool::Sword,
|
|
|
|
Tool::Axe,
|
|
|
|
Tool::Hammer,
|
|
|
|
Tool::Bow,
|
|
|
|
Tool::Staff,
|
2019-06-28 23:42:51 +00:00
|
|
|
];
|
|
|
|
|
2019-08-27 19:56:46 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2019-05-18 16:46:14 +00:00
|
|
|
pub enum Armor {
|
2019-10-09 19:28:05 +00:00
|
|
|
// TODO: Don't make armor be a body part. Wearing enemy's head is funny but also a creepy thing to do.
|
2019-06-28 08:24:13 +00:00
|
|
|
Helmet,
|
2019-06-28 23:42:51 +00:00
|
|
|
Shoulders,
|
|
|
|
Chestplate,
|
|
|
|
Belt,
|
|
|
|
Gloves,
|
|
|
|
Pants,
|
|
|
|
Boots,
|
2019-05-18 16:46:14 +00:00
|
|
|
Back,
|
|
|
|
Tabard,
|
|
|
|
Gem,
|
|
|
|
Necklace,
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:44:16 +00:00
|
|
|
impl Armor {
|
|
|
|
pub fn name(&self) -> &'static str {
|
|
|
|
match self {
|
2019-10-09 19:28:05 +00:00
|
|
|
Armor::Helmet => "Helmet",
|
|
|
|
Armor::Shoulders => "Shoulder Pads",
|
|
|
|
Armor::Chestplate => "Chestplate",
|
|
|
|
Armor::Belt => "Belt",
|
|
|
|
Armor::Gloves => "Gloves",
|
|
|
|
Armor::Pants => "Pants",
|
|
|
|
Armor::Boots => "Boots",
|
|
|
|
Armor::Back => "Back",
|
|
|
|
Armor::Tabard => "Tabard",
|
|
|
|
Armor::Gem => "Gem",
|
|
|
|
Armor::Necklace => "Necklace",
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-09 19:28:05 +00:00
|
|
|
|
|
|
|
pub fn description(&self) -> &'static str {
|
|
|
|
self.name()
|
|
|
|
}
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 14:56:57 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Consumable {
|
|
|
|
Apple,
|
|
|
|
Potion,
|
|
|
|
Mushroom,
|
2019-09-25 20:22:39 +00:00
|
|
|
Velorite,
|
2019-09-25 14:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Consumable {
|
|
|
|
pub fn name(&self) -> &'static str {
|
|
|
|
match self {
|
2019-10-09 19:28:05 +00:00
|
|
|
Consumable::Apple => "Apple",
|
|
|
|
Consumable::Potion => "Potion",
|
|
|
|
Consumable::Mushroom => "Mushroom",
|
|
|
|
Consumable::Velorite => "Velorite",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn description(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
Consumable::Apple => "A tasty Apple.",
|
|
|
|
Consumable::Potion => "This Potion contains the essence of Life.",
|
|
|
|
Consumable::Mushroom => "A common Mushroom.",
|
|
|
|
Consumable::Velorite => "Has a subtle turqoise glow.",
|
2019-09-25 14:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 22:04:18 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Ingredient {
|
|
|
|
Flower,
|
|
|
|
Grass,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ingredient {
|
|
|
|
pub fn name(&self) -> &'static str {
|
|
|
|
match self {
|
2019-10-09 19:28:05 +00:00
|
|
|
Ingredient::Flower => "Flower",
|
|
|
|
Ingredient::Grass => "Grass",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn description(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
Ingredient::Flower => "It smells great.",
|
|
|
|
Ingredient::Grass => "Greener than an orc's snout.",
|
2019-09-25 22:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 20:47:52 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Debug {
|
2019-08-29 17:42:25 +00:00
|
|
|
Boost,
|
2019-10-09 19:28:05 +00:00
|
|
|
Possess,
|
2019-08-28 20:47:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 20:42:43 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
2019-05-18 16:46:14 +00:00
|
|
|
pub enum Item {
|
2019-07-29 13:44:16 +00:00
|
|
|
Tool {
|
|
|
|
kind: Tool,
|
2019-08-26 18:05:13 +00:00
|
|
|
power: u32,
|
2019-10-09 19:28:05 +00:00
|
|
|
stamina: i32,
|
|
|
|
strength: i32,
|
|
|
|
dexterity: i32,
|
|
|
|
intelligence: i32,
|
2019-05-18 16:46:14 +00:00
|
|
|
},
|
|
|
|
Armor {
|
2019-07-25 22:52:28 +00:00
|
|
|
kind: Armor,
|
2019-10-09 19:28:05 +00:00
|
|
|
stamina: i32,
|
|
|
|
strength: i32,
|
|
|
|
dexterity: i32,
|
|
|
|
intelligence: i32,
|
2019-05-18 16:46:14 +00:00
|
|
|
},
|
2019-07-29 13:44:16 +00:00
|
|
|
Consumable {
|
2019-09-25 14:56:57 +00:00
|
|
|
kind: Consumable,
|
2019-09-25 15:52:58 +00:00
|
|
|
effect: Effect,
|
2019-07-29 13:44:16 +00:00
|
|
|
},
|
2019-09-25 22:04:18 +00:00
|
|
|
Ingredient {
|
|
|
|
kind: Ingredient,
|
|
|
|
},
|
2019-08-28 20:47:52 +00:00
|
|
|
Debug(Debug),
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Item {
|
|
|
|
pub fn name(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
Item::Tool { kind, .. } => kind.name(),
|
|
|
|
Item::Armor { kind, .. } => kind.name(),
|
2019-09-25 22:04:18 +00:00
|
|
|
Item::Consumable { kind, .. } => kind.name(),
|
2019-10-09 19:28:05 +00:00
|
|
|
Item::Ingredient { kind, .. } => kind.name(),
|
2019-08-28 20:47:52 +00:00
|
|
|
Item::Debug(_) => "Debugging item",
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 19:28:05 +00:00
|
|
|
pub fn title(&self) -> String {
|
|
|
|
format!("{} ({})", self.name(), self.category())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn info(&self) -> String {
|
|
|
|
match self {
|
|
|
|
Item::Tool { power, .. } => format!("{:+} attack", power),
|
|
|
|
Item::Armor { .. } => String::new(),
|
|
|
|
Item::Consumable { effect, .. } => format!("{}", effect.info()),
|
|
|
|
Item::Ingredient { .. } => String::new(),
|
|
|
|
Item::Debug(_) => format!("+99999 insanity"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:44:16 +00:00
|
|
|
pub fn category(&self) -> &'static str {
|
|
|
|
match self {
|
2019-10-09 19:28:05 +00:00
|
|
|
Item::Tool { .. } => "Tool",
|
|
|
|
Item::Armor { .. } => "Armor",
|
|
|
|
Item::Consumable { .. } => "Consumable",
|
|
|
|
Item::Ingredient { .. } => "Ingredient",
|
|
|
|
Item::Debug(_) => "Debug",
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn description(&self) -> String {
|
2019-10-09 19:28:05 +00:00
|
|
|
match self {
|
|
|
|
Item::Tool { kind, .. } => format!("{}", kind.description()),
|
|
|
|
Item::Armor { kind, .. } => format!("{}", kind.description()),
|
|
|
|
Item::Consumable { kind, .. } => format!("{}", kind.description()),
|
|
|
|
Item::Ingredient { kind, .. } => format!("{}", kind.description()),
|
|
|
|
Item::Debug(_) => format!("Debugging item"),
|
|
|
|
}
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
2019-09-25 14:56:57 +00:00
|
|
|
|
|
|
|
pub fn try_reclaim_from_block(block: Block) -> Option<Self> {
|
|
|
|
match block.kind() {
|
|
|
|
BlockKind::Apple => Some(Self::apple()),
|
|
|
|
BlockKind::Mushroom => Some(Self::mushroom()),
|
2019-09-25 20:22:39 +00:00
|
|
|
BlockKind::Velorite => Some(Self::velorite()),
|
2019-09-25 22:04:18 +00:00
|
|
|
BlockKind::BlueFlower => Some(Self::flower()),
|
|
|
|
BlockKind::PinkFlower => Some(Self::flower()),
|
|
|
|
BlockKind::PurpleFlower => Some(Self::flower()),
|
|
|
|
BlockKind::RedFlower => Some(Self::flower()),
|
|
|
|
BlockKind::WhiteFlower => Some(Self::flower()),
|
|
|
|
BlockKind::YellowFlower => Some(Self::flower()),
|
|
|
|
BlockKind::Sunflower => Some(Self::flower()),
|
|
|
|
BlockKind::LongGrass => Some(Self::grass()),
|
|
|
|
BlockKind::MediumGrass => Some(Self::grass()),
|
|
|
|
BlockKind::ShortGrass => Some(Self::grass()),
|
2019-10-09 19:28:05 +00:00
|
|
|
BlockKind::Chest => Some(match rand::random::<usize>() % 3 {
|
|
|
|
0 => Self::apple(),
|
|
|
|
1 => Self::velorite(),
|
|
|
|
2 => Item::Tool {
|
|
|
|
kind: *(&ALL_TOOLS).choose(&mut rand::thread_rng()).unwrap(),
|
|
|
|
power: 8 + rand::random::<u32>() % (rand::random::<u32>() % 30),
|
|
|
|
stamina: 0,
|
|
|
|
strength: 0,
|
|
|
|
dexterity: 0,
|
|
|
|
intelligence: 0,
|
|
|
|
},
|
|
|
|
_ => unreachable!(),
|
|
|
|
}),
|
2019-09-25 14:56:57 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// General item constructors
|
|
|
|
|
|
|
|
pub fn apple() -> Self {
|
|
|
|
Item::Consumable {
|
|
|
|
kind: Consumable::Apple,
|
2019-10-09 19:28:05 +00:00
|
|
|
effect: Effect::Health(50, comp::HealthSource::Item),
|
2019-09-25 14:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mushroom() -> Self {
|
|
|
|
Item::Consumable {
|
|
|
|
kind: Consumable::Mushroom,
|
2019-09-25 15:52:58 +00:00
|
|
|
effect: Effect::Health(10, comp::HealthSource::Item),
|
2019-09-25 14:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 20:22:39 +00:00
|
|
|
|
|
|
|
pub fn velorite() -> Self {
|
|
|
|
Item::Consumable {
|
2019-10-09 19:28:05 +00:00
|
|
|
kind: Consumable::Velorite,
|
|
|
|
effect: Effect::Xp(50),
|
2019-09-25 20:22:39 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 22:04:18 +00:00
|
|
|
|
|
|
|
pub fn flower() -> Self {
|
|
|
|
Item::Ingredient {
|
|
|
|
kind: Ingredient::Flower,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn grass() -> Self {
|
|
|
|
Item::Ingredient {
|
|
|
|
kind: Ingredient::Grass,
|
|
|
|
}
|
|
|
|
}
|
2019-05-18 16:46:14 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 22:52:28 +00:00
|
|
|
impl Default for Item {
|
|
|
|
fn default() -> Self {
|
2019-07-29 13:44:16 +00:00
|
|
|
Item::Tool {
|
|
|
|
kind: Tool::Hammer,
|
2019-08-26 18:05:13 +00:00
|
|
|
power: 0,
|
2019-10-09 19:28:05 +00:00
|
|
|
stamina: 0,
|
|
|
|
strength: 0,
|
|
|
|
dexterity: 0,
|
|
|
|
intelligence: 0,
|
2019-07-25 22:52:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-18 16:46:14 +00:00
|
|
|
impl Component for Item {
|
2019-07-26 21:01:41 +00:00
|
|
|
type Storage = FlaggedStorage<Self, IDVStorage<Self>>;
|
2019-05-18 16:46:14 +00:00
|
|
|
}
|