lint src/entity/item/*
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
46f1f772f4
commit
95d237af6f
@ -317,9 +317,9 @@ impl Armor {
|
|||||||
|
|
||||||
pub fn from_bytes(data: [u8; 16]) -> Result<Armor, ItemParseError> {
|
pub fn from_bytes(data: [u8; 16]) -> Result<Armor, ItemParseError> {
|
||||||
let a = ArmorType::parse_type([data[0], data[1], data[2]]);
|
let a = ArmorType::parse_type([data[0], data[1], data[2]]);
|
||||||
if a.is_ok() {
|
if let Ok(a) = a {
|
||||||
Ok(Armor {
|
Ok(Armor {
|
||||||
armor: a.unwrap(),
|
armor: a,
|
||||||
dfp: data[6],
|
dfp: data[6],
|
||||||
evp: data[8],
|
evp: data[8],
|
||||||
slots: data[5],
|
slots: data[5],
|
||||||
|
@ -190,10 +190,10 @@ impl ESWeapon {
|
|||||||
pub fn bytes_from_name(&self) -> [u8; 6] {
|
pub fn bytes_from_name(&self) -> [u8; 6] {
|
||||||
let mut result = [0u16; 3];
|
let mut result = [0u16; 3];
|
||||||
let mut letters = [0u8; 8];
|
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() {
|
for letter in letters.iter_mut() {
|
||||||
*letter = *letter & 0x3F;
|
*letter &= 0x3F;
|
||||||
}
|
}
|
||||||
|
|
||||||
result[0] = 0x8000 + (0x20 * letters[0] as u16) + (letters[1] as u16);
|
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
|
// TODO: error handling, ensure name is never more than 8
|
||||||
pub fn name_from_bytes(namebytes: &[u8]) -> String {
|
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] = [
|
let buf: [u16; 3] = [
|
||||||
u16::from_be_bytes([namebytes[0], namebytes[1]]),
|
u16::from_be_bytes([namebytes[0], namebytes[1]]),
|
||||||
u16::from_be_bytes([namebytes[2], namebytes[3]]),
|
u16::from_be_bytes([namebytes[2], namebytes[3]]),
|
||||||
u16::from_be_bytes([namebytes[4], namebytes[5]]),
|
u16::from_be_bytes([namebytes[4], namebytes[5]]),
|
||||||
];
|
];
|
||||||
|
|
||||||
name[0] = ((buf[0] - 0x8000) / 0x20 + 0x40) as u8;
|
let mut name: Vec<u8> = vec![
|
||||||
name[1] = ((buf[0] - 0x8000) % 0x20 + 0x40) as u8;
|
((buf[0] - 0x8000) / 0x20 + 0x40) as u8,
|
||||||
|
((buf[0] - 0x8000) % 0x20 + 0x40) as u8,
|
||||||
name[2] = ((buf[1] - 0x8000) / 0x400 + 0x40) as u8;
|
((buf[1] - 0x8000) / 0x400 + 0x40) as u8,
|
||||||
name[3] = (((buf[1] - 0x8000) % 0x400) / 0x20 + 0x40) as u8;
|
(((buf[1] - 0x8000) % 0x400) / 0x20 + 0x40) as u8,
|
||||||
name[4] = (((buf[1] - 0x8000) % 0x400) % 0x20 + 0x40) as u8;
|
(((buf[1] - 0x8000) % 0x400) % 0x20 + 0x40) as u8,
|
||||||
|
((buf[2] - 0x8000) / 0x400 + 0x40) as u8,
|
||||||
name[5] = ((buf[2] - 0x8000) / 0x400 + 0x40) as u8;
|
(((buf[2] - 0x8000) % 0x400) / 0x20 + 0x40) as u8,
|
||||||
name[6] = (((buf[2] - 0x8000) % 0x400) / 0x20 + 0x40) as u8;
|
(((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);
|
name.retain(|&x| x > 0x40 && x < 0x5B);
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ lazy_static::lazy_static! {
|
|||||||
f.read_to_string(&mut s).unwrap();
|
f.read_to_string(&mut s).unwrap();
|
||||||
|
|
||||||
let mut feed: HashMap<String, Vec<HashMap<String, MagFeedTable>>> = toml::from_str(&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()
|
feed.into_iter()
|
||||||
.map(|table| {
|
.map(|table| {
|
||||||
table.into_iter()
|
table.into_iter()
|
||||||
@ -624,7 +624,7 @@ impl Mag {
|
|||||||
fn photon_blast_count(&self) -> u8 {
|
fn photon_blast_count(&self) -> u8 {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for i in 0..3 {
|
for i in 0..3 {
|
||||||
if let Some(_) = self.photon_blast[i] {
|
if self.photon_blast[i].is_some() {
|
||||||
count |= 1 << i
|
count |= 1 << i
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -633,7 +633,7 @@ impl Mag {
|
|||||||
|
|
||||||
pub fn from_bytes(data: [u8; 16]) -> Result<Mag, ItemParseError> {
|
pub fn from_bytes(data: [u8; 16]) -> Result<Mag, ItemParseError> {
|
||||||
let m = MagType::parse_type([data[0], data[1], data[2]]);
|
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 def = u16::from_le_bytes([data[4], data[5]]);
|
||||||
let mut pow = u16::from_le_bytes([data[6], data[7]]);
|
let mut pow = u16::from_le_bytes([data[6], data[7]]);
|
||||||
let mut dex = u16::from_le_bytes([data[8], data[9]]);
|
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.
|
let iq = data[13] % 201; // TODO: handle invalid values.
|
||||||
|
|
||||||
Ok(Mag{
|
Ok(Mag{
|
||||||
mag: m.unwrap(),
|
mag: m,
|
||||||
def: def,
|
def: def,
|
||||||
pow: pow,
|
pow: pow,
|
||||||
dex: dex,
|
dex: dex,
|
||||||
@ -739,6 +739,7 @@ impl Mag {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
MagType::Vritra => {
|
MagType::Vritra => {
|
||||||
|
#[allow(clippy::if_same_then_else)]
|
||||||
if self.pow > self.dex && self.pow > self.mnd {
|
if self.pow > self.dex && self.pow > self.mnd {
|
||||||
self.mag = MagType::Sumba
|
self.mag = MagType::Sumba
|
||||||
}
|
}
|
||||||
@ -1004,9 +1005,9 @@ impl Mag {
|
|||||||
MAG_STATS.get(&self.mag).map(|stats| {
|
MAG_STATS.get(&self.mag).map(|stats| {
|
||||||
stats.photon_blast.map(|photon_blast| {
|
stats.photon_blast.map(|photon_blast| {
|
||||||
if !self.photon_blast.contains(&Some(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)
|
*pb_slot = Some(photon_blast)
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -1038,10 +1039,10 @@ impl Mag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn bank(&mut self) {
|
pub fn bank(&mut self) {
|
||||||
self.def = self.def & 0xFFFE;
|
self.def &= 0xFFFE;
|
||||||
self.pow = self.pow & 0xFFFE;
|
self.pow &= 0xFFFE;
|
||||||
self.dex = self.dex & 0xFFFE;
|
self.dex &= 0xFFFE;
|
||||||
self.mnd = self.mnd & 0xFFFE;
|
self.mnd &= 0xFFFE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this needs more checks on validity
|
// TODO: this needs more checks on validity
|
||||||
|
@ -121,13 +121,13 @@ impl ItemDetail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_item_from_bytes(data: [u8; 16]) -> Option<ItemDropType> {
|
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))
|
let item_type = weapon::WeaponType::parse_type([data[0],data[1],data[2]]).map(ItemType::Weapon)
|
||||||
.or(armor::ArmorType::parse_type([data[0],data[1],data[2]]).map(|a| ItemType::Armor(a)))
|
.or_else(|_| armor::ArmorType::parse_type([data[0],data[1],data[2]]).map(ItemType::Armor))
|
||||||
.or(shield::ShieldType::parse_type([data[0],data[1],data[2]]).map(|s| ItemType::Shield(s)))
|
.or_else(|_| shield::ShieldType::parse_type([data[0],data[1],data[2]]).map(ItemType::Shield))
|
||||||
.or(unit::UnitType::parse_type([data[0],data[1],data[2]]).map(|u| ItemType::Unit(u)))
|
.or_else(|_| unit::UnitType::parse_type([data[0],data[1],data[2]]).map(ItemType::Unit))
|
||||||
.or(mag::MagType::parse_type([data[0],data[1],data[2]]).map(|m| ItemType::Mag(m)))
|
.or_else(|_| mag::MagType::parse_type([data[0],data[1],data[2]]).map(ItemType::Mag))
|
||||||
.or(tool::ToolType::parse_type([data[0],data[1],data[2]]).map(|t| ItemType::Tool(t)))
|
.or_else(|_| tool::ToolType::parse_type([data[0],data[1],data[2]]).map(ItemType::Tool))
|
||||||
.or(esweapon::ESWeaponType::parse_type([data[0],data[1],data[2]]).map(|e| ItemType::ESWeapon(e))).ok()?;
|
.or_else(|_| esweapon::ESWeaponType::parse_type([data[0],data[1],data[2]]).map(ItemType::ESWeapon)).ok()?;
|
||||||
|
|
||||||
match item_type {
|
match item_type {
|
||||||
ItemType::Weapon(_w) => Some(ItemDropType::Weapon(weapon::Weapon::from_bytes(data).ok()?)),
|
ItemType::Weapon(_w) => Some(ItemDropType::Weapon(weapon::Weapon::from_bytes(data).ok()?)),
|
||||||
|
@ -537,9 +537,9 @@ impl Shield {
|
|||||||
|
|
||||||
pub fn from_bytes(data: [u8; 16]) -> Result<Shield, ItemParseError> {
|
pub fn from_bytes(data: [u8; 16]) -> Result<Shield, ItemParseError> {
|
||||||
let s = ShieldType::parse_type([data[0], data[1], data[2]]);
|
let s = ShieldType::parse_type([data[0], data[1], data[2]]);
|
||||||
if s.is_ok() {
|
if let Ok(s) = s {
|
||||||
Ok(Shield{
|
Ok(Shield{
|
||||||
shield: s.unwrap(),
|
shield: s,
|
||||||
dfp: data[6],
|
dfp: data[6],
|
||||||
evp: data[8],
|
evp: data[8],
|
||||||
})
|
})
|
||||||
|
@ -186,36 +186,33 @@ pub enum ToolType {
|
|||||||
|
|
||||||
impl ToolType {
|
impl ToolType {
|
||||||
pub fn is_stackable(&self) -> bool {
|
pub fn is_stackable(&self) -> bool {
|
||||||
match self {
|
matches!(self, ToolType::Monomate |
|
||||||
ToolType::Monomate => true,
|
ToolType::Dimate |
|
||||||
ToolType::Dimate => true,
|
ToolType::Trimate |
|
||||||
ToolType::Trimate => true,
|
ToolType::Monofluid |
|
||||||
ToolType::Monofluid => true,
|
ToolType::Difluid |
|
||||||
ToolType::Difluid => true,
|
ToolType::Trifluid |
|
||||||
ToolType::Trifluid => true,
|
ToolType::SolAtomizer |
|
||||||
ToolType::SolAtomizer => true,
|
ToolType::MoonAtomizer |
|
||||||
ToolType::MoonAtomizer => true,
|
ToolType::StarAtomizer |
|
||||||
ToolType::StarAtomizer => true,
|
ToolType::Antidote |
|
||||||
ToolType::Antidote => true,
|
ToolType::Antiparalysis |
|
||||||
ToolType::Antiparalysis => true,
|
ToolType::Telepipe |
|
||||||
ToolType::Telepipe => true,
|
ToolType::TrapVision |
|
||||||
ToolType::TrapVision => true,
|
ToolType::Monogrinder |
|
||||||
ToolType::Monogrinder => true,
|
ToolType::Digrinder |
|
||||||
ToolType::Digrinder => true,
|
ToolType::Trigrinder |
|
||||||
ToolType::Trigrinder => true,
|
ToolType::PowerMaterial |
|
||||||
ToolType::PowerMaterial => true,
|
ToolType::MindMaterial |
|
||||||
ToolType::MindMaterial => true,
|
ToolType::EvadeMaterial |
|
||||||
ToolType::EvadeMaterial => true,
|
ToolType::HpMaterial |
|
||||||
ToolType::HpMaterial => true,
|
ToolType::TpMaterial |
|
||||||
ToolType::TpMaterial => true,
|
ToolType::DefMaterial |
|
||||||
ToolType::DefMaterial => true,
|
ToolType::LuckMaterial |
|
||||||
ToolType::LuckMaterial => true,
|
ToolType::Addslot |
|
||||||
ToolType::Addslot => true,
|
ToolType::PhotonDrop |
|
||||||
ToolType::PhotonDrop => true,
|
ToolType::PhotonSphere |
|
||||||
ToolType::PhotonSphere => true,
|
ToolType::PhotonCrystal)
|
||||||
ToolType::PhotonCrystal => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max_stack(&self) -> usize {
|
pub fn max_stack(&self) -> usize {
|
||||||
@ -252,39 +249,36 @@ impl ToolType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_mag_cell(&self) -> bool {
|
pub fn is_mag_cell(&self) -> bool {
|
||||||
match self {
|
matches!(self, ToolType::CellOfMag502 |
|
||||||
ToolType::CellOfMag502 => true,
|
ToolType::CellOfMag213 |
|
||||||
ToolType::CellOfMag213 => true,
|
ToolType::PartsOfRobochao |
|
||||||
ToolType::PartsOfRobochao => true,
|
ToolType::HeartOfOpaOpa |
|
||||||
ToolType::HeartOfOpaOpa => true,
|
ToolType::HeartOfPian |
|
||||||
ToolType::HeartOfPian => true,
|
ToolType::HeartOfChao |
|
||||||
ToolType::HeartOfChao => true,
|
ToolType::HeartOfAngel |
|
||||||
ToolType::HeartOfAngel => true,
|
ToolType::HeartOfDevil |
|
||||||
ToolType::HeartOfDevil => true,
|
ToolType::KitOfHamburger |
|
||||||
ToolType::KitOfHamburger => true,
|
ToolType::PanthersSpirit |
|
||||||
ToolType::PanthersSpirit => true,
|
ToolType::KitOfMark3 |
|
||||||
ToolType::KitOfMark3 => true,
|
ToolType::KitOfMasterSystem |
|
||||||
ToolType::KitOfMasterSystem => true,
|
ToolType::KitOfGenesis |
|
||||||
ToolType::KitOfGenesis => true,
|
ToolType::KitOfSegaSaturn |
|
||||||
ToolType::KitOfSegaSaturn => true,
|
ToolType::KitOfDreamcast |
|
||||||
ToolType::KitOfDreamcast => true,
|
ToolType::Tablet |
|
||||||
ToolType::Tablet => true,
|
ToolType::DragonScale |
|
||||||
ToolType::DragonScale => true,
|
ToolType::HeavenStrikerCoat |
|
||||||
ToolType::HeavenStrikerCoat => true,
|
ToolType::PioneerParts |
|
||||||
ToolType::PioneerParts => true,
|
ToolType::AmitiesMemo |
|
||||||
ToolType::AmitiesMemo => true,
|
ToolType::HeartOfMorolian |
|
||||||
ToolType::HeartOfMorolian => true,
|
ToolType::RappysBeak |
|
||||||
ToolType::RappysBeak => true,
|
ToolType::YahoosEngine |
|
||||||
ToolType::YahoosEngine => true,
|
ToolType::DPhotonCore |
|
||||||
ToolType::DPhotonCore => true,
|
ToolType::LibertaKit |
|
||||||
ToolType::LibertaKit => true,
|
ToolType::CellOfMag0503 |
|
||||||
ToolType::CellOfMag0503 => true,
|
ToolType::CellOfMag0504 |
|
||||||
ToolType::CellOfMag0504 => true,
|
ToolType::CellOfMag0505 |
|
||||||
ToolType::CellOfMag0505 => true,
|
ToolType::CellOfMag0506 |
|
||||||
ToolType::CellOfMag0506 => true,
|
ToolType::CellOfMag0507)
|
||||||
ToolType::CellOfMag0507 => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value(&self) -> [u8; 3] {
|
pub fn value(&self) -> [u8; 3] {
|
||||||
@ -669,9 +663,9 @@ impl Tool {
|
|||||||
|
|
||||||
pub fn from_bytes(data: [u8; 16]) -> Result<Tool, ItemParseError> {
|
pub fn from_bytes(data: [u8; 16]) -> Result<Tool, ItemParseError> {
|
||||||
let t = ToolType::parse_type([data[0], data[1], data[2]]);
|
let t = ToolType::parse_type([data[0], data[1], data[2]]);
|
||||||
if t.is_ok() {
|
if let Ok(t) = t {
|
||||||
Ok(Tool {
|
Ok(Tool {
|
||||||
tool: t.unwrap(),
|
tool: t,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -366,7 +366,7 @@ impl Unit {
|
|||||||
|
|
||||||
pub fn from_bytes(data: [u8; 16]) -> Result<Unit, ItemParseError> {
|
pub fn from_bytes(data: [u8; 16]) -> Result<Unit, ItemParseError> {
|
||||||
let u = UnitType::parse_type([data[0], data[1], data[2]]);
|
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]]) {
|
let m = match u16::from_le_bytes([data[6], data[7]]) {
|
||||||
0x02 => Some(UnitModifier::PlusPlus),
|
0x02 => Some(UnitModifier::PlusPlus),
|
||||||
0x01 => Some(UnitModifier::Plus),
|
0x01 => Some(UnitModifier::Plus),
|
||||||
@ -376,7 +376,7 @@ impl Unit {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(Unit{
|
Ok(Unit{
|
||||||
unit: u.unwrap(),
|
unit: u,
|
||||||
modifier: m,
|
modifier: m,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1476,8 +1476,7 @@ impl Weapon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_modifier(&mut self, modifier: &WeaponModifier) {
|
pub fn apply_modifier(&mut self, modifier: &WeaponModifier) {
|
||||||
match modifier {
|
if let WeaponModifier::Tekked{special, percent, grind} = modifier {
|
||||||
WeaponModifier::Tekked{special, percent, grind} => {
|
|
||||||
match special {
|
match special {
|
||||||
TekSpecialModifier::Plus => {
|
TekSpecialModifier::Plus => {
|
||||||
self.special = self.special.map(|special| {
|
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.grind = std::cmp::max(self.grind as i32 + grind, 0) as u8;
|
||||||
self.tekked = true;
|
self.tekked = true;
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1526,7 +1523,7 @@ impl Weapon {
|
|||||||
result[3] = self.grind;
|
result[3] = self.grind;
|
||||||
result[4] = self.special.map(|s| s.value()).unwrap_or(0);
|
result[4] = self.special.map(|s| s.value()).unwrap_or(0);
|
||||||
|
|
||||||
if self.tekked == false {
|
if !self.tekked {
|
||||||
result[4] += 0x80
|
result[4] += 0x80
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1540,7 +1537,7 @@ impl Weapon {
|
|||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
pub fn from_bytes(data: [u8; 16]) -> Result<Weapon, ItemParseError> {
|
pub fn from_bytes(data: [u8; 16]) -> Result<Weapon, ItemParseError> {
|
||||||
let w = WeaponType::parse_type([data[0], data[1], data[2]]);
|
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 s = None;
|
||||||
let mut t = true;
|
let mut t = true;
|
||||||
let g = data[3];
|
let g = data[3];
|
||||||
@ -1576,7 +1573,7 @@ impl Weapon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(Weapon {
|
Ok(Weapon {
|
||||||
weapon: w.unwrap(),
|
weapon: w,
|
||||||
special: s,
|
special: s,
|
||||||
grind: g,
|
grind: g,
|
||||||
attrs:[
|
attrs:[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user