werewolves/werewolves-proto/src/diedto.rs

150 lines
4.3 KiB
Rust

use core::{fmt::Debug, num::NonZeroU8};
use serde::{Deserialize, Serialize};
use werewolves_macros::Titles;
use crate::{character::CharacterId, game::DateTime};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Titles)]
pub enum DiedTo {
Execution {
day: NonZeroU8,
},
MapleWolf {
source: CharacterId,
night: NonZeroU8,
starves_if_fails: bool,
},
MapleWolfStarved {
night: NonZeroU8,
},
Militia {
killer: CharacterId,
night: NonZeroU8,
},
Wolfpack {
killing_wolf: CharacterId,
night: NonZeroU8,
},
AlphaWolf {
killer: CharacterId,
night: NonZeroU8,
},
Shapeshift {
into: CharacterId,
night: NonZeroU8,
},
Hunter {
killer: CharacterId,
night: NonZeroU8,
},
GuardianProtecting {
source: CharacterId,
protecting: CharacterId,
protecting_from: CharacterId,
protecting_from_cause: Box<DiedTo>,
night: NonZeroU8,
},
PyreMaster {
killer: CharacterId,
night: NonZeroU8,
},
PyreMasterLynchMob {
source: CharacterId,
night: NonZeroU8,
},
MasonLeaderRecruitFail {
tried_recruiting: CharacterId,
night: u8,
},
LoneWolf {
killer: CharacterId,
night: u8,
},
}
impl DiedTo {
pub fn next_night(&self) -> Option<DiedTo> {
let mut next = self.clone();
match &mut next {
DiedTo::Execution { .. } => return None,
DiedTo::MapleWolf { night, .. }
| DiedTo::MapleWolfStarved { night }
| DiedTo::Militia { night, .. }
| DiedTo::Wolfpack { night, .. }
| DiedTo::AlphaWolf { night, .. }
| DiedTo::Shapeshift { night, .. }
| DiedTo::Hunter { night, .. }
| DiedTo::GuardianProtecting { night, .. }
| DiedTo::PyreMasterLynchMob { night, .. }
| DiedTo::PyreMaster { night, .. } => *night = NonZeroU8::new(night.get() + 1)?,
DiedTo::LoneWolf { night, .. } | DiedTo::MasonLeaderRecruitFail { night, .. } => {
*night = *night + 1
}
}
Some(next)
}
pub const fn killer(&self) -> Option<CharacterId> {
match self {
DiedTo::Execution { .. }
| DiedTo::MapleWolfStarved { .. }
| DiedTo::Shapeshift { .. } => None,
DiedTo::MapleWolf { source: killer, .. }
| DiedTo::Militia { killer, .. }
| DiedTo::Wolfpack {
killing_wolf: killer,
..
}
| DiedTo::AlphaWolf { killer, .. }
| DiedTo::Hunter { killer, .. }
| DiedTo::GuardianProtecting {
protecting_from: killer,
..
}
| DiedTo::MasonLeaderRecruitFail {
tried_recruiting: killer,
..
}
| DiedTo::PyreMasterLynchMob { source: killer, .. }
| DiedTo::PyreMaster { killer, .. }
| DiedTo::LoneWolf { killer, .. } => Some(*killer),
}
}
pub const fn date_time(&self) -> DateTime {
match self {
DiedTo::Execution { day } => DateTime::Day { number: *day },
DiedTo::GuardianProtecting {
source: _,
protecting: _,
protecting_from: _,
protecting_from_cause: _,
night,
}
| DiedTo::MapleWolf {
source: _,
night,
starves_if_fails: _,
}
| DiedTo::MapleWolfStarved { night }
| DiedTo::Militia { killer: _, night }
| DiedTo::Wolfpack {
night,
killing_wolf: _,
}
| DiedTo::AlphaWolf { killer: _, night }
| DiedTo::Shapeshift { into: _, night }
| DiedTo::PyreMasterLynchMob { night, .. }
| DiedTo::PyreMaster { night, .. }
| DiedTo::Hunter { killer: _, night } => DateTime::Night {
number: night.get(),
},
DiedTo::LoneWolf { night, .. } | DiedTo::MasonLeaderRecruitFail { night, .. } => {
DateTime::Night { number: *night }
}
}
}
}