2025-10-05 10:54:47 +01:00
|
|
|
use core::num::NonZeroU8;
|
2025-06-23 09:48:28 +01:00
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use werewolves_macros::Extract;
|
|
|
|
|
|
|
|
|
|
use super::Result;
|
|
|
|
|
use crate::{
|
2025-10-06 20:45:15 +01:00
|
|
|
character::{Character, CharacterId},
|
2025-06-23 09:48:28 +01:00
|
|
|
diedto::DiedTo,
|
|
|
|
|
error::GameError,
|
2025-09-28 02:13:34 +01:00
|
|
|
game::{
|
|
|
|
|
DateTime, Village,
|
|
|
|
|
kill::{self, ChangesLookup},
|
|
|
|
|
},
|
2025-10-03 00:00:39 +01:00
|
|
|
message::night::{ActionPrompt, ActionResponse, ActionResult},
|
2025-10-06 20:45:15 +01:00
|
|
|
player::Protection,
|
|
|
|
|
role::{PreviousGuardianAction, RoleBlock, RoleTitle},
|
2025-06-23 09:48:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Extract)]
|
|
|
|
|
pub enum NightChange {
|
|
|
|
|
RoleChange(CharacterId, RoleTitle),
|
|
|
|
|
HunterTarget {
|
|
|
|
|
source: CharacterId,
|
|
|
|
|
target: CharacterId,
|
|
|
|
|
},
|
|
|
|
|
Kill {
|
|
|
|
|
target: CharacterId,
|
|
|
|
|
died_to: DiedTo,
|
|
|
|
|
},
|
|
|
|
|
RoleBlock {
|
|
|
|
|
source: CharacterId,
|
|
|
|
|
target: CharacterId,
|
|
|
|
|
block_type: RoleBlock,
|
|
|
|
|
},
|
|
|
|
|
Shapeshift {
|
|
|
|
|
source: CharacterId,
|
|
|
|
|
},
|
|
|
|
|
Protection {
|
|
|
|
|
target: CharacterId,
|
|
|
|
|
protection: Protection,
|
|
|
|
|
},
|
2025-10-05 10:52:37 +01:00
|
|
|
ElderReveal {
|
|
|
|
|
elder: CharacterId,
|
|
|
|
|
},
|
2025-10-06 20:45:15 +01:00
|
|
|
MasonRecruit {
|
|
|
|
|
mason_leader: CharacterId,
|
|
|
|
|
recruiting: CharacterId,
|
|
|
|
|
},
|
|
|
|
|
EmpathFoundScapegoat {
|
|
|
|
|
empath: CharacterId,
|
|
|
|
|
scapegoat: CharacterId,
|
|
|
|
|
},
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-03 22:47:38 +01:00
|
|
|
enum BlockResolvedOutcome {
|
|
|
|
|
PromptUpdate(ActionPrompt),
|
|
|
|
|
ActionComplete(ActionResult, Option<NightChange>),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ResponseOutcome {
|
|
|
|
|
PromptUpdate(ActionPrompt),
|
|
|
|
|
ActionComplete(ActionComplete),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ActionComplete {
|
2025-06-23 09:48:28 +01:00
|
|
|
pub result: ActionResult,
|
|
|
|
|
pub change: Option<NightChange>,
|
2025-10-06 20:45:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<ActionComplete> for ResponseOutcome {
|
|
|
|
|
fn from(value: ActionComplete) -> Self {
|
|
|
|
|
ResponseOutcome::ActionComplete(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ActionPrompt {
|
|
|
|
|
fn unless(&self) -> Option<Unless> {
|
|
|
|
|
match &self {
|
|
|
|
|
ActionPrompt::MasonsWake { .. }
|
|
|
|
|
| ActionPrompt::WolvesIntro { .. }
|
|
|
|
|
| ActionPrompt::RoleChange { .. }
|
|
|
|
|
| ActionPrompt::Shapeshifter { .. }
|
|
|
|
|
| ActionPrompt::ElderReveal { .. }
|
|
|
|
|
| ActionPrompt::CoverOfDarkness => None,
|
|
|
|
|
|
|
|
|
|
ActionPrompt::Arcanist {
|
|
|
|
|
marked: (Some(marked1), Some(marked2)),
|
|
|
|
|
..
|
|
|
|
|
} => Some(Unless::TargetsBlocked(*marked1, *marked2)),
|
|
|
|
|
|
|
|
|
|
ActionPrompt::Seer {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Protector {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Gravedigger {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Hunter {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Militia {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::MapleWolf {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Guardian {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Adjudicator {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::PowerSeer {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Mortician {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Beholder {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::MasonLeaderRecruit {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Empath {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Vindicator {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::PyreMaster {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::WolfPackKill {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::AlphaWolf {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::DireWolf {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Some(Unless::TargetBlocked(*marked)),
|
|
|
|
|
|
|
|
|
|
ActionPrompt::Seer { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Protector { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Gravedigger { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Hunter { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Militia { marked: None, .. }
|
|
|
|
|
| ActionPrompt::MapleWolf { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Guardian { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Adjudicator { marked: None, .. }
|
|
|
|
|
| ActionPrompt::PowerSeer { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Mortician { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Beholder { marked: None, .. }
|
|
|
|
|
| ActionPrompt::MasonLeaderRecruit { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Empath { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Vindicator { marked: None, .. }
|
|
|
|
|
| ActionPrompt::PyreMaster { marked: None, .. }
|
|
|
|
|
| ActionPrompt::WolfPackKill { marked: None, .. }
|
|
|
|
|
| ActionPrompt::AlphaWolf { marked: None, .. }
|
|
|
|
|
| ActionPrompt::DireWolf { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Arcanist {
|
|
|
|
|
marked: (Some(_), None),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Arcanist {
|
|
|
|
|
marked: (None, Some(_)),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Arcanist {
|
|
|
|
|
marked: (None, None),
|
|
|
|
|
..
|
|
|
|
|
} => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-03 22:47:38 +01:00
|
|
|
impl Default for ActionComplete {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 09:48:28 +01:00
|
|
|
enum Unless {
|
|
|
|
|
TargetBlocked(CharacterId),
|
|
|
|
|
TargetsBlocked(CharacterId, CharacterId),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Unless> for ActionResult {
|
|
|
|
|
fn from(value: Unless) -> Self {
|
|
|
|
|
match value {
|
|
|
|
|
Unless::TargetBlocked(_) | Unless::TargetsBlocked(_, _) => ActionResult::RoleBlocked,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
#[allow(clippy::large_enum_variant)]
|
|
|
|
|
enum NightState {
|
|
|
|
|
Active {
|
|
|
|
|
current_prompt: ActionPrompt,
|
|
|
|
|
current_result: Option<ActionResult>,
|
|
|
|
|
},
|
|
|
|
|
Complete,
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-30 13:07:59 +01:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct Night {
|
|
|
|
|
village: Village,
|
|
|
|
|
night: u8,
|
|
|
|
|
action_queue: VecDeque<ActionPrompt>,
|
2025-10-06 20:45:15 +01:00
|
|
|
used_actions: Vec<(ActionPrompt, ActionResult)>,
|
2025-09-30 13:07:59 +01:00
|
|
|
changes: Vec<NightChange>,
|
|
|
|
|
night_state: NightState,
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 09:48:28 +01:00
|
|
|
impl Night {
|
|
|
|
|
pub fn new(village: Village) -> Result<Self> {
|
|
|
|
|
let night = match village.date_time() {
|
|
|
|
|
DateTime::Day { number: _ } => return Err(GameError::NotNight),
|
|
|
|
|
DateTime::Night { number } => number,
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-05 10:52:37 +01:00
|
|
|
let filter = if village.executed_known_elder() {
|
|
|
|
|
// there is a lynched elder, remove villager PRs from the prompts
|
|
|
|
|
filter::no_village
|
|
|
|
|
} else {
|
|
|
|
|
filter::no_filter
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-23 09:48:28 +01:00
|
|
|
let mut action_queue = village
|
|
|
|
|
.characters()
|
|
|
|
|
.into_iter()
|
2025-10-05 10:52:37 +01:00
|
|
|
.filter(filter)
|
2025-10-06 20:45:15 +01:00
|
|
|
.map(|c| c.night_action_prompts(&village))
|
2025-06-23 09:48:28 +01:00
|
|
|
.collect::<Result<Box<[_]>>>()?
|
|
|
|
|
.into_iter()
|
2025-09-30 13:07:59 +01:00
|
|
|
.flatten()
|
|
|
|
|
.chain((night > 0).then(|| ActionPrompt::WolfPackKill {
|
2025-10-03 22:47:38 +01:00
|
|
|
marked: None,
|
2025-09-30 13:07:59 +01:00
|
|
|
living_villagers: village.living_villagers(),
|
|
|
|
|
}))
|
2025-06-23 09:48:28 +01:00
|
|
|
.collect::<Vec<_>>();
|
2025-09-30 13:07:59 +01:00
|
|
|
action_queue.sort_by(|left_prompt, right_prompt| {
|
2025-06-23 09:48:28 +01:00
|
|
|
left_prompt
|
|
|
|
|
.partial_cmp(right_prompt)
|
|
|
|
|
.unwrap_or(core::cmp::Ordering::Equal)
|
|
|
|
|
});
|
2025-09-30 13:07:59 +01:00
|
|
|
let mut action_queue = VecDeque::from(action_queue);
|
|
|
|
|
|
|
|
|
|
if night == 0 {
|
|
|
|
|
action_queue.push_front(ActionPrompt::WolvesIntro {
|
|
|
|
|
wolves: village
|
2025-09-26 21:15:52 +01:00
|
|
|
.living_wolf_pack_players()
|
|
|
|
|
.into_iter()
|
2025-10-06 20:45:15 +01:00
|
|
|
.map(|w| (w.identity(), w.role_title()))
|
2025-09-30 13:07:59 +01:00
|
|
|
.collect(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// let current_prompt = action_queue.pop_front().ok_or(GameError::NoNightActions)?;
|
2025-06-23 09:48:28 +01:00
|
|
|
let night_state = NightState::Active {
|
2025-09-30 13:07:59 +01:00
|
|
|
current_prompt: ActionPrompt::CoverOfDarkness,
|
2025-06-23 09:48:28 +01:00
|
|
|
current_result: None,
|
|
|
|
|
};
|
2025-10-05 10:52:37 +01:00
|
|
|
|
|
|
|
|
let changes = Self::automatic_changes(&village, night);
|
|
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
night,
|
|
|
|
|
changes,
|
|
|
|
|
village,
|
|
|
|
|
night_state,
|
|
|
|
|
action_queue,
|
|
|
|
|
used_actions: Vec::new(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// changes that require no input (such as hunter firing)
|
|
|
|
|
fn automatic_changes(village: &Village, night: u8) -> Vec<NightChange> {
|
2025-06-23 09:48:28 +01:00
|
|
|
let mut changes = Vec::new();
|
2025-10-05 10:52:37 +01:00
|
|
|
let night = match NonZeroU8::new(night) {
|
|
|
|
|
Some(night) => night,
|
|
|
|
|
None => return changes,
|
|
|
|
|
};
|
|
|
|
|
if !village.executed_known_elder() {
|
|
|
|
|
village
|
2025-06-23 09:48:28 +01:00
|
|
|
.dead_characters()
|
|
|
|
|
.into_iter()
|
|
|
|
|
.filter_map(|c| c.died_to().map(|d| (c, d)))
|
2025-10-06 20:45:15 +01:00
|
|
|
.filter_map(|(c, d)| c.hunter().ok().and_then(|h| *h).map(|t| (c, t, d)))
|
2025-06-23 09:48:28 +01:00
|
|
|
.filter_map(|(c, t, d)| match d.date_time() {
|
2025-10-05 10:52:37 +01:00
|
|
|
DateTime::Day { number } => (number.get() == night.get()).then_some((c, t)),
|
2025-06-23 09:48:28 +01:00
|
|
|
DateTime::Night { number: _ } => None,
|
|
|
|
|
})
|
|
|
|
|
.map(|(c, target)| NightChange::Kill {
|
|
|
|
|
target,
|
|
|
|
|
died_to: DiedTo::Hunter {
|
2025-10-05 10:52:37 +01:00
|
|
|
night,
|
2025-10-05 10:54:47 +01:00
|
|
|
killer: c.character_id(),
|
2025-06-23 09:48:28 +01:00
|
|
|
},
|
|
|
|
|
})
|
2025-10-05 10:52:37 +01:00
|
|
|
.for_each(|c| changes.push(c));
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-05 10:52:37 +01:00
|
|
|
changes
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
|
2025-09-28 02:13:34 +01:00
|
|
|
pub fn previous_state(&mut self) -> Result<()> {
|
2025-10-06 20:45:15 +01:00
|
|
|
return Err(GameError::NoPreviousState);
|
|
|
|
|
let (prev_act, prev_result) = self.used_actions.pop().ok_or(GameError::NoPreviousState)?;
|
2025-09-28 02:13:34 +01:00
|
|
|
log::info!("loading previous prompt: {prev_act:?}");
|
|
|
|
|
match &self.night_state {
|
|
|
|
|
NightState::Active {
|
|
|
|
|
current_prompt,
|
|
|
|
|
current_result: Some(current_result),
|
|
|
|
|
} => {
|
|
|
|
|
log::info!("removing current result: {current_result:?}");
|
|
|
|
|
self.night_state = NightState::Active {
|
|
|
|
|
current_prompt: current_prompt.clone(),
|
|
|
|
|
current_result: None,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
NightState::Active {
|
|
|
|
|
current_prompt,
|
|
|
|
|
current_result: None,
|
|
|
|
|
} => {
|
|
|
|
|
log::info!("pushing current prompt to front of action queue: {current_prompt:?}");
|
2025-09-30 13:07:59 +01:00
|
|
|
self.action_queue.push_front(current_prompt.clone());
|
2025-09-28 02:13:34 +01:00
|
|
|
self.night_state = NightState::Active {
|
|
|
|
|
current_prompt: prev_act,
|
|
|
|
|
current_result: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NightState::Complete => {
|
|
|
|
|
self.night_state = NightState::Active {
|
|
|
|
|
current_prompt: prev_act,
|
|
|
|
|
current_result: None,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-30 13:07:59 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
|
pub fn action_queue(&self) -> Box<[ActionPrompt]> {
|
|
|
|
|
self.action_queue.iter().cloned().collect()
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 09:48:28 +01:00
|
|
|
pub fn collect_completed(&self) -> Result<Village> {
|
|
|
|
|
if !matches!(self.night_state, NightState::Complete) {
|
|
|
|
|
return Err(GameError::NotEndOfNight);
|
|
|
|
|
}
|
|
|
|
|
let mut new_village = self.village.clone();
|
2025-09-28 02:13:34 +01:00
|
|
|
let mut changes = ChangesLookup::new(&self.changes);
|
2025-06-23 09:48:28 +01:00
|
|
|
for change in self.changes.iter() {
|
|
|
|
|
match change {
|
2025-10-06 20:45:15 +01:00
|
|
|
NightChange::ElderReveal { elder } => {
|
|
|
|
|
new_village.character_by_id_mut(*elder)?.elder_reveal()
|
|
|
|
|
}
|
2025-06-23 09:48:28 +01:00
|
|
|
NightChange::RoleChange(character_id, role_title) => new_village
|
2025-10-06 20:45:15 +01:00
|
|
|
.character_by_id_mut(*character_id)?
|
2025-06-23 09:48:28 +01:00
|
|
|
.role_change(*role_title, DateTime::Night { number: self.night })?,
|
|
|
|
|
NightChange::HunterTarget { source, target } => {
|
2025-10-06 20:45:15 +01:00
|
|
|
let hunter_character = new_village.character_by_id_mut(*source).unwrap();
|
|
|
|
|
hunter_character.hunter_mut()?.replace(*target);
|
2025-06-23 09:48:28 +01:00
|
|
|
if changes.killed(source).is_some()
|
|
|
|
|
&& changes.protected(source).is_none()
|
|
|
|
|
&& changes.protected(target).is_none()
|
|
|
|
|
{
|
|
|
|
|
new_village
|
2025-10-05 10:52:37 +01:00
|
|
|
.character_by_id_mut(*target)
|
2025-06-23 09:48:28 +01:00
|
|
|
.unwrap()
|
|
|
|
|
.kill(DiedTo::Hunter {
|
2025-10-05 10:54:47 +01:00
|
|
|
killer: *source,
|
2025-06-23 09:48:28 +01:00
|
|
|
night: NonZeroU8::new(self.night).unwrap(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NightChange::Kill { target, died_to } => {
|
2025-09-28 02:13:34 +01:00
|
|
|
if let Some(kill) = kill::resolve_kill(
|
|
|
|
|
&mut changes,
|
|
|
|
|
target,
|
|
|
|
|
died_to,
|
|
|
|
|
self.night,
|
|
|
|
|
&self.village,
|
|
|
|
|
)? {
|
|
|
|
|
kill.apply_to_village(&mut new_village)?;
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NightChange::Shapeshift { source } => {
|
|
|
|
|
if let Some(target) = changes.wolf_pack_kill_target()
|
|
|
|
|
&& changes.protected(target).is_none()
|
|
|
|
|
{
|
2025-10-05 10:52:37 +01:00
|
|
|
let ss = new_village.character_by_id_mut(*source).unwrap();
|
2025-10-06 20:45:15 +01:00
|
|
|
ss.shapeshifter_mut().unwrap().replace(*target);
|
2025-06-23 09:48:28 +01:00
|
|
|
ss.kill(DiedTo::Shapeshift {
|
2025-10-05 10:54:47 +01:00
|
|
|
into: *target,
|
2025-06-23 09:48:28 +01:00
|
|
|
night: NonZeroU8::new(self.night).unwrap(),
|
|
|
|
|
});
|
2025-09-28 02:13:34 +01:00
|
|
|
// role change pushed in [apply_shapeshift]
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NightChange::RoleBlock {
|
|
|
|
|
source: _,
|
|
|
|
|
target: _,
|
|
|
|
|
block_type: _,
|
|
|
|
|
}
|
|
|
|
|
| NightChange::Protection {
|
|
|
|
|
target: _,
|
|
|
|
|
protection: _,
|
|
|
|
|
} => {}
|
2025-10-06 20:45:15 +01:00
|
|
|
NightChange::MasonRecruit {
|
|
|
|
|
mason_leader,
|
|
|
|
|
recruiting,
|
|
|
|
|
} => {
|
|
|
|
|
if new_village.character_by_id(*recruiting)?.is_wolf() {
|
|
|
|
|
new_village.character_by_id_mut(*mason_leader)?.kill(
|
|
|
|
|
DiedTo::MasonLeaderRecruitFail {
|
|
|
|
|
tried_recruiting: *recruiting,
|
|
|
|
|
night: self.night,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
new_village
|
|
|
|
|
.character_by_id_mut(*mason_leader)?
|
|
|
|
|
.mason_leader_mut()?
|
|
|
|
|
.recruit(*recruiting);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NightChange::EmpathFoundScapegoat { empath, scapegoat } => {
|
|
|
|
|
new_village
|
|
|
|
|
.character_by_id_mut(*scapegoat)?
|
|
|
|
|
.role_change(RoleTitle::Villager, DateTime::Night { number: self.night })?;
|
|
|
|
|
*new_village.character_by_id_mut(*empath)?.empath_mut()? = true;
|
|
|
|
|
}
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-09-26 21:15:52 +01:00
|
|
|
if new_village.is_game_over().is_none() {
|
|
|
|
|
new_village.to_day()?;
|
|
|
|
|
}
|
2025-06-23 09:48:28 +01:00
|
|
|
Ok(new_village)
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-06 20:45:15 +01:00
|
|
|
fn apply_mason_recruit(
|
|
|
|
|
&mut self,
|
|
|
|
|
mason_leader: CharacterId,
|
|
|
|
|
recruiting: CharacterId,
|
|
|
|
|
) -> Result<ActionResult> {
|
|
|
|
|
if self.village.character_by_id(recruiting)?.is_village() {
|
|
|
|
|
if let Some(masons) = self.action_queue.iter_mut().find_map(|a| match a {
|
|
|
|
|
ActionPrompt::MasonsWake {
|
|
|
|
|
character_id,
|
|
|
|
|
masons,
|
|
|
|
|
} => (character_id.character_id == mason_leader).then_some(masons),
|
|
|
|
|
_ => None,
|
|
|
|
|
}) {
|
|
|
|
|
let mut ext_masons = masons.to_vec();
|
|
|
|
|
ext_masons.push(self.village.character_by_id(recruiting)?.identity());
|
|
|
|
|
*masons = ext_masons.into_boxed_slice();
|
|
|
|
|
} else {
|
|
|
|
|
self.action_queue.push_front(ActionPrompt::MasonsWake {
|
|
|
|
|
character_id: self.village.character_by_id(mason_leader)?.identity(),
|
|
|
|
|
masons: Box::new([self.village.character_by_id(recruiting)?.identity()]),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
Ok(ActionResult::Continue)
|
|
|
|
|
} else {
|
|
|
|
|
Ok(ActionResult::GoBackToSleep)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-30 13:07:59 +01:00
|
|
|
fn apply_shapeshift(&mut self, source: &CharacterId) -> Result<()> {
|
2025-09-27 00:14:26 +01:00
|
|
|
if let Some(kill_target) = self.changes.iter().find_map(|c| match c {
|
|
|
|
|
NightChange::Kill {
|
|
|
|
|
target,
|
2025-09-28 02:13:34 +01:00
|
|
|
died_to:
|
|
|
|
|
DiedTo::Wolfpack {
|
|
|
|
|
night: _,
|
|
|
|
|
killing_wolf: _,
|
|
|
|
|
},
|
2025-10-05 10:54:47 +01:00
|
|
|
} => Some(*target),
|
2025-09-27 00:14:26 +01:00
|
|
|
_ => None,
|
|
|
|
|
}) {
|
|
|
|
|
if self.changes.iter().any(|c| match c {
|
|
|
|
|
NightChange::Protection {
|
|
|
|
|
target,
|
|
|
|
|
protection: _,
|
|
|
|
|
} => target == &kill_target,
|
|
|
|
|
_ => false,
|
|
|
|
|
}) {
|
|
|
|
|
// there is protection, so the kill doesn't happen -> no shapeshift
|
2025-09-30 13:07:59 +01:00
|
|
|
return Ok(());
|
2025-09-27 00:14:26 +01:00
|
|
|
}
|
2025-09-30 13:07:59 +01:00
|
|
|
|
2025-09-28 02:13:34 +01:00
|
|
|
if self.changes.iter_mut().any(|c| {
|
2025-09-27 00:14:26 +01:00
|
|
|
matches!(
|
|
|
|
|
c,
|
|
|
|
|
NightChange::Kill {
|
|
|
|
|
target: _,
|
2025-09-28 02:13:34 +01:00
|
|
|
died_to: DiedTo::Wolfpack {
|
|
|
|
|
night: _,
|
|
|
|
|
killing_wolf: _
|
|
|
|
|
}
|
2025-09-27 00:14:26 +01:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}) {
|
2025-09-28 02:13:34 +01:00
|
|
|
self.changes.push(NightChange::Kill {
|
2025-10-05 10:54:47 +01:00
|
|
|
target: *source,
|
2025-09-27 00:14:26 +01:00
|
|
|
died_to: DiedTo::Shapeshift {
|
2025-10-05 10:54:47 +01:00
|
|
|
into: kill_target,
|
2025-09-27 00:14:26 +01:00
|
|
|
night: NonZeroU8::new(self.night).unwrap(),
|
|
|
|
|
},
|
2025-09-28 02:13:34 +01:00
|
|
|
});
|
2025-09-27 00:14:26 +01:00
|
|
|
}
|
2025-10-06 20:45:15 +01:00
|
|
|
self.changes
|
|
|
|
|
.push(NightChange::Shapeshift { source: *source });
|
2025-09-30 13:07:59 +01:00
|
|
|
self.action_queue.push_front(ActionPrompt::RoleChange {
|
|
|
|
|
new_role: RoleTitle::Werewolf,
|
2025-10-06 20:45:15 +01:00
|
|
|
character_id: self.village.character_by_id(kill_target)?.identity(),
|
2025-09-30 13:07:59 +01:00
|
|
|
});
|
2025-09-27 00:14:26 +01:00
|
|
|
}
|
2025-09-30 13:07:59 +01:00
|
|
|
// Remove any further shapeshift prompts from the queue
|
|
|
|
|
let mut new_queue = VecDeque::new();
|
|
|
|
|
while let Some(prompt) = self.action_queue.pop_back() {
|
|
|
|
|
match &prompt {
|
|
|
|
|
ActionPrompt::Shapeshifter { character_id: _ } => {}
|
|
|
|
|
_ => new_queue.push_front(prompt),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.action_queue = new_queue;
|
|
|
|
|
Ok(())
|
2025-09-27 00:14:26 +01:00
|
|
|
}
|
|
|
|
|
|
2025-10-03 22:47:38 +01:00
|
|
|
pub fn received_response(&mut self, resp: ActionResponse) -> Result<ServerAction> {
|
2025-09-30 13:07:59 +01:00
|
|
|
match self.received_response_with_role_blocks(resp)? {
|
2025-10-03 22:47:38 +01:00
|
|
|
BlockResolvedOutcome::PromptUpdate(prompt) => match &mut self.night_state {
|
|
|
|
|
NightState::Active {
|
|
|
|
|
current_result: Some(_),
|
|
|
|
|
..
|
2025-10-04 17:50:29 +01:00
|
|
|
} => Err(GameError::AwaitingResponse),
|
2025-10-03 22:47:38 +01:00
|
|
|
NightState::Active { current_prompt, .. } => {
|
|
|
|
|
*current_prompt = prompt.clone();
|
|
|
|
|
Ok(ServerAction::Prompt(prompt))
|
|
|
|
|
}
|
2025-10-04 17:50:29 +01:00
|
|
|
NightState::Complete => Err(GameError::NightOver),
|
2025-10-03 22:47:38 +01:00
|
|
|
},
|
2025-10-06 20:45:15 +01:00
|
|
|
BlockResolvedOutcome::ActionComplete(mut result, Some(change)) => {
|
2025-06-23 09:48:28 +01:00
|
|
|
match &mut self.night_state {
|
|
|
|
|
NightState::Active {
|
|
|
|
|
current_prompt: _,
|
|
|
|
|
current_result,
|
|
|
|
|
} => current_result.replace(result.clone()),
|
|
|
|
|
NightState::Complete => return Err(GameError::NightOver),
|
|
|
|
|
};
|
2025-09-27 00:14:26 +01:00
|
|
|
if let NightChange::Shapeshift { source } = &change {
|
2025-09-30 13:07:59 +01:00
|
|
|
// needs to be resolved _now_ so that the target can be woken
|
|
|
|
|
// for the role change with the wolves
|
|
|
|
|
self.apply_shapeshift(source)?;
|
2025-10-03 22:47:38 +01:00
|
|
|
return Ok(ServerAction::Result(
|
|
|
|
|
self.action_queue
|
|
|
|
|
.iter()
|
|
|
|
|
.next()
|
|
|
|
|
.and_then(|a| a.is_wolfy().then_some(ActionResult::Continue))
|
|
|
|
|
.unwrap_or(ActionResult::GoBackToSleep),
|
|
|
|
|
));
|
2025-09-27 00:14:26 +01:00
|
|
|
}
|
2025-10-06 20:45:15 +01:00
|
|
|
if let NightChange::MasonRecruit {
|
|
|
|
|
mason_leader,
|
|
|
|
|
recruiting,
|
|
|
|
|
} = &change
|
|
|
|
|
{
|
|
|
|
|
result = self.apply_mason_recruit(*mason_leader, *recruiting)?;
|
|
|
|
|
}
|
2025-06-23 09:48:28 +01:00
|
|
|
self.changes.push(change);
|
2025-10-03 22:47:38 +01:00
|
|
|
Ok(ServerAction::Result(result))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
BlockResolvedOutcome::ActionComplete(result, None) => {
|
2025-06-23 09:48:28 +01:00
|
|
|
match &mut self.night_state {
|
|
|
|
|
NightState::Active {
|
|
|
|
|
current_prompt: _,
|
|
|
|
|
current_result,
|
|
|
|
|
} => {
|
|
|
|
|
current_result.replace(result.clone());
|
|
|
|
|
}
|
|
|
|
|
NightState::Complete => return Err(GameError::NightOver),
|
|
|
|
|
};
|
2025-10-03 22:47:38 +01:00
|
|
|
Ok(ServerAction::Result(result))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-30 13:07:59 +01:00
|
|
|
|
|
|
|
|
fn received_response_consecutive_wolves_dont_sleep(
|
|
|
|
|
&self,
|
|
|
|
|
resp: ActionResponse,
|
|
|
|
|
) -> Result<ResponseOutcome> {
|
2025-10-03 22:47:38 +01:00
|
|
|
let (current_cover, current_wolfy) = self
|
|
|
|
|
.current_prompt()
|
|
|
|
|
.map(|current_prompt| {
|
|
|
|
|
(
|
|
|
|
|
*current_prompt == ActionPrompt::CoverOfDarkness,
|
|
|
|
|
current_prompt.is_wolfy(),
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
.unwrap_or_default();
|
2025-09-30 13:07:59 +01:00
|
|
|
let next_wolfy = self
|
|
|
|
|
.action_queue
|
|
|
|
|
.iter()
|
|
|
|
|
.next()
|
|
|
|
|
.map(|a| a.is_wolfy())
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
|
2025-10-03 22:47:38 +01:00
|
|
|
if current_cover && let ActionResponse::Continue = &resp {
|
|
|
|
|
return Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::Continue,
|
|
|
|
|
change: None,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-30 13:07:59 +01:00
|
|
|
match (
|
|
|
|
|
self.received_response_inner(resp)?,
|
|
|
|
|
current_wolfy,
|
|
|
|
|
next_wolfy,
|
|
|
|
|
) {
|
2025-10-03 22:47:38 +01:00
|
|
|
(ResponseOutcome::PromptUpdate(p), _, _) => Ok(ResponseOutcome::PromptUpdate(p)),
|
2025-09-30 13:07:59 +01:00
|
|
|
(
|
2025-10-03 22:47:38 +01:00
|
|
|
ResponseOutcome::ActionComplete(ActionComplete {
|
2025-09-30 13:07:59 +01:00
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::Shapeshift { source }),
|
2025-10-03 22:47:38 +01:00
|
|
|
}),
|
2025-09-30 13:07:59 +01:00
|
|
|
true,
|
|
|
|
|
_,
|
2025-10-03 22:47:38 +01:00
|
|
|
) => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
2025-09-30 13:07:59 +01:00
|
|
|
result: ActionResult::Continue,
|
|
|
|
|
change: Some(NightChange::Shapeshift { source }),
|
2025-10-03 22:47:38 +01:00
|
|
|
})),
|
2025-09-30 13:07:59 +01:00
|
|
|
(
|
2025-10-03 22:47:38 +01:00
|
|
|
ResponseOutcome::ActionComplete(ActionComplete {
|
2025-09-30 13:07:59 +01:00
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change,
|
2025-10-03 22:47:38 +01:00
|
|
|
}),
|
2025-09-30 13:07:59 +01:00
|
|
|
true,
|
|
|
|
|
true,
|
2025-10-03 22:47:38 +01:00
|
|
|
) => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
2025-09-30 13:07:59 +01:00
|
|
|
result: ActionResult::Continue,
|
|
|
|
|
change,
|
2025-10-03 22:47:38 +01:00
|
|
|
})),
|
2025-09-30 13:07:59 +01:00
|
|
|
(outcome, _, _) => Ok(outcome),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 09:48:28 +01:00
|
|
|
fn received_response_with_role_blocks(
|
|
|
|
|
&self,
|
|
|
|
|
resp: ActionResponse,
|
2025-10-03 22:47:38 +01:00
|
|
|
) -> Result<BlockResolvedOutcome> {
|
2025-09-30 13:07:59 +01:00
|
|
|
match self.received_response_consecutive_wolves_dont_sleep(resp)? {
|
2025-10-03 22:47:38 +01:00
|
|
|
ResponseOutcome::PromptUpdate(update) => Ok(BlockResolvedOutcome::PromptUpdate(update)),
|
2025-10-06 20:45:15 +01:00
|
|
|
ResponseOutcome::ActionComplete(ActionComplete { result, change }) => {
|
|
|
|
|
match self.current_prompt().ok_or(GameError::NightOver)?.unless() {
|
|
|
|
|
Some(Unless::TargetBlocked(unless_blocked)) => {
|
|
|
|
|
if self.changes.iter().any(|c| match c {
|
|
|
|
|
NightChange::RoleBlock {
|
|
|
|
|
source: _,
|
|
|
|
|
target,
|
|
|
|
|
block_type: _,
|
|
|
|
|
} => target == &unless_blocked,
|
|
|
|
|
_ => false,
|
|
|
|
|
}) {
|
|
|
|
|
Ok(BlockResolvedOutcome::ActionComplete(
|
|
|
|
|
ActionResult::RoleBlocked,
|
|
|
|
|
None,
|
|
|
|
|
))
|
|
|
|
|
} else {
|
|
|
|
|
Ok(BlockResolvedOutcome::ActionComplete(result, change))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Some(Unless::TargetsBlocked(unless_blocked1, unless_blocked2)) => {
|
|
|
|
|
if self.changes.iter().any(|c| match c {
|
|
|
|
|
NightChange::RoleBlock {
|
|
|
|
|
source: _,
|
|
|
|
|
target,
|
|
|
|
|
block_type: _,
|
|
|
|
|
} => target == &unless_blocked1 || target == &unless_blocked2,
|
|
|
|
|
_ => false,
|
|
|
|
|
}) {
|
|
|
|
|
Ok(BlockResolvedOutcome::ActionComplete(
|
|
|
|
|
ActionResult::RoleBlocked,
|
|
|
|
|
None,
|
|
|
|
|
))
|
|
|
|
|
} else {
|
|
|
|
|
Ok(BlockResolvedOutcome::ActionComplete(result, change))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None => Ok(BlockResolvedOutcome::ActionComplete(result, change)),
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn received_response_inner(&self, resp: ActionResponse) -> Result<ResponseOutcome> {
|
2025-09-30 13:07:59 +01:00
|
|
|
let current_prompt = match &self.night_state {
|
2025-06-23 09:48:28 +01:00
|
|
|
NightState::Active {
|
|
|
|
|
current_prompt: _,
|
|
|
|
|
current_result: Some(_),
|
|
|
|
|
} => return Err(GameError::NightNeedsNext),
|
|
|
|
|
NightState::Active {
|
|
|
|
|
current_prompt,
|
|
|
|
|
current_result: None,
|
2025-09-30 13:07:59 +01:00
|
|
|
} => current_prompt,
|
2025-06-23 09:48:28 +01:00
|
|
|
NightState::Complete => return Err(GameError::NightOver),
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-03 22:47:38 +01:00
|
|
|
match resp {
|
|
|
|
|
ActionResponse::MarkTarget(mark) => {
|
|
|
|
|
return Ok(ResponseOutcome::PromptUpdate(
|
|
|
|
|
current_prompt.with_mark(mark)?,
|
|
|
|
|
));
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionResponse::Shapeshift => {
|
|
|
|
|
return match current_prompt {
|
|
|
|
|
ActionPrompt::Shapeshifter {
|
|
|
|
|
character_id: source,
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::Shapeshift {
|
2025-10-05 10:54:47 +01:00
|
|
|
source: source.character_id,
|
2025-10-03 22:47:38 +01:00
|
|
|
}),
|
|
|
|
|
})),
|
|
|
|
|
_ => Err(GameError::InvalidMessageForGameState),
|
2025-09-30 13:07:59 +01:00
|
|
|
};
|
|
|
|
|
}
|
2025-10-05 01:22:55 +01:00
|
|
|
ActionResponse::Continue => {
|
|
|
|
|
if let ActionPrompt::RoleChange {
|
|
|
|
|
character_id,
|
|
|
|
|
new_role,
|
|
|
|
|
} = current_prompt
|
|
|
|
|
{
|
|
|
|
|
return Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::RoleChange(
|
2025-10-05 10:54:47 +01:00
|
|
|
character_id.character_id,
|
2025-10-05 01:22:55 +01:00
|
|
|
*new_role,
|
|
|
|
|
)),
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
};
|
2025-06-23 09:48:28 +01:00
|
|
|
|
2025-10-03 22:47:38 +01:00
|
|
|
match current_prompt {
|
|
|
|
|
ActionPrompt::RoleChange { .. }
|
|
|
|
|
| ActionPrompt::WolvesIntro { .. }
|
|
|
|
|
| ActionPrompt::CoverOfDarkness => {
|
|
|
|
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
2025-06-23 09:48:28 +01:00
|
|
|
change: None,
|
2025-10-03 22:47:38 +01:00
|
|
|
}))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-05 10:52:37 +01:00
|
|
|
ActionPrompt::ElderReveal { character_id } => {
|
|
|
|
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::ElderReveal {
|
2025-10-05 10:54:47 +01:00
|
|
|
elder: character_id.character_id,
|
2025-10-05 10:52:37 +01:00
|
|
|
}),
|
|
|
|
|
}))
|
|
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionPrompt::Seer {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => {
|
2025-10-06 20:45:15 +01:00
|
|
|
let alignment = self.village.character_by_id(*marked)?.alignment();
|
2025-10-03 22:47:38 +01:00
|
|
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::Seer(alignment),
|
2025-06-23 09:48:28 +01:00
|
|
|
change: None,
|
2025-10-03 22:47:38 +01:00
|
|
|
}))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionPrompt::Protector {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
character_id,
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::Protection {
|
2025-10-05 10:54:47 +01:00
|
|
|
target: *marked,
|
2025-10-03 22:47:38 +01:00
|
|
|
protection: Protection::Protector {
|
2025-10-05 10:54:47 +01:00
|
|
|
source: character_id.character_id,
|
2025-10-03 22:47:38 +01:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
})),
|
|
|
|
|
ActionPrompt::Arcanist {
|
|
|
|
|
marked: (Some(marked1), Some(marked2)),
|
|
|
|
|
..
|
|
|
|
|
} => {
|
2025-10-06 20:45:15 +01:00
|
|
|
let same = self.village.character_by_id(*marked1)?.alignment()
|
|
|
|
|
== self.village.character_by_id(*marked2)?.alignment();
|
2025-10-03 22:47:38 +01:00
|
|
|
|
|
|
|
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::Arcanist { same },
|
2025-06-23 09:48:28 +01:00
|
|
|
change: None,
|
2025-10-03 22:47:38 +01:00
|
|
|
}))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionPrompt::Gravedigger {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => {
|
2025-10-06 20:45:15 +01:00
|
|
|
let dig_role = self.village.character_by_id(*marked)?.gravedigger_dig();
|
2025-10-03 22:47:38 +01:00
|
|
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GraveDigger(dig_role),
|
|
|
|
|
change: None,
|
|
|
|
|
}))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionPrompt::Hunter {
|
|
|
|
|
character_id,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
2025-09-30 13:07:59 +01:00
|
|
|
result: ActionResult::GoBackToSleep,
|
2025-10-03 22:47:38 +01:00
|
|
|
change: Some(NightChange::HunterTarget {
|
2025-10-05 10:54:47 +01:00
|
|
|
source: character_id.character_id,
|
|
|
|
|
target: *marked,
|
2025-10-03 22:47:38 +01:00
|
|
|
}),
|
|
|
|
|
})),
|
|
|
|
|
ActionPrompt::Militia {
|
|
|
|
|
character_id,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::Kill {
|
2025-10-05 10:54:47 +01:00
|
|
|
target: *marked,
|
2025-10-03 22:47:38 +01:00
|
|
|
died_to: DiedTo::Militia {
|
2025-10-05 10:54:47 +01:00
|
|
|
killer: character_id.character_id,
|
2025-10-03 22:47:38 +01:00
|
|
|
night: NonZeroU8::new(self.night)
|
|
|
|
|
.ok_or(GameError::InvalidMessageForGameState)?,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
})),
|
|
|
|
|
ActionPrompt::Militia { marked: None, .. } => {
|
|
|
|
|
Ok(ResponseOutcome::ActionComplete(Default::default()))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionPrompt::MapleWolf {
|
|
|
|
|
character_id,
|
|
|
|
|
kill_or_die,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
2025-06-23 09:48:28 +01:00
|
|
|
result: ActionResult::GoBackToSleep,
|
2025-10-03 22:47:38 +01:00
|
|
|
change: Some(NightChange::Kill {
|
2025-10-05 10:54:47 +01:00
|
|
|
target: *marked,
|
2025-10-03 22:47:38 +01:00
|
|
|
died_to: DiedTo::MapleWolf {
|
2025-10-05 10:54:47 +01:00
|
|
|
source: character_id.character_id,
|
2025-10-03 22:47:38 +01:00
|
|
|
night: NonZeroU8::new(self.night)
|
|
|
|
|
.ok_or(GameError::InvalidMessageForGameState)?,
|
|
|
|
|
starves_if_fails: *kill_or_die,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
})),
|
|
|
|
|
ActionPrompt::MapleWolf { marked: None, .. } => {
|
|
|
|
|
Ok(ResponseOutcome::ActionComplete(Default::default()))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionPrompt::Guardian {
|
|
|
|
|
character_id,
|
|
|
|
|
previous: None,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::Protection {
|
2025-10-05 10:54:47 +01:00
|
|
|
target: *marked,
|
2025-10-03 22:47:38 +01:00
|
|
|
protection: Protection::Guardian {
|
2025-10-05 10:54:47 +01:00
|
|
|
source: character_id.character_id,
|
2025-10-03 22:47:38 +01:00
|
|
|
guarding: false,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
})),
|
|
|
|
|
ActionPrompt::Guardian {
|
|
|
|
|
character_id,
|
|
|
|
|
previous: Some(PreviousGuardianAction::Guard(prev_target)),
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => {
|
|
|
|
|
if prev_target.character_id == *marked {
|
2025-06-23 09:48:28 +01:00
|
|
|
return Err(GameError::InvalidTarget);
|
|
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
2025-06-23 09:48:28 +01:00
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::Protection {
|
2025-10-05 10:54:47 +01:00
|
|
|
target: *marked,
|
2025-06-23 09:48:28 +01:00
|
|
|
protection: Protection::Guardian {
|
2025-10-05 10:54:47 +01:00
|
|
|
source: character_id.character_id,
|
2025-06-23 09:48:28 +01:00
|
|
|
guarding: false,
|
|
|
|
|
},
|
|
|
|
|
}),
|
2025-10-03 22:47:38 +01:00
|
|
|
}))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionPrompt::Guardian {
|
|
|
|
|
character_id,
|
|
|
|
|
previous: Some(PreviousGuardianAction::Protect(prev_protect)),
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
2025-09-30 13:07:59 +01:00
|
|
|
result: ActionResult::GoBackToSleep,
|
2025-10-03 22:47:38 +01:00
|
|
|
change: Some(NightChange::Protection {
|
2025-10-05 10:54:47 +01:00
|
|
|
target: *marked,
|
2025-10-03 22:47:38 +01:00
|
|
|
protection: Protection::Guardian {
|
2025-10-05 10:54:47 +01:00
|
|
|
source: character_id.character_id,
|
2025-10-03 22:47:38 +01:00
|
|
|
guarding: prev_protect.character_id == *marked,
|
|
|
|
|
},
|
2025-09-30 13:07:59 +01:00
|
|
|
}),
|
2025-10-03 22:47:38 +01:00
|
|
|
})),
|
|
|
|
|
ActionPrompt::WolfPackKill {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
2025-09-30 13:07:59 +01:00
|
|
|
result: ActionResult::GoBackToSleep,
|
2025-10-03 22:47:38 +01:00
|
|
|
change: Some(NightChange::Kill {
|
2025-10-05 10:54:47 +01:00
|
|
|
target: *marked,
|
2025-10-03 22:47:38 +01:00
|
|
|
died_to: DiedTo::Wolfpack {
|
|
|
|
|
killing_wolf: self
|
|
|
|
|
.village
|
|
|
|
|
.killing_wolf()
|
|
|
|
|
.ok_or(GameError::NoWolves)?
|
2025-10-05 10:54:47 +01:00
|
|
|
.character_id(),
|
2025-10-03 22:47:38 +01:00
|
|
|
night: NonZeroU8::new(self.night)
|
|
|
|
|
.ok_or(GameError::InvalidMessageForGameState)?,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
})),
|
|
|
|
|
ActionPrompt::Shapeshifter { character_id } => {
|
|
|
|
|
Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
2025-06-23 09:48:28 +01:00
|
|
|
result: ActionResult::GoBackToSleep,
|
2025-10-03 22:47:38 +01:00
|
|
|
change: Some(NightChange::Shapeshift {
|
2025-10-05 10:54:47 +01:00
|
|
|
source: character_id.character_id,
|
2025-06-23 09:48:28 +01:00
|
|
|
}),
|
2025-10-03 22:47:38 +01:00
|
|
|
}))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionPrompt::AlphaWolf {
|
|
|
|
|
character_id,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::Kill {
|
2025-10-05 10:54:47 +01:00
|
|
|
target: *marked,
|
2025-10-03 22:47:38 +01:00
|
|
|
died_to: DiedTo::AlphaWolf {
|
2025-10-05 10:54:47 +01:00
|
|
|
killer: character_id.character_id,
|
2025-10-03 22:47:38 +01:00
|
|
|
night: NonZeroU8::new(self.night)
|
|
|
|
|
.ok_or(GameError::InvalidMessageForGameState)?,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
})),
|
|
|
|
|
ActionPrompt::AlphaWolf { marked: None, .. } => {
|
|
|
|
|
Ok(ResponseOutcome::ActionComplete(Default::default()))
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
ActionPrompt::DireWolf {
|
|
|
|
|
character_id,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ResponseOutcome::ActionComplete(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::RoleBlock {
|
2025-10-05 10:54:47 +01:00
|
|
|
source: character_id.character_id,
|
|
|
|
|
target: *marked,
|
2025-10-03 22:47:38 +01:00
|
|
|
block_type: RoleBlock::Direwolf,
|
|
|
|
|
}),
|
|
|
|
|
})),
|
2025-10-06 20:45:15 +01:00
|
|
|
ActionPrompt::Adjudicator {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::Adjudicator {
|
|
|
|
|
killer: self.village.character_by_id(*marked)?.killer(),
|
|
|
|
|
},
|
|
|
|
|
change: None,
|
|
|
|
|
}
|
|
|
|
|
.into()),
|
|
|
|
|
ActionPrompt::PowerSeer {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::PowerSeer {
|
|
|
|
|
powerful: self.village.character_by_id(*marked)?.powerful(),
|
|
|
|
|
},
|
|
|
|
|
change: None,
|
|
|
|
|
}
|
|
|
|
|
.into()),
|
|
|
|
|
ActionPrompt::Mortician {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::Mortician(
|
|
|
|
|
self.village
|
|
|
|
|
.character_by_id(*marked)?
|
|
|
|
|
.died_to()
|
|
|
|
|
.ok_or(GameError::InvalidTarget)?
|
|
|
|
|
.title(),
|
|
|
|
|
),
|
|
|
|
|
change: None,
|
|
|
|
|
}
|
|
|
|
|
.into()),
|
|
|
|
|
ActionPrompt::Beholder {
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => {
|
|
|
|
|
if let Some(result) = self.used_actions.iter().find_map(|(prompt, result)| {
|
|
|
|
|
prompt.matches_beholding(*marked).then_some(result)
|
|
|
|
|
}) {
|
|
|
|
|
Ok(ActionComplete {
|
|
|
|
|
result: result.clone(),
|
|
|
|
|
change: None,
|
|
|
|
|
}
|
|
|
|
|
.into())
|
|
|
|
|
} else {
|
|
|
|
|
Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: None,
|
|
|
|
|
}
|
|
|
|
|
.into())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ActionPrompt::MasonsWake { .. } => Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: None,
|
|
|
|
|
}
|
|
|
|
|
.into()),
|
|
|
|
|
ActionPrompt::MasonLeaderRecruit {
|
|
|
|
|
character_id,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::Continue,
|
|
|
|
|
change: Some(NightChange::MasonRecruit {
|
|
|
|
|
mason_leader: character_id.character_id,
|
|
|
|
|
recruiting: *marked,
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
.into()),
|
|
|
|
|
ActionPrompt::Empath {
|
|
|
|
|
character_id,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => {
|
|
|
|
|
let marked = self.village.character_by_id(*marked)?;
|
2025-10-06 21:12:12 +01:00
|
|
|
let scapegoat = marked.role_title() == RoleTitle::Scapegoat;
|
2025-06-23 09:48:28 +01:00
|
|
|
|
2025-10-06 20:45:15 +01:00
|
|
|
Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::Empath { scapegoat },
|
|
|
|
|
change: scapegoat.then(|| NightChange::EmpathFoundScapegoat {
|
|
|
|
|
empath: character_id.character_id,
|
|
|
|
|
scapegoat: marked.character_id(),
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
.into())
|
|
|
|
|
}
|
|
|
|
|
ActionPrompt::Vindicator {
|
|
|
|
|
character_id,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: Some(NightChange::Protection {
|
|
|
|
|
target: *marked,
|
|
|
|
|
protection: Protection::Vindicator {
|
|
|
|
|
source: character_id.character_id,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
.into()),
|
|
|
|
|
ActionPrompt::PyreMaster {
|
|
|
|
|
character_id,
|
|
|
|
|
marked: Some(marked),
|
|
|
|
|
..
|
|
|
|
|
} => Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: NonZeroU8::new(self.night).map(|night| NightChange::Kill {
|
|
|
|
|
target: *marked,
|
|
|
|
|
died_to: DiedTo::PyreMaster {
|
|
|
|
|
killer: character_id.character_id,
|
|
|
|
|
night,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
.into()),
|
|
|
|
|
|
|
|
|
|
ActionPrompt::PyreMaster { marked: None, .. }
|
|
|
|
|
| ActionPrompt::MasonLeaderRecruit { marked: None, .. } => Ok(ActionComplete {
|
|
|
|
|
result: ActionResult::GoBackToSleep,
|
|
|
|
|
change: None,
|
|
|
|
|
}
|
|
|
|
|
.into()),
|
|
|
|
|
|
|
|
|
|
ActionPrompt::Adjudicator { marked: None, .. }
|
|
|
|
|
| ActionPrompt::PowerSeer { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Mortician { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Beholder { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Empath { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Vindicator { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Protector { marked: None, .. }
|
2025-10-03 22:47:38 +01:00
|
|
|
| ActionPrompt::Arcanist {
|
|
|
|
|
marked: (None, None),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Arcanist {
|
|
|
|
|
marked: (None, Some(_)),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Arcanist {
|
|
|
|
|
marked: (Some(_), None),
|
|
|
|
|
..
|
|
|
|
|
}
|
|
|
|
|
| ActionPrompt::Gravedigger { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Hunter { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Guardian { marked: None, .. }
|
|
|
|
|
| ActionPrompt::WolfPackKill { marked: None, .. }
|
|
|
|
|
| ActionPrompt::DireWolf { marked: None, .. }
|
|
|
|
|
| ActionPrompt::Seer { marked: None, .. } => Err(GameError::InvalidMessageForGameState),
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const fn village(&self) -> &Village {
|
|
|
|
|
&self.village
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const fn current_result(&self) -> Option<&ActionResult> {
|
|
|
|
|
match &self.night_state {
|
|
|
|
|
NightState::Active {
|
|
|
|
|
current_prompt: _,
|
|
|
|
|
current_result,
|
|
|
|
|
} => current_result.as_ref(),
|
|
|
|
|
NightState::Complete => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const fn current_prompt(&self) -> Option<&ActionPrompt> {
|
|
|
|
|
match &self.night_state {
|
|
|
|
|
NightState::Active {
|
|
|
|
|
current_prompt,
|
|
|
|
|
current_result: _,
|
|
|
|
|
} => Some(current_prompt),
|
|
|
|
|
NightState::Complete => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-05 10:52:37 +01:00
|
|
|
pub const fn current_character_id(&self) -> Option<CharacterId> {
|
2025-06-23 09:48:28 +01:00
|
|
|
match &self.night_state {
|
|
|
|
|
NightState::Active {
|
2025-09-30 13:07:59 +01:00
|
|
|
current_prompt,
|
2025-06-23 09:48:28 +01:00
|
|
|
current_result: _,
|
2025-09-30 13:07:59 +01:00
|
|
|
} => match current_prompt {
|
2025-10-05 10:52:37 +01:00
|
|
|
ActionPrompt::ElderReveal { character_id }
|
|
|
|
|
| ActionPrompt::RoleChange { character_id, .. }
|
2025-10-03 22:47:38 +01:00
|
|
|
| ActionPrompt::Seer { character_id, .. }
|
|
|
|
|
| ActionPrompt::Protector { character_id, .. }
|
|
|
|
|
| ActionPrompt::Arcanist { character_id, .. }
|
|
|
|
|
| ActionPrompt::Gravedigger { character_id, .. }
|
|
|
|
|
| ActionPrompt::Hunter { character_id, .. }
|
|
|
|
|
| ActionPrompt::Militia { character_id, .. }
|
|
|
|
|
| ActionPrompt::MapleWolf { character_id, .. }
|
|
|
|
|
| ActionPrompt::Guardian { character_id, .. }
|
2025-09-30 13:07:59 +01:00
|
|
|
| ActionPrompt::Shapeshifter { character_id }
|
2025-10-03 22:47:38 +01:00
|
|
|
| ActionPrompt::AlphaWolf { character_id, .. }
|
2025-10-06 20:45:15 +01:00
|
|
|
| ActionPrompt::Adjudicator { character_id, .. }
|
|
|
|
|
| ActionPrompt::PowerSeer { character_id, .. }
|
|
|
|
|
| ActionPrompt::Mortician { character_id, .. }
|
|
|
|
|
| ActionPrompt::Beholder { character_id, .. }
|
|
|
|
|
| ActionPrompt::MasonsWake { character_id, .. }
|
|
|
|
|
| ActionPrompt::MasonLeaderRecruit { character_id, .. }
|
|
|
|
|
| ActionPrompt::Empath { character_id, .. }
|
|
|
|
|
| ActionPrompt::Vindicator { character_id, .. }
|
|
|
|
|
| ActionPrompt::PyreMaster { character_id, .. }
|
2025-10-05 10:52:37 +01:00
|
|
|
| ActionPrompt::DireWolf { character_id, .. } => Some(character_id.character_id),
|
2025-09-30 13:07:59 +01:00
|
|
|
ActionPrompt::WolvesIntro { wolves: _ }
|
2025-10-03 22:47:38 +01:00
|
|
|
| ActionPrompt::WolfPackKill { .. }
|
2025-09-30 13:07:59 +01:00
|
|
|
| ActionPrompt::CoverOfDarkness => None,
|
|
|
|
|
},
|
2025-06-23 09:48:28 +01:00
|
|
|
NightState::Complete => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn current_character(&self) -> Option<&Character> {
|
|
|
|
|
self.current_character_id()
|
2025-10-06 20:45:15 +01:00
|
|
|
.and_then(|id| self.village.character_by_id(id).ok())
|
2025-06-23 09:48:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const fn complete(&self) -> bool {
|
|
|
|
|
matches!(self.night_state, NightState::Complete)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn next(&mut self) -> Result<()> {
|
|
|
|
|
match &self.night_state {
|
|
|
|
|
NightState::Active {
|
2025-10-06 20:45:15 +01:00
|
|
|
current_prompt,
|
|
|
|
|
current_result: Some(result),
|
|
|
|
|
} => {
|
|
|
|
|
self.used_actions
|
|
|
|
|
.push((current_prompt.clone(), result.clone()));
|
|
|
|
|
}
|
2025-06-23 09:48:28 +01:00
|
|
|
NightState::Active {
|
|
|
|
|
current_prompt: _,
|
|
|
|
|
current_result: None,
|
|
|
|
|
} => return Err(GameError::AwaitingResponse),
|
|
|
|
|
NightState::Complete => return Err(GameError::NightOver),
|
|
|
|
|
}
|
2025-09-30 13:07:59 +01:00
|
|
|
if let Some(prompt) = self.action_queue.pop_front() {
|
2025-06-23 09:48:28 +01:00
|
|
|
self.night_state = NightState::Active {
|
|
|
|
|
current_prompt: prompt,
|
|
|
|
|
current_result: None,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
self.night_state = NightState::Complete;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const fn changes(&self) -> &[NightChange] {
|
|
|
|
|
self.changes.as_slice()
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-03 22:47:38 +01:00
|
|
|
|
|
|
|
|
pub enum ServerAction {
|
|
|
|
|
Prompt(ActionPrompt),
|
|
|
|
|
Result(ActionResult),
|
|
|
|
|
}
|
2025-10-05 10:52:37 +01:00
|
|
|
|
|
|
|
|
mod filter {
|
2025-10-06 20:45:15 +01:00
|
|
|
use crate::character::Character;
|
2025-10-05 10:52:37 +01:00
|
|
|
|
|
|
|
|
pub fn no_filter(_: &Character) -> bool {
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn no_village(c: &Character) -> bool {
|
|
|
|
|
!c.is_village()
|
|
|
|
|
}
|
|
|
|
|
}
|