105 lines
2.1 KiB
Rust

pub mod weapon;
pub mod armor;
pub mod shield;
pub mod tool;
pub mod unit;
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)]
pub enum ItemLocation {
Inventory {
character_id: u32,
index: usize,
},
Bank {
character_id: u32,
slot: usize,
},
Floor {
// floor: eventually
// x y z: ?????
},
/*Destroyed {
// marks an item that has been consumed in some way
},
Transformed {
item_id,
change_event
}
*/
}
#[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,
}
#[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),
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(),
ItemDetail::Unit(unit) => unit.unit.as_bytes(),
ItemDetail::Tool(tool) => tool.as_bytes(),
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Item {
pub id: ItemEntityId,
pub location: ItemLocation,
pub item: ItemDetail,
}