105 lines
2.1 KiB
Rust
Raw Normal View History

pub mod weapon;
pub mod armor;
pub mod shield;
pub mod tool;
2020-02-29 14:50:17 -08:00
pub mod unit;
2020-03-14 20:26:12 -07:00
pub mod mag;
#[derive(PartialEq, Copy, Clone, Debug, Hash, Eq)]
pub struct ItemEntityId(pub u32);
#[derive(Hash, PartialEq, Eq, Debug, Clone)]
pub struct ItemId(u32);
#[derive(Clone, Debug, PartialEq)]
2019-12-09 23:11:27 -08:00
pub enum ItemLocation {
Inventory {
character_id: u32,
index: usize,
},
Bank {
character_id: u32,
slot: usize,
2019-12-09 23:11:27 -08:00
},
Floor {
// floor: eventually
// x y z: ?????
},
/*Destroyed {
// marks an item that has been consumed in some way
},
Transformed {
item_id,
change_event
}
*/
2019-12-09 23:11:27 -08:00
}
#[derive(Clone, Debug, PartialEq)]
pub struct Armor {
pub equipped: bool,
pub armor: armor::Armor,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Shield {
pub equipped: bool,
pub shield: shield::Shield,
}
2020-02-29 14:50:17 -08:00
#[derive(Clone, Debug, PartialEq)]
pub struct Unit {
pub equipped: bool,
pub unit: unit::Unit,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Tool {
pub tool: tool::ToolType,
}
impl Tool {
pub fn as_bytes(&self) -> [u8; 16] {
let mut result = [0; 16];
result[0..3].copy_from_slice(&self.tool.value());
result
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum ItemDetail {
Weapon(weapon::Weapon),
Armor(Armor),
Shield(Shield),
2020-02-29 14:50:17 -08:00
Unit(Unit),
Tool(Tool),
}
impl ItemDetail {
pub fn is_stackable(&self) -> bool {
match self {
ItemDetail::Tool(tool) => tool.tool.is_stackable(),
_ => false,
}
}
pub fn as_bytes(&self) -> [u8; 16] {
match self {
ItemDetail::Weapon(weapon) => weapon.as_bytes(),
ItemDetail::Armor(armor) => armor.armor.as_bytes(),
ItemDetail::Shield(shield) => shield.shield.as_bytes(),
2020-02-29 14:50:17 -08:00
ItemDetail::Unit(unit) => unit.unit.as_bytes(),
ItemDetail::Tool(tool) => tool.as_bytes(),
}
}
}
#[derive(Clone, Debug, PartialEq)]
2019-12-09 23:11:27 -08:00
pub struct Item {
pub id: ItemEntityId,
2019-12-09 23:11:27 -08:00
pub location: ItemLocation,
pub item: ItemDetail,
2019-12-09 23:11:27 -08:00
}