111 changed files with 989 additions and 572 deletions
-
48Cargo.toml
-
8common/Cargo.toml
-
0common/src/lib.rs
-
57entity/Cargo.toml
-
0entity/src/account.rs
-
4entity/src/character.rs
-
8entity/src/gateway/entitygateway.rs
-
10entity/src/gateway/inmemory.rs
-
0entity/src/gateway/mod.rs
-
0entity/src/gateway/postgres/migrations/V0001__initial.sql
-
0entity/src/gateway/postgres/migrations/V0002__equips.sql
-
0entity/src/gateway/postgres/migrations/V0003__item_notes.sql
-
0entity/src/gateway/postgres/migrations/V0004__meseta.sql
-
0entity/src/gateway/postgres/migrations/V0005__trade.sql
-
0entity/src/gateway/postgres/migrations/V0006__playtime.sql
-
0entity/src/gateway/postgres/migrations/V0007__player_keyconfig.sql
-
0entity/src/gateway/postgres/migrations/V0008__playtime_not_null.sql
-
0entity/src/gateway/postgres/migrations/V0009__no_player_keyconfig.sql
-
0entity/src/gateway/postgres/migrations/V0010__char_create_timestamp.sql
-
0entity/src/gateway/postgres/migrations/V0011__shared_bank.sql
-
0entity/src/gateway/postgres/migrations/V0012__room.sql
-
0entity/src/gateway/postgres/migrations/V0013__room2.sql
-
3entity/src/gateway/postgres/migrations/mod.rs
-
0entity/src/gateway/postgres/mod.rs
-
14entity/src/gateway/postgres/models.rs
-
14entity/src/gateway/postgres/postgres.rs
-
2entity/src/item/armor.rs
-
0entity/src/item/esweapon.rs
-
8entity/src/item/mag.rs
-
30entity/src/item/mod.rs
-
0entity/src/item/shield.rs
-
0entity/src/item/tech.rs
-
0entity/src/item/tool.rs
-
0entity/src/item/unit.rs
-
2entity/src/item/weapon.rs
-
0entity/src/lib.rs
-
4entity/src/room.rs
-
31entity/src/team.rs
-
15maps/Cargo.toml
-
2maps/src/area.rs
-
43maps/src/enemy.rs
-
7maps/src/lib.rs
-
18maps/src/maps.rs
-
212maps/src/monster.rs
-
8maps/src/object.rs
-
150maps/src/room.rs
-
3maps/src/variant.rs
-
4networking/Cargo.toml
-
0networking/src/lib.rs
-
2src/bin/login.rs
-
10src/bin/main.rs
-
2src/bin/ship.rs
-
4src/common/interserver.rs
-
2src/common/leveltable.rs
-
3src/common/mainloop/interserver.rs
-
3src/entity/gateway/postgres/migrations/mod.rs
-
2src/lib.rs
-
44src/login/character.rs
-
27src/login/login.rs
-
4src/ship/character.rs
-
4src/ship/chatcommand.rs
-
8src/ship/client.rs
-
12src/ship/drops/box_drop_table.rs
-
10src/ship/drops/generic_armor.rs
-
10src/ship/drops/generic_shield.rs
-
10src/ship/drops/generic_unit.rs
-
10src/ship/drops/generic_weapon.rs
-
46src/ship/drops/mod.rs
-
20src/ship/drops/rare_drop_table.rs
-
8src/ship/drops/tech_table.rs
-
12src/ship/drops/tool_table.rs
-
14src/ship/item_stats.rs
-
16src/ship/items/actions.rs
-
14src/ship/items/apply_item.rs
-
6src/ship/items/bank.rs
-
8src/ship/items/floor.rs
-
10src/ship/items/inventory.rs
-
12src/ship/items/state.rs
-
14src/ship/items/tasks.rs
-
12src/ship/map/mod.rs
-
4src/ship/mod.rs
-
2src/ship/packet/builder/message.rs
-
2src/ship/packet/handler/auth.rs
-
2src/ship/packet/handler/communication.rs
-
4src/ship/packet/handler/direct_message.rs
-
6src/ship/packet/handler/lobby.rs
-
4src/ship/packet/handler/message.rs
-
4src/ship/packet/handler/quest.rs
-
24src/ship/packet/handler/room.rs
-
2src/ship/packet/handler/settings.rs
-
4src/ship/packet/handler/trade.rs
-
11src/ship/quests.rs
-
168src/ship/room.rs
-
143src/ship/ship.rs
-
8src/ship/shops/armor.rs
-
2src/ship/shops/mod.rs
-
6src/ship/shops/tool.rs
-
8src/ship/shops/weapon.rs
-
12tests/common.rs
-
4tests/test_bank.rs
@ -0,0 +1,8 @@ |
|||
[package] |
|||
name = "common" |
|||
version = "0.1.0" |
|||
edition = "2021" |
|||
|
|||
|
|||
[dependencies] |
|||
derive_more = { workspace = true } |
@ -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" |
@ -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?
|
@ -0,0 +1,3 @@ |
|||
use refinery::include_migration_mods;
|
|||
|
|||
include_migration_mods!("src/gateway/postgres/migrations");
|
@ -1,5 +1,5 @@ |
|||
use serde::{Serialize, Deserialize};
|
|||
use crate::entity::item::ItemEntityId;
|
|||
use crate::item::ItemEntityId;
|
|||
|
|||
#[derive(Debug, Copy, Clone)]
|
|||
pub enum ItemParseError {
|
@ -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};
|
@ -1,4 +1,4 @@ |
|||
use crate::entity::item::ItemEntityId;
|
|||
use crate::item::ItemEntityId;
|
|||
use serde::{Serialize, Deserialize};
|
|||
|
|||
#[derive(Debug, Copy, Clone)]
|
@ -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)]
|
@ -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],
|
|||
}
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -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 } |
@ -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;
|
@ -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<MonsterType, MonsterStats> {
|
|||
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::<HashMap<String, MonsterStats>>(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<HashMap<MonsterType, MonsterStats>, 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),
|
|||
}
|
|||
}
|
@ -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)]
|
@ -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<u8> for Episode {
|
|||
type Error = ();
|
|||
|
|||
fn try_from(value: u8) -> Result<Episode, ()> {
|
|||
match value {
|
|||
1 => Ok(Episode::One),
|
|||
2 => Ok(Episode::Two),
|
|||
3 => Ok(Episode::Four),
|
|||
_ => Err(())
|
|||
}
|
|||
}
|
|||
}
|
|||
|
|||
impl From<Episode> 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<Episode> {
|
|||
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<u8> for Difficulty {
|
|||
type Error = ();
|
|||
|
|||
fn try_from(value: u8) -> Result<Difficulty, ()> {
|
|||
match value {
|
|||
0 => Ok(Difficulty::Normal),
|
|||
1 => Ok(Difficulty::Hard),
|
|||
2 => Ok(Difficulty::VeryHard),
|
|||
3 => Ok(Difficulty::Ultimate),
|
|||
_ => Err(())
|
|||
}
|
|||
}
|
|||
}
|
|||
|
|||
impl From<Difficulty> 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,
|
|||
}
|
|||
}
|
|||
}
|
@ -0,0 +1,4 @@ |
|||
[package] |
|||
name = "networking" |
|||
version = "0.1.0" |
|||
edition = "2021" |
@ -1,3 +0,0 @@ |
|||
use refinery::include_migration_mods;
|
|||
|
|||
include_migration_mods!("src/entity/gateway/postgres/migrations");
|
@ -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::*;
|
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue