164 lines
5.0 KiB
Rust
164 lines
5.0 KiB
Rust
// Copyright (C) 2025 Emilis Bliūdžius
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
use core::{fmt::Debug, num::NonZeroU8};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use werewolves_macros::Titles;
|
|
|
|
use crate::{character::CharacterId, game::GameTime};
|
|
|
|
#[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) -> GameTime {
|
|
match self {
|
|
DiedTo::Execution { day } => GameTime::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 } => GameTime::Night {
|
|
number: night.get(),
|
|
},
|
|
DiedTo::LoneWolf { night, .. } | DiedTo::MasonLeaderRecruitFail { night, .. } => {
|
|
GameTime::Night { number: *night }
|
|
}
|
|
}
|
|
}
|
|
}
|