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-06-28 23:42:51 +00:00
|
|
|
Daggers,
|
|
|
|
SwordShield,
|
|
|
|
Sword,
|
|
|
|
Axe,
|
|
|
|
Hammer,
|
|
|
|
Bow,
|
|
|
|
Staff,
|
|
|
|
}
|
2019-07-29 13:44:16 +00:00
|
|
|
|
|
|
|
impl Tool {
|
|
|
|
pub fn name(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
Tool::Daggers => "daggers",
|
|
|
|
Tool::SwordShield => "sword and shield",
|
|
|
|
Tool::Sword => "sword",
|
|
|
|
Tool::Axe => "axe",
|
|
|
|
Tool::Hammer => "hammer",
|
|
|
|
Tool::Bow => "bow",
|
|
|
|
Tool::Staff => "staff",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const ALL_TOOLS: [Tool; 7] = [
|
|
|
|
Tool::Daggers,
|
|
|
|
Tool::SwordShield,
|
|
|
|
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-06-06 14:48:41 +00:00
|
|
|
// TODO: Don't make armor be a body part. Wearing enemy's head is funny but also 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 {
|
|
|
|
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",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum ConsumptionEffect {
|
|
|
|
Health(i32),
|
|
|
|
Xp(i32),
|
|
|
|
}
|
|
|
|
|
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-08-28 20:47:52 +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 Item {
|
2019-07-29 13:44:16 +00:00
|
|
|
Tool {
|
|
|
|
kind: Tool,
|
2019-08-26 18:05:13 +00:00
|
|
|
power: u32,
|
2019-05-18 16:46:14 +00:00
|
|
|
},
|
|
|
|
Armor {
|
2019-07-25 22:52:28 +00:00
|
|
|
kind: Armor,
|
2019-05-18 16:46:14 +00:00
|
|
|
defense: i32,
|
|
|
|
health_bonus: i32,
|
|
|
|
},
|
2019-07-29 13:44:16 +00:00
|
|
|
Consumable {
|
|
|
|
effect: ConsumptionEffect,
|
|
|
|
},
|
|
|
|
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(),
|
|
|
|
Item::Consumable { .. } => "<consumable>",
|
|
|
|
Item::Ingredient => "<ingredient>",
|
2019-08-28 20:47:52 +00:00
|
|
|
Item::Debug(_) => "Debugging item",
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn category(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
Item::Tool { .. } => "tool",
|
|
|
|
Item::Armor { .. } => "armour",
|
|
|
|
Item::Consumable { .. } => "consumable",
|
|
|
|
Item::Ingredient => "ingredient",
|
2019-08-28 20:47:52 +00:00
|
|
|
Item::Debug(_) => "debug",
|
2019-07-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn description(&self) -> String {
|
|
|
|
format!("{} ({})", self.name(), self.category())
|
|
|
|
}
|
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-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
|
|
|
}
|