use serde::{Serialize, Deserialize}; use crate::entity::item::ItemEntityId; #[derive(Debug, Copy, Clone)] pub enum ItemParseError { InvalidArmorBytes, InvalidArmorType, } #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, enum_utils::FromStr, derive_more::Display, strum_macros::EnumIter)] pub enum ArmorType { Frame, Armor, PsyArmor, GigaFrame, SoulFrame, CrossArmor, SolidFrame, BraveArmor, HyperFrame, GrandArmor, ShockFrame, KingsFrame, DragonFrame, AbsorbArmor, ProtectFrame, GeneralArmor, PerfectFrame, ValiantFrame, ImperialArmor, HolinessArmor, GuardianArmor, DivinityArmor, UltimateFrame, CelestialArmor, HunterField, RangerField, ForceField, RevivalGarment, SpiritGarment, StinkFrame, DPartsVer101, DPartsVer210, ParasiteWearDeRol, ParasiteWearNelgal, ParasiteWearVajulla, SensePlate, GravitonPlate, AttributePlate, FlowensFrame, CustomFrameVerOo, DbsArmor, GuardWave, DfField, LuminousField, ChuChuFever, LoveHeart, FlameGarment, VirusArmorLafuteria, BrightnessCircle, AuraField, ElectroFrame, SacredCloth, SmokingPlate, StarCuirass, BlackHoundCuirass, MorningPrayer, BlackOdoshiDomaru, RedOdoshiDomaru, BlackOdoshiRedNimaidou, BlueOdoshiVioletNimaidou, DirtyLifejacket, KroesSweater, WeddingDress, SonicteamArmor, RedCoat, Thirteen, MotherGarb, MotherGarbPlus, DressPlate, Sweetheart, IgnitionCloak, CongealCloak, TempestCloak, CursedCloak, SelectCloak, SpiritCuirass, RevivalCuriass, AllianceUniform, OfficerUniform, CommanderUniform, CrimsonCoat, InfantryGear, LieutenantGear, InfantryMantle, LieutenantMantle, UnionField, SamuraiArmor, StealthSuit, } impl ArmorType { pub fn value(&self) -> [u8; 3] { match self { ArmorType::Frame => [0x01, 0x01, 0x00], ArmorType::Armor => [0x01, 0x01, 0x01], ArmorType::PsyArmor => [0x01, 0x01, 0x02], ArmorType::GigaFrame => [0x01, 0x01, 0x03], ArmorType::SoulFrame => [0x01, 0x01, 0x04], ArmorType::CrossArmor => [0x01, 0x01, 0x05], ArmorType::SolidFrame => [0x01, 0x01, 0x06], ArmorType::BraveArmor => [0x01, 0x01, 0x07], ArmorType::HyperFrame => [0x01, 0x01, 0x08], ArmorType::GrandArmor => [0x01, 0x01, 0x09], ArmorType::ShockFrame => [0x01, 0x01, 0x0A], ArmorType::KingsFrame => [0x01, 0x01, 0x0B], ArmorType::DragonFrame => [0x01, 0x01, 0x0C], ArmorType::AbsorbArmor => [0x01, 0x01, 0x0D], ArmorType::ProtectFrame => [0x01, 0x01, 0x0E], ArmorType::GeneralArmor => [0x01, 0x01, 0x0F], ArmorType::PerfectFrame => [0x01, 0x01, 0x10], ArmorType::ValiantFrame => [0x01, 0x01, 0x11], ArmorType::ImperialArmor => [0x01, 0x01, 0x12], ArmorType::HolinessArmor => [0x01, 0x01, 0x13], ArmorType::GuardianArmor => [0x01, 0x01, 0x14], ArmorType::DivinityArmor => [0x01, 0x01, 0x15], ArmorType::UltimateFrame => [0x01, 0x01, 0x16], ArmorType::CelestialArmor => [0x01, 0x01, 0x17], ArmorType::HunterField => [0x01, 0x01, 0x18], ArmorType::RangerField => [0x01, 0x01, 0x19], ArmorType::ForceField => [0x01, 0x01, 0x1A], ArmorType::RevivalGarment => [0x01, 0x01, 0x1B], ArmorType::SpiritGarment => [0x01, 0x01, 0x1C], ArmorType::StinkFrame => [0x01, 0x01, 0x1D], ArmorType::DPartsVer101 => [0x01, 0x01, 0x1E], ArmorType::DPartsVer210 => [0x01, 0x01, 0x1F], ArmorType::ParasiteWearDeRol => [0x01, 0x01, 0x20], ArmorType::ParasiteWearNelgal => [0x01, 0x01, 0x21], ArmorType::ParasiteWearVajulla => [0x01, 0x01, 0x22], ArmorType::SensePlate => [0x01, 0x01, 0x23], ArmorType::GravitonPlate => [0x01, 0x01, 0x24], ArmorType::AttributePlate => [0x01, 0x01, 0x25], ArmorType::FlowensFrame => [0x01, 0x01, 0x26], ArmorType::CustomFrameVerOo => [0x01, 0x01, 0x27], ArmorType::DbsArmor => [0x01, 0x01, 0x28], ArmorType::GuardWave => [0x01, 0x01, 0x29], ArmorType::DfField => [0x01, 0x01, 0x2A], ArmorType::LuminousField => [0x01, 0x01, 0x2B], ArmorType::ChuChuFever => [0x01, 0x01, 0x2C], ArmorType::LoveHeart => [0x01, 0x01, 0x2D], ArmorType::FlameGarment => [0x01, 0x01, 0x2E], ArmorType::VirusArmorLafuteria => [0x01, 0x01, 0x2F], ArmorType::BrightnessCircle => [0x01, 0x01, 0x30], ArmorType::AuraField => [0x01, 0x01, 0x31], ArmorType::ElectroFrame => [0x01, 0x01, 0x32], ArmorType::SacredCloth => [0x01, 0x01, 0x33], ArmorType::SmokingPlate => [0x01, 0x01, 0x34], ArmorType::StarCuirass => [0x01, 0x01, 0x35], ArmorType::BlackHoundCuirass => [0x01, 0x01, 0x36], ArmorType::MorningPrayer => [0x01, 0x01, 0x37], ArmorType::BlackOdoshiDomaru => [0x01, 0x01, 0x38], ArmorType::RedOdoshiDomaru => [0x01, 0x01, 0x39], ArmorType::BlackOdoshiRedNimaidou => [0x01, 0x01, 0x3A], ArmorType::BlueOdoshiVioletNimaidou => [0x01, 0x01, 0x3B], ArmorType::DirtyLifejacket => [0x01, 0x01, 0x3C], ArmorType::KroesSweater => [0x01, 0x01, 0x3D], ArmorType::WeddingDress => [0x01, 0x01, 0x3E], ArmorType::SonicteamArmor => [0x01, 0x01, 0x3F], ArmorType::RedCoat => [0x01, 0x01, 0x40], ArmorType::Thirteen => [0x01, 0x01, 0x41], ArmorType::MotherGarb => [0x01, 0x01, 0x42], ArmorType::MotherGarbPlus => [0x01, 0x01, 0x43], ArmorType::DressPlate => [0x01, 0x01, 0x44], ArmorType::Sweetheart => [0x01, 0x01, 0x45], ArmorType::IgnitionCloak => [0x01, 0x01, 0x46], ArmorType::CongealCloak => [0x01, 0x01, 0x47], ArmorType::TempestCloak => [0x01, 0x01, 0x48], ArmorType::CursedCloak => [0x01, 0x01, 0x49], ArmorType::SelectCloak => [0x01, 0x01, 0x4A], ArmorType::SpiritCuirass => [0x01, 0x01, 0x4B], ArmorType::RevivalCuriass => [0x01, 0x01, 0x4C], ArmorType::AllianceUniform => [0x01, 0x01, 0x4D], ArmorType::OfficerUniform => [0x01, 0x01, 0x4E], ArmorType::CommanderUniform => [0x01, 0x01, 0x4F], ArmorType::CrimsonCoat => [0x01, 0x01, 0x50], ArmorType::InfantryGear => [0x01, 0x01, 0x51], ArmorType::LieutenantGear => [0x01, 0x01, 0x52], ArmorType::InfantryMantle => [0x01, 0x01, 0x53], ArmorType::LieutenantMantle => [0x01, 0x01, 0x54], ArmorType::UnionField => [0x01, 0x01, 0x55], ArmorType::SamuraiArmor => [0x01, 0x01, 0x56], ArmorType::StealthSuit => [0x01, 0x01, 0x57], } } pub fn parse_type(data: [u8; 3]) -> Result { match data { [0x01, 0x01, 0x00] => Ok(ArmorType::Frame), [0x01, 0x01, 0x01] => Ok(ArmorType::Armor), [0x01, 0x01, 0x02] => Ok(ArmorType::PsyArmor), [0x01, 0x01, 0x03] => Ok(ArmorType::GigaFrame), [0x01, 0x01, 0x04] => Ok(ArmorType::SoulFrame), [0x01, 0x01, 0x05] => Ok(ArmorType::CrossArmor), [0x01, 0x01, 0x06] => Ok(ArmorType::SolidFrame), [0x01, 0x01, 0x07] => Ok(ArmorType::BraveArmor), [0x01, 0x01, 0x08] => Ok(ArmorType::HyperFrame), [0x01, 0x01, 0x09] => Ok(ArmorType::GrandArmor), [0x01, 0x01, 0x0A] => Ok(ArmorType::ShockFrame), [0x01, 0x01, 0x0B] => Ok(ArmorType::KingsFrame), [0x01, 0x01, 0x0C] => Ok(ArmorType::DragonFrame), [0x01, 0x01, 0x0D] => Ok(ArmorType::AbsorbArmor), [0x01, 0x01, 0x0E] => Ok(ArmorType::ProtectFrame), [0x01, 0x01, 0x0F] => Ok(ArmorType::GeneralArmor), [0x01, 0x01, 0x10] => Ok(ArmorType::PerfectFrame), [0x01, 0x01, 0x11] => Ok(ArmorType::ValiantFrame), [0x01, 0x01, 0x12] => Ok(ArmorType::ImperialArmor), [0x01, 0x01, 0x13] => Ok(ArmorType::HolinessArmor), [0x01, 0x01, 0x14] => Ok(ArmorType::GuardianArmor), [0x01, 0x01, 0x15] => Ok(ArmorType::DivinityArmor), [0x01, 0x01, 0x16] => Ok(ArmorType::UltimateFrame), [0x01, 0x01, 0x17] => Ok(ArmorType::CelestialArmor), [0x01, 0x01, 0x18] => Ok(ArmorType::HunterField), [0x01, 0x01, 0x19] => Ok(ArmorType::RangerField), [0x01, 0x01, 0x1A] => Ok(ArmorType::ForceField), [0x01, 0x01, 0x1B] => Ok(ArmorType::RevivalGarment), [0x01, 0x01, 0x1C] => Ok(ArmorType::SpiritGarment), [0x01, 0x01, 0x1D] => Ok(ArmorType::StinkFrame), [0x01, 0x01, 0x1E] => Ok(ArmorType::DPartsVer101), [0x01, 0x01, 0x1F] => Ok(ArmorType::DPartsVer210), [0x01, 0x01, 0x20] => Ok(ArmorType::ParasiteWearDeRol), [0x01, 0x01, 0x21] => Ok(ArmorType::ParasiteWearNelgal), [0x01, 0x01, 0x22] => Ok(ArmorType::ParasiteWearVajulla), [0x01, 0x01, 0x23] => Ok(ArmorType::SensePlate), [0x01, 0x01, 0x24] => Ok(ArmorType::GravitonPlate), [0x01, 0x01, 0x25] => Ok(ArmorType::AttributePlate), [0x01, 0x01, 0x26] => Ok(ArmorType::FlowensFrame), [0x01, 0x01, 0x27] => Ok(ArmorType::CustomFrameVerOo), [0x01, 0x01, 0x28] => Ok(ArmorType::DbsArmor), [0x01, 0x01, 0x29] => Ok(ArmorType::GuardWave), [0x01, 0x01, 0x2A] => Ok(ArmorType::DfField), [0x01, 0x01, 0x2B] => Ok(ArmorType::LuminousField), [0x01, 0x01, 0x2C] => Ok(ArmorType::ChuChuFever), [0x01, 0x01, 0x2D] => Ok(ArmorType::LoveHeart), [0x01, 0x01, 0x2E] => Ok(ArmorType::FlameGarment), [0x01, 0x01, 0x2F] => Ok(ArmorType::VirusArmorLafuteria), [0x01, 0x01, 0x30] => Ok(ArmorType::BrightnessCircle), [0x01, 0x01, 0x31] => Ok(ArmorType::AuraField), [0x01, 0x01, 0x32] => Ok(ArmorType::ElectroFrame), [0x01, 0x01, 0x33] => Ok(ArmorType::SacredCloth), [0x01, 0x01, 0x34] => Ok(ArmorType::SmokingPlate), [0x01, 0x01, 0x35] => Ok(ArmorType::StarCuirass), [0x01, 0x01, 0x36] => Ok(ArmorType::BlackHoundCuirass), [0x01, 0x01, 0x37] => Ok(ArmorType::MorningPrayer), [0x01, 0x01, 0x38] => Ok(ArmorType::BlackOdoshiDomaru), [0x01, 0x01, 0x39] => Ok(ArmorType::RedOdoshiDomaru), [0x01, 0x01, 0x3A] => Ok(ArmorType::BlackOdoshiRedNimaidou), [0x01, 0x01, 0x3B] => Ok(ArmorType::BlueOdoshiVioletNimaidou), [0x01, 0x01, 0x3C] => Ok(ArmorType::DirtyLifejacket), [0x01, 0x01, 0x3D] => Ok(ArmorType::KroesSweater), [0x01, 0x01, 0x3E] => Ok(ArmorType::WeddingDress), [0x01, 0x01, 0x3F] => Ok(ArmorType::SonicteamArmor), [0x01, 0x01, 0x40] => Ok(ArmorType::RedCoat), [0x01, 0x01, 0x41] => Ok(ArmorType::Thirteen), [0x01, 0x01, 0x42] => Ok(ArmorType::MotherGarb), [0x01, 0x01, 0x43] => Ok(ArmorType::MotherGarbPlus), [0x01, 0x01, 0x44] => Ok(ArmorType::DressPlate), [0x01, 0x01, 0x45] => Ok(ArmorType::Sweetheart), [0x01, 0x01, 0x46] => Ok(ArmorType::IgnitionCloak), [0x01, 0x01, 0x47] => Ok(ArmorType::CongealCloak), [0x01, 0x01, 0x48] => Ok(ArmorType::TempestCloak), [0x01, 0x01, 0x49] => Ok(ArmorType::CursedCloak), [0x01, 0x01, 0x4A] => Ok(ArmorType::SelectCloak), [0x01, 0x01, 0x4B] => Ok(ArmorType::SpiritCuirass), [0x01, 0x01, 0x4C] => Ok(ArmorType::RevivalCuriass), [0x01, 0x01, 0x4D] => Ok(ArmorType::AllianceUniform), [0x01, 0x01, 0x4E] => Ok(ArmorType::OfficerUniform), [0x01, 0x01, 0x4F] => Ok(ArmorType::CommanderUniform), [0x01, 0x01, 0x50] => Ok(ArmorType::CrimsonCoat), [0x01, 0x01, 0x51] => Ok(ArmorType::InfantryGear), [0x01, 0x01, 0x52] => Ok(ArmorType::LieutenantGear), [0x01, 0x01, 0x53] => Ok(ArmorType::InfantryMantle), [0x01, 0x01, 0x54] => Ok(ArmorType::LieutenantMantle), [0x01, 0x01, 0x55] => Ok(ArmorType::UnionField), [0x01, 0x01, 0x56] => Ok(ArmorType::SamuraiArmor), [0x01, 0x01, 0x57] => Ok(ArmorType::StealthSuit), _ => Err(ItemParseError::InvalidArmorType), } } } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum ArmorModifier { AddSlot { addslot: ItemEntityId, } } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Armor { pub armor: ArmorType, pub dfp: u8, pub evp: u8, pub slots: u8, } impl Armor { pub fn as_bytes(&self) -> [u8; 16] { let mut result = [0; 16]; result[0..3].copy_from_slice(&self.armor.value()); result[5] = self.slots; result[6] = self.dfp; result[8] = self.evp; result } pub fn from_bytes(data: [u8; 16]) -> Result { let a = ArmorType::parse_type([data[0], data[1], data[2]]); if a.is_ok() { Ok(Armor { armor: a.unwrap(), dfp: data[6], evp: data[8], slots: data[5], }) } else { Err(ItemParseError::InvalidArmorBytes) // TODO: error handling if wrong bytes are given } } }