From 88959c24f939f94d3a96e25d0a9465ad0a00e0c7 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 19 Nov 2023 00:06:50 -0700 Subject: [PATCH] move characterclass/sectionid to libpso --- Cargo.toml | 2 +- src/drops/Cargo.toml | 2 + src/drops/src/box_drop_table.rs | 2 +- src/drops/src/generic_armor.rs | 2 +- src/drops/src/generic_shield.rs | 2 +- src/drops/src/generic_unit.rs | 2 +- src/drops/src/generic_weapon.rs | 2 +- src/drops/src/lib.rs | 2 +- src/drops/src/rare_drop_table.rs | 2 +- src/drops/src/tech_table.rs | 2 +- src/drops/src/tool_table.rs | 2 +- src/entity/src/character.rs | 135 +--------------------- src/entity/src/gateway/postgres/models.rs | 1 + src/entity/src/item/mag.rs | 2 +- src/entity/src/room.rs | 3 +- src/login_server/src/character.rs | 3 +- src/room/Cargo.toml | 2 + src/room/src/lib.rs | 2 +- src/ship_server/src/lib.rs | 2 +- src/ship_server/src/room.rs | 2 +- src/shops/Cargo.toml | 2 + src/shops/src/lib.rs | 2 +- src/shops/src/weapon.rs | 2 +- src/stats/Cargo.toml | 1 + src/stats/src/leveltable.rs | 2 +- tests/common.rs | 3 +- tests/test_mags.rs | 2 +- 27 files changed, 33 insertions(+), 155 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bbda680..741fd94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ patch_server = { path = "./src/patch_server" } login_server = { path = "./src/login_server" } ship_server = { path = "./src/ship_server" } -libpso = { git = "http://git.sharnoth.com/jake/libpso", rev="90246b6" } +libpso = { git = "http://git.sharnoth.com/jake/libpso", rev="552f7d5" } async-std = { version = "1.9.0", features = ["unstable", "attributes"] } futures = "0.3.5" diff --git a/src/drops/Cargo.toml b/src/drops/Cargo.toml index 199e7c6..a12bb6d 100644 --- a/src/drops/Cargo.toml +++ b/src/drops/Cargo.toml @@ -9,6 +9,8 @@ entity = { workspace = true } maps = { workspace = true } stats = { workspace = true } +libpso = { workspace = true } + rand = { workspace = true } rand_chacha = { workspace = true } serde = { workspace = true } diff --git a/src/drops/src/box_drop_table.rs b/src/drops/src/box_drop_table.rs index 01f41eb..02a40c7 100644 --- a/src/drops/src/box_drop_table.rs +++ b/src/drops/src/box_drop_table.rs @@ -2,7 +2,7 @@ use rand::{Rng}; use rand::distributions::{WeightedIndex, Distribution}; use serde::{Serialize, Deserialize}; -use entity::character::SectionID; +use libpso::character::SectionID; use maps::room::{Difficulty, Episode}; use maps::area::MapArea; use crate::{ItemDropType, load_data_file}; diff --git a/src/drops/src/generic_armor.rs b/src/drops/src/generic_armor.rs index 82e9a58..134a379 100644 --- a/src/drops/src/generic_armor.rs +++ b/src/drops/src/generic_armor.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; use rand::Rng; use rand::distributions::{WeightedIndex, Distribution}; -use entity::character::SectionID; +use libpso::character::SectionID; use entity::item::armor::{ArmorType, Armor}; use maps::room::{Difficulty, Episode}; use maps::area::MapArea; diff --git a/src/drops/src/generic_shield.rs b/src/drops/src/generic_shield.rs index c7bbf1f..e7e9df8 100644 --- a/src/drops/src/generic_shield.rs +++ b/src/drops/src/generic_shield.rs @@ -4,7 +4,7 @@ use rand::Rng; use rand::distributions::{WeightedIndex, Distribution}; use entity::item::shield::{ShieldType, Shield}; -use entity::character::SectionID; +use libpso::character::SectionID; use maps::room::{Difficulty, Episode}; use maps::area::MapArea; use crate::{ItemDropType, load_data_file}; diff --git a/src/drops/src/generic_unit.rs b/src/drops/src/generic_unit.rs index cc1caa0..0920843 100644 --- a/src/drops/src/generic_unit.rs +++ b/src/drops/src/generic_unit.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; use rand::Rng; use rand::seq::IteratorRandom; -use entity::character::SectionID; +use libpso::character::SectionID; use entity::item::unit::{UnitType, Unit, UnitModifier}; use maps::room::{Difficulty, Episode}; use maps::area::MapArea; diff --git a/src/drops/src/generic_weapon.rs b/src/drops/src/generic_weapon.rs index 557130c..b2a9199 100644 --- a/src/drops/src/generic_weapon.rs +++ b/src/drops/src/generic_weapon.rs @@ -4,7 +4,7 @@ use rand::Rng; use rand::distributions::{WeightedIndex, Distribution}; use rand::seq::SliceRandom; -use entity::character::SectionID; +use libpso::character::SectionID; use entity::item::weapon::{Weapon, WeaponType, Attribute, WeaponAttribute, WeaponSpecial}; use maps::room::{Difficulty, Episode}; use maps::area::MapArea; diff --git a/src/drops/src/lib.rs b/src/drops/src/lib.rs index 32a14db..c27bb19 100644 --- a/src/drops/src/lib.rs +++ b/src/drops/src/lib.rs @@ -24,7 +24,7 @@ use rand::{Rng, SeedableRng}; use maps::monster::MonsterType; use maps::room::{Difficulty, Episode}; use maps::area::MapArea; -use entity::character::SectionID; +use libpso::character::SectionID; use crate::generic_weapon::GenericWeaponTable; use crate::generic_armor::GenericArmorTable; use crate::generic_shield::GenericShieldTable; diff --git a/src/drops/src/rare_drop_table.rs b/src/drops/src/rare_drop_table.rs index b9ab745..906d453 100644 --- a/src/drops/src/rare_drop_table.rs +++ b/src/drops/src/rare_drop_table.rs @@ -7,7 +7,7 @@ use entity::item::shield::{Shield, ShieldType}; use entity::item::unit::{Unit, UnitType}; use entity::item::tool::{Tool, ToolType}; use entity::item::mag::{Mag, MagType}; -use entity::character::SectionID; +use libpso::character::SectionID; use maps::monster::MonsterType; use maps::room::{Difficulty, Episode}; use maps::area::MapArea; diff --git a/src/drops/src/tech_table.rs b/src/drops/src/tech_table.rs index 9b1101b..2c6eb8d 100644 --- a/src/drops/src/tech_table.rs +++ b/src/drops/src/tech_table.rs @@ -6,7 +6,7 @@ use rand::distributions::{WeightedIndex, Distribution}; use entity::item::tech::{Technique, TechniqueDisk}; use maps::room::{Difficulty, Episode}; use maps::area::MapArea; -use entity::character::SectionID; +use libpso::character::SectionID; use crate::{ItemDropType, load_data_file}; diff --git a/src/drops/src/tool_table.rs b/src/drops/src/tool_table.rs index 9645c34..cb545da 100644 --- a/src/drops/src/tool_table.rs +++ b/src/drops/src/tool_table.rs @@ -6,7 +6,7 @@ use rand::distributions::{WeightedIndex, Distribution}; use entity::item::tool::{Tool, ToolType}; use maps::room::{Difficulty, Episode}; use maps::area::MapArea; -use entity::character::SectionID; +use libpso::character::SectionID; use crate::{ItemDropType, load_data_file}; use crate::tech_table::TechniqueTable; diff --git a/src/entity/src/character.rs b/src/entity/src/character.rs index d766f28..14d13e6 100644 --- a/src/entity/src/character.rs +++ b/src/entity/src/character.rs @@ -3,144 +3,11 @@ use std::collections::HashMap; use serde::{Serialize, Deserialize}; use libpso::packet::ship::{UpdateConfig, WriteInfoboard}; +use libpso::character::{CharacterClass, SectionID}; use libpso::character::settings::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU}; use crate::item::tech::Technique; use crate::account::UserAccountId; -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, enum_utils::FromStr, derive_more::Display, Serialize, Deserialize, Default)] -pub enum CharacterClass { - #[default] - HUmar, - HUnewearl, - HUcast, - HUcaseal, - RAmar, - RAmarl, - RAcast, - RAcaseal, - FOmar, - FOmarl, - FOnewm, - FOnewearl, -} - -// TODO: TryFrom -impl From for CharacterClass { - fn from(f: u8) -> CharacterClass { - match f { - 0 => CharacterClass::HUmar, - 1 => CharacterClass::HUnewearl, - 2 => CharacterClass::HUcast, - 3 => CharacterClass::RAmar, - 4 => CharacterClass::RAcast, - 5 => CharacterClass::RAcaseal, - 6 => CharacterClass::FOmarl, - 7 => CharacterClass::FOnewm, - 8 => CharacterClass::FOnewearl, - 9 => CharacterClass::HUcaseal, - 10 => CharacterClass::FOmar, - 11 => CharacterClass::RAmarl, - _ => panic!("unknown class") - } - } -} - -impl From for u8 { - fn from(other: CharacterClass) -> u8 { - match other { - CharacterClass::HUmar => 0, - CharacterClass::HUnewearl => 1, - CharacterClass::HUcast => 2, - CharacterClass::RAmar => 3, - CharacterClass::RAcast => 4, - CharacterClass::RAcaseal => 5, - CharacterClass::FOmarl => 6, - CharacterClass::FOnewm => 7, - CharacterClass::FOnewearl => 8, - CharacterClass::HUcaseal => 9, - CharacterClass::FOmar => 10, - CharacterClass::RAmarl => 11, - } - } -} - -impl CharacterClass { - pub fn is_human(&self) -> bool { - matches!(self, - CharacterClass::HUmar | - CharacterClass::RAmar | - CharacterClass::RAmarl | - CharacterClass::FOmar | - CharacterClass::FOmarl) - } - - pub fn is_newman(&self) -> bool { - matches!(self, - CharacterClass::HUnewearl | - CharacterClass::FOnewm | - CharacterClass::FOnewearl) - } - - pub fn is_android(&self) -> bool { - matches!(self, - CharacterClass::HUcast | - CharacterClass::HUcaseal | - CharacterClass::RAcast | - CharacterClass::RAcaseal) - } -} - - -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, enum_utils::FromStr, derive_more::Display, Serialize, Deserialize, Default)] -pub enum SectionID { - #[default] - Viridia, - Greenill, - Skyly, - Bluefull, - Purplenum, - Pinkal, - Redria, - Oran, - Yellowboze, - Whitill, -} - -impl From for SectionID { - fn from(id: u8) -> SectionID { - match id { - 0 => SectionID::Viridia, - 1 => SectionID::Greenill, - 2 => SectionID::Skyly, - 3 => SectionID::Bluefull, - 4 => SectionID::Purplenum, - 5 => SectionID::Pinkal, - 6 => SectionID::Redria, - 7 => SectionID::Oran, - 8 => SectionID::Yellowboze, - 9 => SectionID::Whitill, - _ => panic!(), - } - } -} - -impl From for u8 { - fn from(other: SectionID) -> u8 { - match other { - SectionID::Viridia => 0, - SectionID::Greenill => 1, - SectionID::Skyly => 2, - SectionID::Bluefull => 3, - SectionID::Purplenum => 4, - SectionID::Pinkal => 5, - SectionID::Redria => 6, - SectionID::Oran => 7, - SectionID::Yellowboze => 8, - SectionID::Whitill => 9, - } - } -} - #[derive(Clone, Debug, Default)] pub struct CharacterAppearance { diff --git a/src/entity/src/gateway/postgres/models.rs b/src/entity/src/gateway/postgres/models.rs index a7cfe94..ca9c05d 100644 --- a/src/entity/src/gateway/postgres/models.rs +++ b/src/entity/src/gateway/postgres/models.rs @@ -6,6 +6,7 @@ use libpso::character::settings; use libpso::util::vec_to_array; use crate::account::*; use crate::character::*; +use libpso::character::{CharacterClass, SectionID}; use crate::item::*; use crate::room::*; use maps::area::MapArea; diff --git a/src/entity/src/item/mag.rs b/src/entity/src/item/mag.rs index 45d424a..acb1fd8 100644 --- a/src/entity/src/item/mag.rs +++ b/src/entity/src/item/mag.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use thiserror::Error; use serde::{Serialize, Deserialize}; +use libpso::character::{CharacterClass, SectionID}; use crate::item::tool::ToolType; -use crate::character::{CharacterClass, SectionID}; use crate::item::ItemEntityId; use std::io::Read; diff --git a/src/entity/src/room.rs b/src/entity/src/room.rs index 30d3b6b..8314923 100644 --- a/src/entity/src/room.rs +++ b/src/entity/src/room.rs @@ -1,7 +1,8 @@ use serde::{Serialize, Deserialize}; -use crate::character::{CharacterEntityId, SectionID}; +use crate::character::CharacterEntityId; +use libpso::character::SectionID; use maps::room::{Episode, Difficulty}; diff --git a/src/login_server/src/character.rs b/src/login_server/src/character.rs index 3bce346..a5cbc3b 100644 --- a/src/login_server/src/character.rs +++ b/src/login_server/src/character.rs @@ -13,6 +13,7 @@ use libpso::packet::ship::{MenuDetail, SmallLeftDialog}; use libpso::{PacketParseError, PSOPacket}; use libpso::crypto::bb::PSOBBCipher; use libpso::character::character; +use libpso::character::CharacterClass; use entity::item; use networking::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; @@ -29,7 +30,7 @@ use entity::item::armor::Armor; use entity::item::tech::Technique; use entity::item::tool::Tool; use entity::item::mag::Mag; -use entity::character::{CharacterEntity, NewCharacterEntity, CharacterClass, TechLevel}; +use entity::character::{CharacterEntity, NewCharacterEntity, TechLevel}; use crate::login::get_login_status; use networking::interserver::AuthToken; diff --git a/src/room/Cargo.toml b/src/room/Cargo.toml index d081284..aca8478 100644 --- a/src/room/Cargo.toml +++ b/src/room/Cargo.toml @@ -10,6 +10,8 @@ quests = { workspace = true } location = { workspace = true } drops = { workspace = true } +libpso = { workspace = true } + rand = { workspace = true } async-std = { workspace = true } futures = { workspace = true } diff --git a/src/room/src/lib.rs b/src/room/src/lib.rs index fca3669..4df425d 100644 --- a/src/room/src/lib.rs +++ b/src/room/src/lib.rs @@ -10,7 +10,7 @@ use rand::Rng; use quests::{QuestList, QuestLoadError}; use maps::maps::Maps; use drops::DropTable; -use entity::character::SectionID; +use libpso::character::SectionID; use entity::room::{RoomEntityId, RoomEntityMode}; use maps::monster::{load_monster_stats_table, MonsterType, MonsterStats}; use maps::area::MapAreaLookup; diff --git a/src/ship_server/src/lib.rs b/src/ship_server/src/lib.rs index f6d0ed1..5a2995c 100644 --- a/src/ship_server/src/lib.rs +++ b/src/ship_server/src/lib.rs @@ -30,7 +30,7 @@ use networking::serverstate::{SendServerPacket, RecvServerPacket, ServerState, O use networking::interserver::{AuthToken, Ship, ServerId, InterserverActor, LoginMessage, ShipMessage}; use pktbuilder::ship::SHIP_MENU_ID; use entity::gateway::{EntityGateway, GatewayError}; -use entity::character::SectionID; +use libpso::character::SectionID; use entity::room::RoomNote; use location::{ClientLocation, RoomLobby, ClientLocationError, RoomId}; use drops::{DropTable, StandardDropTable}; diff --git a/src/ship_server/src/room.rs b/src/ship_server/src/room.rs index 73bdb39..0ab96f1 100644 --- a/src/ship_server/src/room.rs +++ b/src/ship_server/src/room.rs @@ -8,7 +8,7 @@ use libpso::packet::messages::*; use networking::serverstate::ClientId; use stats::leveltable::LEVEL_TABLE; use entity::gateway::EntityGateway; -use entity::character::SectionID; +use libpso::character::SectionID; use entity::room::{NewRoomEntity, RoomEntityMode, RoomNote}; use drops::DropTable; use crate::SendShipPacket; diff --git a/src/shops/Cargo.toml b/src/shops/Cargo.toml index 25e3055..7fdf29a 100644 --- a/src/shops/Cargo.toml +++ b/src/shops/Cargo.toml @@ -8,6 +8,8 @@ maps = { workspace = true } stats = { workspace = true } entity = { workspace = true } +libpso = { workspace = true } + async-std = { workspace = true } async-trait = { workspace = true } futures = { workspace = true } diff --git a/src/shops/src/lib.rs b/src/shops/src/lib.rs index 94abdec..3f4b411 100644 --- a/src/shops/src/lib.rs +++ b/src/shops/src/lib.rs @@ -7,7 +7,7 @@ use futures::future::OptionFuture; use std::collections::HashMap; use entity::item::ItemDetail; use maps::room::Difficulty; -use entity::character::SectionID; +use libpso::character::SectionID; pub use weapon::{WeaponShop, WeaponShopItem}; pub use tool::{ToolShop, ToolShopItem}; diff --git a/src/shops/src/weapon.rs b/src/shops/src/weapon.rs index 06a8c1e..3522645 100644 --- a/src/shops/src/weapon.rs +++ b/src/shops/src/weapon.rs @@ -8,7 +8,7 @@ use serde::Deserialize; use rand::{Rng, SeedableRng}; use rand::distributions::{WeightedIndex, Distribution}; use rand::seq::{SliceRandom, IteratorRandom}; -use entity::character::SectionID; +use libpso::character::SectionID; use maps::room::Difficulty; use entity::item::ItemDetail; use entity::item::weapon::{Weapon, WeaponType, WeaponSpecial, Attribute, WeaponAttribute}; diff --git a/src/stats/Cargo.toml b/src/stats/Cargo.toml index 6cebc62..fbde53f 100644 --- a/src/stats/Cargo.toml +++ b/src/stats/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +libpso = { workspace = true } entity = { workspace = true } toml = { workspace = true } serde = { workspace = true } diff --git a/src/stats/src/leveltable.rs b/src/stats/src/leveltable.rs index 7b06966..f5f64e3 100644 --- a/src/stats/src/leveltable.rs +++ b/src/stats/src/leveltable.rs @@ -1,6 +1,6 @@ use std::fs::File; use serde_json::Value; -use entity::character::CharacterClass; +use libpso::character::CharacterClass; use std::sync::LazyLock; pub static LEVEL_TABLE: LazyLock = LazyLock::new(CharacterLevelTable::default); diff --git a/tests/common.rs b/tests/common.rs index 31f373e..c8836ca 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -3,7 +3,8 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::EntityGateway; use entity::account::{UserAccountEntity, NewUserAccountEntity, NewUserSettingsEntity}; -use entity::character::{CharacterEntity, NewCharacterEntity, SectionID}; +use entity::character::{CharacterEntity, NewCharacterEntity}; +use libpso::character::SectionID; use entity::item::{Meseta, BankIdentifier}; use ship_server::{ShipServerState, ShipServerStateBuilder, RecvShipPacket}; use maps::room::{RoomMode, Difficulty, Episode}; diff --git a/tests/test_mags.rs b/tests/test_mags.rs index 8ffc6a9..ca8a601 100644 --- a/tests/test_mags.rs +++ b/tests/test_mags.rs @@ -2,7 +2,7 @@ use networking::serverstate::{ClientId, ServerState}; use entity::gateway::{EntityGateway, InMemoryGateway}; use entity::item; use ship_server::RecvShipPacket; -use entity::character::{CharacterClass, SectionID}; +use libpso::character::{CharacterClass, SectionID}; use libpso::packet::ship::*; use libpso::packet::messages::*;