begin removing weird middleman item structs: weapons
This commit is contained in:
parent
aa6e5bbafe
commit
2e2f9c6c17
@ -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)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Armor {
|
pub struct Armor {
|
||||||
pub equipped: bool,
|
pub equipped: bool,
|
||||||
@ -81,7 +73,7 @@ impl Tool {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum ItemDetail {
|
pub enum ItemDetail {
|
||||||
Weapon(Weapon),
|
Weapon(weapon::Weapon),
|
||||||
Armor(Armor),
|
Armor(Armor),
|
||||||
Shield(Shield),
|
Shield(Shield),
|
||||||
Unit(Unit),
|
Unit(Unit),
|
||||||
@ -91,14 +83,14 @@ pub enum ItemDetail {
|
|||||||
impl ItemDetail {
|
impl ItemDetail {
|
||||||
pub fn is_stackable(&self) -> bool {
|
pub fn is_stackable(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
ItemDetail::Tool(tool) => true,
|
ItemDetail::Tool(tool) => tool.tool.is_stackable(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_bytes(&self) -> [u8; 16] {
|
pub fn as_bytes(&self) -> [u8; 16] {
|
||||||
match self {
|
match self {
|
||||||
ItemDetail::Weapon(weapon) => weapon.weapon.as_bytes(),
|
ItemDetail::Weapon(weapon) => weapon.as_bytes(),
|
||||||
ItemDetail::Armor(armor) => armor.armor.as_bytes(),
|
ItemDetail::Armor(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(),
|
||||||
|
@ -860,6 +860,8 @@ pub struct Weapon {
|
|||||||
pub special: Option<WeaponSpecial>,
|
pub special: Option<WeaponSpecial>,
|
||||||
pub grind: u8,
|
pub grind: u8,
|
||||||
pub attrs: [Option<WeaponAttribute>; 3],
|
pub attrs: [Option<WeaponAttribute>; 3],
|
||||||
|
pub equipped: bool,
|
||||||
|
pub tekked: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -869,7 +871,9 @@ impl Weapon {
|
|||||||
weapon: wep,
|
weapon: wep,
|
||||||
special: None,
|
special: None,
|
||||||
grind: 0,
|
grind: 0,
|
||||||
attrs: [None; 3]
|
attrs: [None; 3],
|
||||||
|
equipped: false,
|
||||||
|
tekked: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ 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, 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::entity::character::{Character, CharacterClass, Technique, TechLevel};
|
||||||
|
|
||||||
use crate::login::login::get_login_status;
|
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(
|
entity_gateway.new_item(
|
||||||
ItemDetail::Weapon(
|
ItemDetail::Weapon(
|
||||||
Weapon {
|
Weapon {
|
||||||
|
weapon: new_weapon,
|
||||||
|
grind: 0,
|
||||||
|
special: None,
|
||||||
|
attrs: [None; 3],
|
||||||
equipped: true,
|
equipped: true,
|
||||||
tekked: true,
|
tekked: true,
|
||||||
weapon: item::weapon::Weapon {
|
|
||||||
weapon: new_weapon,
|
|
||||||
grind: 0,
|
|
||||||
special: None,
|
|
||||||
attrs: [None; 3]
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
ItemLocation::Inventory {
|
ItemLocation::Inventory {
|
||||||
character_id: char.id,
|
character_id: char.id,
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -84,15 +84,13 @@ fn main() {
|
|||||||
|
|
||||||
entity_gateway.new_item(
|
entity_gateway.new_item(
|
||||||
item::ItemDetail::Weapon(
|
item::ItemDetail::Weapon(
|
||||||
item::Weapon {
|
item::weapon::Weapon {
|
||||||
|
weapon: item::weapon::WeaponType::Handgun,
|
||||||
|
grind: 5,
|
||||||
|
special: None,
|
||||||
|
attrs: [None; 3],
|
||||||
equipped: true,
|
equipped: true,
|
||||||
tekked: true,
|
tekked: true,
|
||||||
weapon: item::weapon::Weapon {
|
|
||||||
weapon: item::weapon::WeaponType::Handgun,
|
|
||||||
grind: 5,
|
|
||||||
special: None,
|
|
||||||
attrs: [None; 3],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
ItemLocation::Inventory {
|
ItemLocation::Inventory {
|
||||||
|
@ -5,7 +5,7 @@ use rand::{Rng, SeedableRng};
|
|||||||
use rand::distributions::{WeightedIndex, Distribution};
|
use rand::distributions::{WeightedIndex, Distribution};
|
||||||
use rand::seq::SliceRandom;
|
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::entity::item::weapon::{Weapon, WeaponType, Attribute, WeaponAttribute, WeaponSpecial};
|
||||||
use crate::ship::monster::MonsterType;
|
use crate::ship::monster::MonsterType;
|
||||||
use crate::ship::room::{Difficulty, Episode};
|
use crate::ship::room::{Difficulty, Episode};
|
||||||
@ -487,15 +487,13 @@ impl GenericWeaponTable {
|
|||||||
let weapon_special = self.special_table.get_special(map_area, rng);
|
let weapon_special = self.special_table.get_special(map_area, rng);
|
||||||
let actual_weapon = self.actual_weapon(&weapon_type, weapon_rank);
|
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,
|
equipped: false,
|
||||||
tekked: weapon_special.is_none(),
|
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 mut rng = rand_chacha::ChaCha20Rng::from_seed([23;32]);
|
||||||
|
|
||||||
let gwt = GenericWeaponTable::new(Episode::One, Difficulty::Normal, SectionID::Skyly);
|
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,
|
equipped: false,
|
||||||
tekked: true,
|
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);
|
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,
|
equipped: false,
|
||||||
tekked: true,
|
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);
|
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,
|
equipped: false,
|
||||||
tekked: 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);
|
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,
|
equipped: false,
|
||||||
tekked: true,
|
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]
|
|
||||||
}
|
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,14 @@ use std::hash::{Hash, Hasher};
|
|||||||
|
|
||||||
use libpso::character::character::InventoryItem;
|
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;
|
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.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::Armor(a), ItemDetail::Armor(b)) => a.armor.armor == b.armor.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,
|
||||||
@ -105,7 +106,7 @@ struct StackedItemKey(Item);
|
|||||||
impl Hash for StackedItemKey {
|
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.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.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),
|
||||||
@ -227,7 +228,7 @@ pub fn split_items_into_inventory_and_bank(items: Vec<Item>) -> (Vec<Item>, Vec<
|
|||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::entity::item;
|
use crate::entity::item;
|
||||||
use crate::entity::item::{Item, ItemDetail, ItemEntityId, ItemLocation, Weapon, Tool};
|
use crate::entity::item::{Item, ItemDetail, ItemEntityId, ItemLocation, Tool};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stacked_items() {
|
fn test_stacked_items() {
|
||||||
@ -237,15 +238,13 @@ mod test {
|
|||||||
character_id: 0,
|
character_id: 0,
|
||||||
index: 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,
|
equipped: false,
|
||||||
tekked: true,
|
tekked: true,
|
||||||
weapon: item::weapon::Weapon {
|
|
||||||
weapon: item::weapon::WeaponType::Saber,
|
|
||||||
grind: 0,
|
|
||||||
special: None,
|
|
||||||
attrs: [None; 3]
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
let item2 = Item {
|
let item2 = Item {
|
||||||
@ -264,15 +263,13 @@ mod test {
|
|||||||
character_id: 0,
|
character_id: 0,
|
||||||
index: 2,
|
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,
|
equipped: false,
|
||||||
tekked: true,
|
tekked: true,
|
||||||
weapon: item::weapon::Weapon {
|
|
||||||
weapon: item::weapon::WeaponType::Handgun,
|
|
||||||
grind: 12,
|
|
||||||
special: None,
|
|
||||||
attrs: [None; 3]
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
let item4 = Item {
|
let item4 = Item {
|
||||||
@ -301,15 +298,13 @@ mod test {
|
|||||||
character_id: 0,
|
character_id: 0,
|
||||||
index: 3,
|
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,
|
equipped: false,
|
||||||
tekked: true,
|
tekked: true,
|
||||||
weapon: item::weapon::Weapon {
|
|
||||||
weapon: item::weapon::WeaponType::Handgun,
|
|
||||||
grind: 12,
|
|
||||||
special: None,
|
|
||||||
attrs: [None; 3]
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
let item7 = Item {
|
let item7 = Item {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user