2025-06-23 09:48:28 +01:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
2025-10-04 17:50:29 +01:00
|
|
|
use crate::{message::PublicIdentity, player::PlayerId, role::RoleTitle};
|
2025-06-23 09:48:28 +01:00
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Error, Serialize, Deserialize)]
|
|
|
|
|
pub enum GameError {
|
2025-10-04 17:50:29 +01:00
|
|
|
#[error("too many roles. there's {players} players, but {roles} roles")]
|
2025-06-23 09:48:28 +01:00
|
|
|
TooManyRoles { players: u8, roles: u8 },
|
2025-10-04 17:50:29 +01:00
|
|
|
#[error("no wolves?")]
|
2025-06-23 09:48:28 +01:00
|
|
|
NoWolves,
|
|
|
|
|
#[error("message invalid for game state")]
|
|
|
|
|
InvalidMessageForGameState,
|
|
|
|
|
#[error("no executions during night time")]
|
|
|
|
|
NoExecutionsAtNight,
|
|
|
|
|
#[error("chracter is already dead")]
|
|
|
|
|
CharacterAlreadyDead,
|
|
|
|
|
#[error("no matching character found")]
|
|
|
|
|
NoMatchingCharacterFound,
|
|
|
|
|
#[error("character not in joined player pool")]
|
|
|
|
|
CharacterNotInJoinedPlayers,
|
|
|
|
|
#[error("{0}")]
|
|
|
|
|
GenericError(String),
|
|
|
|
|
#[error("invalid cause of death")]
|
|
|
|
|
InvalidCauseOfDeath,
|
|
|
|
|
#[error("invalid target")]
|
|
|
|
|
InvalidTarget,
|
|
|
|
|
#[error("timed out")]
|
|
|
|
|
TimedOut,
|
|
|
|
|
#[error("host channel closed")]
|
|
|
|
|
HostChannelClosed,
|
2025-10-04 17:50:29 +01:00
|
|
|
#[error("too many players: there's {got} players but only {need} roles")]
|
|
|
|
|
TooManyPlayers { got: u8, need: u8 },
|
2025-06-23 09:48:28 +01:00
|
|
|
#[error("it's already daytime")]
|
|
|
|
|
AlreadyDaytime,
|
|
|
|
|
#[error("it's not the end of the night yet")]
|
|
|
|
|
NotEndOfNight,
|
|
|
|
|
#[error("it's not day yet")]
|
|
|
|
|
NotDayYet,
|
|
|
|
|
#[error("it's not night")]
|
|
|
|
|
NotNight,
|
|
|
|
|
#[error("invalid role, expected {expected:?} got {got:?}")]
|
|
|
|
|
InvalidRole { expected: RoleTitle, got: RoleTitle },
|
|
|
|
|
#[error("no mentor for an apprentice to be an apprentice to :(")]
|
|
|
|
|
NoApprenticeMentor,
|
2025-10-04 17:50:29 +01:00
|
|
|
#[error("{0} isn't a mentor role")]
|
|
|
|
|
NotAMentor(RoleTitle),
|
2025-06-23 09:48:28 +01:00
|
|
|
#[error("inactive game object")]
|
|
|
|
|
InactiveGameObject,
|
|
|
|
|
#[error("socket error: {0}")]
|
|
|
|
|
SocketError(String),
|
|
|
|
|
#[error("this night is over")]
|
|
|
|
|
NightOver,
|
|
|
|
|
#[error("no night actions")]
|
|
|
|
|
NoNightActions,
|
|
|
|
|
#[error("still awaiting response")]
|
|
|
|
|
AwaitingResponse,
|
|
|
|
|
#[error("current state already has a response")]
|
|
|
|
|
NightNeedsNext,
|
|
|
|
|
#[error("night zero actions can only be obtained on night zero")]
|
|
|
|
|
NotNightZero,
|
|
|
|
|
#[error("wolves intro in progress")]
|
|
|
|
|
WolvesIntroInProgress,
|
|
|
|
|
#[error("a game is still ongoing")]
|
|
|
|
|
GameOngoing,
|
|
|
|
|
#[error("needs a role reveal")]
|
|
|
|
|
NeedRoleReveal,
|
2025-09-28 02:13:34 +01:00
|
|
|
#[error("no previous state")]
|
|
|
|
|
NoPreviousState,
|
|
|
|
|
#[error("invalid original kill for guardian guard")]
|
|
|
|
|
GuardianInvalidOriginalKill,
|
2025-10-02 17:52:12 +01:00
|
|
|
#[error("player not assigned number: {0}")]
|
|
|
|
|
PlayerNotAssignedNumber(String),
|
2025-10-04 17:50:29 +01:00
|
|
|
#[error("player [{0}] has an assigned role slot, but isn't in the player list")]
|
|
|
|
|
AssignedPlayerMissing(PlayerId),
|
|
|
|
|
#[error(" {0} assigned to {1} roles")]
|
|
|
|
|
AssignedMultipleTimes(PublicIdentity, usize),
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|