115 lines
2.6 KiB
Rust
Raw Normal View History

pub mod weapon;
pub mod armor;
pub mod shield;
pub mod tool;
2020-03-18 18:21:34 -07:00
pub mod tech;
2020-02-29 14:50:17 -08:00
pub mod unit;
2020-03-14 20:26:12 -07:00
pub mod mag;
2020-03-29 14:40:24 -07:00
use crate::entity::character::CharacterEntityId;
2020-04-26 22:01:05 -06:00
use crate::ship::map::MapArea;
2020-03-29 14:40:24 -07:00
#[derive(PartialEq, Copy, Clone, Debug, Hash, Eq)]
pub struct ItemEntityId(pub u32);
#[derive(Hash, PartialEq, Eq, Debug, Clone)]
pub struct ItemId(u32);
2020-03-29 14:40:24 -07:00
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BankName(String);
2020-04-26 21:58:43 -06:00
#[derive(Clone, Debug)]
2019-12-09 23:11:27 -08:00
pub enum ItemLocation {
Inventory {
2020-03-29 14:40:24 -07:00
character_id: CharacterEntityId,
2019-12-09 23:11:27 -08:00
index: usize,
equipped: bool,
2019-12-09 23:11:27 -08:00
},
Bank {
2020-03-29 14:40:24 -07:00
character_id: CharacterEntityId,
slot: BankName,
2019-12-09 23:11:27 -08:00
},
Floor {
2020-04-26 22:01:05 -06:00
map_area: MapArea,
x: f32,
y: f32,
z: f32,
2019-12-09 23:11:27 -08:00
},
/*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(Debug, PartialEq)]
pub struct Meseta(pub u32);
impl Meseta {
pub fn as_bytes(&self) -> [u8; 16] {
let mut result = [0; 16];
2020-04-26 22:51:09 -06:00
result[0] = 4;
result[12..16].copy_from_slice(&u32::to_le_bytes(self.0));
result
}
}
2020-03-21 17:47:28 -07:00
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ItemType {
Weapon(weapon::WeaponType),
Armor(armor::ArmorType),
Shield(shield::ShieldType),
Unit(unit::UnitType),
Tool(tool::ToolType),
2020-03-21 21:46:52 -07:00
TechniqueDisk(tech::Technique),
Mag(mag::MagType),
}
2020-03-21 17:47:28 -07:00
#[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),
2020-03-21 17:47:28 -07:00
Tool(tool::Tool),
2020-03-21 21:46:52 -07:00
TechniqueDisk(tech::TechniqueDisk),
Mag(mag::Mag),
}
impl ItemDetail {
pub fn is_stackable(&self) -> bool {
match self {
ItemDetail::Tool(tool) => tool.tool.is_stackable(),
_ => false,
}
}
2020-03-21 17:47:28 -07:00
pub fn item_type(&self) -> ItemType {
match self {
2020-03-21 17:47:28 -07:00
ItemDetail::Weapon(w) => ItemType::Weapon(w.weapon),
ItemDetail::Armor(a) => ItemType::Armor(a.armor),
ItemDetail::Shield(s) => ItemType::Shield(s.shield),
ItemDetail::Unit(u) => ItemType::Unit(u.unit),
ItemDetail::Tool(t) => ItemType::Tool(t.tool),
ItemDetail::TechniqueDisk(d) => ItemType::TechniqueDisk(d.tech),
2020-03-21 21:46:52 -07:00
ItemDetail::Mag(m) => ItemType::Mag(m.mag),
}
}
}
2020-04-26 21:58:43 -06:00
#[derive(Clone, Debug)]
pub struct NewItemEntity {
pub location: ItemLocation,
pub item: ItemDetail,
}
2020-04-26 21:58:43 -06:00
#[derive(Clone, Debug)]
2020-03-29 14:53:51 -07:00
pub struct ItemEntity {
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
}