2020-05-02 22:08:37 -03:00
|
|
|
#![allow(dead_code)]
|
2020-02-06 23:03:51 -08:00
|
|
|
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-02-06 23:03:51 -08:00
|
|
|
|
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-05-22 18:58:51 -03:00
|
|
|
use crate::ship::drops::ItemDropType;
|
2020-03-29 14:40:24 -07:00
|
|
|
|
2020-01-18 23:36:28 -08: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-01-18 23:36:28 -08:00
|
|
|
|
2020-04-27 07:07:09 -06:00
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
2019-12-09 23:11:27 -08:00
|
|
|
pub enum ItemLocation {
|
|
|
|
Inventory {
|
2020-03-29 14:40:24 -07:00
|
|
|
character_id: CharacterEntityId,
|
2020-05-05 21:53:04 -06:00
|
|
|
slot: usize,
|
2020-03-29 10:45:01 -07:00
|
|
|
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
|
|
|
},
|
2020-05-05 21:53:04 -06:00
|
|
|
LocalFloor {
|
|
|
|
character_id: CharacterEntityId,
|
|
|
|
map_area: MapArea,
|
|
|
|
x: f32,
|
|
|
|
y: f32,
|
|
|
|
z: f32,
|
|
|
|
},
|
|
|
|
SharedFloor {
|
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
|
|
|
},
|
2020-02-06 23:03:51 -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
|
|
|
}
|
|
|
|
|
2020-05-05 21:53:04 -06:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2020-04-03 22:56:14 -07:00
|
|
|
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;
|
2020-04-03 22:56:14 -07:00
|
|
|
result[12..16].copy_from_slice(&u32::to_le_bytes(self.0));
|
|
|
|
result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 23:36:28 -08:00
|
|
|
|
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-01-18 23:36:28 -08:00
|
|
|
}
|
|
|
|
|
2020-05-22 18:58:51 -03:00
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
pub enum ItemParseError {
|
|
|
|
InvalidBytes
|
|
|
|
}
|
2020-03-21 17:47:28 -07:00
|
|
|
|
2020-01-18 23:36:28 -08:00
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
pub enum ItemDetail {
|
2020-03-16 20:34:50 -07:00
|
|
|
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),
|
2020-01-18 23:36:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ItemDetail {
|
|
|
|
pub fn is_stackable(&self) -> bool {
|
|
|
|
match self {
|
2020-03-16 20:34:50 -07:00
|
|
|
ItemDetail::Tool(tool) => tool.tool.is_stackable(),
|
2020-01-18 23:36:28 -08:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-21 17:47:28 -07:00
|
|
|
pub fn item_type(&self) -> ItemType {
|
2020-01-18 23:36:28 -08:00
|
|
|
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-01-18 23:36:28 -08:00
|
|
|
}
|
|
|
|
}
|
2020-05-22 18:58:51 -03:00
|
|
|
|
|
|
|
pub fn parse_item_from_bytes(data: [u8; 16]) -> Option<ItemDropType> {
|
|
|
|
let item_type = weapon::WeaponType::parse_type([data[0],data[1],data[2]]).map(|w| ItemType::Weapon(w))
|
|
|
|
.or(armor::ArmorType::parse_type([data[0],data[1],data[2]]).map(|a| ItemType::Armor(a)))
|
|
|
|
.or(shield::ShieldType::parse_type([data[0],data[1],data[2]]).map(|s| ItemType::Shield(s)))
|
|
|
|
.or(unit::UnitType::parse_type([data[0],data[1],data[2]]).map(|u| ItemType::Unit(u)))
|
|
|
|
.or(mag::MagType::parse_type([data[0],data[1],data[2]]).map(|m| ItemType::Mag(m)))
|
2020-05-23 01:16:02 -03:00
|
|
|
.or(tool::ToolType::parse_type([data[0],data[1],data[2]]).map(|t| ItemType::Tool(t))).ok()?;
|
2020-05-22 18:58:51 -03:00
|
|
|
|
|
|
|
match item_type {
|
2020-05-23 01:16:02 -03:00
|
|
|
ItemType::Weapon(_w) => Some(ItemDropType::Weapon(weapon::Weapon::from_bytes(data).ok()?)),
|
|
|
|
ItemType::Armor(_a) => Some(ItemDropType::Armor(armor::Armor::from_bytes(data).ok()?)),
|
|
|
|
ItemType::Shield(_s) => Some(ItemDropType::Shield(shield::Shield::from_bytes(data).ok()?)),
|
|
|
|
ItemType::Unit(_u) => Some(ItemDropType::Unit(unit::Unit::from_bytes(data).ok()?)),
|
|
|
|
ItemType::Mag(_m) => Some(ItemDropType::Mag(mag::Mag::from_bytes(data).ok()?)),
|
|
|
|
ItemType::Tool(_t) => Some(ItemDropType::Tool(tool::Tool::from_bytes(data).ok()?)),
|
2020-05-22 18:58:51 -03:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2020-01-18 23:36:28 -08:00
|
|
|
}
|
|
|
|
|
2020-04-26 21:58:43 -06:00
|
|
|
#[derive(Clone, Debug)]
|
2020-03-30 19:28:49 -07:00
|
|
|
pub struct NewItemEntity {
|
|
|
|
pub location: ItemLocation,
|
|
|
|
pub item: ItemDetail,
|
|
|
|
}
|
2020-01-18 23:36:28 -08:00
|
|
|
|
2020-04-27 07:07:09 -06:00
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
2020-03-29 14:53:51 -07:00
|
|
|
pub struct ItemEntity {
|
2020-03-30 19:28:49 -07:00
|
|
|
pub id: ItemEntityId,
|
2019-12-09 23:11:27 -08:00
|
|
|
pub location: ItemLocation,
|
2020-01-18 23:36:28 -08:00
|
|
|
pub item: ItemDetail,
|
2019-12-09 23:11:27 -08:00
|
|
|
}
|