Browse Source

remove armor midstruct

pbs
jake 5 years ago
parent
commit
e72caebbf8
  1. 1
      src/entity/item/armor.rs
  2. 11
      src/entity/item/mod.rs
  3. 7
      src/login/character.rs
  4. 34
      src/ship/drops/generic_armor.rs
  5. 7
      src/ship/items.rs

1
src/entity/item/armor.rs

@ -194,6 +194,7 @@ pub struct Armor {
pub dfp: u8, pub dfp: u8,
pub evp: u8, pub evp: u8,
pub slots: u8, pub slots: u8,
pub equipped: bool,
} }
impl Armor { impl Armor {

11
src/entity/item/mod.rs

@ -35,13 +35,6 @@ pub enum ItemLocation {
*/ */
} }
#[derive(Clone, Debug, PartialEq)]
pub struct Armor {
pub equipped: bool,
pub armor: armor::Armor,
}
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct Shield { pub struct Shield {
pub equipped: bool, pub equipped: bool,
@ -70,7 +63,7 @@ impl Tool {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum ItemDetail { pub enum ItemDetail {
Weapon(weapon::Weapon), Weapon(weapon::Weapon),
Armor(Armor),
Armor(armor::Armor),
Shield(Shield), Shield(Shield),
Unit(Unit), Unit(Unit),
Tool(Tool), Tool(Tool),
@ -87,7 +80,7 @@ impl ItemDetail {
pub fn as_bytes(&self) -> [u8; 16] { pub fn as_bytes(&self) -> [u8; 16] {
match self { match self {
ItemDetail::Weapon(weapon) => weapon.as_bytes(), ItemDetail::Weapon(weapon) => weapon.as_bytes(),
ItemDetail::Armor(armor) => armor.armor.as_bytes(),
ItemDetail::Armor(armor) => armor.as_bytes(),
ItemDetail::Shield(shield) => shield.shield.as_bytes(), ItemDetail::Shield(shield) => shield.shield.as_bytes(),
ItemDetail::Unit(unit) => unit.unit.as_bytes(), ItemDetail::Unit(unit) => unit.unit.as_bytes(),
ItemDetail::Tool(tool) => tool.as_bytes(), ItemDetail::Tool(tool) => tool.as_bytes(),

7
src/login/character.rs

@ -17,8 +17,9 @@ use libpso::{utf8_to_array, utf8_to_utf16_array};
use crate::entity::gateway::EntityGateway; use crate::entity::gateway::EntityGateway;
use crate::entity::account::{UserAccount, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM}; use crate::entity::account::{UserAccount, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM};
use crate::entity::item::{ItemDetail, ItemLocation, Armor, Tool};
use crate::entity::item::{ItemDetail, ItemLocation, Tool};
use crate::entity::item::weapon::Weapon; use crate::entity::item::weapon::Weapon;
use crate::entity::item::armor::Armor;
use crate::entity::character::{Character, CharacterClass, Technique, TechLevel}; use crate::entity::character::{Character, CharacterClass, Technique, TechLevel};
use crate::login::login::get_login_status; use crate::login::login::get_login_status;
@ -219,13 +220,11 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccount,
entity_gateway.new_item( entity_gateway.new_item(
ItemDetail::Armor ( ItemDetail::Armor (
Armor { Armor {
equipped: true,
armor: item::armor::Armor {
armor: item::armor::ArmorType::Frame, armor: item::armor::ArmorType::Frame,
dfp: 0, dfp: 0,
evp: 0, evp: 0,
slots: 0, slots: 0,
}
equipped: true,
}), }),
ItemLocation::Inventory { ItemLocation::Inventory {
character_id: char.id, character_id: char.id,

34
src/ship/drops/generic_armor.rs

@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize};
use rand::{Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use rand::distributions::{WeightedIndex, Distribution}; use rand::distributions::{WeightedIndex, Distribution};
use crate::entity::item::{ItemDetail, Armor as ArmorDetail};
use crate::entity::item::ItemDetail;
use crate::entity::item::armor::{ArmorType, Armor}; use crate::entity::item::armor::{ArmorType, Armor};
use crate::ship::room::{Difficulty, Episode}; use crate::ship::room::{Difficulty, Episode};
use crate::ship::map::MapVariantType; use crate::ship::map::MapVariantType;
@ -105,14 +105,12 @@ impl GenericArmorTable {
let evp_modifier = self.dfp_modifier(&armor_type, rng); let evp_modifier = self.dfp_modifier(&armor_type, rng);
Some(ItemDetail::Armor(ArmorDetail {
equipped: false,
armor: Armor {
Some(ItemDetail::Armor(Armor {
armor: armor_type, armor: armor_type,
dfp: dfp_modifier as u8, dfp: dfp_modifier as u8,
evp: evp_modifier as u8, evp: evp_modifier as u8,
slots: slots as u8
}
slots: slots as u8,
equipped: false,
})) }))
} }
} }
@ -126,41 +124,33 @@ mod test {
let mut rng = rand_chacha::ChaCha20Rng::from_seed([23;32]); let mut rng = rand_chacha::ChaCha20Rng::from_seed([23;32]);
let gat = GenericArmorTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly); let gat = GenericArmorTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly);
assert!(gat.get_drop(&MapVariantType::Mines1, &mut rng) == Some(ItemDetail::Armor(ArmorDetail {
equipped: false,
armor: Armor {
assert!(gat.get_drop(&MapVariantType::Mines1, &mut rng) == Some(ItemDetail::Armor(Armor {
armor: ArmorType::GeneralArmor, armor: ArmorType::GeneralArmor,
dfp: 0, dfp: 0,
evp: 0, evp: 0,
slots: 1, slots: 1,
}
})));
assert!(gat.get_drop(&MapVariantType::Caves3, &mut rng) == Some(ItemDetail::Armor(ArmorDetail {
equipped: false, equipped: false,
armor: Armor {
})));
assert!(gat.get_drop(&MapVariantType::Caves3, &mut rng) == Some(ItemDetail::Armor(Armor {
armor: ArmorType::AbsorbArmor, armor: ArmorType::AbsorbArmor,
dfp: 1, dfp: 1,
evp: 1, evp: 1,
slots: 1, slots: 1,
}
})));
assert!(gat.get_drop(&MapVariantType::Forest2, &mut rng) == Some(ItemDetail::Armor(ArmorDetail {
equipped: false, equipped: false,
armor: Armor {
})));
assert!(gat.get_drop(&MapVariantType::Forest2, &mut rng) == Some(ItemDetail::Armor(Armor {
armor: ArmorType::HyperFrame, armor: ArmorType::HyperFrame,
dfp: 0, dfp: 0,
evp: 0, evp: 0,
slots: 0, slots: 0,
}
})));
assert!(gat.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDetail::Armor(ArmorDetail {
equipped: false, equipped: false,
armor: Armor {
})));
assert!(gat.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDetail::Armor(Armor {
armor: ArmorType::ImperialArmor, armor: ArmorType::ImperialArmor,
dfp: 2, dfp: 2,
evp: 1, evp: 1,
slots: 0, slots: 0,
}
equipped: false,
}))); })));
} }
} }

7
src/ship/items.rs

@ -3,15 +3,16 @@ use std::hash::{Hash, Hasher};
use libpso::character::character::InventoryItem; use libpso::character::character::InventoryItem;
use crate::entity::item::{Item, ItemDetail, ItemLocation, Armor, Shield};
use crate::entity::item::{Item, ItemDetail, ItemLocation, Shield};
use crate::entity::item::weapon::Weapon; use crate::entity::item::weapon::Weapon;
use crate::entity::item::armor::Armor;
use crate::entity::item::tool::StackedTool; use crate::entity::item::tool::StackedTool;
fn are_items_same_type(itema: &Item, itemb: &Item) -> bool { fn are_items_same_type(itema: &Item, itemb: &Item) -> bool {
match (&itema.item, &itemb.item) { match (&itema.item, &itemb.item) {
(ItemDetail::Weapon(a), ItemDetail::Weapon(b)) => a.weapon == b.weapon, (ItemDetail::Weapon(a), ItemDetail::Weapon(b)) => a.weapon == b.weapon,
(ItemDetail::Armor(a), ItemDetail::Armor(b)) => a.armor.armor == b.armor.armor,
(ItemDetail::Armor(a), ItemDetail::Armor(b)) => a.armor == b.armor,
(ItemDetail::Shield(a), ItemDetail::Shield(b)) => a.shield.shield == b.shield.shield, (ItemDetail::Shield(a), ItemDetail::Shield(b)) => a.shield.shield == b.shield.shield,
(ItemDetail::Tool(a), ItemDetail::Tool(b)) => a.tool == b.tool, (ItemDetail::Tool(a), ItemDetail::Tool(b)) => a.tool == b.tool,
_ => false _ => false
@ -107,7 +108,7 @@ impl Hash for StackedItemKey {
fn hash<H: Hasher>(&self, hasher: &mut H) { fn hash<H: Hasher>(&self, hasher: &mut H) {
match &self.0.item { match &self.0.item {
ItemDetail::Weapon(w) => w.weapon.value().hash(hasher), ItemDetail::Weapon(w) => w.weapon.value().hash(hasher),
ItemDetail::Armor(a) => a.armor.armor.value().hash(hasher),
ItemDetail::Armor(a) => a.armor.value().hash(hasher),
ItemDetail::Shield(s) => s.shield.shield.value().hash(hasher), ItemDetail::Shield(s) => s.shield.shield.value().hash(hasher),
ItemDetail::Unit(u) => u.unit.unit.value().hash(hasher), ItemDetail::Unit(u) => u.unit.unit.value().hash(hasher),
ItemDetail::Tool(t) => t.tool.value().hash(hasher), ItemDetail::Tool(t) => t.tool.value().hash(hasher),

Loading…
Cancel
Save