Browse Source

fix esweap type + special numbering. add to other files and tests

pbs
andy 4 years ago
parent
commit
27a87ffe96
  1. 123
      src/entity/item/esweapon.rs
  2. 3
      src/entity/item/mod.rs
  3. 1
      src/ship/items/bank.rs
  4. 1
      src/ship/items/inventory.rs

123
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<ESWeaponType, ESWeaponError> {
pub fn from_value(value: u8) -> Result<ESWeaponType, ItemParseError> {
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<ESWeaponType, ItemParseError> {
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<ESWeaponSpecial, ESWeaponError> {
pub fn from_value(value: u8) -> Result<ESWeaponSpecial, ItemParseError> {
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]);
}
}

3
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()?)),

1
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) => {

1
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) => {

Loading…
Cancel
Save