remove shield+unit midstruct
This commit is contained in:
parent
e72caebbf8
commit
2981b163c2
@ -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)]
|
||||
pub struct Tool {
|
||||
pub tool: tool::ToolType,
|
||||
@ -64,8 +52,8 @@ impl Tool {
|
||||
pub enum ItemDetail {
|
||||
Weapon(weapon::Weapon),
|
||||
Armor(armor::Armor),
|
||||
Shield(Shield),
|
||||
Unit(Unit),
|
||||
Shield(shield::Shield),
|
||||
Unit(unit::Unit),
|
||||
Tool(Tool),
|
||||
}
|
||||
|
||||
@ -81,8 +69,8 @@ impl ItemDetail {
|
||||
match self {
|
||||
ItemDetail::Weapon(weapon) => weapon.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(),
|
||||
}
|
||||
}
|
||||
|
@ -347,6 +347,7 @@ pub struct Shield {
|
||||
pub shield: ShieldType,
|
||||
pub dfp: u8,
|
||||
pub evp: u8,
|
||||
pub equipped: bool,
|
||||
}
|
||||
|
||||
impl Shield {
|
||||
|
@ -224,6 +224,7 @@ pub enum UnitModifier {
|
||||
pub struct Unit {
|
||||
pub unit: UnitType,
|
||||
pub modifier: Option<UnitModifier>,
|
||||
pub equipped: bool,
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize};
|
||||
use rand::{Rng, SeedableRng};
|
||||
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::ship::room::{Difficulty, Episode};
|
||||
use crate::ship::map::MapVariantType;
|
||||
@ -85,13 +85,11 @@ impl GenericShieldTable {
|
||||
let evp_modifier = self.dfp_modifier(&shield_type, rng);
|
||||
|
||||
|
||||
Some(ItemDetail::Shield(ShieldDetail {
|
||||
Some(ItemDetail::Shield(Shield {
|
||||
shield: shield_type,
|
||||
dfp: dfp_modifier as u8,
|
||||
evp: evp_modifier as u8,
|
||||
equipped: false,
|
||||
shield: Shield {
|
||||
shield: shield_type,
|
||||
dfp: dfp_modifier as u8,
|
||||
evp: evp_modifier as u8,
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
@ -106,37 +104,29 @@ mod test {
|
||||
|
||||
let gst = GenericShieldTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly);
|
||||
|
||||
assert!(gst.get_drop(&MapVariantType::Forest1, &mut rng) == Some(ItemDetail::Shield(ShieldDetail {
|
||||
assert!(gst.get_drop(&MapVariantType::Forest1, &mut rng) == Some(ItemDetail::Shield(Shield {
|
||||
shield: ShieldType::FreezeBarrier,
|
||||
dfp: 4,
|
||||
evp: 1,
|
||||
equipped: false,
|
||||
shield: Shield {
|
||||
shield: ShieldType::FreezeBarrier,
|
||||
dfp: 4,
|
||||
evp: 1,
|
||||
}
|
||||
})));
|
||||
assert!(gst.get_drop(&MapVariantType::Caves3, &mut rng) == Some(ItemDetail::Shield(ShieldDetail {
|
||||
assert!(gst.get_drop(&MapVariantType::Caves3, &mut rng) == Some(ItemDetail::Shield(Shield {
|
||||
shield: ShieldType::PsychicBarrier,
|
||||
dfp: 3,
|
||||
evp: 2,
|
||||
equipped: false,
|
||||
shield: Shield {
|
||||
shield: ShieldType::PsychicBarrier,
|
||||
dfp: 3,
|
||||
evp: 2,
|
||||
}
|
||||
})));
|
||||
assert!(gst.get_drop(&MapVariantType::Mines2, &mut rng) == Some(ItemDetail::Shield(ShieldDetail {
|
||||
assert!(gst.get_drop(&MapVariantType::Mines2, &mut rng) == Some(ItemDetail::Shield(Shield {
|
||||
shield: ShieldType::ImperialBarrier,
|
||||
dfp: 0,
|
||||
evp: 4,
|
||||
equipped: false,
|
||||
shield: Shield {
|
||||
shield: ShieldType::ImperialBarrier,
|
||||
dfp: 0,
|
||||
evp: 4,
|
||||
}
|
||||
})));
|
||||
assert!(gst.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDetail::Shield(ShieldDetail {
|
||||
assert!(gst.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDetail::Shield(Shield {
|
||||
shield: ShieldType::DivinityBarrier,
|
||||
dfp: 1,
|
||||
evp: 0,
|
||||
equipped: false,
|
||||
shield: Shield {
|
||||
shield: ShieldType::DivinityBarrier,
|
||||
dfp: 1,
|
||||
evp: 0,
|
||||
}
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use rand::{Rng, SeedableRng};
|
||||
use rand::distributions::{WeightedIndex, Distribution};
|
||||
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::ship::room::{Difficulty, Episode};
|
||||
use crate::ship::map::MapVariantType;
|
||||
@ -88,12 +88,10 @@ impl GenericUnitTable {
|
||||
let unit_type_modifier = self.unit_type_and_modifier(area_map, rng);
|
||||
|
||||
unit_type_modifier.map(|(unit_type, unit_modifier)| {
|
||||
ItemDetail::Unit(UnitDetail {
|
||||
ItemDetail::Unit(Unit {
|
||||
unit: unit_type,
|
||||
modifier: unit_modifier,
|
||||
equipped: false,
|
||||
unit: Unit {
|
||||
unit: unit_type,
|
||||
modifier: unit_modifier,
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -117,12 +115,10 @@ mod test {
|
||||
(MapVariantType::Mines2, UnitType::ResistEvil, Some(UnitModifier::PlusPlus)),
|
||||
(MapVariantType::DarkFalz, UnitType::DragonHP, Some(UnitModifier::Minus))];
|
||||
for (area, unit, umod) in unit_tests {
|
||||
assert!(gut.get_drop(&area, &mut rng) == Some(ItemDetail::Unit(UnitDetail {
|
||||
assert!(gut.get_drop(&area, &mut rng) == Some(ItemDetail::Unit(Unit {
|
||||
unit: unit,
|
||||
modifier: umod,
|
||||
equipped: false,
|
||||
unit: Unit {
|
||||
unit: unit,
|
||||
modifier: umod,
|
||||
}
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,11 @@ use std::hash::{Hash, Hasher};
|
||||
|
||||
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::armor::Armor;
|
||||
use crate::entity::item::shield::Shield;
|
||||
use crate::entity::item::unit::Unit;
|
||||
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) {
|
||||
(ItemDetail::Weapon(a), ItemDetail::Weapon(b)) => a.weapon == b.weapon,
|
||||
(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,
|
||||
_ => false
|
||||
}
|
||||
@ -109,8 +112,8 @@ impl Hash for StackedItemKey {
|
||||
match &self.0.item {
|
||||
ItemDetail::Weapon(w) => w.weapon.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),
|
||||
}
|
||||
}
|
||||
@ -195,6 +198,7 @@ impl Inventory {
|
||||
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::Shield(Shield {equipped: true, ..}), ..}) => 1,
|
||||
StackedItem::Individual(Item {item: ItemDetail::Unit(Unit{equipped: true, ..}), ..}) => 1,
|
||||
_ => 0,
|
||||
};
|
||||
// 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::Armor(Armor {equipped: true, ..}), ..}) => 8,
|
||||
StackedItem::Individual(Item {item: ItemDetail::Shield(Shield {equipped: true, ..}), ..}) => 8,
|
||||
StackedItem::Individual(Item {item: ItemDetail::Unit(Unit {equipped: true, ..}), ..}) => 8,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user