86 lines
1.8 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 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),
2020-03-16 20:57:19 -07:00
Armor(armor::Armor),
2020-03-16 21:48:26 -07:00
Shield(shield::Shield),
Unit(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(),
2020-03-16 20:57:19 -07:00
ItemDetail::Armor(armor) => armor.as_bytes(),
2020-03-16 21:48:26 -07:00
ItemDetail::Shield(shield) => shield.as_bytes(),
ItemDetail::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
}