From d158ac1d7f20b5cd05f627e01eb21cda3368190a Mon Sep 17 00:00:00 2001 From: jake Date: Fri, 10 Nov 2023 21:37:23 -0700 Subject: [PATCH] break out entity and maps into separate crates --- Cargo.toml | 48 +++- common/Cargo.toml | 8 + common/src/lib.rs | 0 entity/Cargo.toml | 57 +++++ {src/entity => entity/src}/account.rs | 0 {src/entity => entity/src}/character.rs | 4 +- .../src}/gateway/entitygateway.rs | 8 +- .../entity => entity/src}/gateway/inmemory.rs | 10 +- {src/entity => entity/src}/gateway/mod.rs | 0 .../postgres/migrations/V0001__initial.sql | 0 .../postgres/migrations/V0002__equips.sql | 0 .../postgres/migrations/V0003__item_notes.sql | 0 .../postgres/migrations/V0004__meseta.sql | 0 .../postgres/migrations/V0005__trade.sql | 0 .../postgres/migrations/V0006__playtime.sql | 0 .../migrations/V0007__player_keyconfig.sql | 0 .../migrations/V0008__playtime_not_null.sql | 0 .../migrations/V0009__no_player_keyconfig.sql | 0 .../V0010__char_create_timestamp.sql | 0 .../migrations/V0011__shared_bank.sql | 0 .../postgres/migrations/V0012__room.sql | 0 .../postgres/migrations/V0013__room2.sql | 0 entity/src/gateway/postgres/migrations/mod.rs | 3 + .../src}/gateway/postgres/mod.rs | 0 .../src}/gateway/postgres/models.rs | 14 +- .../src}/gateway/postgres/postgres.rs | 14 +- {src/entity => entity/src}/item/armor.rs | 2 +- {src/entity => entity/src}/item/esweapon.rs | 0 {src/entity => entity/src}/item/mag.rs | 8 +- {src/entity => entity/src}/item/mod.rs | 30 +-- {src/entity => entity/src}/item/shield.rs | 0 {src/entity => entity/src}/item/tech.rs | 0 {src/entity => entity/src}/item/tool.rs | 0 {src/entity => entity/src}/item/unit.rs | 0 {src/entity => entity/src}/item/weapon.rs | 2 +- src/entity/mod.rs => entity/src/lib.rs | 0 {src/entity => entity/src}/room.rs | 4 +- entity/src/team.rs | 31 +++ maps/Cargo.toml | 15 ++ {src/ship/map => maps/src}/area.rs | 2 +- {src/ship/map => maps/src}/enemy.rs | 43 ++-- maps/src/lib.rs | 7 + {src/ship/map => maps/src}/maps.rs | 18 +- maps/src/monster.rs | 212 ++++++++++++++++++ {src/ship/map => maps/src}/object.rs | 8 +- maps/src/room.rs | 150 +++++++++++++ {src/ship/map => maps/src}/variant.rs | 3 +- networking/Cargo.toml | 4 + networking/src/lib.rs | 0 src/bin/login.rs | 2 +- src/bin/main.rs | 10 +- src/bin/ship.rs | 2 +- src/common/interserver.rs | 4 +- src/common/leveltable.rs | 2 +- src/common/mainloop/interserver.rs | 3 +- src/entity/gateway/postgres/migrations/mod.rs | 3 - src/lib.rs | 2 +- src/login/character.rs | 44 ++-- src/login/login.rs | 29 +-- src/ship/character.rs | 4 +- src/ship/chatcommand.rs | 4 +- src/ship/client.rs | 8 +- src/ship/drops/box_drop_table.rs | 12 +- src/ship/drops/generic_armor.rs | 10 +- src/ship/drops/generic_shield.rs | 10 +- src/ship/drops/generic_unit.rs | 10 +- src/ship/drops/generic_weapon.rs | 10 +- src/ship/drops/mod.rs | 46 ++-- src/ship/drops/rare_drop_table.rs | 20 +- src/ship/drops/tech_table.rs | 8 +- src/ship/drops/tool_table.rs | 12 +- src/ship/item_stats.rs | 14 +- src/ship/items/actions.rs | 16 +- src/ship/items/apply_item.rs | 14 +- src/ship/items/bank.rs | 6 +- src/ship/items/floor.rs | 8 +- src/ship/items/inventory.rs | 10 +- src/ship/items/state.rs | 12 +- src/ship/items/tasks.rs | 14 +- src/ship/map/mod.rs | 12 - src/ship/mod.rs | 4 +- src/ship/packet/builder/message.rs | 2 +- src/ship/packet/handler/auth.rs | 2 +- src/ship/packet/handler/communication.rs | 2 +- src/ship/packet/handler/direct_message.rs | 4 +- src/ship/packet/handler/lobby.rs | 6 +- src/ship/packet/handler/message.rs | 4 +- src/ship/packet/handler/quest.rs | 4 +- src/ship/packet/handler/room.rs | 24 +- src/ship/packet/handler/settings.rs | 2 +- src/ship/packet/handler/trade.rs | 4 +- src/ship/quests.rs | 11 +- src/ship/room.rs | 168 +------------- src/ship/ship.rs | 143 ++++++------ src/ship/shops/armor.rs | 8 +- src/ship/shops/mod.rs | 2 +- src/ship/shops/tool.rs | 6 +- src/ship/shops/weapon.rs | 8 +- tests/common.rs | 12 +- tests/test_bank.rs | 4 +- tests/test_character.rs | 2 +- tests/test_exp_gain.rs | 12 +- tests/test_item_actions.rs | 4 +- tests/test_item_drop.rs | 15 +- tests/test_item_id.rs | 6 +- tests/test_item_pickup.rs | 4 +- tests/test_item_use.rs | 6 +- tests/test_mags.rs | 6 +- tests/test_rooms.rs | 4 +- tests/test_shops.rs | 6 +- tests/test_trade.rs | 10 +- 111 files changed, 989 insertions(+), 572 deletions(-) create mode 100644 common/Cargo.toml create mode 100644 common/src/lib.rs create mode 100644 entity/Cargo.toml rename {src/entity => entity/src}/account.rs (100%) rename {src/entity => entity/src}/character.rs (98%) rename {src/entity => entity/src}/gateway/entitygateway.rs (98%) rename {src/entity => entity/src}/gateway/inmemory.rs (99%) rename {src/entity => entity/src}/gateway/mod.rs (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0001__initial.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0002__equips.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0003__item_notes.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0004__meseta.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0005__trade.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0006__playtime.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0007__player_keyconfig.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0008__playtime_not_null.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0009__no_player_keyconfig.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0010__char_create_timestamp.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0011__shared_bank.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0012__room.sql (100%) rename {src/entity => entity/src}/gateway/postgres/migrations/V0013__room2.sql (100%) create mode 100644 entity/src/gateway/postgres/migrations/mod.rs rename {src/entity => entity/src}/gateway/postgres/mod.rs (100%) rename {src/entity => entity/src}/gateway/postgres/models.rs (99%) rename {src/entity => entity/src}/gateway/postgres/postgres.rs (99%) rename {src/entity => entity/src}/item/armor.rs (99%) rename {src/entity => entity/src}/item/esweapon.rs (100%) rename {src/entity => entity/src}/item/mag.rs (99%) rename {src/entity => entity/src}/item/mod.rs (84%) rename {src/entity => entity/src}/item/shield.rs (100%) rename {src/entity => entity/src}/item/tech.rs (100%) rename {src/entity => entity/src}/item/tool.rs (100%) rename {src/entity => entity/src}/item/unit.rs (100%) rename {src/entity => entity/src}/item/weapon.rs (99%) rename src/entity/mod.rs => entity/src/lib.rs (100%) rename {src/entity => entity/src}/room.rs (93%) create mode 100644 entity/src/team.rs create mode 100644 maps/Cargo.toml rename {src/ship/map => maps/src}/area.rs (99%) rename {src/ship/map => maps/src}/enemy.rs (93%) create mode 100644 maps/src/lib.rs rename {src/ship/map => maps/src}/maps.rs (97%) create mode 100644 maps/src/monster.rs rename {src/ship/map => maps/src}/object.rs (98%) create mode 100644 maps/src/room.rs rename {src/ship/map => maps/src}/variant.rs (99%) create mode 100644 networking/Cargo.toml create mode 100644 networking/src/lib.rs delete mode 100644 src/entity/gateway/postgres/migrations/mod.rs delete mode 100644 src/ship/map/mod.rs diff --git a/Cargo.toml b/Cargo.toml index c2e511d..7561e6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,20 @@ version = "0.1.0" authors = ["Jake Probst "] edition = "2021" -[dependencies] +[workspace] +members = [ + "entity", + "maps", + "common", + "networking", +] + +[workspace.dependencies] libpso = { git = "http://git.sharnoth.com/jake/libpso" } +entity = { path = "./entity" } +maps = { path = "./maps" } +common = { path = "./common" } +networking = { path = "./networking" } async-std = { version = "1.9.0", features = ["unstable", "attributes"] } futures = "0.3.5" rand = "0.7.3" @@ -33,3 +45,37 @@ sqlx = { version = "0.6.2", features = ["runtime-async-std-native-tls", "postgre strum = "0.19.5" strum_macros = "0.19" anyhow = { version = "1.0.68", features = ["backtrace"] } + +[dependencies] +libpso = { git = "http://git.sharnoth.com/jake/libpso" } +entity = { path = "./entity" } +maps = { path = "./maps" } +common = { path = "./common" } +networking = { path = "./networking" } +async-std = { version = "1.9.0", features = ["unstable", "attributes"] } +futures = "0.3.5" +rand = "0.7.3" +rand_chacha = "0.2.2" +crc = "^1.0.0" +bcrypt = "0.10" +chrono = { workspace = true } +serde = "*" +serde_json = "*" +ron = "*" +toml = "*" +log = "*" +fern = { version = "0.5", features = ["colored"] } +byteorder = "1" +enum-utils = "0.1.2" +derive_more = { version = "0.99.3", features = ["display"]} +thiserror = "1.0.37" +ages-prs = "0.1" +async-trait = "0.1.51" +async-recursion= "1.0.0" +lazy_static = "1.4.0" +barrel = { version = "0.6.5", features = ["pg"] } +refinery = { version = "0.5.0", features = ["postgres"] } +#sqlx = { version = "0.6.2", features = ["runtime-async-std-native-tls", "postgres", "json", "chrono"] } +strum = "0.19.5" +strum_macros = "0.19" +anyhow = { workspace = true } \ No newline at end of file diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..552f659 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "common" +version = "0.1.0" +edition = "2021" + + +[dependencies] +derive_more = { workspace = true } \ No newline at end of file diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/entity/Cargo.toml b/entity/Cargo.toml new file mode 100644 index 0000000..6603cbb --- /dev/null +++ b/entity/Cargo.toml @@ -0,0 +1,57 @@ +[package] +name = "entity" +version = "0.1.0" +edition = "2021" + +[dependencies] +libpso = { workspace = true } +maps = { workspace = true } +chrono = { workspace = true } +anyhow = { workspace = true } +async-std = { workspace = true } +sqlx = { workspace = true } +thiserror = { workspace = true } +serde = { workspace = true } +async-trait = { workspace = true } +enum-utils = { workspace = true } +derive_more = { workspace = true } +refinery = { workspace = true } +lazy_static = { workspace = true } +futures = { workspace = true } +strum = { workspace = true } +strum_macros = { workspace = true } +toml = { workspace = true } + + +#libpso = { git = "http://git.sharnoth.com/jake/libpso" } +#async-std = { version = "1.9.0", features = ["unstable", "attributes"] } +#futures = "0.3.5" +#rand = "0.7.3" +#rand_chacha = "0.2.2" +#crc = "^1.0.0" +#bcrypt = "0.10" +#chrono = "0.4.11" +#serde = "*" +#serde_json = "*" +#ron = "*" +#toml = "*" +#log = "*" +#fern = { version = "0.5", features = ["colored"] } +#byteorder = "1" +#enum-utils = "0.1.2" +#derive_more = { version = "0.99.3", features = ["display"]} +#thiserror = "1.0.37" +#ages-prs = "0.1" +#async-trait = "0.1.51" +#async-recursion= "1.0.0" +#lazy_static = "1.4.0" +#barrel = { version = "0.6.5", features = ["pg"] } +#refinery = { version = "0.5.0", features = ["postgres"] } +#sqlx = { version = "0.6.2", features = ["runtime-async-std-native-tls", "postgres", "json", "chrono"] } +#strum = "0.19.5" +#strum_macros = "0.19" +#anyhow = { version = "1.0.68", features = ["backtrace"] } + +#[lib] +#name = "entity" +#path = "lib.rs" \ No newline at end of file diff --git a/src/entity/account.rs b/entity/src/account.rs similarity index 100% rename from src/entity/account.rs rename to entity/src/account.rs diff --git a/src/entity/character.rs b/entity/src/character.rs similarity index 98% rename from src/entity/character.rs rename to entity/src/character.rs index 080bb1b..643e009 100644 --- a/src/entity/character.rs +++ b/entity/src/character.rs @@ -4,8 +4,8 @@ use serde::{Serialize, Deserialize}; use libpso::packet::ship::{UpdateConfig, WriteInfoboard}; use libpso::character::settings::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU}; -use crate::entity::item::tech::Technique; -use crate::entity::account::UserAccountId; +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 { diff --git a/src/entity/gateway/entitygateway.rs b/entity/src/gateway/entitygateway.rs similarity index 98% rename from src/entity/gateway/entitygateway.rs rename to entity/src/gateway/entitygateway.rs index df922ac..4f7ae67 100644 --- a/src/entity/gateway/entitygateway.rs +++ b/entity/src/gateway/entitygateway.rs @@ -1,10 +1,10 @@ use thiserror::Error; use futures::future::{Future, BoxFuture}; -use crate::entity::account::*; -use crate::entity::character::*; -use crate::entity::item::*; -use crate::entity::room::*; +use crate::account::*; +use crate::character::*; +use crate::item::*; +use crate::room::*; // TODO: better granularity? diff --git a/src/entity/gateway/inmemory.rs b/entity/src/gateway/inmemory.rs similarity index 99% rename from src/entity/gateway/inmemory.rs rename to entity/src/gateway/inmemory.rs index 50a650e..970beed 100644 --- a/src/entity/gateway/inmemory.rs +++ b/entity/src/gateway/inmemory.rs @@ -2,11 +2,11 @@ use std::collections::BTreeMap; use std::convert::TryInto; use futures::future::{Future, BoxFuture}; -use crate::entity::account::*; -use crate::entity::character::*; -use crate::entity::gateway::{EntityGateway, EntityGatewayTransaction, GatewayError}; -use crate::entity::item::*; -use crate::entity::room::*; +use crate::account::*; +use crate::character::*; +use crate::gateway::{EntityGateway, EntityGatewayTransaction, GatewayError}; +use crate::item::*; +use crate::room::*; use async_std::sync::{Arc, Mutex}; diff --git a/src/entity/gateway/mod.rs b/entity/src/gateway/mod.rs similarity index 100% rename from src/entity/gateway/mod.rs rename to entity/src/gateway/mod.rs diff --git a/src/entity/gateway/postgres/migrations/V0001__initial.sql b/entity/src/gateway/postgres/migrations/V0001__initial.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0001__initial.sql rename to entity/src/gateway/postgres/migrations/V0001__initial.sql diff --git a/src/entity/gateway/postgres/migrations/V0002__equips.sql b/entity/src/gateway/postgres/migrations/V0002__equips.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0002__equips.sql rename to entity/src/gateway/postgres/migrations/V0002__equips.sql diff --git a/src/entity/gateway/postgres/migrations/V0003__item_notes.sql b/entity/src/gateway/postgres/migrations/V0003__item_notes.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0003__item_notes.sql rename to entity/src/gateway/postgres/migrations/V0003__item_notes.sql diff --git a/src/entity/gateway/postgres/migrations/V0004__meseta.sql b/entity/src/gateway/postgres/migrations/V0004__meseta.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0004__meseta.sql rename to entity/src/gateway/postgres/migrations/V0004__meseta.sql diff --git a/src/entity/gateway/postgres/migrations/V0005__trade.sql b/entity/src/gateway/postgres/migrations/V0005__trade.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0005__trade.sql rename to entity/src/gateway/postgres/migrations/V0005__trade.sql diff --git a/src/entity/gateway/postgres/migrations/V0006__playtime.sql b/entity/src/gateway/postgres/migrations/V0006__playtime.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0006__playtime.sql rename to entity/src/gateway/postgres/migrations/V0006__playtime.sql diff --git a/src/entity/gateway/postgres/migrations/V0007__player_keyconfig.sql b/entity/src/gateway/postgres/migrations/V0007__player_keyconfig.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0007__player_keyconfig.sql rename to entity/src/gateway/postgres/migrations/V0007__player_keyconfig.sql diff --git a/src/entity/gateway/postgres/migrations/V0008__playtime_not_null.sql b/entity/src/gateway/postgres/migrations/V0008__playtime_not_null.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0008__playtime_not_null.sql rename to entity/src/gateway/postgres/migrations/V0008__playtime_not_null.sql diff --git a/src/entity/gateway/postgres/migrations/V0009__no_player_keyconfig.sql b/entity/src/gateway/postgres/migrations/V0009__no_player_keyconfig.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0009__no_player_keyconfig.sql rename to entity/src/gateway/postgres/migrations/V0009__no_player_keyconfig.sql diff --git a/src/entity/gateway/postgres/migrations/V0010__char_create_timestamp.sql b/entity/src/gateway/postgres/migrations/V0010__char_create_timestamp.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0010__char_create_timestamp.sql rename to entity/src/gateway/postgres/migrations/V0010__char_create_timestamp.sql diff --git a/src/entity/gateway/postgres/migrations/V0011__shared_bank.sql b/entity/src/gateway/postgres/migrations/V0011__shared_bank.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0011__shared_bank.sql rename to entity/src/gateway/postgres/migrations/V0011__shared_bank.sql diff --git a/src/entity/gateway/postgres/migrations/V0012__room.sql b/entity/src/gateway/postgres/migrations/V0012__room.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0012__room.sql rename to entity/src/gateway/postgres/migrations/V0012__room.sql diff --git a/src/entity/gateway/postgres/migrations/V0013__room2.sql b/entity/src/gateway/postgres/migrations/V0013__room2.sql similarity index 100% rename from src/entity/gateway/postgres/migrations/V0013__room2.sql rename to entity/src/gateway/postgres/migrations/V0013__room2.sql diff --git a/entity/src/gateway/postgres/migrations/mod.rs b/entity/src/gateway/postgres/migrations/mod.rs new file mode 100644 index 0000000..fd67f6f --- /dev/null +++ b/entity/src/gateway/postgres/migrations/mod.rs @@ -0,0 +1,3 @@ +use refinery::include_migration_mods; + +include_migration_mods!("src/gateway/postgres/migrations"); diff --git a/src/entity/gateway/postgres/mod.rs b/entity/src/gateway/postgres/mod.rs similarity index 100% rename from src/entity/gateway/postgres/mod.rs rename to entity/src/gateway/postgres/mod.rs diff --git a/src/entity/gateway/postgres/models.rs b/entity/src/gateway/postgres/models.rs similarity index 99% rename from src/entity/gateway/postgres/models.rs rename to entity/src/gateway/postgres/models.rs index f3a2f39..13c2a6b 100644 --- a/src/entity/gateway/postgres/models.rs +++ b/entity/src/gateway/postgres/models.rs @@ -4,13 +4,13 @@ use std::convert::Into; use serde::{Serialize, Deserialize}; use libpso::character::settings; use libpso::util::vec_to_array; -use crate::entity::account::*; -use crate::entity::character::*; -use crate::entity::item::*; -use crate::entity::room::*; -use crate::ship::map::MapArea; -use crate::ship::room::{Episode, Difficulty}; -use crate::ship::monster::MonsterType; +use crate::account::*; +use crate::character::*; +use crate::item::*; +use crate::room::*; +use maps::area::MapArea; +use maps::room::{Episode, Difficulty}; +use maps::monster::MonsterType; #[derive(Debug, sqlx::FromRow)] pub struct PgUserAccount { diff --git a/src/entity/gateway/postgres/postgres.rs b/entity/src/gateway/postgres/postgres.rs similarity index 99% rename from src/entity/gateway/postgres/postgres.rs rename to entity/src/gateway/postgres/postgres.rs index c31217f..f1219ba 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/entity/src/gateway/postgres/postgres.rs @@ -1,16 +1,16 @@ // this lint is currently bugged and suggests incorrect code https://github.com/rust-lang/rust-clippy/issues/9123 #![allow(clippy::explicit_auto_deref)] -use std::convert::{From, TryFrom, Into}; +use std::convert::{From, Into}; use futures::future::{Future, BoxFuture}; use futures::stream::{StreamExt, FuturesOrdered}; use async_std::sync::{Arc, Mutex}; use libpso::character::guildcard; -use crate::entity::account::*; -use crate::entity::character::*; -use crate::entity::gateway::{EntityGateway, EntityGatewayTransaction, GatewayError}; -use crate::entity::item::*; -use crate::entity::room::*; +use crate::account::*; +use crate::character::*; +use crate::gateway::{EntityGateway, EntityGatewayTransaction, GatewayError}; +use crate::item::*; +use crate::room::*; use super::models::*; use sqlx::postgres::PgPoolOptions; @@ -19,7 +19,7 @@ use sqlx::Connection; mod embedded { use refinery::embed_migrations; - embed_migrations!("src/entity/gateway/postgres/migrations"); + embed_migrations!("src/gateway/postgres/migrations"); } diff --git a/src/entity/item/armor.rs b/entity/src/item/armor.rs similarity index 99% rename from src/entity/item/armor.rs rename to entity/src/item/armor.rs index 45e9ed4..bd0cc48 100644 --- a/src/entity/item/armor.rs +++ b/entity/src/item/armor.rs @@ -1,5 +1,5 @@ use serde::{Serialize, Deserialize}; -use crate::entity::item::ItemEntityId; +use crate::item::ItemEntityId; #[derive(Debug, Copy, Clone)] pub enum ItemParseError { diff --git a/src/entity/item/esweapon.rs b/entity/src/item/esweapon.rs similarity index 100% rename from src/entity/item/esweapon.rs rename to entity/src/item/esweapon.rs diff --git a/src/entity/item/mag.rs b/entity/src/item/mag.rs similarity index 99% rename from src/entity/item/mag.rs rename to entity/src/item/mag.rs index 17fa1b4..45d424a 100644 --- a/src/entity/item/mag.rs +++ b/entity/src/item/mag.rs @@ -1,9 +1,9 @@ -use thiserror::Error; use std::collections::HashMap; +use thiserror::Error; use serde::{Serialize, Deserialize}; -use crate::entity::item::tool::ToolType; -use crate::entity::character::{CharacterClass, SectionID}; -use crate::entity::item::ItemEntityId; +use crate::item::tool::ToolType; +use crate::character::{CharacterClass, SectionID}; +use crate::item::ItemEntityId; use std::io::Read; use std::cmp::Ordering::{Less, Greater, Equal}; diff --git a/src/entity/item/mod.rs b/entity/src/item/mod.rs similarity index 84% rename from src/entity/item/mod.rs rename to entity/src/item/mod.rs index 7023f7c..d418579 100644 --- a/src/entity/item/mod.rs +++ b/entity/src/item/mod.rs @@ -9,11 +9,11 @@ pub mod mag; pub mod esweapon; use serde::{Serialize, Deserialize}; -use crate::entity::character::CharacterEntityId; -use crate::entity::room::RoomEntityId; -use crate::ship::map::MapArea; -use crate::ship::monster::MonsterType; -use crate::ship::drops::ItemDropType; +use crate::character::CharacterEntityId; +use crate::room::RoomEntityId; +use maps::area::MapArea; +use maps::monster::MonsterType; +//use crate::ship::drops::ItemDropType; #[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd, Ord, Serialize, Deserialize)] pub struct ItemEntityId(pub u32); @@ -156,26 +156,6 @@ impl ItemDetail { } } - pub fn parse_item_from_bytes(data: [u8; 16]) -> Option { - let item_type = weapon::WeaponType::parse_type([data[0],data[1],data[2]]).map(ItemType::Weapon) - .or_else(|_| armor::ArmorType::parse_type([data[0],data[1],data[2]]).map(ItemType::Armor)) - .or_else(|_| shield::ShieldType::parse_type([data[0],data[1],data[2]]).map(ItemType::Shield)) - .or_else(|_| unit::UnitType::parse_type([data[0],data[1],data[2]]).map(ItemType::Unit)) - .or_else(|_| mag::MagType::parse_type([data[0],data[1],data[2]]).map(ItemType::Mag)) - .or_else(|_| tool::ToolType::parse_type([data[0],data[1],data[2]]).map(ItemType::Tool)) - .or_else(|_| esweapon::ESWeaponType::parse_type([data[0],data[1],data[2]]).map(ItemType::ESWeapon)).ok()?; - - match item_type { - ItemType::Weapon(_w) => Some(ItemDropType::Weapon(weapon::Weapon::from_bytes(data).ok()?)), - ItemType::Armor(_a) => Some(ItemDropType::Armor(armor::Armor::from_bytes(data).ok()?)), - ItemType::Shield(_s) => Some(ItemDropType::Shield(shield::Shield::from_bytes(data).ok()?)), - ItemType::Unit(_u) => Some(ItemDropType::Unit(unit::Unit::from_bytes(data).ok()?)), - ItemType::Mag(_m) => Some(ItemDropType::Mag(mag::Mag::from_bytes(data).ok()?)), - ItemType::Tool(_t) => Some(ItemDropType::Tool(tool::Tool::from_bytes(data).ok()?)), - _ => None, - } - } - pub fn as_client_bytes(&self) -> [u8; 16] { match self { ItemDetail::Weapon(w) => w.as_bytes(), diff --git a/src/entity/item/shield.rs b/entity/src/item/shield.rs similarity index 100% rename from src/entity/item/shield.rs rename to entity/src/item/shield.rs diff --git a/src/entity/item/tech.rs b/entity/src/item/tech.rs similarity index 100% rename from src/entity/item/tech.rs rename to entity/src/item/tech.rs diff --git a/src/entity/item/tool.rs b/entity/src/item/tool.rs similarity index 100% rename from src/entity/item/tool.rs rename to entity/src/item/tool.rs diff --git a/src/entity/item/unit.rs b/entity/src/item/unit.rs similarity index 100% rename from src/entity/item/unit.rs rename to entity/src/item/unit.rs diff --git a/src/entity/item/weapon.rs b/entity/src/item/weapon.rs similarity index 99% rename from src/entity/item/weapon.rs rename to entity/src/item/weapon.rs index 29a9357..a5753d6 100644 --- a/src/entity/item/weapon.rs +++ b/entity/src/item/weapon.rs @@ -1,4 +1,4 @@ -use crate::entity::item::ItemEntityId; +use crate::item::ItemEntityId; use serde::{Serialize, Deserialize}; #[derive(Debug, Copy, Clone)] diff --git a/src/entity/mod.rs b/entity/src/lib.rs similarity index 100% rename from src/entity/mod.rs rename to entity/src/lib.rs diff --git a/src/entity/room.rs b/entity/src/room.rs similarity index 93% rename from src/entity/room.rs rename to entity/src/room.rs index a5eeea4..30d3b6b 100644 --- a/src/entity/room.rs +++ b/entity/src/room.rs @@ -1,8 +1,8 @@ use serde::{Serialize, Deserialize}; -use crate::entity::character::{CharacterEntityId, SectionID}; -use crate::ship::room::{Episode, Difficulty}; +use crate::character::{CharacterEntityId, SectionID}; +use maps::room::{Episode, Difficulty}; #[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd, Ord, Serialize, Deserialize)] diff --git a/entity/src/team.rs b/entity/src/team.rs new file mode 100644 index 0000000..2a5bfac --- /dev/null +++ b/entity/src/team.rs @@ -0,0 +1,31 @@ +use serde::{Serialize, Deserialize}; + +use super::account::UserAccountId; + +// [2022-10-23 00:11:18][elseware::common::mainloop::client][WARN] error RecvServerPacket::from_bytes: WrongPacketForServerType(490, [40, 0, 234, 1, 0, 0, 0, 0, 9, 0, 74, 0, 97, 0, 115, 0, 100, 0, 102, 0, 0, 0, 0, 0, 192, 52, 67, 3, 60, 159, 129, 0, 32, 64, 233, 10, 196, 156, 152, 0]) +// [2022-10-23 00:20:14][elseware::common::mainloop::client][WARN] error RecvServerPacket::from_bytes: WrongPacketForServerType(490, [40, 0, 234, 1, 0, 0, 0, 0, 9, 0, 74, 0, 97, 0, 97, 0, 97, 0, 97, 0, 97, 0, 97, 0, 97, 0, 97, 0, 97, 0, 97, 0, 97, 0, 97, 0, 0, 0, 152, 0]) + + +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct TeamEntityId(pub u32); + +pub struct NewTeamEntity { + pub created_by: UserAccountId, + pub name: String, +} + + +#[derive(Debug, Clone)] +pub struct TeamEntity { + pub id: TeamEntityId, + pub owner: UserAccountId, + pub name: String, + + pub team_flag: [u8; 2048], +} + + + + + + diff --git a/maps/Cargo.toml b/maps/Cargo.toml new file mode 100644 index 0000000..cf0401e --- /dev/null +++ b/maps/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "maps" +version = "0.1.0" +edition = "2021" + +[dependencies] +common = { workspace = true } +byteorder = { workspace = true } +serde = { workspace = true } +thiserror = { workspace = true } +rand = { workspace = true } +rand_chacha = { workspace = true } +toml = { workspace = true } +enum-utils = { workspace = true } +derive_more = { workspace = true } diff --git a/src/ship/map/area.rs b/maps/src/area.rs similarity index 99% rename from src/ship/map/area.rs rename to maps/src/area.rs index 02361c3..bb64737 100644 --- a/src/ship/map/area.rs +++ b/maps/src/area.rs @@ -2,7 +2,7 @@ use serde::{Serialize, Deserialize}; use std::collections::HashMap; use thiserror::Error; -use crate::ship::room::Episode; +use crate::room::Episode; use std::fmt; #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/src/ship/map/enemy.rs b/maps/src/enemy.rs similarity index 93% rename from src/ship/map/enemy.rs rename to maps/src/enemy.rs index 4989041..08e0f61 100644 --- a/src/ship/map/enemy.rs +++ b/maps/src/enemy.rs @@ -1,19 +1,24 @@ // TOOD: `pub(super) for most of these?` use std::io::{Read}; use std::collections::HashMap; +use std::fs::File; +use std::path::PathBuf; use byteorder::{LittleEndian, ReadBytesExt}; use thiserror::Error; - -use crate::ship::ship::ShipEvent; -use crate::ship::monster::MonsterType; -use crate::ship::room::Episode; - -use crate::ship::map::*; - use rand::{Rng, SeedableRng}; use serde::{Serialize, Deserialize}; -use crate::ship::drops::{load_rare_monster_file}; + +use crate::area::{MapArea, MapAreaError}; +use crate::room::Episode; +use crate::monster::MonsterType; + +#[derive(Clone, Copy)] +pub enum RareEnemyEvent { + Easter, + Halloween, + Christmas, +} #[derive(Debug, Copy, Clone)] pub struct RawMapEnemy { @@ -69,6 +74,17 @@ impl RawMapEnemy { } +pub fn load_rare_monster_file(episode: Episode) -> T { + // TODO: where does the rare monster toml file actually live + let mut path = PathBuf::from("data/battle_param/"); + path.push(episode.to_string().to_lowercase() + "_rare_monster.toml"); + + let mut f = File::open(path).unwrap(); + let mut s = String::new(); + f.read_to_string(&mut s); + toml::from_str::(s.as_str()).unwrap() +} + #[derive(Error, Debug)] #[error("")] pub enum MapEnemyError { @@ -76,6 +92,7 @@ pub enum MapEnemyError { MapAreaError(#[from] MapAreaError), } + // making this `pub type` doesn't allow `impl`s to be defined? #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RareMonsterAppearTable { @@ -103,7 +120,7 @@ impl RareMonsterAppearTable { rand_chacha::ChaChaRng::from_entropy().gen::() < *self.appear_rate.get(monster).unwrap_or(&0.0f32) } - pub fn apply(&self, enemy: MapEnemy, event: ShipEvent) -> MapEnemy { + pub fn apply(&self, enemy: MapEnemy, event: Option) -> MapEnemy { if enemy.can_be_rare() && self.roll_is_rare(&enemy.monster) { enemy.into_rare(event) } @@ -345,12 +362,12 @@ impl MapEnemy { guaranteed rare monsters don't count towards the limit */ #[must_use] - pub fn into_rare(self, event: ShipEvent) -> MapEnemy { + pub fn into_rare(self, event: Option) -> MapEnemy { match (self.monster, self.map_area.to_episode(), event) { (MonsterType::RagRappy, Episode::One, _) => {MapEnemy {monster: MonsterType::AlRappy, shiny:true, ..self}}, - (MonsterType::RagRappy, Episode::Two, ShipEvent::Easter) => {MapEnemy {monster: MonsterType::EasterRappy, shiny:true, ..self}}, - (MonsterType::RagRappy, Episode::Two, ShipEvent::Halloween) => {MapEnemy {monster: MonsterType::HalloRappy, shiny:true, ..self}}, - (MonsterType::RagRappy, Episode::Two, ShipEvent::Christmas) => {MapEnemy {monster: MonsterType::StRappy, shiny:true, ..self}}, + (MonsterType::RagRappy, Episode::Two, Some(RareEnemyEvent::Easter)) => {MapEnemy {monster: MonsterType::EasterRappy, shiny:true, ..self}}, + (MonsterType::RagRappy, Episode::Two, Some(RareEnemyEvent::Halloween)) => {MapEnemy {monster: MonsterType::HalloRappy, shiny:true, ..self}}, + (MonsterType::RagRappy, Episode::Two, Some(RareEnemyEvent::Christmas)) => {MapEnemy {monster: MonsterType::StRappy, shiny:true, ..self}}, (MonsterType::RagRappy, Episode::Two, _) => {MapEnemy {monster: MonsterType::LoveRappy, shiny:true, ..self}}, (MonsterType::Hildebear, _, _) => {MapEnemy {monster: MonsterType::Hildeblue, shiny:true, ..self}}, (MonsterType::PoisonLily, _, _) => {MapEnemy {monster: MonsterType::NarLily, shiny:true, ..self}}, diff --git a/maps/src/lib.rs b/maps/src/lib.rs new file mode 100644 index 0000000..fa2b60e --- /dev/null +++ b/maps/src/lib.rs @@ -0,0 +1,7 @@ +pub mod area; +pub mod enemy; +pub mod object; +pub mod variant; +pub mod maps; +pub mod monster; +pub mod room; diff --git a/src/ship/map/maps.rs b/maps/src/maps.rs similarity index 97% rename from src/ship/map/maps.rs rename to maps/src/maps.rs index 05c7e29..6684d52 100644 --- a/src/ship/map/maps.rs +++ b/maps/src/maps.rs @@ -6,14 +6,14 @@ use std::fs::File; use thiserror::Error; -use crate::ship::ship::ShipEvent; -use crate::ship::monster::MonsterType; -use crate::ship::room::{Episode, RoomMode, PlayerMode}; - -// TODO: don't use * -use crate::ship::map::*; - +//use crate::ship::ship::ShipEvent; +use crate::area::MapArea; +use crate::enemy::{MapEnemy, RawMapEnemy, RareEnemyEvent, RareMonsterAppearTable}; +use crate::monster::MonsterType; +use crate::variant::{MapVariant, MapVariantMode}; +use crate::object::{MapObject, RawMapObject}; +use crate::room::{Episode, RoomMode, PlayerMode}; pub fn objects_from_stream(cursor: &mut impl Read, episode: &Episode, map_area: &MapArea) -> Vec> { let mut object_data = Vec::new(); @@ -325,7 +325,7 @@ impl Maps { enemies: Vec>, objects: Vec>, rare_monster_table: &RareMonsterAppearTable, - event: ShipEvent) + event: Option) { self.enemy_data = enemies .into_iter() @@ -358,7 +358,7 @@ impl Maps { } } -pub fn generate_free_roam_maps(room_mode: RoomMode, event: ShipEvent) -> Maps { +pub fn generate_free_roam_maps(room_mode: RoomMode, event: Option) -> Maps { let rare_monster_table = RareMonsterAppearTable::new(room_mode.episode()); let map_variants = default_map_variants(room_mode.episode(), room_mode.player_mode()); Maps { diff --git a/maps/src/monster.rs b/maps/src/monster.rs new file mode 100644 index 0000000..a72288d --- /dev/null +++ b/maps/src/monster.rs @@ -0,0 +1,212 @@ +#![allow(dead_code)] +use std::collections::HashMap; +use std::fs::File; +use std::io::Read; +use std::path::PathBuf; +use serde::{Serialize, Deserialize}; +use crate::room::{Difficulty, Episode, RoomMode}; + + +#[derive(Debug)] +pub enum MonsterParseError { + UnknownMonster(String), +} + +pub struct MonsterStatError; + +#[derive(Debug, Serialize, Deserialize, Copy, Clone, Hash, Eq, PartialEq, enum_utils::FromStr, derive_more::Display)] +pub enum MonsterType { + Hildebear, + Hildeblue, + Mothmant, + Monest, + RagRappy, + AlRappy, + SavageWolf, + BarbarousWolf, + Booma, + Gobooma, + Gigobooma, + GrassAssassin, + PoisonLily, + NarLily, + NanoDragon, + EvilShark, + PalShark, + GuilShark, + PofuillySlime, + PouillySlime, + PanArms, + Hidoom, + Migium, + Dubchic, + Garanz, + SinowBeat, + SinowGold, + Canadine, + Canane, + RingCanadine, + Delsaber, + ChaosSorcerer, + BeeR, + BeeL, + DarkGunner, + DeathGunner, + ChaosBringer, + DarkBelra, + Claw, + Bulk, + Bulclaw, + Dimenian, + LaDimenian, + SoDimenian, + Dragon, + DeRolLe, + DeRolLeBody, + DeRolLeMine, + VolOptPartA, + VolOptPillar, + VolOptMonitor, + VolOptAmp, + VolOptCore, + VolOptUnused, + VolOpt, + VolOptTrap, + DarkFalz, + DarkFalz1, + DarkFalz2, + DarkFalz3, + Darvant, + UltDarvant, + Dubwitch, + Gillchic, + EventRappy, + Merillia, + Meriltas, + Gee, + GiGue, + Mericarol, + Merikle, + Mericus, + UlGibbon, + ZolGibbon, + Gibbles, + SinowBerill, + SinowSpigell, + Dolmolm, + Dolmdarl, + Morfos, + Recobox, + Recon, + SinowZoa, + SinowZele, + Deldepth, + Delbiter, + BarbaRay, + PigRay, + GolDragon, + GalGryphon, + OlgaFlow, + OlgaFlow1, + OlgaFlow2, + Gael, + Giel, + StRappy, + HalloRappy, + EasterRappy, + LoveRappy, + IllGill, + DelLily, + Epsilon, + Epsiguard, + Boota, + ZeBoota, + BaBoota, + SandRappyCrater, + SandRappyDesert, + ZuCrater, + PazuzuCrater, + Astark, + SatelliteLizardCrater, + YowieCrater, + Dorphon, + DorphonEclair, + Goran, + GoranDetonator, + PyroGoran, + DelRappyCrater, + DelRappyDesert, + MerissaA, + MerissaAA, + ZuDesert, + PazuzuDesert, + SatelliteLizardDesert, + YowieDesert, + Girtablulu, + SaintMillion, + Shambertin, + Kondrieu, +} + + +#[derive(Deserialize, Debug)] +pub struct MonsterStats { + pub atp: u16, + pub mst: u16, + pub evp: u16, + pub hp: u16, + pub dfp: u16, + pub ata: u16, + pub lck: u16, + pub esp: u16, + pub exp: u32, +} + +fn load_battle_param(filename: &str) -> HashMap { + let mut path = PathBuf::from("data/battle_param/"); + path.push(filename); + + let mut f = File::open(path).unwrap(); + let mut s = String::new(); + f.read_to_string(&mut s).unwrap(); + toml::from_str::>(s.as_str()).unwrap() + .into_iter() + .map(|(monster_name, stats)| { + (monster_name.parse().unwrap(), stats) + }).collect() +} + +pub fn load_monster_stats_table(mode: &RoomMode) -> Result, MonsterStatError> { + match mode { + RoomMode::Multi {episode: Episode::One, difficulty: Difficulty::Normal} => Ok(load_battle_param("ep1_multi_normal.toml")), + RoomMode::Multi {episode: Episode::One, difficulty: Difficulty::Hard} => Ok(load_battle_param("ep1_multi_hard.toml")), + RoomMode::Multi {episode: Episode::One, difficulty: Difficulty::VeryHard} => Ok(load_battle_param("ep1_multi_veryhard.toml")), + RoomMode::Multi {episode: Episode::One, difficulty: Difficulty::Ultimate} => Ok(load_battle_param("ep1_multi_ultimate.toml")), + + RoomMode::Multi {episode: Episode::Two, difficulty: Difficulty::Normal} => Ok(load_battle_param("ep2_multi_normal.toml")), + RoomMode::Multi {episode: Episode::Two, difficulty: Difficulty::Hard} => Ok(load_battle_param("ep2_multi_hard.toml")), + RoomMode::Multi {episode: Episode::Two, difficulty: Difficulty::VeryHard} => Ok(load_battle_param("ep2_multi_veryhard.toml")), + RoomMode::Multi {episode: Episode::Two, difficulty: Difficulty::Ultimate} => Ok(load_battle_param("ep2_multi_ultimate.toml")), + + RoomMode::Multi {episode: Episode::Four, difficulty: Difficulty::Normal} => Ok(load_battle_param("ep4_multi_normal.toml")), + RoomMode::Multi {episode: Episode::Four, difficulty: Difficulty::Hard} => Ok(load_battle_param("ep4_multi_hard.toml")), + RoomMode::Multi {episode: Episode::Four, difficulty: Difficulty::VeryHard} => Ok(load_battle_param("ep4_multi_veryhard.toml")), + RoomMode::Multi {episode: Episode::Four, difficulty: Difficulty::Ultimate} => Ok(load_battle_param("ep4_multi_ultimate.toml")), + + RoomMode::Single {episode: Episode::One, difficulty: Difficulty::Normal} => Ok(load_battle_param("ep1_solo_normal.toml")), + RoomMode::Single {episode: Episode::One, difficulty: Difficulty::Hard} => Ok(load_battle_param("ep1_solo_hard.toml")), + RoomMode::Single {episode: Episode::One, difficulty: Difficulty::VeryHard} => Ok(load_battle_param("ep1_solo_veryhard.toml")), + RoomMode::Single {episode: Episode::One, difficulty: Difficulty::Ultimate} => Ok(load_battle_param("ep1_solo_ultimate.toml")), + + RoomMode::Single {episode: Episode::Two, difficulty: Difficulty::Normal} => Ok(load_battle_param("ep2_solo_normal.toml")), + RoomMode::Single {episode: Episode::Two, difficulty: Difficulty::Hard} => Ok(load_battle_param("ep2_solo_hard.toml")), + RoomMode::Single {episode: Episode::Two, difficulty: Difficulty::VeryHard} => Ok(load_battle_param("ep2_solo_veryhard.toml")), + RoomMode::Single {episode: Episode::Two, difficulty: Difficulty::Ultimate} => Ok(load_battle_param("ep2_solo_ultimate.toml")), + + RoomMode::Single {episode: Episode::Four, difficulty: Difficulty::Normal} => Ok(load_battle_param("ep4_solo_normal.toml")), + RoomMode::Single {episode: Episode::Four, difficulty: Difficulty::Hard} => Ok(load_battle_param("ep4_solo_hard.toml")), + RoomMode::Single {episode: Episode::Four, difficulty: Difficulty::VeryHard} => Ok(load_battle_param("ep4_solo_veryhard.toml")), + RoomMode::Single {episode: Episode::Four, difficulty: Difficulty::Ultimate} => Ok(load_battle_param("ep4_solo_ultimate.toml")), + _ => Err(MonsterStatError), + } +} diff --git a/src/ship/map/object.rs b/maps/src/object.rs similarity index 98% rename from src/ship/map/object.rs rename to maps/src/object.rs index 81bce6a..0f73442 100644 --- a/src/ship/map/object.rs +++ b/maps/src/object.rs @@ -1,13 +1,11 @@ // TOOD: `pub(super) for most of these?` -use std::io::{Read}; +use std::io::Read; use byteorder::{LittleEndian, ReadBytesExt}; -use crate::ship::room::Episode; - -// TODO: don't use * -use crate::ship::map::*; +use crate::room::Episode; +use crate::area::MapArea; #[derive(Debug, Copy, Clone)] diff --git a/maps/src/room.rs b/maps/src/room.rs new file mode 100644 index 0000000..8370e7c --- /dev/null +++ b/maps/src/room.rs @@ -0,0 +1,150 @@ +#[derive(Debug, Copy, Clone, derive_more::Display)] +pub enum Episode { + #[display(fmt="ep1")] + One, + #[display(fmt="ep2")] + Two, + #[display(fmt="ep4")] + Four, +} + +impl TryFrom for Episode { + type Error = (); + + fn try_from(value: u8) -> Result { + match value { + 1 => Ok(Episode::One), + 2 => Ok(Episode::Two), + 3 => Ok(Episode::Four), + _ => Err(()) + } + } +} + +impl From for u8 { + fn from(other: Episode) -> u8 { + match other { + Episode::One => 1, + Episode::Two => 2, + Episode::Four => 3, + } + } +} + +impl Episode { + pub fn from_quest(value: u8) -> Option { + match value { + 0 => Some(Episode::One), + 1 => Some(Episode::Two), + 2 => Some(Episode::Four), + _ => None, + } + } +} + +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, derive_more::Display)] +pub enum Difficulty { + Normal, + Hard, + VeryHard, + Ultimate, +} + +impl TryFrom for Difficulty { + type Error = (); + + fn try_from(value: u8) -> Result { + match value { + 0 => Ok(Difficulty::Normal), + 1 => Ok(Difficulty::Hard), + 2 => Ok(Difficulty::VeryHard), + 3 => Ok(Difficulty::Ultimate), + _ => Err(()) + } + } +} + +impl From for u8 { + fn from(other: Difficulty) -> u8 { + match other { + Difficulty::Normal => 0, + Difficulty::Hard => 1, + Difficulty::VeryHard => 2, + Difficulty::Ultimate => 3, + } + } +} + +#[derive(Debug, Copy, Clone)] +pub enum PlayerMode { + Single, + Multi, +} + +impl PlayerMode { + pub fn value(&self) -> u8 { + match self { + PlayerMode::Single => 1, + PlayerMode::Multi => 0, + } + } +} + +#[derive(Debug, Copy, Clone, derive_more::Display)] +pub enum RoomMode { + #[display(fmt="single")] + Single { + episode: Episode, + difficulty: Difficulty, + }, + #[display(fmt="multi")] + Multi { + episode: Episode, + difficulty: Difficulty, + }, + #[display(fmt="challenge")] + Challenge { + episode: Episode, + }, + #[display(fmt="battle")] + Battle { + episode: Episode, + difficulty: Difficulty, + } +} + + +impl RoomMode { + pub fn difficulty(&self) -> Difficulty { + match self { + RoomMode::Single {difficulty, ..} => *difficulty, + RoomMode::Multi {difficulty, ..} => *difficulty, + RoomMode::Battle {difficulty, ..} => *difficulty, + RoomMode::Challenge {..} => Difficulty::Normal, + } + } + + pub fn episode(&self) -> Episode { + match self { + RoomMode::Single {episode, ..} => *episode, + RoomMode::Multi {episode, ..} => *episode, + RoomMode::Battle {episode, ..} => *episode, + RoomMode::Challenge {episode, ..} => *episode, + } + } + + pub fn battle(&self) -> bool { + matches!(self, RoomMode::Battle {..}) + } + + pub fn challenge(&self) -> bool { + matches!(self, RoomMode::Challenge {..}) + } + + pub fn player_mode(&self) -> PlayerMode { + match self { + RoomMode::Single {..} => PlayerMode::Single, + _ => PlayerMode::Multi, + } + } +} diff --git a/src/ship/map/variant.rs b/maps/src/variant.rs similarity index 99% rename from src/ship/map/variant.rs rename to maps/src/variant.rs index 0fa7c65..78fa4bf 100644 --- a/src/ship/map/variant.rs +++ b/maps/src/variant.rs @@ -3,7 +3,8 @@ use rand::Rng; // TODO: don't use * -use crate::ship::map::*; +//use crate::map::*; +use crate::area::MapArea; #[derive(Debug, PartialEq, Eq)] pub enum MapVariantMode { diff --git a/networking/Cargo.toml b/networking/Cargo.toml new file mode 100644 index 0000000..b0ee8a2 --- /dev/null +++ b/networking/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "networking" +version = "0.1.0" +edition = "2021" diff --git a/networking/src/lib.rs b/networking/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/bin/login.rs b/src/bin/login.rs index f8b6b94..28d78f0 100644 --- a/src/bin/login.rs +++ b/src/bin/login.rs @@ -1,5 +1,5 @@ use log::{info}; -use elseware::entity::gateway::postgres::PostgresGateway; +use entity::gateway::postgres::PostgresGateway; use elseware::login::login::LoginServerState; use elseware::login::character::CharacterServerState; use elseware::common::interserver::AuthToken; diff --git a/src/bin/main.rs b/src/bin/main.rs index 0a3ada0..23aa720 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -8,11 +8,11 @@ use elseware::patch::patch::{PatchServerState, generate_patch_tree, load_config, use elseware::ship::ship::{ShipServerStateBuilder, ShipEvent}; #[allow(unused_imports)] -use elseware::entity::gateway::{EntityGateway, InMemoryGateway, PostgresGateway}; -use elseware::entity::account::{NewUserAccountEntity, NewUserSettingsEntity}; -use elseware::entity::character::NewCharacterEntity; -use elseware::entity::item::{NewItemEntity, ItemDetail, InventoryItemEntity}; -use elseware::entity::item; +use entity::gateway::{EntityGateway, InMemoryGateway, PostgresGateway}; +use entity::account::{NewUserAccountEntity, NewUserSettingsEntity}; +use entity::character::NewCharacterEntity; +use entity::item::{NewItemEntity, ItemDetail, InventoryItemEntity}; +use entity::item; fn setup_logger() { let colors = fern::colors::ColoredLevelConfig::new() diff --git a/src/bin/ship.rs b/src/bin/ship.rs index ff1ccc6..0f289b7 100644 --- a/src/bin/ship.rs +++ b/src/bin/ship.rs @@ -1,5 +1,5 @@ use log::{info}; -use elseware::entity::gateway::postgres::PostgresGateway; +use entity::gateway::postgres::PostgresGateway; use elseware::ship::ship::ShipServerStateBuilder; use elseware::common::interserver::AuthToken; diff --git a/src/common/interserver.rs b/src/common/interserver.rs index 1f6e0ff..be49a9f 100644 --- a/src/common/interserver.rs +++ b/src/common/interserver.rs @@ -2,8 +2,8 @@ use std::net::Ipv4Addr; use async_std::channel; use serde::{Serialize, Deserialize}; use serde::de::DeserializeOwned; -use crate::entity::account::UserAccountId; -use crate::entity::character::CharacterEntityId; +use entity::account::UserAccountId; +use entity::character::CharacterEntityId; #[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct ServerId(pub usize); diff --git a/src/common/leveltable.rs b/src/common/leveltable.rs index 9fb1465..7b06966 100644 --- a/src/common/leveltable.rs +++ b/src/common/leveltable.rs @@ -1,6 +1,6 @@ use std::fs::File; use serde_json::Value; -use crate::entity::character::CharacterClass; +use entity::character::CharacterClass; use std::sync::LazyLock; pub static LEVEL_TABLE: LazyLock = LazyLock::new(CharacterLevelTable::default); diff --git a/src/common/mainloop/interserver.rs b/src/common/mainloop/interserver.rs index dbe940d..d524952 100644 --- a/src/common/mainloop/interserver.rs +++ b/src/common/mainloop/interserver.rs @@ -13,8 +13,7 @@ use crate::common::interserver::{ServerId, InterserverActor}; use libpso::crypto::{PSOCipher, NullCipher, CipherError}; use crate::common::serverstate::{ServerState, SendServerPacket, RecvServerPacket}; use crate::login::character::CharacterServerState; -//use crate::ship::ship::ShipServerState; -use crate::entity::gateway::entitygateway::EntityGateway; +use entity::gateway::entitygateway::EntityGateway; use async_std::channel; use std::fmt::Debug; diff --git a/src/entity/gateway/postgres/migrations/mod.rs b/src/entity/gateway/postgres/migrations/mod.rs deleted file mode 100644 index 533298a..0000000 --- a/src/entity/gateway/postgres/migrations/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -use refinery::include_migration_mods; - -include_migration_mods!("src/entity/gateway/postgres/migrations"); diff --git a/src/lib.rs b/src/lib.rs index 54fc603..3802b3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ extern crate test; pub mod common; -pub mod entity; +//pub mod entity; pub mod patch; pub mod login; pub mod ship; diff --git a/src/login/character.rs b/src/login/character.rs index f23beea..07969ef 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -12,8 +12,8 @@ use libpso::packet::login::*; use libpso::packet::ship::{MenuDetail, SmallLeftDialog}; use libpso::{PacketParseError, PSOPacket}; use libpso::crypto::bb::PSOBBCipher; -use crate::entity::item; use libpso::character::character; +use entity::item; use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; @@ -21,15 +21,15 @@ use crate::common::interserver::{ServerId, InterserverActor, LoginMessage, ShipM use crate::common::leveltable::LEVEL_TABLE; use libpso::{utf8_to_array, utf8_to_utf16_array}; -use crate::entity::gateway::{EntityGateway, GatewayError}; -use crate::entity::account::{UserAccountId, UserAccountEntity, NewUserSettingsEntity, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM}; -use crate::entity::item::{NewItemEntity, ItemDetail, ItemNote, InventoryItemEntity, InventoryEntity, BankEntity, BankIdentifier, EquippedEntity, Meseta}; -use crate::entity::item::weapon::Weapon; -use crate::entity::item::armor::Armor; -use crate::entity::item::tech::Technique; -use crate::entity::item::tool::Tool; -use crate::entity::item::mag::Mag; -use crate::entity::character::{CharacterEntity, NewCharacterEntity, CharacterClass, TechLevel}; +use entity::gateway::{EntityGateway, GatewayError}; +use entity::account::{UserAccountId, UserAccountEntity, NewUserSettingsEntity, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM}; +use entity::item::{NewItemEntity, ItemDetail, ItemNote, InventoryItemEntity, InventoryEntity, BankEntity, BankIdentifier, EquippedEntity, Meseta}; +use entity::item::weapon::Weapon; +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 crate::login::login::{get_login_status}; use crate::common::interserver::AuthToken; @@ -484,7 +484,7 @@ impl CharacterServerState { async fn set_flag(&mut self, id: ClientId, setflag: &SetFlag) -> Result, anyhow::Error> { let mut client = self.clients.write().await; let client = client.get_mut(&id).ok_or_else(|| CharacterError::ClientNotFound(id))?; - let mut user = client.user.as_mut().unwrap(); + let user = client.user.as_mut().unwrap(); user.flags = setflag.flags; self.entity_gateway.save_user(user).await.unwrap(); Ok(None.into_iter()) @@ -515,7 +515,7 @@ impl CharacterServerState { async fn character_preview(&mut self, id: ClientId, preview: &CharacterPreview) -> Result, anyhow::Error> { let mut client = self.clients.write().await; let client = client.get_mut(&id).ok_or_else(|| CharacterError::ClientNotFound(id))?; - let mut user = client.user.as_mut().unwrap(); + let user = client.user.as_mut().unwrap(); if user.flags == USERFLAG_NEWCHAR { new_character(&mut self.entity_gateway, user, preview).await? } @@ -834,9 +834,21 @@ impl<'a> SelectScreenCharacterBuilder<'a> { #[cfg(test)] mod test { use super::*; - use crate::entity::account::*; + use entity::account::*; use libpso::character::{settings, character}; - use crate::entity::gateway::{InMemoryGateway, GatewayError}; + use entity::gateway::{InMemoryGateway, EntityGatewayTransaction, GatewayError}; + + #[derive(Clone)] + struct CharTestDb; + + impl EntityGateway for CharTestDb { + type Transaction<'t> = CharTestDb where Self: 't; + } + + impl EntityGatewayTransaction for CharTestDb { + type ParentGateway = CharTestDb; + } + #[async_std::test] async fn test_option_send() { @@ -846,7 +858,7 @@ mod test { #[async_trait::async_trait] impl EntityGateway for TestData { - type Transaction<'a> = () where Self: 'a; + type Transaction<'a> = CharTestDb where Self: 'a; async fn get_user_settings_by_user(&mut self, user: &UserAccountEntity) -> Result { Ok(UserSettingsEntity { id: UserSettingsId(0), @@ -889,7 +901,7 @@ mod test { #[derive(Clone)] struct TestData; impl EntityGateway for TestData { - type Transaction<'a> = () where Self: 'a; + type Transaction<'a> = CharTestDb where Self: 'a; } let mut server = CharacterServerState::new(TestData {}, AuthToken("".into())); let send = server.handle(ClientId(1), RecvCharacterPacket::Checksum(Checksum {checksum: 1234, diff --git a/src/login/login.rs b/src/login/login.rs index b4fcad6..4b1433c 100644 --- a/src/login/login.rs +++ b/src/login/login.rs @@ -14,8 +14,8 @@ use libpso::util::array_to_utf8; use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; -use crate::entity::gateway::EntityGateway; -use crate::entity::account::{UserAccountEntity}; +use entity::gateway::EntityGateway; +use entity::account::{UserAccountEntity}; pub const LOGIN_PORT: u16 = 12000; pub const COMMUNICATION_PORT: u16 = 12123; @@ -178,8 +178,8 @@ impl ServerState for LoginServerState { #[cfg(test)] mod test { use super::*; - use crate::entity::account::{UserAccountId}; - use crate::entity::gateway::{EntityGatewayTransaction, GatewayError}; + use entity::account::{UserAccountId}; + use entity::gateway::{EntityGatewayTransaction, GatewayError}; const LOGIN_PACKET: RecvLoginPacket = RecvLoginPacket::Login(Login { tag: 65536, @@ -204,13 +204,16 @@ mod test { character_slot: 0, } }); - - impl EntityGateway for () { - type Transaction<'t> = () where Self: 't; + + #[derive(Clone)] + struct LoginTestDb; + + impl EntityGateway for LoginTestDb { + type Transaction<'t> = LoginTestDb where Self: 't; } - impl EntityGatewayTransaction for () { - type ParentGateway = (); + impl EntityGatewayTransaction for LoginTestDb { + type ParentGateway = LoginTestDb; } #[async_std::test] @@ -221,7 +224,7 @@ mod test { #[async_trait::async_trait] impl EntityGateway for TestData { - type Transaction<'t> = () where Self: 't; + type Transaction<'t> = LoginTestDb where Self: 't; async fn get_user_by_name(&mut self, name: String) -> Result { assert!(name == "testuser"); Ok(UserAccountEntity { @@ -280,7 +283,7 @@ mod test { #[async_trait::async_trait] impl EntityGateway for TestData { - type Transaction<'t> = () where Self: 't; + type Transaction<'t> = LoginTestDb where Self: 't; async fn get_user_by_name(&mut self, _name: String) -> Result { Err(GatewayError::Error) } @@ -315,7 +318,7 @@ mod test { #[async_trait::async_trait] impl EntityGateway for TestData { - type Transaction<'t> = () where Self: 't; + type Transaction<'t> = LoginTestDb where Self: 't; async fn get_user_by_name(&mut self, name: String) -> Result { assert!(name == "testuser"); Ok(UserAccountEntity { @@ -365,7 +368,7 @@ mod test { #[async_trait::async_trait] impl EntityGateway for TestData { - type Transaction<'t> = () where Self: 't; + type Transaction<'t> = LoginTestDb where Self: 't; async fn get_user_by_name(&mut self, name: String) -> Result { assert!(name == "testuser"); Ok(UserAccountEntity { diff --git a/src/ship/character.rs b/src/ship/character.rs index 348f8ac..afe73c6 100644 --- a/src/ship/character.rs +++ b/src/ship/character.rs @@ -1,10 +1,10 @@ use libpso::character::character; use crate::common::leveltable::CharacterStats; -use crate::entity::character::CharacterEntity; +use entity::character::CharacterEntity; //use crate::ship::items::{CharacterInventory, CharacterBank}; use crate::ship::items::bank::BankState; use crate::ship::items::inventory::InventoryState; -use crate::entity::item::Meseta; +use entity::item::Meseta; #[derive(Default)] diff --git a/src/ship/chatcommand.rs b/src/ship/chatcommand.rs index 97d5054..7d2c643 100644 --- a/src/ship/chatcommand.rs +++ b/src/ship/chatcommand.rs @@ -1,10 +1,10 @@ use libpso::packet::ship::PlayerChat; -use crate::entity::gateway::EntityGateway; +use entity::gateway::EntityGateway; use crate::common::serverstate::ClientId; use crate::ship::ship::{ShipServerState, SendShipPacket}; use crate::ship::client::Clients; use crate::ship::items::state::ItemState; -use crate::entity::item::{BankName, BankIdentifier}; +use entity::item::{BankName, BankIdentifier}; use crate::ship::packet::builder::message::bank_item_list; async fn default_bank<'a, EG>(id: ClientId, diff --git a/src/ship/client.rs b/src/ship/client.rs index 5495309..58f75f7 100644 --- a/src/ship/client.rs +++ b/src/ship/client.rs @@ -7,13 +7,13 @@ use libpso::packet::ship::*; use libpso::packet::login::Session; use crate::common::serverstate::ClientId; -use crate::entity::account::{UserAccountEntity, UserSettingsEntity}; -use crate::entity::character::CharacterEntity; -use crate::entity::item; +use entity::account::{UserAccountEntity, UserSettingsEntity}; +use entity::character::CharacterEntity; +use entity::item; use crate::ship::ship::ShipError; use crate::ship::items; -use crate::ship::map::MapArea; +use maps::area::MapArea; use crate::ship::shops::{WeaponShopItem, ToolShopItem, ArmorShopItem}; diff --git a/src/ship/drops/box_drop_table.rs b/src/ship/drops/box_drop_table.rs index f507d27..4ad1e60 100644 --- a/src/ship/drops/box_drop_table.rs +++ b/src/ship/drops/box_drop_table.rs @@ -2,18 +2,18 @@ use rand::{Rng}; use rand::distributions::{WeightedIndex, Distribution}; use serde::{Serialize, Deserialize}; -use crate::entity::character::SectionID; -use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapArea; +use entity::character::SectionID; +use maps::room::{Difficulty, Episode}; +use maps::area::MapArea; use crate::ship::drops::{ItemDropType, load_data_file}; -use crate::ship::map::{MapObject, MapObjectType, FixedBoxDropType}; +use maps::object::{MapObject, MapObjectType, FixedBoxDropType}; use crate::ship::drops::rare_drop_table::{RareDropTable, RareDropItem}; use crate::ship::drops::generic_weapon::GenericWeaponTable; use crate::ship::drops::generic_armor::GenericArmorTable; use crate::ship::drops::generic_shield::GenericShieldTable; use crate::ship::drops::generic_unit::GenericUnitTable; use crate::ship::drops::tool_table::ToolTable; -use crate::entity::item::ItemDetail; +use entity::item::ItemDetail; #[derive(Debug, Serialize, Deserialize)] struct BoxDropRate { @@ -204,7 +204,7 @@ impl BoxDropTable { FixedBoxDropType::Specific(value) => { let mut buf: [u8; 16] = [0; 16]; buf[0..4].copy_from_slice(&u32::to_be_bytes(value)); - ItemDetail::parse_item_from_bytes(buf) + ItemDropType::parse_item_from_bytes(buf) }, } } diff --git a/src/ship/drops/generic_armor.rs b/src/ship/drops/generic_armor.rs index 2bf5895..80e4761 100644 --- a/src/ship/drops/generic_armor.rs +++ b/src/ship/drops/generic_armor.rs @@ -1,12 +1,12 @@ use std::collections::HashMap; use serde::{Serialize, Deserialize}; -use rand::{Rng}; +use rand::Rng; use rand::distributions::{WeightedIndex, Distribution}; -use crate::entity::item::armor::{ArmorType, Armor}; -use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapArea; -use crate::entity::character::SectionID; +use entity::character::SectionID; +use entity::item::armor::{ArmorType, Armor}; +use maps::room::{Difficulty, Episode}; +use maps::area::MapArea; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::item_stats::{armor_stats, ArmorStats}; diff --git a/src/ship/drops/generic_shield.rs b/src/ship/drops/generic_shield.rs index 9eec585..fd5752e 100644 --- a/src/ship/drops/generic_shield.rs +++ b/src/ship/drops/generic_shield.rs @@ -1,12 +1,12 @@ use std::collections::HashMap; use serde::{Serialize, Deserialize}; -use rand::{Rng}; +use rand::Rng; use rand::distributions::{WeightedIndex, Distribution}; -use crate::entity::item::shield::{ShieldType, Shield}; -use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapArea; -use crate::entity::character::SectionID; +use entity::item::shield::{ShieldType, Shield}; +use entity::character::SectionID; +use maps::room::{Difficulty, Episode}; +use maps::area::MapArea; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::item_stats::{shield_stats, ShieldStats}; diff --git a/src/ship/drops/generic_unit.rs b/src/ship/drops/generic_unit.rs index 73bc4a6..137f7d0 100644 --- a/src/ship/drops/generic_unit.rs +++ b/src/ship/drops/generic_unit.rs @@ -1,12 +1,12 @@ use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; -use rand::{Rng}; +use rand::Rng; use rand::seq::IteratorRandom; -use crate::entity::item::unit::{UnitType, Unit, UnitModifier}; -use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapArea; -use crate::entity::character::SectionID; +use entity::character::SectionID; +use entity::item::unit::{UnitType, Unit, UnitModifier}; +use maps::room::{Difficulty, Episode}; +use maps::area::MapArea; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::item_stats::{unit_stats, UnitStats}; diff --git a/src/ship/drops/generic_weapon.rs b/src/ship/drops/generic_weapon.rs index d1fb2bb..38290e7 100644 --- a/src/ship/drops/generic_weapon.rs +++ b/src/ship/drops/generic_weapon.rs @@ -1,13 +1,13 @@ use std::collections::{HashMap, BTreeMap}; use serde::{Serialize, Deserialize}; -use rand::{Rng}; +use rand::Rng; use rand::distributions::{WeightedIndex, Distribution}; use rand::seq::SliceRandom; -use crate::entity::item::weapon::{Weapon, WeaponType, Attribute, WeaponAttribute, WeaponSpecial}; -use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapArea; -use crate::entity::character::SectionID; +use entity::character::SectionID; +use entity::item::weapon::{Weapon, WeaponType, Attribute, WeaponAttribute, WeaponSpecial}; +use maps::room::{Difficulty, Episode}; +use maps::area::MapArea; use crate::ship::drops::{ItemDropType, load_data_file}; diff --git a/src/ship/drops/mod.rs b/src/ship/drops/mod.rs index 5d8062c..5c228e0 100644 --- a/src/ship/drops/mod.rs +++ b/src/ship/drops/mod.rs @@ -22,10 +22,10 @@ use std::io::Read; use serde::{Serialize, Deserialize}; use rand::{Rng, SeedableRng}; -use crate::ship::monster::MonsterType; -use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapArea; -use crate::entity::character::SectionID; +use maps::monster::MonsterType; +use maps::room::{Difficulty, Episode}; +use maps::area::MapArea; +use entity::character::SectionID; use crate::ship::drops::generic_weapon::GenericWeaponTable; use crate::ship::drops::generic_armor::GenericArmorTable; use crate::ship::drops::generic_shield::GenericShieldTable; @@ -33,8 +33,8 @@ use crate::ship::drops::generic_unit::GenericUnitTable; use crate::ship::drops::tool_table::ToolTable; use crate::ship::drops::rare_drop_table::RareDropTable; use crate::ship::drops::box_drop_table::BoxDropTable; -use crate::ship::map::MapObject; -use crate::entity::item::{weapon, armor, shield, unit, mag, tool, tech}; +use maps::object::MapObject; +use entity::item::{ItemType, weapon, armor, shield, unit, mag, tool, tech, esweapon}; fn data_file_path(episode: Episode, difficulty: Difficulty, section_id: SectionID, filename: &str) -> PathBuf { @@ -55,18 +55,6 @@ pub fn load_data_file(episode: Episode, difficul toml::from_str::(s.as_str()).unwrap() } -// this is just copypaste -pub fn load_rare_monster_file(episode: Episode) -> T { - // TODO: where does the rare monster toml file actually live - let mut path = PathBuf::from("data/battle_param/"); - path.push(episode.to_string().to_lowercase() + "_rare_monster.toml"); - - let mut f = File::open(path).unwrap(); - let mut s = String::new(); - f.read_to_string(&mut s); - toml::from_str::(s.as_str()).unwrap() -} - #[derive(Debug, Serialize, Deserialize, Copy, Clone)] pub enum MonsterDropType { #[serde(rename = "weapon")] @@ -102,6 +90,28 @@ pub enum ItemDropType { Meseta(u32), } +impl ItemDropType { + pub fn parse_item_from_bytes(data: [u8; 16]) -> Option { + let item_type = weapon::WeaponType::parse_type([data[0],data[1],data[2]]).map(ItemType::Weapon) + .or_else(|_| armor::ArmorType::parse_type([data[0],data[1],data[2]]).map(ItemType::Armor)) + .or_else(|_| shield::ShieldType::parse_type([data[0],data[1],data[2]]).map(ItemType::Shield)) + .or_else(|_| unit::UnitType::parse_type([data[0],data[1],data[2]]).map(ItemType::Unit)) + .or_else(|_| mag::MagType::parse_type([data[0],data[1],data[2]]).map(ItemType::Mag)) + .or_else(|_| tool::ToolType::parse_type([data[0],data[1],data[2]]).map(ItemType::Tool)) + .or_else(|_| esweapon::ESWeaponType::parse_type([data[0],data[1],data[2]]).map(ItemType::ESWeapon)).ok()?; + + match item_type { + ItemType::Weapon(_w) => Some(ItemDropType::Weapon(weapon::Weapon::from_bytes(data).ok()?)), + ItemType::Armor(_a) => Some(ItemDropType::Armor(armor::Armor::from_bytes(data).ok()?)), + ItemType::Shield(_s) => Some(ItemDropType::Shield(shield::Shield::from_bytes(data).ok()?)), + ItemType::Unit(_u) => Some(ItemDropType::Unit(unit::Unit::from_bytes(data).ok()?)), + ItemType::Mag(_m) => Some(ItemDropType::Mag(mag::Mag::from_bytes(data).ok()?)), + ItemType::Tool(_t) => Some(ItemDropType::Tool(tool::Tool::from_bytes(data).ok()?)), + _ => None, + } + } +} + #[derive(Clone, Debug)] pub struct ItemDrop { pub map_area: MapArea, diff --git a/src/ship/drops/rare_drop_table.rs b/src/ship/drops/rare_drop_table.rs index 51151ba..0eb6cc8 100644 --- a/src/ship/drops/rare_drop_table.rs +++ b/src/ship/drops/rare_drop_table.rs @@ -1,16 +1,16 @@ use std::collections::HashMap; use rand::Rng; use serde::{Serialize, Deserialize}; -use crate::entity::item::weapon::{Weapon, WeaponType}; -use crate::entity::item::armor::{Armor, ArmorType}; -use crate::entity::item::shield::{Shield, ShieldType}; -use crate::entity::item::unit::{Unit, UnitType}; -use crate::entity::item::tool::{Tool, ToolType}; -use crate::entity::item::mag::{Mag, MagType}; -use crate::entity::character::SectionID; -use crate::ship::monster::MonsterType; -use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapArea; +use entity::item::weapon::{Weapon, WeaponType}; +use entity::item::armor::{Armor, ArmorType}; +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 maps::monster::MonsterType; +use maps::room::{Difficulty, Episode}; +use maps::area::MapArea; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::drops::generic_weapon::AttributeTable; use crate::ship::drops::generic_armor::GenericArmorTable; diff --git a/src/ship/drops/tech_table.rs b/src/ship/drops/tech_table.rs index 6e6396f..79bf095 100644 --- a/src/ship/drops/tech_table.rs +++ b/src/ship/drops/tech_table.rs @@ -3,10 +3,10 @@ use serde::{Serialize, Deserialize}; use rand::{Rng}; use rand::distributions::{WeightedIndex, Distribution}; -use crate::entity::item::tech::{Technique, TechniqueDisk}; -use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapArea; -use crate::entity::character::SectionID; +use entity::item::tech::{Technique, TechniqueDisk}; +use maps::room::{Difficulty, Episode}; +use maps::area::MapArea; +use entity::character::SectionID; use crate::ship::drops::{ItemDropType, load_data_file}; diff --git a/src/ship/drops/tool_table.rs b/src/ship/drops/tool_table.rs index 69a14cd..0ce9e6d 100644 --- a/src/ship/drops/tool_table.rs +++ b/src/ship/drops/tool_table.rs @@ -1,12 +1,12 @@ -use std::collections::{BTreeMap}; +use std::collections::BTreeMap; use serde::{Serialize, Deserialize}; -use rand::{Rng}; +use rand::Rng; use rand::distributions::{WeightedIndex, Distribution}; -use crate::entity::item::tool::{Tool, ToolType}; -use crate::ship::room::{Difficulty, Episode}; -use crate::ship::map::MapArea; -use crate::entity::character::SectionID; +use entity::item::tool::{Tool, ToolType}; +use maps::room::{Difficulty, Episode}; +use maps::area::MapArea; +use entity::character::SectionID; use crate::ship::drops::{ItemDropType, load_data_file}; use crate::ship::drops::tech_table::TechniqueTable; diff --git a/src/ship/item_stats.rs b/src/ship/item_stats.rs index 919c076..13d0855 100644 --- a/src/ship/item_stats.rs +++ b/src/ship/item_stats.rs @@ -4,13 +4,13 @@ use serde::{Serialize, Deserialize}; use std::fs::File; use std::io::Read; -use crate::entity::item::weapon::WeaponType; -use crate::entity::item::armor::ArmorType; -use crate::entity::item::shield::ShieldType; -use crate::entity::item::unit::UnitType; -use crate::entity::item::mag::MagType; -use crate::entity::item::tool::ToolType; -use crate::entity::item::tech::Technique; +use entity::item::weapon::WeaponType; +use entity::item::armor::ArmorType; +use entity::item::shield::ShieldType; +use entity::item::unit::UnitType; +use entity::item::mag::MagType; +use entity::item::tool::ToolType; +use entity::item::tech::Technique; lazy_static::lazy_static! { diff --git a/src/ship/items/actions.rs b/src/ship/items/actions.rs index 0c06691..2359950 100644 --- a/src/ship/items/actions.rs +++ b/src/ship/items/actions.rs @@ -1,6 +1,6 @@ // TODO: replace various u32s and usizes denoting item amounts for ItemAmount(u32) for consistency use crate::ship::items::ClientItemId; -use crate::entity::item::{Meseta, ItemNote}; +use entity::item::{Meseta, ItemNote}; use async_std::sync::Arc; use std::future::Future; use futures::future::BoxFuture; @@ -9,12 +9,12 @@ use std::iter::IntoIterator; use anyhow::Context; use libpso::packet::{ship::Message, messages::GameMessage}; -use crate::entity::character::{CharacterEntity, CharacterEntityId}; -use crate::entity::gateway::{EntityGateway, EntityGatewayTransaction}; -use crate::entity::item::{ItemDetail, NewItemEntity, TradeId, ItemModifier}; -use crate::entity::item::tool::Tool; -use crate::entity::room::RoomEntityId; -use crate::ship::map::MapArea; +use entity::character::{CharacterEntity, CharacterEntityId}; +use entity::gateway::{EntityGateway, EntityGatewayTransaction}; +use entity::item::{ItemDetail, NewItemEntity, TradeId, ItemModifier}; +use entity::item::tool::Tool; +use entity::room::RoomEntityId; +use maps::area::MapArea; use crate::ship::ship::SendShipPacket; use crate::ship::items::state::{ItemStateProxy, ItemStateError, AddItemResult, StackedItemDetail, IndividualItemDetail}; use crate::ship::items::bank::{BankItem, BankItemDetail}; @@ -25,7 +25,7 @@ use crate::ship::shops::ShopItem; use crate::ship::drops::{ItemDrop, ItemDropType}; use crate::ship::packet::builder; use crate::ship::location::AreaClient; -use crate::ship::monster::MonsterType; +use maps::monster::MonsterType; pub enum TriggerCreateItem { Yes, diff --git a/src/ship/items/apply_item.rs b/src/ship/items/apply_item.rs index 4c1a636..9c7e3c2 100644 --- a/src/ship/items/apply_item.rs +++ b/src/ship/items/apply_item.rs @@ -4,13 +4,13 @@ use thiserror::Error; use anyhow::Context; use rand::SeedableRng; use rand::distributions::{WeightedIndex, Distribution}; -use crate::entity::gateway::{EntityGateway, GatewayError}; -use crate::entity::character::{CharacterEntity, TechLevel}; -use crate::entity::item::mag::{MagCell, MagCellError}; -use crate::entity::item::tool::{Tool, ToolType}; -use crate::entity::item::tech::TechniqueDisk; -use crate::entity::item::{ItemDetail, ItemEntityId}; -use crate::entity::item::weapon::WeaponModifier; +use entity::gateway::{EntityGateway, GatewayError}; +use entity::character::{CharacterEntity, TechLevel}; +use entity::item::mag::{MagCell, MagCellError}; +use entity::item::tool::{Tool, ToolType}; +use entity::item::tech::TechniqueDisk; +use entity::item::{ItemDetail, ItemEntityId}; +use entity::item::weapon::WeaponModifier; use crate::ship::items::state::ItemStateProxy; use crate::ship::items::inventory::InventoryItemDetail; diff --git a/src/ship/items/bank.rs b/src/ship/items/bank.rs index 73f0e10..f6d12cd 100644 --- a/src/ship/items/bank.rs +++ b/src/ship/items/bank.rs @@ -1,12 +1,12 @@ use std::cmp::Ordering; use libpso::character::character; use crate::ship::items::ClientItemId; -use crate::entity::item::{Meseta, ItemEntityId, ItemDetail, ItemEntity, BankEntity, BankItemEntity}; +use entity::item::{Meseta, ItemEntityId, ItemDetail, ItemEntity, BankEntity, BankItemEntity}; use std::future::Future; use async_std::sync::{Arc, Mutex}; -use crate::entity::character::CharacterEntityId; -use crate::entity::item::BankIdentifier; +use entity::character::CharacterEntityId; +use entity::item::BankIdentifier; use crate::ship::items::state::ItemStateError; use crate::ship::items::state::{IndividualItemDetail, StackedItemDetail, AddItemResult}; use crate::ship::items::inventory::{InventoryItem, InventoryItemDetail}; diff --git a/src/ship/items/floor.rs b/src/ship/items/floor.rs index b0e968f..6d03133 100644 --- a/src/ship/items/floor.rs +++ b/src/ship/items/floor.rs @@ -1,10 +1,10 @@ use crate::ship::items::ClientItemId; -use crate::entity::item::{Meseta, ItemEntityId, ItemDetail}; +use entity::item::{Meseta, ItemEntityId, ItemDetail}; use std::future::Future; -use crate::ship::map::MapArea; -use crate::entity::character::CharacterEntityId; -use crate::entity::item::mag::Mag; +use maps::area::MapArea; +use entity::character::CharacterEntityId; +use entity::item::mag::Mag; use crate::ship::items::state::ItemStateError; use crate::ship::items::state::{IndividualItemDetail, StackedItemDetail}; diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index da131d8..ca0e51d 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -1,14 +1,14 @@ use std::cmp::Ordering; use libpso::character::character; use crate::ship::items::ClientItemId; -use crate::entity::item::{Meseta, ItemEntityId, ItemDetail, ItemEntity, InventoryEntity, InventoryItemEntity, EquippedEntity}; +use entity::item::{Meseta, ItemEntityId, ItemDetail, ItemEntity, InventoryEntity, InventoryItemEntity, EquippedEntity}; use std::future::Future; use async_std::sync::{Arc, Mutex}; -use crate::entity::character::CharacterEntityId; -use crate::entity::item::tool::ToolType; -use crate::entity::item::mag::Mag; -use crate::entity::item::weapon::Weapon; +use entity::character::CharacterEntityId; +use entity::item::tool::ToolType; +use entity::item::mag::Mag; +use entity::item::weapon::Weapon; use crate::ship::shops::{ShopItem, ArmorShopItem, ToolShopItem, WeaponShopItem}; use crate::ship::items::state::ItemStateError; use crate::ship::items::state::{IndividualItemDetail, StackedItemDetail, AddItemResult}; diff --git a/src/ship/items/state.rs b/src/ship/items/state.rs index 906762a..9058c05 100644 --- a/src/ship/items/state.rs +++ b/src/ship/items/state.rs @@ -4,12 +4,12 @@ use async_std::sync::{Arc, RwLock, Mutex}; use futures::stream::{FuturesOrdered, StreamExt}; use anyhow::Context; -use crate::entity::gateway::{EntityGateway, GatewayError}; -use crate::entity::character::{CharacterEntity, CharacterEntityId}; -use crate::entity::item::{ItemEntityId, ItemDetail, ItemEntity, InventoryItemEntity, BankItemEntity, BankIdentifier}; -use crate::entity::item::tool::Tool; -use crate::entity::item::weapon::Weapon; -use crate::entity::item::mag::Mag; +use entity::gateway::{EntityGateway, GatewayError}; +use entity::character::{CharacterEntity, CharacterEntityId}; +use entity::item::{ItemEntityId, ItemDetail, ItemEntity, InventoryItemEntity, BankItemEntity, BankIdentifier}; +use entity::item::tool::Tool; +use entity::item::weapon::Weapon; +use entity::item::mag::Mag; use crate::ship::drops::ItemDrop; use crate::ship::items::ClientItemId; use crate::ship::items::inventory::{Inventory, InventoryItem, InventoryItemDetail, InventoryError, InventoryState}; diff --git a/src/ship/items/tasks.rs b/src/ship/items/tasks.rs index 0c3f948..f224f4c 100644 --- a/src/ship/items/tasks.rs +++ b/src/ship/items/tasks.rs @@ -1,13 +1,13 @@ use futures::future::BoxFuture; use crate::ship::items::ClientItemId; -use crate::entity::item::Meseta; +use entity::item::Meseta; use crate::ship::ship::SendShipPacket; -use crate::ship::map::MapArea; -use crate::entity::character::{CharacterEntity, CharacterEntityId}; -use crate::entity::gateway::{EntityGateway, EntityGatewayTransaction}; -use crate::entity::item::ItemModifier; -use crate::entity::room::RoomEntityId; +use maps::area::MapArea; +use entity::character::{CharacterEntity, CharacterEntityId}; +use entity::gateway::{EntityGateway, EntityGatewayTransaction}; +use entity::item::ItemModifier; +use entity::room::RoomEntityId; use crate::ship::items::state::{ItemState, ItemStateProxy, IndividualItemDetail}; use crate::ship::items::itemstateaction::{ItemStateAction, ItemAction}; use crate::ship::items::inventory::InventoryItem; @@ -16,7 +16,7 @@ use crate::ship::shops::ShopItem; use crate::ship::trade::TradeItem; use crate::ship::location::AreaClient; use crate::ship::drops::ItemDrop; -use crate::ship::monster::MonsterType; +use maps::monster::MonsterType; use crate::ship::items::actions; diff --git a/src/ship/map/mod.rs b/src/ship/map/mod.rs deleted file mode 100644 index 693fd46..0000000 --- a/src/ship/map/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -pub mod area; -pub mod enemy; -pub mod object; -pub mod variant; -pub mod maps; - -// TODO: don't just forward everything to the module scope -pub use area::*; -pub use enemy::*; -pub use object::*; -pub use variant::*; -pub use maps::*; diff --git a/src/ship/mod.rs b/src/ship/mod.rs index c58edb6..3978099 100644 --- a/src/ship/mod.rs +++ b/src/ship/mod.rs @@ -6,8 +6,8 @@ pub mod client; pub mod room; pub mod items; pub mod item_stats; -pub mod map; -pub mod monster; +//pub mod map; +//pub mod monster; pub mod drops; pub mod packet; pub mod quests; diff --git a/src/ship/packet/builder/message.rs b/src/ship/packet/builder/message.rs index ac60484..f83ebbd 100644 --- a/src/ship/packet/builder/message.rs +++ b/src/ship/packet/builder/message.rs @@ -1,6 +1,6 @@ use libpso::packet::messages::*; use libpso::packet::ship::*; -use crate::entity::item; +use entity::item; use crate::common::leveltable::CharacterStats; use crate::ship::ship::{ShipError}; use crate::ship::items::ClientItemId; diff --git a/src/ship/packet/handler/auth.rs b/src/ship/packet/handler/auth.rs index 698de75..bd0c846 100644 --- a/src/ship/packet/handler/auth.rs +++ b/src/ship/packet/handler/auth.rs @@ -3,7 +3,7 @@ use libpso::packet::ship::*; use crate::common::serverstate::ClientId; use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Clients}; use crate::login::login::get_login_status; -use crate::entity::gateway::EntityGateway; +use entity::gateway::EntityGateway; use crate::ship::items::state::ItemState; use crate::common::interserver::ShipMessage; diff --git a/src/ship/packet/handler/communication.rs b/src/ship/packet/handler/communication.rs index c0ac3e5..2f7ef43 100644 --- a/src/ship/packet/handler/communication.rs +++ b/src/ship/packet/handler/communication.rs @@ -2,7 +2,7 @@ use libpso::packet::ship::*; use crate::common::serverstate::ClientId; use crate::ship::ship::{SendShipPacket, Clients}; use crate::ship::location::{ClientLocation}; -use crate::entity::gateway::EntityGateway; +use entity::gateway::EntityGateway; use futures::future::join_all; diff --git a/src/ship/packet/handler/direct_message.rs b/src/ship/packet/handler/direct_message.rs index 3c914e8..0886f79 100644 --- a/src/ship/packet/handler/direct_message.rs +++ b/src/ship/packet/handler/direct_message.rs @@ -10,8 +10,8 @@ use crate::ship::location::ClientLocation; use crate::ship::drops::ItemDrop; use crate::ship::room::Rooms; use crate::ship::items::ClientItemId; -use crate::entity::gateway::EntityGateway; -use crate::entity::item; +use entity::gateway::EntityGateway; +use entity::item; use libpso::utf8_to_utf16_array; use crate::ship::packet::builder; use crate::ship::shops::{ShopItem, ToolShopItem, ArmorShopItem}; diff --git a/src/ship/packet/handler/lobby.rs b/src/ship/packet/handler/lobby.rs index d5506c4..ae95afb 100644 --- a/src/ship/packet/handler/lobby.rs +++ b/src/ship/packet/handler/lobby.rs @@ -7,9 +7,9 @@ use crate::ship::character::{FullCharacterBytesBuilder}; use crate::ship::location::{ClientLocation, LobbyId, RoomLobby, ClientLocationError, RoomId}; use crate::ship::packet; use crate::ship::items::state::ItemState; -use crate::entity::gateway::EntityGateway; -use crate::entity::room::RoomNote; -use crate::ship::map::MapArea; +use entity::gateway::EntityGateway; +use entity::room::RoomNote; +use maps::area::MapArea; use futures::future::join_all; // this function needs a better home diff --git a/src/ship/packet/handler/message.rs b/src/ship/packet/handler/message.rs index f380d14..a46b90c 100644 --- a/src/ship/packet/handler/message.rs +++ b/src/ship/packet/handler/message.rs @@ -1,7 +1,7 @@ use libpso::packet::ship::*; use libpso::packet::messages::*; -use crate::entity::gateway::EntityGateway; -use crate::entity::item::Meseta; +use entity::gateway::EntityGateway; +use entity::item::Meseta; use crate::common::serverstate::ClientId; use crate::common::leveltable::LEVEL_TABLE; use crate::ship::ship::{SendShipPacket, ShipError, Clients, ItemDropLocation}; diff --git a/src/ship/packet/handler/quest.rs b/src/ship/packet/handler/quest.rs index 1c8c31e..b219684 100644 --- a/src/ship/packet/handler/quest.rs +++ b/src/ship/packet/handler/quest.rs @@ -4,7 +4,7 @@ use libpso::packet::ship::*; use crate::common::serverstate::ClientId; use crate::ship::ship::{SendShipPacket, ShipError, Clients, ShipEvent}; use crate::ship::room::Rooms; -use crate::ship::map::enemy::RareMonsterAppearTable; +use maps::enemy::RareMonsterAppearTable; use crate::ship::location::{ClientLocation}; use crate::ship::packet::builder::quest; use libpso::util::array_to_utf8; @@ -118,7 +118,7 @@ pub async fn player_chose_quest(id: ClientId, .clone(); let rare_monster_table = RareMonsterAppearTable::new(room.mode.episode()); - room.maps.set_quest_data(quest.enemies.clone(), quest.objects.clone(), &rare_monster_table, event); + room.maps.set_quest_data(quest.enemies.clone(), quest.objects.clone(), &rare_monster_table, event.rare_enemy_event()); room.map_areas = quest.map_areas.clone(); let bin = quest::quest_header(&questmenuselect, &quest.bin_blob, "bin"); diff --git a/src/ship/packet/handler/room.rs b/src/ship/packet/handler/room.rs index 9198c63..cf5d6af 100644 --- a/src/ship/packet/handler/room.rs +++ b/src/ship/packet/handler/room.rs @@ -1,4 +1,4 @@ -use std::convert::{TryFrom, Into}; +use std::convert::Into; use futures::stream::StreamExt; use async_std::sync::Arc; @@ -7,13 +7,15 @@ use libpso::packet::ship::*; use libpso::packet::messages::*; use crate::common::serverstate::ClientId; use crate::common::leveltable::LEVEL_TABLE; -use crate::entity::gateway::EntityGateway; -use crate::entity::character::SectionID; -use crate::entity::room::{NewRoomEntity, RoomEntityMode, RoomNote}; +use entity::gateway::EntityGateway; +use entity::character::SectionID; +use entity::room::{NewRoomEntity, RoomEntityMode, RoomNote}; use crate::ship::drops::DropTable; use crate::ship::ship::{SendShipPacket, Clients, ShipEvent}; -use crate::ship::room::{Rooms, Episode, Difficulty, RoomState, RoomMode}; -use crate::ship::map::Maps; +use crate::ship::room::{Rooms, RoomState, RoomCreationError}; +use maps::room::{Episode, Difficulty, RoomMode}; +use maps::enemy::RareEnemyEvent; +use maps::maps::Maps; use crate::ship::location::{ClientLocation, RoomId, RoomLobby, GetAreaError}; use crate::ship::packet::builder; use crate::ship::items::state::ItemState; @@ -26,7 +28,7 @@ pub async fn create_room(id: ClientId, clients: &Clients, item_state: &mut ItemState, rooms: &Rooms, - map_builder: Arc Maps + Send + Sync>>, + map_builder: Arc) -> Maps + Send + Sync>>, drop_table_builder: Arc DropTable + Send + Sync>>, event: ShipEvent) -> Result, anyhow::Error> @@ -36,7 +38,8 @@ where let level = clients.with(id, |client| Box::pin(async move { LEVEL_TABLE.get_level_from_exp(client.character.char_class, client.character.exp) })).await?; - let difficulty = Difficulty::try_from(create_room.difficulty)?; + let difficulty = create_room.difficulty.try_into() + .map_err(|()| RoomCreationError::InvalidDifficulty(create_room.difficulty))?; match difficulty { Difficulty::Ultimate if level < 80 => { return Ok(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("You must be at least level 80 \nto create Ultimate rooms.".into())))]) @@ -64,8 +67,9 @@ where (0, 0, 1) => RoomEntityMode::Single, _ => RoomEntityMode::Multi, }; - let episode = create_room.episode.try_into()?; - let difficulty = create_room.difficulty.try_into()?; + let episode = create_room.episode.try_into() + .map_err(|()| RoomCreationError::InvalidEpisode(create_room.episode))?; + //let difficulty = create_room.difficulty.try_into()?; let room = clients.with(id, |client| { let mut item_state = item_state.clone(); diff --git a/src/ship/packet/handler/settings.rs b/src/ship/packet/handler/settings.rs index de7bfaa..c8ebd52 100644 --- a/src/ship/packet/handler/settings.rs +++ b/src/ship/packet/handler/settings.rs @@ -1,7 +1,7 @@ use libpso::packet::ship::*; use crate::common::serverstate::ClientId; use crate::ship::ship::{SendShipPacket, Clients}; -use crate::entity::gateway::EntityGateway; +use entity::gateway::EntityGateway; pub async fn update_config(id: ClientId, update_config: UpdateConfig, diff --git a/src/ship/packet/handler/trade.rs b/src/ship/packet/handler/trade.rs index c1cb2d0..f3128d0 100644 --- a/src/ship/packet/handler/trade.rs +++ b/src/ship/packet/handler/trade.rs @@ -8,11 +8,11 @@ use crate::ship::items::ClientItemId; use crate::ship::items::state::{ItemState, ItemStateError}; use crate::ship::items::inventory::InventoryItemDetail; use crate::ship::trade::{TradeItem, TradeState, TradeStatus}; -use crate::entity::gateway::EntityGateway; +use entity::gateway::EntityGateway; use crate::ship::packet::builder; use crate::ship::items::tasks::trade_items; use crate::ship::location::{AreaClient, RoomId}; -use crate::entity::item::Meseta; +use entity::item::Meseta; use crate::ship::trade::ClientTradeState; pub const MESETA_ITEM_ID: ClientItemId = ClientItemId(0xFFFFFF01); diff --git a/src/ship/quests.rs b/src/ship/quests.rs index 4f5eb26..91e5d4d 100644 --- a/src/ship/quests.rs +++ b/src/ship/quests.rs @@ -10,9 +10,12 @@ use serde::{Serialize, Deserialize}; use ages_prs::{LegacyPrsDecoder, LegacyPrsEncoder}; use byteorder::{LittleEndian, ReadBytesExt}; use libpso::util::array_to_utf16; -use crate::ship::map::{MapArea, MapAreaError, MapObject, MapEnemy, enemy_data_from_stream, objects_from_stream}; -use crate::ship::room::{Episode, RoomMode}; -use crate::ship::map::area::{MapAreaLookup, MapAreaLookupBuilder}; +use maps::area::{MapArea, MapAreaError}; +use maps::object::MapObject; +use maps::enemy::MapEnemy; +use maps::maps::{objects_from_stream, enemy_data_from_stream}; +use maps::room::{Episode, RoomMode}; +use maps::area::{MapAreaLookup, MapAreaLookupBuilder}; #[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, PartialOrd, Ord)] @@ -101,7 +104,7 @@ fn quest_episode(bin: &[u8]) -> Option { for bytes in bin.windows(3) { // set_episode if bytes[0] == 0xF8 && bytes[1] == 0xBC { - return Episode::from_quest(bytes[2]).ok() + return Episode::from_quest(bytes[2]) } } None diff --git a/src/ship/room.rs b/src/ship/room.rs index b3a03c2..441feb5 100644 --- a/src/ship/room.rs +++ b/src/ship/room.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::convert::{From, Into, TryFrom}; +use std::convert::{From, Into}; use async_std::sync::{Arc, RwLock, RwLockReadGuard}; use futures::future::BoxFuture; use futures::stream::{FuturesOrdered, Stream}; @@ -7,16 +7,19 @@ use futures::stream::{FuturesOrdered, Stream}; use thiserror::Error; use rand::Rng; -use crate::ship::map::Maps; +use maps::maps::Maps; use crate::ship::drops::DropTable; -use crate::entity::character::SectionID; -use crate::entity::room::{RoomEntityId, RoomEntityMode}; -use crate::ship::monster::{load_monster_stats_table, MonsterType, MonsterStats}; -use crate::ship::map::area::MapAreaLookup; +use entity::character::SectionID; +use entity::room::{RoomEntityId, RoomEntityMode}; +use maps::monster::{load_monster_stats_table, MonsterType, MonsterStats}; +use maps::area::MapAreaLookup; +use maps::enemy::RareEnemyEvent; use crate::ship::quests; use crate::ship::ship::{ShipError, ShipEvent}; use crate::ship::location::{MAX_ROOMS, RoomId}; +use maps::room::{Episode, Difficulty, RoomMode}; + #[derive(Clone)] pub struct Rooms([Arc>>; MAX_ROOMS]); @@ -123,156 +126,7 @@ pub enum RoomCreationError { CouldNotLoadQuests, } -#[derive(Debug, Copy, Clone, derive_more::Display)] -pub enum Episode { - #[display(fmt="ep1")] - One, - #[display(fmt="ep2")] - Two, - #[display(fmt="ep4")] - Four, -} - -#[derive(Debug, Copy, Clone)] -pub enum PlayerMode{ - Single, - Multi, -} - -impl PlayerMode { - pub fn value(&self) -> u8 { - match self { - PlayerMode::Single => 1, - PlayerMode::Multi => 0, - } - } -} - -impl TryFrom for Episode { - type Error = RoomCreationError; - - fn try_from(value: u8) -> Result { - match value { - 1 => Ok(Episode::One), - 2 => Ok(Episode::Two), - 3 => Ok(Episode::Four), - _ => Err(RoomCreationError::InvalidEpisode(value)) - } - } -} -impl From for u8 { - fn from(other: Episode) -> u8 { - match other { - Episode::One => 1, - Episode::Two => 2, - Episode::Four => 3, - } - } -} - -impl Episode { - pub fn from_quest(value: u8) -> Result { - match value { - 0 => Ok(Episode::One), - 1 => Ok(Episode::Two), - 2 => Ok(Episode::Four), - _ => Err(RoomCreationError::InvalidEpisode(value)) - } - } -} - -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, derive_more::Display)] -pub enum Difficulty { - Normal, - Hard, - VeryHard, - Ultimate, -} - -impl TryFrom for Difficulty { - type Error = RoomCreationError; - - fn try_from(value: u8) -> Result { - match value { - 0 => Ok(Difficulty::Normal), - 1 => Ok(Difficulty::Hard), - 2 => Ok(Difficulty::VeryHard), - 3 => Ok(Difficulty::Ultimate), - _ => Err(RoomCreationError::InvalidDifficulty(value)) - } - } -} - -impl From for u8 { - fn from(other: Difficulty) -> u8 { - match other { - Difficulty::Normal => 0, - Difficulty::Hard => 1, - Difficulty::VeryHard => 2, - Difficulty::Ultimate => 3, - } - } -} - -#[derive(Debug, Copy, Clone, derive_more::Display)] -pub enum RoomMode { - #[display(fmt="single")] - Single { - episode: Episode, - difficulty: Difficulty, - }, - #[display(fmt="multi")] - Multi { - episode: Episode, - difficulty: Difficulty, - }, - #[display(fmt="challenge")] - Challenge { - episode: Episode, - }, - #[display(fmt="battle")] - Battle { - episode: Episode, - difficulty: Difficulty, - } -} - - -impl RoomMode { - pub fn difficulty(&self) -> Difficulty { - match self { - RoomMode::Single {difficulty, ..} => *difficulty, - RoomMode::Multi {difficulty, ..} => *difficulty, - RoomMode::Battle {difficulty, ..} => *difficulty, - RoomMode::Challenge {..} => Difficulty::Normal, - } - } - - pub fn episode(&self) -> Episode { - match self { - RoomMode::Single {episode, ..} => *episode, - RoomMode::Multi {episode, ..} => *episode, - RoomMode::Battle {episode, ..} => *episode, - RoomMode::Challenge {episode, ..} => *episode, - } - } - - pub fn battle(&self) -> bool { - matches!(self, RoomMode::Battle {..}) - } - - pub fn challenge(&self) -> bool { - matches!(self, RoomMode::Challenge {..}) - } - - pub fn player_mode(&self) -> PlayerMode { - match self { - RoomMode::Single {..} => PlayerMode::Single, - _ => PlayerMode::Multi, - } - } -} pub enum QuestCategoryType { Standard, Government, @@ -369,7 +223,7 @@ impl RoomState { name: String, password: [u16; 16], event: ShipEvent, - map_builder: Arc Maps + Send + Sync>>, + map_builder: Arc) -> Maps + Send + Sync>>, drop_table_builder: Arc DropTable + Send + Sync>>, ) -> Result { let mode = match mode { @@ -397,7 +251,7 @@ impl RoomState { random_seed: rand::thread_rng().gen(), name, password, - maps: map_builder(mode, event), + maps: map_builder(mode, event.rare_enemy_event()), section_id, drop_table: Box::new(drop_table_builder(episode, difficulty, section_id)), bursting: false, diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 554d9d5..7e6293d 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -18,14 +18,16 @@ use crate::common::cipherkeys::{ELSEWHERE_PRIVATE_KEY, ELSEWHERE_PARRAY}; use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; use crate::common::interserver::{AuthToken, Ship, ServerId, InterserverActor, LoginMessage, ShipMessage}; use crate::login::character::SHIP_MENU_ID; -use crate::entity::gateway::{EntityGateway, GatewayError}; -use crate::entity::character::SectionID; -use crate::entity::room::RoomNote; +use entity::gateway::{EntityGateway, GatewayError}; +use entity::character::SectionID; +use entity::room::RoomNote; use crate::ship::location::{ClientLocation, RoomLobby, ClientLocationError, RoomId}; use crate::ship::drops::DropTable; use crate::ship::items; use crate::ship::room; -use crate::ship::map::{Maps, MapsError, MapAreaError, generate_free_roam_maps}; +use maps::area::MapAreaError; +use maps::maps::{Maps, MapsError, generate_free_roam_maps}; +use maps::enemy::RareEnemyEvent; use crate::ship::packet::handler; use crate::ship::shops::{WeaponShop, ToolShop, ArmorShop}; use crate::ship::trade::TradeState; @@ -38,57 +40,6 @@ pub const SHIP_PORT: u16 = 23423; pub const QUEST_CATEGORY_MENU_ID: u32 = 0xA2; pub const QUEST_SELECT_MENU_ID: u32 = 0xA3; -#[derive(Clone, Copy)] -pub enum ShipEvent { - None, - Christmas, - Valentines, - Easter, - Halloween, - Sonic, - NewYear, - Summer, - White, - Wedding, - Fall, - Spring, - Summer2, - Spring2, -} - -impl From for u32 { - fn from(other: ShipEvent) -> u32 { - u16::from(other) as u32 - } -} - -impl From for u16 { - fn from(other: ShipEvent) -> u16 { - u8::from(other) as u16 - } -} - -impl From for u8 { - fn from(other: ShipEvent) -> u8 { - match other { - ShipEvent::None => 0, - ShipEvent::Christmas => 1, - ShipEvent::Valentines => 3, - ShipEvent::Easter => 4, - ShipEvent::Halloween => 5, - ShipEvent::Sonic => 6, - ShipEvent::NewYear => 7, - ShipEvent::Summer => 8, - ShipEvent::White => 9, - ShipEvent::Wedding => 10, - ShipEvent::Fall => 11, - ShipEvent::Spring => 12, - ShipEvent::Summer2 => 13, - ShipEvent::Spring2 => 14, - } - } -} - #[derive(Error, Debug)] pub enum ShipError { @@ -139,7 +90,7 @@ pub enum ShipError { #[error("gateway error {0}")] GatewayError(#[from] GatewayError), #[error("unknown monster {0}")] - UnknownMonster(crate::ship::monster::MonsterType), + UnknownMonster(maps::monster::MonsterType), #[error("invalid ship {0}")] InvalidShip(usize), #[error("invalid block {0}")] @@ -166,6 +117,70 @@ impl> From for ShipError { } */ +#[derive(Clone, Copy)] +pub enum ShipEvent { + None, + Christmas, + Valentines, + Easter, + Halloween, + Sonic, + NewYear, + Summer, + White, + Wedding, + Fall, + Spring, + Summer2, + Spring2, +} + + +impl From for u32 { + fn from(other: ShipEvent) -> u32 { + u16::from(other) as u32 + } +} + +impl From for u16 { + fn from(other: ShipEvent) -> u16 { + u8::from(other) as u16 + } +} + +impl From for u8 { + fn from(other: ShipEvent) -> u8 { + match other { + ShipEvent::None => 0, + ShipEvent::Christmas => 1, + ShipEvent::Valentines => 3, + ShipEvent::Easter => 4, + ShipEvent::Halloween => 5, + ShipEvent::Sonic => 6, + ShipEvent::NewYear => 7, + ShipEvent::Summer => 8, + ShipEvent::White => 9, + ShipEvent::Wedding => 10, + ShipEvent::Fall => 11, + ShipEvent::Spring => 12, + ShipEvent::Summer2 => 13, + ShipEvent::Spring2 => 14, + } + } +} + +impl ShipEvent { + pub fn rare_enemy_event(&self) -> Option { + match self { + ShipEvent::Easter => Some(RareEnemyEvent::Easter), + ShipEvent::Halloween => Some(RareEnemyEvent::Halloween), + ShipEvent::Christmas => Some(RareEnemyEvent::Christmas), + _ => None, + } + } +} + + #[derive(Debug)] pub enum RecvShipPacket { @@ -345,14 +360,14 @@ impl SendServerPacket for SendShipPacket { #[derive(Clone)] pub struct ItemShops { - pub weapon_shop: HashMap<(room::Difficulty, SectionID), Arc>>>, + pub weapon_shop: HashMap<(maps::room::Difficulty, SectionID), Arc>>>, pub tool_shop: Arc>>, pub armor_shop: Arc>>, } impl Default for ItemShops { fn default() -> ItemShops { - let difficulty = [room::Difficulty::Normal, room::Difficulty::Hard, room::Difficulty::VeryHard, room::Difficulty::Ultimate]; + let difficulty = [maps::room::Difficulty::Normal, maps::room::Difficulty::Hard, maps::room::Difficulty::VeryHard, maps::room::Difficulty::Ultimate]; let section_id = [SectionID::Viridia, SectionID::Greenill, SectionID::Skyly, SectionID::Bluefull, SectionID::Purplenum, SectionID::Pinkal, SectionID::Redria, SectionID::Oran, SectionID::Yellowboze, SectionID::Whitill]; @@ -379,8 +394,8 @@ pub struct ShipServerStateBuilder { port: Option, auth_token: Option, event: Option, - map_builder: Option Maps + Send + Sync>>, - drop_table_builder: Option DropTable + Send + Sync>>, + map_builder: Option) -> Maps + Send + Sync>>, + drop_table_builder: Option DropTable + Send + Sync>>, num_blocks: usize, } @@ -438,13 +453,13 @@ impl ShipServerStateBuilder { } #[must_use] - pub fn map_builder(mut self, map_builder: Box Maps + Send + Sync>) -> ShipServerStateBuilder { + pub fn map_builder(mut self, map_builder: Box) -> Maps + Send + Sync>) -> ShipServerStateBuilder { self.map_builder = Some(map_builder); self } #[must_use] - pub fn drop_table_builder(mut self, drop_table_builder: Box DropTable + Send + Sync>) -> ShipServerStateBuilder { + pub fn drop_table_builder(mut self, drop_table_builder: Box DropTable + Send + Sync>) -> ShipServerStateBuilder { self.drop_table_builder = Some(drop_table_builder); self } @@ -516,8 +531,8 @@ pub struct ShipServerState { ship_list: Arc>>, shipgate_sender: Option>, trades: TradeState, - map_builder: Arc Maps + Send + Sync>>, - drop_table_builder: Arc DropTable + Send + Sync>>, + map_builder: Arc) -> Maps + Send + Sync>>, + drop_table_builder: Arc DropTable + Send + Sync>>, } impl ShipServerState { diff --git a/src/ship/shops/armor.rs b/src/ship/shops/armor.rs index d1d8b47..23fca20 100644 --- a/src/ship/shops/armor.rs +++ b/src/ship/shops/armor.rs @@ -5,10 +5,10 @@ use std::convert::TryInto; use serde::Deserialize; use rand::{Rng, SeedableRng}; use rand::distributions::{WeightedIndex, Distribution}; -use crate::entity::item::ItemDetail; -use crate::entity::item::armor::{Armor, ArmorType}; -use crate::entity::item::shield::{Shield, ShieldType}; -use crate::entity::item::unit::{Unit, UnitType}; +use entity::item::ItemDetail; +use entity::item::armor::{Armor, ArmorType}; +use entity::item::shield::{Shield, ShieldType}; +use entity::item::unit::{Unit, UnitType}; use crate::ship::shops::ShopItem; use crate::ship::item_stats::{ARMOR_STATS, SHIELD_STATS, UNIT_STATS}; diff --git a/src/ship/shops/mod.rs b/src/ship/shops/mod.rs index 573b667..7a999b7 100644 --- a/src/ship/shops/mod.rs +++ b/src/ship/shops/mod.rs @@ -2,7 +2,7 @@ mod weapon; mod tool; mod armor; -use crate::entity::item::ItemDetail; +use entity::item::ItemDetail; pub trait ShopItem { fn price(&self) -> usize; diff --git a/src/ship/shops/tool.rs b/src/ship/shops/tool.rs index b5f9718..73a44c7 100644 --- a/src/ship/shops/tool.rs +++ b/src/ship/shops/tool.rs @@ -6,9 +6,9 @@ use std::convert::TryInto; use serde::Deserialize; use rand::{Rng, SeedableRng}; use rand::distributions::{WeightedIndex, Distribution}; -use crate::entity::item::ItemDetail; -use crate::entity::item::tool::{Tool, ToolType}; -use crate::entity::item::tech::{Technique, TechniqueDisk}; +use entity::item::ItemDetail; +use entity::item::tool::{Tool, ToolType}; +use entity::item::tech::{Technique, TechniqueDisk}; use crate::ship::shops::ShopItem; use crate::ship::item_stats::{TOOL_STATS, TECH_STATS}; diff --git a/src/ship/shops/weapon.rs b/src/ship/shops/weapon.rs index 14509c8..6174b5a 100644 --- a/src/ship/shops/weapon.rs +++ b/src/ship/shops/weapon.rs @@ -8,10 +8,10 @@ use serde::Deserialize; use rand::{Rng, SeedableRng}; use rand::distributions::{WeightedIndex, Distribution}; use rand::seq::{SliceRandom, IteratorRandom}; -use crate::entity::character::SectionID; -use crate::ship::room::Difficulty; -use crate::entity::item::ItemDetail; -use crate::entity::item::weapon::{Weapon, WeaponType, WeaponSpecial, Attribute, WeaponAttribute}; +use entity::character::SectionID; +use maps::room::Difficulty; +use entity::item::ItemDetail; +use entity::item::weapon::{Weapon, WeaponType, WeaponSpecial, Attribute, WeaponAttribute}; use crate::ship::shops::ShopItem; use crate::ship::item_stats::WEAPON_STATS; diff --git a/tests/common.rs b/tests/common.rs index e9dccd0..6c8b577 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -1,14 +1,14 @@ #![allow(dead_code)] use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::EntityGateway; -use elseware::entity::account::{UserAccountEntity, NewUserAccountEntity, NewUserSettingsEntity}; -use elseware::entity::character::{CharacterEntity, NewCharacterEntity}; -use elseware::entity::item::{Meseta, BankName, BankIdentifier}; +use entity::gateway::EntityGateway; +use entity::account::{UserAccountEntity, NewUserAccountEntity, NewUserSettingsEntity}; +use entity::character::{CharacterEntity, NewCharacterEntity}; +use entity::item::{Meseta, BankName, BankIdentifier}; use elseware::ship::ship::{ShipServerState, RecvShipPacket}; -use elseware::ship::room::Difficulty; +use maps::room::Difficulty; -use elseware::entity::item; +use entity::item; use libpso::packet::ship::*; use libpso::packet::login::{Login, Session}; diff --git a/tests/test_bank.rs b/tests/test_bank.rs index 71fc8f5..227e043 100644 --- a/tests/test_bank.rs +++ b/tests/test_bank.rs @@ -1,7 +1,7 @@ use std::collections::BTreeSet; use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::item; +use entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket}; use libpso::packet::ship::*; diff --git a/tests/test_character.rs b/tests/test_character.rs index ca16eac..9ea3c93 100644 --- a/tests/test_character.rs +++ b/tests/test_character.rs @@ -1,5 +1,5 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::gateway::{EntityGateway, InMemoryGateway}; use elseware::ship::ship::{ShipServerState, RecvShipPacket}; use libpso::character::settings::{DEFAULT_KEYBOARD_CONFIG1, DEFAULT_KEYBOARD_CONFIG2, DEFAULT_KEYBOARD_CONFIG3, DEFAULT_KEYBOARD_CONFIG4}; diff --git a/tests/test_exp_gain.rs b/tests/test_exp_gain.rs index 0317e9d..6cecb60 100644 --- a/tests/test_exp_gain.rs +++ b/tests/test_exp_gain.rs @@ -1,13 +1,13 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::gateway::{EntityGateway, InMemoryGateway}; use elseware::common::leveltable::CharacterLevelTable; use elseware::ship::ship::{ShipServerState, SendShipPacket, RecvShipPacket}; -use elseware::ship::monster::MonsterType; use elseware::ship::location::RoomId; -use elseware::ship::map::variant::{MapVariant, MapVariantMode}; -use elseware::ship::map::maps::Maps; -use elseware::ship::map::area::MapArea; -use elseware::ship::map::enemy::MapEnemy; +use maps::variant::{MapVariant, MapVariantMode}; +use maps::maps::Maps; +use maps::area::MapArea; +use maps::enemy::MapEnemy; +use maps::monster::MonsterType; use libpso::packet::ship::*; use libpso::packet::messages::*; diff --git a/tests/test_item_actions.rs b/tests/test_item_actions.rs index 77d52bc..d840cab 100644 --- a/tests/test_item_actions.rs +++ b/tests/test_item_actions.rs @@ -1,7 +1,7 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::gateway::{EntityGateway, InMemoryGateway}; use elseware::ship::ship::{ShipServerState, RecvShipPacket}; -use elseware::entity::item; +use entity::item; use libpso::packet::ship::*; use libpso::packet::messages::*; diff --git a/tests/test_item_drop.rs b/tests/test_item_drop.rs index 02b01b1..3f2f55a 100644 --- a/tests/test_item_drop.rs +++ b/tests/test_item_drop.rs @@ -1,15 +1,18 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::character::SectionID; +use entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::character::SectionID; use elseware::common::leveltable::CharacterLevelTable; use elseware::ship::ship::{ShipServerState, SendShipPacket, RecvShipPacket}; -use elseware::ship::room::{Episode, Difficulty}; -use elseware::ship::monster::MonsterType; +use maps::room::{Episode, Difficulty}; +use maps::monster::MonsterType; use elseware::ship::location::RoomId; use elseware::ship::drops::{DropTable, MonsterDropStats, MonsterDropType}; use elseware::ship::drops::rare_drop_table::{RareDropTable, RareDropRate, RareDropItem}; -use elseware::ship::map::{Maps, MapVariant, MapArea, MapVariantMode, MapEnemy}; -use elseware::entity::item::weapon::WeaponType; +use maps::maps::Maps; +use maps::area::MapArea; +use maps::variant::{MapVariant, MapVariantMode}; +use maps::enemy::MapEnemy; +use entity::item::weapon::WeaponType; use libpso::packet::ship::*; use libpso::packet::messages::*; diff --git a/tests/test_item_id.rs b/tests/test_item_id.rs index f8ba644..0d8d70e 100644 --- a/tests/test_item_id.rs +++ b/tests/test_item_id.rs @@ -1,8 +1,8 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::item; +use entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket}; -use elseware::entity::character::TechLevel; +use entity::character::TechLevel; //use elseware::ship::items::{ClientItemId, ActiveItemEntityId, HeldItemType, FloorItemType}; use libpso::packet::ship::*; diff --git a/tests/test_item_pickup.rs b/tests/test_item_pickup.rs index 394cc3a..ca1b118 100644 --- a/tests/test_item_pickup.rs +++ b/tests/test_item_pickup.rs @@ -1,6 +1,6 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::item; +use entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket}; use libpso::packet::ship::*; diff --git a/tests/test_item_use.rs b/tests/test_item_use.rs index b6b8502..fab748b 100644 --- a/tests/test_item_use.rs +++ b/tests/test_item_use.rs @@ -1,8 +1,8 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::item; +use entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket}; -use elseware::entity::character::TechLevel; +use entity::character::TechLevel; //use elseware::ship::items::{ClientItemId, ActiveItemEntityId, HeldItemType, FloorItemType}; use libpso::packet::ship::*; diff --git a/tests/test_mags.rs b/tests/test_mags.rs index 1a7d687..fe098d9 100644 --- a/tests/test_mags.rs +++ b/tests/test_mags.rs @@ -1,8 +1,8 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::item; +use entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket}; -use elseware::entity::character::{CharacterClass, SectionID}; +use entity::character::{CharacterClass, SectionID}; use libpso::packet::ship::*; use libpso::packet::messages::*; diff --git a/tests/test_rooms.rs b/tests/test_rooms.rs index 00b512d..73c2a77 100644 --- a/tests/test_rooms.rs +++ b/tests/test_rooms.rs @@ -1,6 +1,6 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::item; +use entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket}; use elseware::ship::location::RoomId; diff --git a/tests/test_shops.rs b/tests/test_shops.rs index cf230c9..6a94a04 100644 --- a/tests/test_shops.rs +++ b/tests/test_shops.rs @@ -1,8 +1,8 @@ use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::item; +use entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket, ShipError}; -use elseware::ship::room::Difficulty; +use maps::room::Difficulty; use elseware::ship::items::state::ItemStateError; use libpso::packet::ship::*; diff --git a/tests/test_trade.rs b/tests/test_trade.rs index 4155a46..a895ed4 100644 --- a/tests/test_trade.rs +++ b/tests/test_trade.rs @@ -1,9 +1,9 @@ use std::convert::TryInto; use elseware::common::serverstate::{ClientId, ServerState}; -use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::item; +use entity::gateway::{EntityGateway, InMemoryGateway}; +use entity::item; use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket, ShipError}; -use elseware::entity::item::{Meseta, ItemEntity}; +use entity::item::{Meseta, ItemEntity, InventoryItemEntity}; use elseware::ship::packet::handler::trade::TradeError; use libpso::packet::ship::*; @@ -62,7 +62,7 @@ struct TradeItemBuilder { } impl TradeItemBuilder { - fn individual(mut self, item: &elseware::entity::item::InventoryItemEntity, item_id: u32) -> Self { + fn individual(mut self, item: &InventoryItemEntity, item_id: u32) -> Self { let idata = item.with_individual(|i| i.item.as_client_bytes()).unwrap(); self.items[self.count] = TradeItem { item_data: idata[0..12].try_into().unwrap(), @@ -74,7 +74,7 @@ impl TradeItemBuilder { self } - fn stacked(mut self, item: &elseware::entity::item::InventoryItemEntity, item_id: u32, amount: u8) -> Self { + fn stacked(mut self, item: &InventoryItemEntity, item_id: u32, amount: u8) -> Self { let idata = item .with_stacked(|i| i[0].item.tool().unwrap().as_stacked_bytes(i.len())) .map(|mut data| {