You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.8 KiB

use serde::{Serialize, Deserialize};
use crate::entity::character::{CharacterEntityId, SectionID};
use crate::ship::room::{Episode, Difficulty, RoomMode};
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct RoomEntityId(pub u32);
#[derive(Debug, Copy, Clone)]
pub enum RoomEntityMode {
Multi,
Single,
Challenge,
Battle,
}
impl From<u8> for RoomEntityMode {
fn from(other: u8) -> RoomEntityMode {
match other {
0 => RoomEntityMode::Multi,
1 => RoomEntityMode::Single,
2 => RoomEntityMode::Challenge,
3 => RoomEntityMode::Battle,
_ => unreachable!()
}
}
}
impl From<RoomEntityMode> for u8 {
fn from(other: RoomEntityMode) -> u8 {
match other {
RoomEntityMode::Multi => 0,
RoomEntityMode::Single => 1,
RoomEntityMode::Challenge => 2,
RoomEntityMode::Battle => 3,
}
}
}
#[derive(Debug, Clone)]
pub struct RoomEntity {
pub id: RoomEntityId,
pub name: String,
pub section_id: SectionID,
pub mode: RoomEntityMode,
pub episode: Episode,
pub difficulty: Difficulty,
}
#[derive(Debug, Clone)]
pub struct NewRoomEntity {
pub name: String,
pub section_id: SectionID,
pub mode: RoomEntityMode,
pub episode: Episode,
pub difficulty: Difficulty,
}
impl NewRoomEntity {
fn new(name: String, section_id: SectionID, mode: RoomMode) -> NewRoomEntity {
NewRoomEntity {
name: name,
section_id: section_id,
mode: match mode {
RoomMode::Single {..} => RoomEntityMode::Single,
RoomMode::Multi {..} => RoomEntityMode::Multi,
RoomMode::Challenge {..} => RoomEntityMode::Challenge,
RoomMode::Battle {..} => RoomEntityMode::Battle,
},
episode: match mode {
RoomMode::Single { episode, .. } => episode,
RoomMode::Multi { episode, ..} => episode ,
RoomMode::Challenge { episode, ..} => episode,
RoomMode::Battle { episode, ..} => episode,
},
difficulty: match mode {
RoomMode::Single { difficulty, .. } => difficulty,
RoomMode::Multi { difficulty, ..} => difficulty ,
RoomMode::Challenge {..} => Difficulty::Normal,
RoomMode::Battle { difficulty, ..} => difficulty,
},
}
}
}
#[derive(Debug, Copy, Clone, Serialize)]
pub enum RoomNote {
Create {
character_id: CharacterEntityId,
},
PlayerJoin {
character_id: CharacterEntityId,
},
PlayerLeave {
character_id: CharacterEntityId,
},
QuestStart {
// quest id
},
QuestComplete {
// quest id
},
}