Browse Source

remove shield+unit midstruct

pbs
jake 5 years ago
parent
commit
2981b163c2
  1. 20
      src/entity/item/mod.rs
  2. 1
      src/entity/item/shield.rs
  3. 1
      src/entity/item/unit.rs
  4. 32
      src/ship/drops/generic_shield.rs
  5. 14
      src/ship/drops/generic_unit.rs
  6. 13
      src/ship/items.rs

20
src/entity/item/mod.rs

@ -35,18 +35,6 @@ pub enum ItemLocation {
*/ */
} }
#[derive(Clone, Debug, PartialEq)]
pub struct Shield {
pub equipped: bool,
pub shield: shield::Shield,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Unit {
pub equipped: bool,
pub unit: unit::Unit,
}
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct Tool { pub struct Tool {
pub tool: tool::ToolType, pub tool: tool::ToolType,
@ -64,8 +52,8 @@ impl Tool {
pub enum ItemDetail { pub enum ItemDetail {
Weapon(weapon::Weapon), Weapon(weapon::Weapon),
Armor(armor::Armor), Armor(armor::Armor),
Shield(Shield),
Unit(Unit),
Shield(shield::Shield),
Unit(unit::Unit),
Tool(Tool), Tool(Tool),
} }
@ -81,8 +69,8 @@ impl ItemDetail {
match self { match self {
ItemDetail::Weapon(weapon) => weapon.as_bytes(), ItemDetail::Weapon(weapon) => weapon.as_bytes(),
ItemDetail::Armor(armor) => armor.as_bytes(), ItemDetail::Armor(armor) => armor.as_bytes(),
ItemDetail::Shield(shield) => shield.shield.as_bytes(),
ItemDetail::Unit(unit) => unit.unit.as_bytes(),
ItemDetail::Shield(shield) => shield.as_bytes(),
ItemDetail::Unit(unit) => unit.as_bytes(),
ItemDetail::Tool(tool) => tool.as_bytes(), ItemDetail::Tool(tool) => tool.as_bytes(),
} }
} }

1
src/entity/item/shield.rs

@ -347,6 +347,7 @@ pub struct Shield {
pub shield: ShieldType, pub shield: ShieldType,
pub dfp: u8, pub dfp: u8,
pub evp: u8, pub evp: u8,
pub equipped: bool,
} }
impl Shield { impl Shield {

1
src/entity/item/unit.rs

@ -224,6 +224,7 @@ pub enum UnitModifier {
pub struct Unit { pub struct Unit {
pub unit: UnitType, pub unit: UnitType,
pub modifier: Option<UnitModifier>, pub modifier: Option<UnitModifier>,
pub equipped: bool,
} }

32
src/ship/drops/generic_shield.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, Shield as ShieldDetail};
use crate::entity::item::ItemDetail;
use crate::entity::item::shield::{ShieldType, Shield}; use crate::entity::item::shield::{ShieldType, Shield};
use crate::ship::room::{Difficulty, Episode}; use crate::ship::room::{Difficulty, Episode};
use crate::ship::map::MapVariantType; use crate::ship::map::MapVariantType;
@ -85,13 +85,11 @@ impl GenericShieldTable {
let evp_modifier = self.dfp_modifier(&shield_type, rng); let evp_modifier = self.dfp_modifier(&shield_type, rng);
Some(ItemDetail::Shield(ShieldDetail {
equipped: false,
shield: Shield {
Some(ItemDetail::Shield(Shield {
shield: shield_type, shield: shield_type,
dfp: dfp_modifier as u8, dfp: dfp_modifier as u8,
evp: evp_modifier as u8, evp: evp_modifier as u8,
}
equipped: false,
})) }))
} }
} }
@ -106,37 +104,29 @@ mod test {
let gst = GenericShieldTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly); let gst = GenericShieldTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly);
assert!(gst.get_drop(&MapVariantType::Forest1, &mut rng) == Some(ItemDetail::Shield(ShieldDetail {
equipped: false,
shield: Shield {
assert!(gst.get_drop(&MapVariantType::Forest1, &mut rng) == Some(ItemDetail::Shield(Shield {
shield: ShieldType::FreezeBarrier, shield: ShieldType::FreezeBarrier,
dfp: 4, dfp: 4,
evp: 1, evp: 1,
}
})));
assert!(gst.get_drop(&MapVariantType::Caves3, &mut rng) == Some(ItemDetail::Shield(ShieldDetail {
equipped: false, equipped: false,
shield: Shield {
})));
assert!(gst.get_drop(&MapVariantType::Caves3, &mut rng) == Some(ItemDetail::Shield(Shield {
shield: ShieldType::PsychicBarrier, shield: ShieldType::PsychicBarrier,
dfp: 3, dfp: 3,
evp: 2, evp: 2,
}
})));
assert!(gst.get_drop(&MapVariantType::Mines2, &mut rng) == Some(ItemDetail::Shield(ShieldDetail {
equipped: false, equipped: false,
shield: Shield {
})));
assert!(gst.get_drop(&MapVariantType::Mines2, &mut rng) == Some(ItemDetail::Shield(Shield {
shield: ShieldType::ImperialBarrier, shield: ShieldType::ImperialBarrier,
dfp: 0, dfp: 0,
evp: 4, evp: 4,
}
})));
assert!(gst.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDetail::Shield(ShieldDetail {
equipped: false, equipped: false,
shield: Shield {
})));
assert!(gst.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDetail::Shield(Shield {
shield: ShieldType::DivinityBarrier, shield: ShieldType::DivinityBarrier,
dfp: 1, dfp: 1,
evp: 0, evp: 0,
}
equipped: false,
}))); })));
} }
} }

