werewolves/werewolves-proto/src/message/host.rs

82 lines
1.9 KiB
Rust
Raw Normal View History

use core::num::NonZeroU8;
use serde::{Deserialize, Serialize};
use crate::{
error::GameError,
game::{GameOver, GameSettings},
message::{
CharacterIdentity, PublicIdentity,
night::{ActionPrompt, ActionResponse, ActionResult},
},
player::{CharacterId, PlayerId},
};
use super::{CharacterState, PlayerState};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostMessage {
GetState,
Lobby(HostLobbyMessage),
InGame(HostGameMessage),
ForceRoleAckFor(CharacterId),
NewLobby,
Echo(ServerToHostMessage),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostGameMessage {
Day(HostDayMessage),
Night(HostNightMessage),
PreviousState,
GetState,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostNightMessage {
ActionResponse(ActionResponse),
Next,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostDayMessage {
Execute,
MarkForExecution(CharacterId),
}
impl From<HostDayMessage> for HostGameMessage {
fn from(value: HostDayMessage) -> Self {
HostGameMessage::Day(value)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostLobbyMessage {
GetState,
Kick(PlayerId),
SetPlayerNumber(PlayerId, NonZeroU8),
GetGameSettings,
SetGameSettings(GameSettings),
Start,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, werewolves_macros::Titles)]
pub enum ServerToHostMessage {
Disconnect,
Daytime {
characters: Box<[CharacterState]>,
marked: Box<[CharacterId]>,
day: NonZeroU8,
},
ActionPrompt(ActionPrompt),
ActionResult(Option<CharacterIdentity>, ActionResult),
Lobby(Box<[PlayerState]>),
GameSettings(GameSettings),
Error(GameError),
GameOver(GameOver),
WaitingForRoleRevealAcks {
ackd: Box<[CharacterIdentity]>,
waiting: Box<[CharacterIdentity]>,
},
}