Browse Source

lint src/entity/item/*

pull/42/head
jake 4 years ago
parent
commit
95d237af6f
  1. 4
      src/entity/item/armor.rs
  2. 31
      src/entity/item/esweapon.rs
  3. 21
      src/entity/item/mag.rs
  4. 14
      src/entity/item/mod.rs
  5. 4
      src/entity/item/shield.rs
  6. 124
      src/entity/item/tool.rs
  7. 4
      src/entity/item/unit.rs
  8. 11
      src/entity/item/weapon.rs

4
src/entity/item/armor.rs

@ -317,9 +317,9 @@ impl Armor {
pub fn from_bytes(data: [u8; 16]) -> Result<Armor, ItemParseError> {
let a = ArmorType::parse_type([data[0], data[1], data[2]]);
if a.is_ok() {
if let Ok(a) = a {
Ok(Armor {
armor: a.unwrap(),
armor: a,
dfp: data[6],
evp: data[8],
slots: data[5],

31
src/entity/item/esweapon.rs

@ -190,10 +190,10 @@ impl ESWeapon {
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());
letters[0..self.name.len()].clone_from_slice(&self.name.to_uppercase().into_bytes());
for letter in letters.iter_mut() {
*letter = *letter & 0x3F;
*letter &= 0x3F;
}
result[0] = 0x8000 + (0x20 * letters[0] as u16) + (letters[1] as u16);
@ -207,29 +207,22 @@ impl ESWeapon {
// TODO: error handling, ensure name is never more than 8
pub fn name_from_bytes(namebytes: &[u8]) -> String {
let mut name: Vec<u8> = 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;
let mut name: Vec<u8> = vec![
((buf[0] - 0x8000) / 0x20 + 0x40) as u8,
((buf[0] - 0x8000) % 0x20 + 0x40) as u8,
((buf[1] - 0x8000) / 0x400 + 0x40) as u8,
(((buf[1] - 0x8000) % 0x400) / 0x20 + 0x40) as u8,
(((buf[1] - 0x8000) % 0x400) % 0x20 + 0x40) as u8,
((buf[2] - 0x8000) / 0x400 + 0x40) as u8,
(((buf[2] - 0x8000) % 0x400) / 0x20 + 0x40) as u8,
(((buf[2] - 0x8000) % 0x400) % 0x20 + 0x40) as u8,
];
name.retain(|&x| x > 0x40 && x < 0x5B);

21
src/entity/item/mag.rs

@ -43,7 +43,7 @@ lazy_static::lazy_static! {
f.read_to_string(&mut s).unwrap();
let mut feed: HashMap<String, Vec<HashMap<String, MagFeedTable>>> = toml::from_str(&s).unwrap();
let feed = feed.remove("feedtable".into()).unwrap();
let feed = feed.remove("feedtable").unwrap();
feed.into_iter()
.map(|table| {
table.into_iter()
@ -624,7 +624,7 @@ impl Mag {
fn photon_blast_count(&self) -> u8 {
let mut count = 0;
for i in 0..3 {
if let Some(_) = self.photon_blast[i] {
if self.photon_blast[i].is_some() {
count |= 1 << i
};
}
@ -633,7 +633,7 @@ impl Mag {
pub fn from_bytes(data: [u8; 16]) -> Result<Mag, ItemParseError> {
let m = MagType::parse_type([data[0], data[1], data[2]]);
if m.is_ok() {
if let Ok(m) = m {
let mut def = u16::from_le_bytes([data[4], data[5]]);
let mut pow = u16::from_le_bytes([data[6], data[7]]);
let mut dex = u16::from_le_bytes([data[8], data[9]]);
@ -650,7 +650,7 @@ impl Mag {
let iq = data[13] % 201; // TODO: handle invalid values.
Ok(Mag{
mag: m.unwrap(),
mag: m,
def: def,
pow: pow,
dex: dex,
@ -739,6 +739,7 @@ impl Mag {
}
},
MagType::Vritra => {
#[allow(clippy::if_same_then_else)]
if self.pow > self.dex && self.pow > self.mnd {
self.mag = MagType::Sumba
}
@ -1004,9 +1005,9 @@ impl Mag {
MAG_STATS.get(&self.mag).map(|stats| {
stats.photon_blast.map(|photon_blast| {
if !self.photon_blast.contains(&Some(photon_blast)) {
self.photon_blast.iter_mut().find(|k| k.is_none()).map(|pb_slot| {
if let Some(pb_slot) = self.photon_blast.iter_mut().find(|k| k.is_none()) {
*pb_slot = Some(photon_blast)
});
}
}
})
});
@ -1038,10 +1039,10 @@ impl Mag {
}
pub fn bank(&mut self) {
self.def = self.def & 0xFFFE;
self.pow = self.pow & 0xFFFE;
self.dex = self.dex & 0xFFFE;
self.mnd = self.mnd & 0xFFFE;
self.def &= 0xFFFE;
self.pow &= 0xFFFE;
self.dex &= 0xFFFE;
self.mnd &= 0xFFFE;
}
// TODO: this needs more checks on validity

14
src/entity/item/mod.rs

@ -121,13 +121,13 @@ impl ItemDetail {
}
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)))
.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()?;
let item_type = weapon::WeaponType::parse_type([data[0],data[1],data[2]]).map(ItemType::Weapon)
.or_else(|_| armor::ArmorType::parse_type([data[0],data[1],data[2]]).map(ItemType::Armor))
.or_else(|_| shield::ShieldType::parse_type([data[0],data[1],data[2]]).map(ItemType::Shield))
.or_else(|_| unit::UnitType::parse_type([data[0],data[1],data[2]]).map(ItemType::Unit))
.or_else(|_| mag::MagType::parse_type([data[0],data[1],data[2]]).map(ItemType::Mag))
.or_else(|_| tool::ToolType::parse_type([data[0],data[1],data[2]]).map(ItemType::Tool))
.or_else(|_| esweapon::ESWeaponType::parse_type([data[0],data[1],data[2]]).map(ItemType::ESWeapon)).ok()?;
match item_type {
ItemType::Weapon(_w) => Some(ItemDropType::Weapon(weapon::Weapon::from_bytes(data).ok()?)),

4
src/entity/item/shield.rs

@ -537,9 +537,9 @@ impl Shield {
pub fn from_bytes(data: [u8; 16]) -> Result<Shield, ItemParseError> {
let s = ShieldType::parse_type([data[0], data[1], data[2]]);
if s.is_ok() {
if let Ok(s) = s {
Ok(Shield{
shield: s.unwrap(),
shield: s,
dfp: data[6],
evp: data[8],
})

124
src/entity/item/tool.rs

@ -186,36 +186,33 @@ pub enum ToolType {
impl ToolType {
pub fn is_stackable(&self) -> bool {
match self {
ToolType::Monomate => true,
ToolType::Dimate => true,
ToolType::Trimate => true,
ToolType::Monofluid => true,
ToolType::Difluid => true,
ToolType::Trifluid => true,
ToolType::SolAtomizer => true,
ToolType::MoonAtomizer => true,
ToolType::StarAtomizer => true,
ToolType::Antidote => true,
ToolType::Antiparalysis => true,
ToolType::Telepipe => true,
ToolType::TrapVision => true,
ToolType::Monogrinder => true,
ToolType::Digrinder => true,
ToolType::Trigrinder => true,
ToolType::PowerMaterial => true,
ToolType::MindMaterial => true,
ToolType::EvadeMaterial => true,
ToolType::HpMaterial => true,
ToolType::TpMaterial => true,
ToolType::DefMaterial => true,
ToolType::LuckMaterial => true,
ToolType::Addslot => true,
ToolType::PhotonDrop => true,
ToolType::PhotonSphere => true,
ToolType::PhotonCrystal => true,
_ => false,
}
matches!(self, ToolType::Monomate |
ToolType::Dimate |
ToolType::Trimate |
ToolType::Monofluid |
ToolType::Difluid |
ToolType::Trifluid |
ToolType::SolAtomizer |
ToolType::MoonAtomizer |
ToolType::StarAtomizer |
ToolType::Antidote |
ToolType::Antiparalysis |
ToolType::Telepipe |
ToolType::TrapVision |
ToolType::Monogrinder |
ToolType::Digrinder |
ToolType::Trigrinder |
ToolType::PowerMaterial |
ToolType::MindMaterial |
ToolType::EvadeMaterial |
ToolType::HpMaterial |
ToolType::TpMaterial |
ToolType::DefMaterial |
ToolType::LuckMaterial |
ToolType::Addslot |
ToolType::PhotonDrop |
ToolType::PhotonSphere |
ToolType::PhotonCrystal)
}
pub fn max_stack(&self) -> usize {
@ -252,39 +249,36 @@ impl ToolType {
}
pub fn is_mag_cell(&self) -> bool {
match self {
ToolType::CellOfMag502 => true,
ToolType::CellOfMag213 => true,
ToolType::PartsOfRobochao => true,
ToolType::HeartOfOpaOpa => true,
ToolType::HeartOfPian => true,
ToolType::HeartOfChao => true,
ToolType::HeartOfAngel => true,
ToolType::HeartOfDevil => true,
ToolType::KitOfHamburger => true,
ToolType::PanthersSpirit => true,
ToolType::KitOfMark3 => true,
ToolType::KitOfMasterSystem => true,
ToolType::KitOfGenesis => true,
ToolType::KitOfSegaSaturn => true,
ToolType::KitOfDreamcast => true,
ToolType::Tablet => true,
ToolType::DragonScale => true,
ToolType::HeavenStrikerCoat => true,
ToolType::PioneerParts => true,
ToolType::AmitiesMemo => true,
ToolType::HeartOfMorolian => true,
ToolType::RappysBeak => true,
ToolType::YahoosEngine => true,
ToolType::DPhotonCore => true,
ToolType::LibertaKit => true,
ToolType::CellOfMag0503 => true,
ToolType::CellOfMag0504 => true,
ToolType::CellOfMag0505 => true,
ToolType::CellOfMag0506 => true,
ToolType::CellOfMag0507 => true,
_ => false,
}
matches!(self, ToolType::CellOfMag502 |
ToolType::CellOfMag213 |
ToolType::PartsOfRobochao |
ToolType::HeartOfOpaOpa |
ToolType::HeartOfPian |
ToolType::HeartOfChao |
ToolType::HeartOfAngel |
ToolType::HeartOfDevil |
ToolType::KitOfHamburger |
ToolType::PanthersSpirit |
ToolType::KitOfMark3 |
ToolType::KitOfMasterSystem |
ToolType::KitOfGenesis |
ToolType::KitOfSegaSaturn |
ToolType::KitOfDreamcast |
ToolType::Tablet |
ToolType::DragonScale |
ToolType::HeavenStrikerCoat |
ToolType::PioneerParts |
ToolType::AmitiesMemo |
ToolType::HeartOfMorolian |
ToolType::RappysBeak |
ToolType::YahoosEngine |
ToolType::DPhotonCore |
ToolType::LibertaKit |
ToolType::CellOfMag0503 |
ToolType::CellOfMag0504 |
ToolType::CellOfMag0505 |
ToolType::CellOfMag0506 |
ToolType::CellOfMag0507)
}
pub fn value(&self) -> [u8; 3] {
@ -669,9 +663,9 @@ impl Tool {
pub fn from_bytes(data: [u8; 16]) -> Result<Tool, ItemParseError> {
let t = ToolType::parse_type([data[0], data[1], data[2]]);
if t.is_ok() {
if let Ok(t) = t {
Ok(Tool {
tool: t.unwrap(),
tool: t,
})
}
else {

4
src/entity/item/unit.rs

@ -366,7 +366,7 @@ impl Unit {
pub fn from_bytes(data: [u8; 16]) -> Result<Unit, ItemParseError> {
let u = UnitType::parse_type([data[0], data[1], data[2]]);
if u.is_ok() {
if let Ok(u) = u {
let m = match u16::from_le_bytes([data[6], data[7]]) {
0x02 => Some(UnitModifier::PlusPlus),
0x01 => Some(UnitModifier::Plus),
@ -376,7 +376,7 @@ impl Unit {
};
Ok(Unit{
unit: u.unwrap(),
unit: u,
modifier: m,
})
}

11
src/entity/item/weapon.rs

@ -1476,8 +1476,7 @@ impl Weapon {
}
pub fn apply_modifier(&mut self, modifier: &WeaponModifier) {
match modifier {
WeaponModifier::Tekked{special, percent, grind} => {
if let WeaponModifier::Tekked{special, percent, grind} = modifier {
match special {
TekSpecialModifier::Plus => {
self.special = self.special.map(|special| {
@ -1515,8 +1514,6 @@ impl Weapon {
}
self.grind = std::cmp::max(self.grind as i32 + grind, 0) as u8;
self.tekked = true;
},
_ => {}
}
}
@ -1526,7 +1523,7 @@ impl Weapon {
result[3] = self.grind;
result[4] = self.special.map(|s| s.value()).unwrap_or(0);
if self.tekked == false {
if !self.tekked {
result[4] += 0x80
};
@ -1540,7 +1537,7 @@ impl Weapon {
// TODO: error handling
pub fn from_bytes(data: [u8; 16]) -> Result<Weapon, ItemParseError> {
let w = WeaponType::parse_type([data[0], data[1], data[2]]);
if w.is_ok() {
if let Ok(w) = w {
let mut s = None;
let mut t = true;
let g = data[3];
@ -1576,7 +1573,7 @@ impl Weapon {
}
Ok(Weapon {
weapon: w.unwrap(),
weapon: w,
special: s,
grind: g,
attrs:[

Loading…
Cancel
Save