14
src/ship/drops/generic_unit.rs

@ -4,7 +4,7 @@ use rand::{Rng, SeedableRng};
use rand::distributions::{WeightedIndex, Distribution}; use rand::distributions::{WeightedIndex, Distribution};
use rand::seq::IteratorRandom; use rand::seq::IteratorRandom;
use crate::entity::item::{ItemDetail, Unit as UnitDetail};
use crate::entity::item::ItemDetail;
use crate::entity::item::unit::{UnitType, Unit, UnitModifier}; use crate::entity::item::unit::{UnitType, Unit, UnitModifier};
use crate::ship::room::{Difficulty, Episode}; use crate::ship::room::{Difficulty, Episode};
use crate::ship::map::MapVariantType; use crate::ship::map::MapVariantType;
@ -88,12 +88,10 @@ impl GenericUnitTable {
let unit_type_modifier = self.unit_type_and_modifier(area_map, rng); let unit_type_modifier = self.unit_type_and_modifier(area_map, rng);
unit_type_modifier.map(|(unit_type, unit_modifier)| { unit_type_modifier.map(|(unit_type, unit_modifier)| {
ItemDetail::Unit(UnitDetail {
equipped: false,
unit: Unit {
ItemDetail::Unit(Unit {
unit: unit_type, unit: unit_type,
modifier: unit_modifier, modifier: unit_modifier,
}
equipped: false,
}) })
}) })
} }
@ -117,12 +115,10 @@ mod test {
(MapVariantType::Mines2, UnitType::ResistEvil, Some(UnitModifier::PlusPlus)), (MapVariantType::Mines2, UnitType::ResistEvil, Some(UnitModifier::PlusPlus)),
(MapVariantType::DarkFalz, UnitType::DragonHP, Some(UnitModifier::Minus))]; (MapVariantType::DarkFalz, UnitType::DragonHP, Some(UnitModifier::Minus))];
for (area, unit, umod) in unit_tests { for (area, unit, umod) in unit_tests {
assert!(gut.get_drop(&area, &mut rng) == Some(ItemDetail::Unit(UnitDetail {
equipped: false,
unit: Unit {
assert!(gut.get_drop(&area, &mut rng) == Some(ItemDetail::Unit(Unit {
unit: unit, unit: unit,
modifier: umod, modifier: umod,
}
equipped: false,
}))); })));
} }
} }

