Browse Source

begin removing weird middleman item structs: weapons

pbs
jake 5 years ago
parent
commit
2e2f9c6c17
  1. 14
      src/entity/item/mod.rs
  2. 6
      src/entity/item/weapon.rs
  3. 13
      src/login/character.rs
  4. 12
      src/main.rs
  5. 62
      src/ship/drops/generic_weapon.rs
  6. 45
      src/ship/items.rs

14
src/entity/item/mod.rs

@ -40,14 +40,6 @@ pub enum ItemLocation {
}
#[derive(Clone, Debug, PartialEq)]
pub struct Weapon {
pub equipped: bool,
pub tekked: bool,
pub weapon: weapon::Weapon,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Armor {
pub equipped: bool,
@ -81,7 +73,7 @@ impl Tool {
#[derive(Clone, Debug, PartialEq)]
pub enum ItemDetail {
Weapon(Weapon),
Weapon(weapon::Weapon),
Armor(Armor),
Shield(Shield),
Unit(Unit),
@ -91,14 +83,14 @@ pub enum ItemDetail {
impl ItemDetail {
pub fn is_stackable(&self) -> bool {
match self {
ItemDetail::Tool(tool) => true,
ItemDetail::Tool(tool) => tool.tool.is_stackable(),
_ => false,
}
}
pub fn as_bytes(&self) -> [u8; 16] {
match self {
ItemDetail::Weapon(weapon) => weapon.weapon.as_bytes(),
ItemDetail::Weapon(weapon) => weapon.as_bytes(),
ItemDetail::Armor(armor) => armor.armor.as_bytes(),
ItemDetail::Shield(shield) => shield.shield.as_bytes(),
ItemDetail::Unit(unit) => unit.unit.as_bytes(),

6
src/entity/item/weapon.rs

@ -860,6 +860,8 @@ pub struct Weapon {
pub special: Option<WeaponSpecial>,
pub grind: u8,
pub attrs: [Option<WeaponAttribute>; 3],
pub equipped: bool,
pub tekked: bool,
}
@ -869,7 +871,9 @@ impl Weapon {
weapon: wep,
special: None,
grind: 0,
attrs: [None; 3]
attrs: [None; 3],
equipped: false,
tekked: true,
}
}

13
src/login/character.rs

@ -17,7 +17,8 @@ use libpso::{utf8_to_array, utf8_to_utf16_array};
use crate::entity::gateway::EntityGateway;
use crate::entity::account::{UserAccount, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM};
use crate::entity::item::{ItemDetail, ItemLocation, Weapon, Armor, Shield, Tool};
use crate::entity::item::{ItemDetail, ItemLocation, Armor, Tool};
use crate::entity::item::weapon::Weapon;
use crate::entity::character::{Character, CharacterClass, Technique, TechLevel};
use crate::login::login::get_login_status;
@ -203,14 +204,12 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccount,
entity_gateway.new_item(
ItemDetail::Weapon(
Weapon {
weapon: new_weapon,
grind: 0,
special: None,
attrs: [None; 3],
equipped: true,
tekked: true,
weapon: item::weapon::Weapon {
weapon: new_weapon,
grind: 0,
special: None,
attrs: [None; 3]
}
}),
ItemLocation::Inventory {
character_id: char.id,

12
src/main.rs

@ -84,15 +84,13 @@ fn main() {
entity_gateway.new_item(
item::ItemDetail::Weapon(
item::Weapon {
item::weapon::Weapon {
weapon: item::weapon::WeaponType::Handgun,
grind: 5,
special: None,
attrs: [None; 3],
equipped: true,
tekked: true,
weapon: item::weapon::Weapon {
weapon: item::weapon::WeaponType::Handgun,
grind: 5,
special: None,
attrs: [None; 3],
}
}
),
ItemLocation::Inventory {

62
src/ship/drops/generic_weapon.rs

@ -5,7 +5,7 @@ use rand::{Rng, SeedableRng};
use rand::distributions::{WeightedIndex, Distribution};
use rand::seq::SliceRandom;
use crate::entity::item::{ItemDetail, Weapon as WeaponDetail};
use crate::entity::item::{ItemDetail};
use crate::entity::item::weapon::{Weapon, WeaponType, Attribute, WeaponAttribute, WeaponSpecial};
use crate::ship::monster::MonsterType;
use crate::ship::room::{Difficulty, Episode};
@ -487,15 +487,13 @@ impl GenericWeaponTable {
let weapon_special = self.special_table.get_special(map_area, rng);
let actual_weapon = self.actual_weapon(&weapon_type, weapon_rank);
Some(ItemDetail::Weapon(WeaponDetail {
Some(ItemDetail::Weapon(Weapon {
weapon: actual_weapon,
special: weapon_special,
grind: weapon_grind as u8,
attrs: weapon_attributes,
equipped: false,
tekked: weapon_special.is_none(),
weapon: Weapon {
weapon: actual_weapon,
special: weapon_special,
grind: weapon_grind as u8,
attrs: weapon_attributes,
}
}))
}
}
@ -510,51 +508,43 @@ mod test {
let mut rng = rand_chacha::ChaCha20Rng::from_seed([23;32]);
let gwt = GenericWeaponTable::new(Episode::One, Difficulty::Normal, SectionID::Skyly);
assert!(gwt.get_drop(&MapVariantType::Forest1, &mut rng) == Some(ItemDetail::Weapon(WeaponDetail {
assert!(gwt.get_drop(&MapVariantType::Forest1, &mut rng) == Some(ItemDetail::Weapon(Weapon {
weapon: WeaponType::Cane,
special: None,
grind: 0,
attrs: [None, None, None],
equipped: false,
tekked: true,
weapon: Weapon {
weapon: WeaponType::Cane,
special: None,
grind: 0,
attrs: [None, None, None]
}
})));
let gwt = GenericWeaponTable::new(Episode::One, Difficulty::Hard, SectionID::Skyly);
assert!(gwt.get_drop(&MapVariantType::Caves2, &mut rng) == Some(ItemDetail::Weapon(WeaponDetail {
assert!(gwt.get_drop(&MapVariantType::Caves2, &mut rng) == Some(ItemDetail::Weapon(Weapon {
weapon: WeaponType::Sniper,
special: None,
grind: 2,
attrs: [None, None, None],
equipped: false,
tekked: true,
weapon: Weapon {
weapon: WeaponType::Sniper,
special: None,
grind: 2,
attrs: [None, None, None]
}
})));
let gwt = GenericWeaponTable::new(Episode::One, Difficulty::VeryHard, SectionID::Skyly);
assert!(gwt.get_drop(&MapVariantType::Mines1, &mut rng) == Some(ItemDetail::Weapon(WeaponDetail {
assert!(gwt.get_drop(&MapVariantType::Mines1, &mut rng) == Some(ItemDetail::Weapon(Weapon {
weapon: WeaponType::Club,
special: Some(WeaponSpecial::Berserk),
grind: 0,
attrs: [None, None, None],
equipped: false,
tekked: false,
weapon: Weapon {
weapon: WeaponType::Club,
special: Some(WeaponSpecial::Berserk),
grind: 0,
attrs: [None, None, None]
}
})));
let gwt = GenericWeaponTable::new(Episode::One, Difficulty::Ultimate, SectionID::Skyly);
assert!(gwt.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDetail::Weapon(WeaponDetail {
assert!(gwt.get_drop(&MapVariantType::DarkFalz, &mut rng) == Some(ItemDetail::Weapon(Weapon {
weapon: WeaponType::Vulcan,
special: None,
grind: 0,
attrs: [Some(WeaponAttribute {attr: Attribute::ABeast, value: 30}), Some(WeaponAttribute {attr: Attribute::Dark, value: 30}), None],
equipped: false,
tekked: true,
weapon: Weapon {
weapon: WeaponType::Vulcan,
special: None,
grind: 0,
attrs: [Some(WeaponAttribute {attr: Attribute::ABeast, value: 30}), Some(WeaponAttribute {attr: Attribute::Dark, value: 30}), None]
}
})));
}
}

45
src/ship/items.rs

@ -3,13 +3,14 @@ use std::hash::{Hash, Hasher};
use libpso::character::character::InventoryItem;
use crate::entity::item::{Item, ItemDetail, ItemLocation, Weapon, Armor, Shield};
use crate::entity::item::{Item, ItemDetail, ItemLocation, Armor, Shield};
use crate::entity::item::weapon::Weapon;
use crate::entity::item::tool::StackedTool;
fn are_items_same_type(itema: &Item, itemb: &Item) -> bool {
match (&itema.item, &itemb.item) {
(ItemDetail::Weapon(a), ItemDetail::Weapon(b)) => a.weapon.weapon == b.weapon.weapon,
(ItemDetail::Weapon(a), ItemDetail::Weapon(b)) => a.weapon == b.weapon,
(ItemDetail::Armor(a), ItemDetail::Armor(b)) => a.armor.armor == b.armor.armor,
(ItemDetail::Shield(a), ItemDetail::Shield(b)) => a.shield.shield == b.shield.shield,
(ItemDetail::Tool(a), ItemDetail::Tool(b)) => a.tool == b.tool,
@ -105,7 +106,7 @@ struct StackedItemKey(Item);
impl Hash for StackedItemKey {
fn hash<H: Hasher>(&self, hasher: &mut H) {
match &self.0.item {
ItemDetail::Weapon(w) => w.weapon.weapon.value().hash(hasher),
ItemDetail::Weapon(w) => w.weapon.value().hash(hasher),
ItemDetail::Armor(a) => a.armor.armor.value().hash(hasher),
ItemDetail::Shield(s) => s.shield.shield.value().hash(hasher),
ItemDetail::Unit(u) => u.unit.unit.value().hash(hasher),
@ -227,7 +228,7 @@ pub fn split_items_into_inventory_and_bank(items: Vec<Item>) -> (Vec<Item>, Vec<
mod test {
use super::*;
use crate::entity::item;
use crate::entity::item::{Item, ItemDetail, ItemEntityId, ItemLocation, Weapon, Tool};
use crate::entity::item::{Item, ItemDetail, ItemEntityId, ItemLocation, Tool};
#[test]
fn test_stacked_items() {
@ -237,15 +238,13 @@ mod test {
character_id: 0,
index: 0,
},
item: ItemDetail::Weapon(Weapon {
item: ItemDetail::Weapon(item::weapon::Weapon {
weapon: item::weapon::WeaponType::Saber,
grind: 0,
special: None,
attrs: [None; 3],
equipped: false,
tekked: true,
weapon: item::weapon::Weapon {
weapon: item::weapon::WeaponType::Saber,
grind: 0,
special: None,
attrs: [None; 3]
}
})
};
let item2 = Item {
@ -264,15 +263,13 @@ mod test {
character_id: 0,
index: 2,
},
item: ItemDetail::Weapon(Weapon {
item: ItemDetail::Weapon(item::weapon::Weapon {
weapon: item::weapon::WeaponType::Handgun,
grind: 12,
special: None,
attrs: [None; 3],
equipped: false,
tekked: true,
weapon: item::weapon::Weapon {
weapon: item::weapon::WeaponType::Handgun,
grind: 12,
special: None,
attrs: [None; 3]
}
})
};
let item4 = Item {
@ -301,15 +298,13 @@ mod test {
character_id: 0,
index: 3,
},
item: ItemDetail::Weapon(Weapon {
item: ItemDetail::Weapon(item::weapon::Weapon {
weapon: item::weapon::WeaponType::Handgun,
grind: 12,
special: None,
attrs: [None; 3],
equipped: false,
tekked: true,
weapon: item::weapon::Weapon {
weapon: item::weapon::WeaponType::Handgun,
grind: 12,
special: None,
attrs: [None; 3]
}
})
};
let item7 = Item {

Loading…
Cancel
Save