From 5ba9908b5061e6a20d5eb36d587ce8c35f2108a1 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 6 Sep 2020 02:16:46 -0300 Subject: [PATCH 1/5] basic srank structs and functions --- src/entity/item/esweapon.rs | 221 ++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 src/entity/item/esweapon.rs diff --git a/src/entity/item/esweapon.rs b/src/entity/item/esweapon.rs new file mode 100644 index 0000000..be38a8a --- /dev/null +++ b/src/entity/item/esweapon.rs @@ -0,0 +1,221 @@ +// TODO: actually use this +pub enum SrankError { + InvalidSrankType, + InvalidSrankSpecial, + InvalidSrankName, +} + +pub enum SrankType { + Saber = 0, + Sword, + Blade, + Partisan, + Slicer, + Gun, + Rifle, + Mechgun, + Shot, + Can, + Rod, + Wand, + Twin, + Claw, + Bazooka, + Needle, + Scythe, + Hammer, + Moon, + Psychogun, + Punch, + Windmill, + Harisen, + Katana, + JCutter, + Swords, + Launcher, + Cards, + Knuckle, + Axe, +} + +impl SrankType { + pub fn to_value(&self) -> u8 { + *self as u8 + } + + pub fn from_value(value: u8) -> Result { + match value { + 0 => Ok(SrankType::Saber), + 1 => Ok(SrankType::Sword), + 2 => Ok(SrankType::Blade), + 3 => Ok(SrankType::Partisan), + 4 => Ok(SrankType::Slicer), + 5 => Ok(SrankType::Gun), + 6 => Ok(SrankType::Rifle), + 7 => Ok(SrankType::Mechgun), + 8 => Ok(SrankType::Shot), + 9 => Ok(SrankType::Can), + 10 => Ok(SrankType::Rod), + 11 => Ok(SrankType::Wand), + 12 => Ok(SrankType::Twin), + 13 => Ok(SrankType::Claw), + 14 => Ok(SrankType::Bazooka), + 15 => Ok(SrankType::Needle), + 16 => Ok(SrankType::Scythe), + 17 => Ok(SrankType::Hammer), + 18 => Ok(SrankType::Moon), + 19 => Ok(SrankType::Psychogun), + 20 => Ok(SrankType::Punch), + 21 => Ok(SrankType::Windmill), + 22 => Ok(SrankType::Harisen), + 23 => Ok(SrankType::Katana), + 24 => Ok(SrankType::JCutter), + 25 => Ok(SrankType::Swords), + 26 => Ok(SrankType::Launcher), + 27 => Ok(SrankType::Cards), + 28 => Ok(SrankType::Knuckle), + 29 => Ok(SrankType::Axe), + _ => Err(SrankError::InvalidSrankype), + } + } +} + +pub enum SrankSpecial { + Jellen = 0, + Zalure, + HPRegen, + TPRegen, + Burning, + Tempest, + Blizzard, + Arrest, + Chaos, + Hell, + Spirit, + Berserk, + Demons, + Gush, + Geist, + Kings, +} + +impl SrankSpecial { + pub fn to_value(&self) -> u8 { + *self as u8 + } + + pub fn from_value(value: u8) -> Result { + match value{ + 0 => Ok(SrankSpecial::Jellen), + 1 => Ok(SrankSpecial::Zalure), + 2 => Ok(SrankSpecial::HPRegen), + 3 => Ok(SrankSpecial::TPRegen), + 4 => Ok(SrankSpecial::Burning), + 5 => Ok(SrankSpecial::Tempest), + 6 => Ok(SrankSpecial::Blizzard), + 7 => Ok(SrankSpecial::Arrest), + 8 => Ok(SrankSpecial::Chaos), + 9 => Ok(SrankSpecial::Hell), + 10 => Ok(SrankSpecial::Spirit), + 11 => Ok(SrankSpecial::Berserk), + 12 => Ok(SrankSpecial::Demons), + 13 => Ok(SrankSpecial::Gush), + 14 => Ok(SrankSpecial::Geist), + 15 => Ok(SrankSpecial::Kings), + _ => Err(SrankError::InvalidSrankSpecial), + } + } +} + +pub struct SRankWeapon { + pub type: SrankType, + pub special: Option, + pub name: String, + pub grind: u8, +} + +impl SRankWeapon { + pub fn new(t: SrankType) -> SRankWeapon { + SRankWeapon { + type: t, + special: None, + name: "".to_owned(), + grind: 0, + } + } + + pub fn bytes_from_name(&self) -> [u8; 6] { + let mut result = [0u16; 3]; + let mut letters = [0u8; 8]; + letters[0..self.name.len()].clone_from_slice(&self.name.to_uppercase().clone().into_bytes()); + + for letter in letters.iter_mut() { + *letter = *letter & 0x3F; + } + + result[0] = 0x8000 + (0x20 * letters[0] as u16) + (letters[1] as u16); + result[1] = 0x8000 + (0x400 * letters[2] as u16) + (0x20 * letters[3] as u16) + (letters[4] as u16); + result[2] = 0x8000 + (0x400 * letters[5] as u16) + (0x20 * letters[6] as u16) + (letters[7] as u16); + + [result[0].to_be_bytes()[0], result[0].to_be_bytes()[1], + result[1].to_be_bytes()[0], result[1].to_be_bytes()[1], + result[2].to_be_bytes()[0], result[2].to_be_bytes()[1]] + } + + // TODO: error handling, ensure name is never more than 8 + pub fn name_from_bytes(namebytes: &[u8]) -> String { + let mut name: Vec = Vec::with_capacity(8); + name.extend_from_slice(namebytes); + + for _ in name.len()..name.capacity() { + name.push(0); + } + + let buf: [u16; 3] = [ + u16::from_be_bytes([namebytes[0], namebytes[1]]), + u16::from_be_bytes([namebytes[2], namebytes[3]]), + u16::from_be_bytes([namebytes[4], namebytes[5]]), + ]; + + name[0] = ((buf[0] - 0x8000) / 0x20 + 0x40) as u8; + name[1] = ((buf[0] - 0x8000) % 0x20 + 0x40) as u8; + + name[2] = ((buf[1] - 0x8000) / 0x400 + 0x40) as u8; + name[3] = (((buf[1] - 0x8000) % 0x400) / 0x20 + 0x40) as u8; + name[4] = (((buf[1] - 0x8000) % 0x400) % 0x20 + 0x40) as u8; + + name[5] = ((buf[2] - 0x8000) / 0x400 + 0x40) as u8; + name[6] = (((buf[2] - 0x8000) % 0x400) / 0x20 + 0x40) as u8; + name[7] = (((buf[2] - 0x8000) % 0x400) % 0x20 + 0x40) as u8; + + name.retain(|&x| x > 0x40 && x < 0x5B); + + String::from_utf8(name).unwrap() + } + + pub fn as_bytes(&self) -> [u8; 16] { + let mut result = [0u8; 16]; + result[1] = 0x70 + self.type.to_value(); + result[2] = self.special.to_value(); + result[3] = self.grind; + //result[4] = tekked/untekked flag + result[6..12].clone_from_slice(self.name.bytes_from_name()); + result + } + + // TODO: return Result + pub fn from_bytes(bytes: [u8; 16]) -> SRankWeapon { + let type = bytes[1]; + let special = bytes[2]; + let grind = bytes[3]; + let name = SRankWeapon::name_from_bytes(bytes[6..12]); + + SRankWeapon { + type: type, + special: special, + grind: grind, + name: name, + } + } +} + From 85798c83a212d2cb316e8734551953a72caf5778 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 6 Sep 2020 02:20:27 -0300 Subject: [PATCH 2/5] use from_value --- src/entity/item/esweapon.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/entity/item/esweapon.rs b/src/entity/item/esweapon.rs index be38a8a..71d1e74 100644 --- a/src/entity/item/esweapon.rs +++ b/src/entity/item/esweapon.rs @@ -205,8 +205,8 @@ impl SRankWeapon { // TODO: return Result pub fn from_bytes(bytes: [u8; 16]) -> SRankWeapon { - let type = bytes[1]; - let special = bytes[2]; + let type = SrankType.from_value(bytes[1] - 0x70).unwrap(); + let special = SrankSpecial.from_value(bytes[2]).unwrap(); let grind = bytes[3]; let name = SRankWeapon::name_from_bytes(bytes[6..12]); From 48b162f2219f6e46252f70fd3a53bc26e80a3175 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 6 Sep 2020 23:46:52 -0300 Subject: [PATCH 3/5] add esweapon to item mod.rs and fix dumb mistakes --- src/entity/item/esweapon.rs | 156 ++++++++++++++++++------------------ src/entity/item/mod.rs | 5 ++ 2 files changed, 85 insertions(+), 76 deletions(-) diff --git a/src/entity/item/esweapon.rs b/src/entity/item/esweapon.rs index 71d1e74..63c1de4 100644 --- a/src/entity/item/esweapon.rs +++ b/src/entity/item/esweapon.rs @@ -1,11 +1,13 @@ // TODO: actually use this -pub enum SrankError { - InvalidSrankType, - InvalidSrankSpecial, - InvalidSrankName, +#[derive(Debug)] +pub enum ESWeaponError { + InvalidESWeaponType, + InvalidESWeaponSpecial, + InvalidESWeaponName, } -pub enum SrankType { +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum ESWeaponType { Saber = 0, Sword, Blade, @@ -38,49 +40,50 @@ pub enum SrankType { Axe, } -impl SrankType { +impl ESWeaponType { pub fn to_value(&self) -> u8 { *self as u8 } - pub fn from_value(value: u8) -> Result { + pub fn from_value(value: u8) -> Result { match value { - 0 => Ok(SrankType::Saber), - 1 => Ok(SrankType::Sword), - 2 => Ok(SrankType::Blade), - 3 => Ok(SrankType::Partisan), - 4 => Ok(SrankType::Slicer), - 5 => Ok(SrankType::Gun), - 6 => Ok(SrankType::Rifle), - 7 => Ok(SrankType::Mechgun), - 8 => Ok(SrankType::Shot), - 9 => Ok(SrankType::Can), - 10 => Ok(SrankType::Rod), - 11 => Ok(SrankType::Wand), - 12 => Ok(SrankType::Twin), - 13 => Ok(SrankType::Claw), - 14 => Ok(SrankType::Bazooka), - 15 => Ok(SrankType::Needle), - 16 => Ok(SrankType::Scythe), - 17 => Ok(SrankType::Hammer), - 18 => Ok(SrankType::Moon), - 19 => Ok(SrankType::Psychogun), - 20 => Ok(SrankType::Punch), - 21 => Ok(SrankType::Windmill), - 22 => Ok(SrankType::Harisen), - 23 => Ok(SrankType::Katana), - 24 => Ok(SrankType::JCutter), - 25 => Ok(SrankType::Swords), - 26 => Ok(SrankType::Launcher), - 27 => Ok(SrankType::Cards), - 28 => Ok(SrankType::Knuckle), - 29 => Ok(SrankType::Axe), - _ => Err(SrankError::InvalidSrankype), + 0 => Ok(ESWeaponType::Saber), + 1 => Ok(ESWeaponType::Sword), + 2 => Ok(ESWeaponType::Blade), + 3 => Ok(ESWeaponType::Partisan), + 4 => Ok(ESWeaponType::Slicer), + 5 => Ok(ESWeaponType::Gun), + 6 => Ok(ESWeaponType::Rifle), + 7 => Ok(ESWeaponType::Mechgun), + 8 => Ok(ESWeaponType::Shot), + 9 => Ok(ESWeaponType::Can), + 10 => Ok(ESWeaponType::Rod), + 11 => Ok(ESWeaponType::Wand), + 12 => Ok(ESWeaponType::Twin), + 13 => Ok(ESWeaponType::Claw), + 14 => Ok(ESWeaponType::Bazooka), + 15 => Ok(ESWeaponType::Needle), + 16 => Ok(ESWeaponType::Scythe), + 17 => Ok(ESWeaponType::Hammer), + 18 => Ok(ESWeaponType::Moon), + 19 => Ok(ESWeaponType::Psychogun), + 20 => Ok(ESWeaponType::Punch), + 21 => Ok(ESWeaponType::Windmill), + 22 => Ok(ESWeaponType::Harisen), + 23 => Ok(ESWeaponType::Katana), + 24 => Ok(ESWeaponType::JCutter), + 25 => Ok(ESWeaponType::Swords), + 26 => Ok(ESWeaponType::Launcher), + 27 => Ok(ESWeaponType::Cards), + 28 => Ok(ESWeaponType::Knuckle), + 29 => Ok(ESWeaponType::Axe), + _ => Err(ESWeaponError::InvalidESWeaponType), } } } -pub enum SrankSpecial { +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum ESWeaponSpecial { Jellen = 0, Zalure, HPRegen, @@ -99,45 +102,46 @@ pub enum SrankSpecial { Kings, } -impl SrankSpecial { +impl ESWeaponSpecial { pub fn to_value(&self) -> u8 { *self as u8 } - pub fn from_value(value: u8) -> Result { + pub fn from_value(value: u8) -> Result { match value{ - 0 => Ok(SrankSpecial::Jellen), - 1 => Ok(SrankSpecial::Zalure), - 2 => Ok(SrankSpecial::HPRegen), - 3 => Ok(SrankSpecial::TPRegen), - 4 => Ok(SrankSpecial::Burning), - 5 => Ok(SrankSpecial::Tempest), - 6 => Ok(SrankSpecial::Blizzard), - 7 => Ok(SrankSpecial::Arrest), - 8 => Ok(SrankSpecial::Chaos), - 9 => Ok(SrankSpecial::Hell), - 10 => Ok(SrankSpecial::Spirit), - 11 => Ok(SrankSpecial::Berserk), - 12 => Ok(SrankSpecial::Demons), - 13 => Ok(SrankSpecial::Gush), - 14 => Ok(SrankSpecial::Geist), - 15 => Ok(SrankSpecial::Kings), - _ => Err(SrankError::InvalidSrankSpecial), + 0 => Ok(ESWeaponSpecial::Jellen), + 1 => Ok(ESWeaponSpecial::Zalure), + 2 => Ok(ESWeaponSpecial::HPRegen), + 3 => Ok(ESWeaponSpecial::TPRegen), + 4 => Ok(ESWeaponSpecial::Burning), + 5 => Ok(ESWeaponSpecial::Tempest), + 6 => Ok(ESWeaponSpecial::Blizzard), + 7 => Ok(ESWeaponSpecial::Arrest), + 8 => Ok(ESWeaponSpecial::Chaos), + 9 => Ok(ESWeaponSpecial::Hell), + 10 => Ok(ESWeaponSpecial::Spirit), + 11 => Ok(ESWeaponSpecial::Berserk), + 12 => Ok(ESWeaponSpecial::Demons), + 13 => Ok(ESWeaponSpecial::Gush), + 14 => Ok(ESWeaponSpecial::Geist), + 15 => Ok(ESWeaponSpecial::Kings), + _ => Err(ESWeaponError::InvalidESWeaponSpecial), } } } -pub struct SRankWeapon { - pub type: SrankType, - pub special: Option, +#[derive(Clone, Debug, PartialEq)] +pub struct ESWeapon { + pub esweapon: ESWeaponType, + pub special: Option, pub name: String, pub grind: u8, } -impl SRankWeapon { - pub fn new(t: SrankType) -> SRankWeapon { - SRankWeapon { - type: t, +impl ESWeapon { + pub fn new(t: ESWeaponType) -> ESWeapon { + ESWeapon { + esweapon: t, special: None, name: "".to_owned(), grind: 0, @@ -195,24 +199,24 @@ impl SRankWeapon { pub fn as_bytes(&self) -> [u8; 16] { let mut result = [0u8; 16]; - result[1] = 0x70 + self.type.to_value(); - result[2] = self.special.to_value(); + result[1] = 0x70 + self.esweapon.to_value(); + result[2] = self.special.map(|s| s.to_value()).unwrap_or(0); result[3] = self.grind; //result[4] = tekked/untekked flag - result[6..12].clone_from_slice(self.name.bytes_from_name()); + result[6..12].clone_from_slice(&self.bytes_from_name()); result } - // TODO: return Result - pub fn from_bytes(bytes: [u8; 16]) -> SRankWeapon { - let type = SrankType.from_value(bytes[1] - 0x70).unwrap(); - let special = SrankSpecial.from_value(bytes[2]).unwrap(); + // TODO: return Result + pub fn from_bytes(bytes: [u8; 16]) -> ESWeapon { + let esweapon = ESWeaponType::from_value(bytes[1] - 0x70).unwrap(); + let special = ESWeaponSpecial::from_value(bytes[2]); let grind = bytes[3]; - let name = SRankWeapon::name_from_bytes(bytes[6..12]); + let name = ESWeapon::name_from_bytes(&bytes[6..12]); - SRankWeapon { - type: type, - special: special, + ESWeapon { + esweapon: esweapon, + special: special.ok(), grind: grind, name: name, } diff --git a/src/entity/item/mod.rs b/src/entity/item/mod.rs index b6add91..92810e3 100644 --- a/src/entity/item/mod.rs +++ b/src/entity/item/mod.rs @@ -6,6 +6,7 @@ pub mod tool; pub mod tech; pub mod unit; pub mod mag; +pub mod esweapon; use crate::entity::character::CharacterEntityId; use crate::ship::map::MapArea; @@ -75,6 +76,7 @@ pub enum ItemType { Tool(tool::ToolType), TechniqueDisk(tech::Technique), Mag(mag::MagType), + ESWeapon(esweapon::ESWeaponType), } #[derive(Clone, Debug, PartialEq)] @@ -91,6 +93,7 @@ pub enum ItemDetail { Tool(tool::Tool), TechniqueDisk(tech::TechniqueDisk), Mag(mag::Mag), + ESWeapon(esweapon::ESWeapon), } impl ItemDetail { @@ -110,6 +113,7 @@ impl ItemDetail { ItemDetail::Tool(t) => ItemType::Tool(t.tool), ItemDetail::TechniqueDisk(d) => ItemType::TechniqueDisk(d.tech), ItemDetail::Mag(m) => ItemType::Mag(m.mag), + ItemDetail::ESWeapon(e) => ItemType::ESWeapon(e.esweapon), } } @@ -141,6 +145,7 @@ impl ItemDetail { ItemDetail::Tool(t) => t.as_individual_bytes(), ItemDetail::TechniqueDisk(d) => d.as_bytes(), ItemDetail::Mag(m) => m.as_bytes(), + ItemDetail::ESWeapon(e) => e.as_bytes(), } } } From 27a87ffe969e9cb21750e7b3af5f79f636d0386e Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 7 Sep 2020 00:39:23 -0300 Subject: [PATCH 4/5] fix esweap type + special numbering. add to other files and tests --- src/entity/item/esweapon.rs | 123 ++++++++++++++++++++++++++++-------- src/entity/item/mod.rs | 3 +- src/ship/items/bank.rs | 1 + src/ship/items/inventory.rs | 1 + 4 files changed, 99 insertions(+), 29 deletions(-) diff --git a/src/entity/item/esweapon.rs b/src/entity/item/esweapon.rs index 63c1de4..76bd003 100644 --- a/src/entity/item/esweapon.rs +++ b/src/entity/item/esweapon.rs @@ -1,7 +1,9 @@ // TODO: actually use this #[derive(Debug)] -pub enum ESWeaponError { +pub enum ItemParseError { + InvalidESWeaponBytes, InvalidESWeaponType, + InvalidESWeaponGrind, InvalidESWeaponSpecial, InvalidESWeaponName, } @@ -33,7 +35,7 @@ pub enum ESWeaponType { Harisen, Katana, JCutter, - Swords, + Swords = 0x35, Launcher, Cards, Knuckle, @@ -45,7 +47,7 @@ impl ESWeaponType { *self as u8 } - pub fn from_value(value: u8) -> Result { + pub fn from_value(value: u8) -> Result { match value { 0 => Ok(ESWeaponType::Saber), 1 => Ok(ESWeaponType::Sword), @@ -72,19 +74,55 @@ impl ESWeaponType { 22 => Ok(ESWeaponType::Harisen), 23 => Ok(ESWeaponType::Katana), 24 => Ok(ESWeaponType::JCutter), - 25 => Ok(ESWeaponType::Swords), - 26 => Ok(ESWeaponType::Launcher), - 27 => Ok(ESWeaponType::Cards), - 28 => Ok(ESWeaponType::Knuckle), - 29 => Ok(ESWeaponType::Axe), - _ => Err(ESWeaponError::InvalidESWeaponType), + 53 => Ok(ESWeaponType::Swords), + 54 => Ok(ESWeaponType::Launcher), + 55 => Ok(ESWeaponType::Cards), + 56 => Ok(ESWeaponType::Knuckle), + 57 => Ok(ESWeaponType::Axe), + _ => Err(ItemParseError::InvalidESWeaponType), + } + } + + pub fn parse_type(data: [u8; 3]) -> Result { + match data { + [0x00, 0x70, 0x00] => Ok(ESWeaponType::Saber), + [0x00, 0x71, 0x00] => Ok(ESWeaponType::Sword), + [0x00, 0x72, 0x00] => Ok(ESWeaponType::Blade), + [0x00, 0x73, 0x00] => Ok(ESWeaponType::Partisan), + [0x00, 0x74, 0x00] => Ok(ESWeaponType::Slicer), + [0x00, 0x75, 0x00] => Ok(ESWeaponType::Gun), + [0x00, 0x76, 0x00] => Ok(ESWeaponType::Rifle), + [0x00, 0x77, 0x00] => Ok(ESWeaponType::Mechgun), + [0x00, 0x78, 0x00] => Ok(ESWeaponType::Shot), + [0x00, 0x79, 0x00] => Ok(ESWeaponType::Can), + [0x00, 0x7A, 0x00] => Ok(ESWeaponType::Rod), + [0x00, 0x7B, 0x00] => Ok(ESWeaponType::Wand), + [0x00, 0x7C, 0x00] => Ok(ESWeaponType::Twin), + [0x00, 0x7D, 0x00] => Ok(ESWeaponType::Claw), + [0x00, 0x7E, 0x00] => Ok(ESWeaponType::Bazooka), + [0x00, 0x7F, 0x00] => Ok(ESWeaponType::Needle), + [0x00, 0x80, 0x00] => Ok(ESWeaponType::Scythe), + [0x00, 0x81, 0x00] => Ok(ESWeaponType::Hammer), + [0x00, 0x82, 0x00] => Ok(ESWeaponType::Moon), + [0x00, 0x83, 0x00] => Ok(ESWeaponType::Psychogun), + [0x00, 0x84, 0x00] => Ok(ESWeaponType::Punch), + [0x00, 0x85, 0x00] => Ok(ESWeaponType::Windmill), + [0x00, 0x86, 0x00] => Ok(ESWeaponType::Harisen), + [0x00, 0x87, 0x00] => Ok(ESWeaponType::Katana), + [0x00, 0x88, 0x00] => Ok(ESWeaponType::JCutter), + [0x00, 0xA5, 0x00] => Ok(ESWeaponType::Swords), + [0x00, 0xA6, 0x00] => Ok(ESWeaponType::Launcher), + [0x00, 0xA7, 0x00] => Ok(ESWeaponType::Cards), + [0x00, 0xA8, 0x00] => Ok(ESWeaponType::Knuckle), + [0x00, 0xA9, 0x00] => Ok(ESWeaponType::Axe), + _ => Err(ItemParseError::InvalidESWeaponBytes), } } } #[derive(Clone, Copy, Debug, PartialEq)] pub enum ESWeaponSpecial { - Jellen = 0, + Jellen = 1, Zalure, HPRegen, TPRegen, @@ -107,25 +145,25 @@ impl ESWeaponSpecial { *self as u8 } - pub fn from_value(value: u8) -> Result { + pub fn from_value(value: u8) -> Result { match value{ - 0 => Ok(ESWeaponSpecial::Jellen), - 1 => Ok(ESWeaponSpecial::Zalure), - 2 => Ok(ESWeaponSpecial::HPRegen), - 3 => Ok(ESWeaponSpecial::TPRegen), - 4 => Ok(ESWeaponSpecial::Burning), - 5 => Ok(ESWeaponSpecial::Tempest), - 6 => Ok(ESWeaponSpecial::Blizzard), - 7 => Ok(ESWeaponSpecial::Arrest), - 8 => Ok(ESWeaponSpecial::Chaos), - 9 => Ok(ESWeaponSpecial::Hell), - 10 => Ok(ESWeaponSpecial::Spirit), - 11 => Ok(ESWeaponSpecial::Berserk), - 12 => Ok(ESWeaponSpecial::Demons), - 13 => Ok(ESWeaponSpecial::Gush), - 14 => Ok(ESWeaponSpecial::Geist), - 15 => Ok(ESWeaponSpecial::Kings), - _ => Err(ESWeaponError::InvalidESWeaponSpecial), + 1 => Ok(ESWeaponSpecial::Jellen), + 2 => Ok(ESWeaponSpecial::Zalure), + 3 => Ok(ESWeaponSpecial::HPRegen), + 4 => Ok(ESWeaponSpecial::TPRegen), + 5 => Ok(ESWeaponSpecial::Burning), + 6 => Ok(ESWeaponSpecial::Tempest), + 7 => Ok(ESWeaponSpecial::Blizzard), + 8 => Ok(ESWeaponSpecial::Arrest), + 9 => Ok(ESWeaponSpecial::Chaos), + 10 => Ok(ESWeaponSpecial::Hell), + 11 => Ok(ESWeaponSpecial::Spirit), + 12 => Ok(ESWeaponSpecial::Berserk), + 13 => Ok(ESWeaponSpecial::Demons), + 14 => Ok(ESWeaponSpecial::Gush), + 15 => Ok(ESWeaponSpecial::Geist), + 16 => Ok(ESWeaponSpecial::Kings), + _ => Err(ItemParseError::InvalidESWeaponSpecial), } } } @@ -223,3 +261,32 @@ impl ESWeapon { } } +#[cfg(test)] +mod test { + use super::*; + #[test] + fn test_create_esweapon_from_bytes() { + // JAKESERV BAZOOKA + 137 (Berserk) + let weapon_bytes = [0x00, 0x7E, 0x0C, 0x89, 0x00, 0x00, 0x81, 0x41, 0xAC, 0xB3, 0x96, 0x56, 0x00, 0x00, 0x00, 0x00]; + + let testweapon = ESWeapon::from_bytes(weapon_bytes); + assert_eq!(testweapon, ESWeapon { + esweapon: ESWeaponType::Bazooka, + special: Some(ESWeaponSpecial::Berserk), + grind: 137u8, + name: "JAKESERV".to_owned(), + }); + } + + #[test] + fn test_create_bytes_from_esweapon() { + let testweapon = ESWeapon { + esweapon: ESWeaponType::Wand, + special: Some(ESWeaponSpecial::Chaos), + grind: 72u8, + name: "PSYCHO".to_owned(), + }; + let bytes = testweapon.as_bytes(); + assert_eq!(bytes, [0x00, 0x7B, 0x09, 0x48, 0x00, 0x00, 0x82, 0x13, 0xE4, 0x68, 0xBC, 0x00, 0x00, 0x00, 0x00, 0x00]); + } +} \ No newline at end of file diff --git a/src/entity/item/mod.rs b/src/entity/item/mod.rs index 92810e3..b65bebb 100644 --- a/src/entity/item/mod.rs +++ b/src/entity/item/mod.rs @@ -123,7 +123,8 @@ impl ItemDetail { .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))) - .or(tool::ToolType::parse_type([data[0],data[1],data[2]]).map(|t| ItemType::Tool(t))).ok()?; + .or(tool::ToolType::parse_type([data[0],data[1],data[2]]).map(|t| ItemType::Tool(t))) + .or(esweapon::ESWeaponType::parse_type([data[0],data[1],data[2]]).map(|e| ItemType::ESWeapon(e))).ok()?; match item_type { ItemType::Weapon(_w) => Some(ItemDropType::Weapon(weapon::Weapon::from_bytes(data).ok()?)), diff --git a/src/ship/items/bank.rs b/src/ship/items/bank.rs index aa98796..2bbe097 100644 --- a/src/ship/items/bank.rs +++ b/src/ship/items/bank.rs @@ -126,6 +126,7 @@ impl BankItem { ItemDetail::Tool(t) => t.as_individual_bytes(), ItemDetail::TechniqueDisk(d) => d.as_bytes(), ItemDetail::Mag(m) => m.as_bytes(), + ItemDetail::ESWeapon(e) => e.as_bytes(), } }, BankItem::Stacked(item) => { diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index b0cd347..94d634e 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -147,6 +147,7 @@ impl InventoryItem { ItemDetail::Tool(t) => t.as_individual_bytes(), ItemDetail::TechniqueDisk(d) => d.as_bytes(), ItemDetail::Mag(m) => m.as_bytes(), + ItemDetail::ESWeapon(e) => e.as_bytes(), } }, InventoryItem::Stacked(item) => { From bc7e513a742c5c82f7f5d2cbc5cedfff6258b9f5 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 7 Sep 2020 00:45:35 -0300 Subject: [PATCH 5/5] one more test --- src/entity/item/esweapon.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/entity/item/esweapon.rs b/src/entity/item/esweapon.rs index 76bd003..1d091ec 100644 --- a/src/entity/item/esweapon.rs +++ b/src/entity/item/esweapon.rs @@ -280,6 +280,7 @@ mod test { #[test] fn test_create_bytes_from_esweapon() { + // PSYCHO WAND + 72 (Chaos) let testweapon = ESWeapon { esweapon: ESWeaponType::Wand, special: Some(ESWeaponSpecial::Chaos), @@ -289,4 +290,19 @@ mod test { let bytes = testweapon.as_bytes(); assert_eq!(bytes, [0x00, 0x7B, 0x09, 0x48, 0x00, 0x00, 0x82, 0x13, 0xE4, 0x68, 0xBC, 0x00, 0x00, 0x00, 0x00, 0x00]); } + + #[test] + fn test_create_bytes_from_higher_esweapon_type() { + // YUGIOH CARDS + 105 (Spirit) + let testweapon = ESWeapon { + esweapon: ESWeaponType::Cards, + special: Some(ESWeaponSpecial::Spirit), + grind: 105u8, + name: "YUGIOH".to_owned(), + }; + let bytes = testweapon.as_bytes(); + assert_eq!(bytes, [0x00, 0xA7, 0x0B, 0x69, 0x00, 0x00, 0x83, 0x35, 0x9D, 0x2F, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00]); + } + + } \ No newline at end of file