13
src/ship/items.rs

@ -3,9 +3,11 @@ use std::hash::{Hash, Hasher};
use libpso::character::character::InventoryItem; use libpso::character::character::InventoryItem;
use crate::entity::item::{Item, ItemDetail, ItemLocation, Shield};
use crate::entity::item::{Item, ItemDetail, ItemLocation};
use crate::entity::item::weapon::Weapon; use crate::entity::item::weapon::Weapon;
use crate::entity::item::armor::Armor; use crate::entity::item::armor::Armor;
use crate::entity::item::shield::Shield;
use crate::entity::item::unit::Unit;
use crate::entity::item::tool::StackedTool; use crate::entity::item::tool::StackedTool;
@ -13,7 +15,8 @@ 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 == b.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 == b.shield,
(ItemDetail::Unit(a), ItemDetail::Unit(b)) => a.unit == b.unit,
(ItemDetail::Tool(a), ItemDetail::Tool(b)) => a.tool == b.tool, (ItemDetail::Tool(a), ItemDetail::Tool(b)) => a.tool == b.tool,
_ => false _ => false
} }
@ -109,8 +112,8 @@ impl Hash for StackedItemKey {
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.value().hash(hasher), ItemDetail::Armor(a) => a.armor.value().hash(hasher),
ItemDetail::Shield(s) => s.shield.shield.value().hash(hasher),
ItemDetail::Unit(u) => u.unit.unit.value().hash(hasher),
ItemDetail::Shield(s) => s.shield.value().hash(hasher),
ItemDetail::Unit(u) => u.unit.value().hash(hasher),
ItemDetail::Tool(t) => t.tool.value().hash(hasher), ItemDetail::Tool(t) => t.tool.value().hash(hasher),
} }
} }
@ -195,6 +198,7 @@ impl Inventory {
StackedItem::Individual(Item {item: ItemDetail::Weapon(Weapon {equipped: true, ..}), ..}) => 1, StackedItem::Individual(Item {item: ItemDetail::Weapon(Weapon {equipped: true, ..}), ..}) => 1,
StackedItem::Individual(Item {item: ItemDetail::Armor(Armor {equipped: true, ..}), ..}) => 1, StackedItem::Individual(Item {item: ItemDetail::Armor(Armor {equipped: true, ..}), ..}) => 1,
StackedItem::Individual(Item {item: ItemDetail::Shield(Shield {equipped: true, ..}), ..}) => 1, StackedItem::Individual(Item {item: ItemDetail::Shield(Shield {equipped: true, ..}), ..}) => 1,
StackedItem::Individual(Item {item: ItemDetail::Unit(Unit{equipped: true, ..}), ..}) => 1,
_ => 0, _ => 0,
}; };
// because this actually equips the item // because this actually equips the item
@ -202,6 +206,7 @@ impl Inventory {
StackedItem::Individual(Item {item: ItemDetail::Weapon(Weapon {equipped: true, ..}), ..}) => 8, StackedItem::Individual(Item {item: ItemDetail::Weapon(Weapon {equipped: true, ..}), ..}) => 8,
StackedItem::Individual(Item {item: ItemDetail::Armor(Armor {equipped: true, ..}), ..}) => 8, StackedItem::Individual(Item {item: ItemDetail::Armor(Armor {equipped: true, ..}), ..}) => 8,
StackedItem::Individual(Item {item: ItemDetail::Shield(Shield {equipped: true, ..}), ..}) => 8, StackedItem::Individual(Item {item: ItemDetail::Shield(Shield {equipped: true, ..}), ..}) => 8,
StackedItem::Individual(Item {item: ItemDetail::Unit(Unit {equipped: true, ..}), ..}) => 8,
_ => 0, _ => 0,
}; };
} }

Loading…
Cancel
Save