werewolves/werewolves-proto/src/diedto.rs

87 lines
2.2 KiB
Rust
Raw Normal View History

use core::{fmt::Debug, num::NonZeroU8};
use serde::{Deserialize, Serialize};
use werewolves_macros::Extract;
use crate::{game::DateTime, player::CharacterId};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Extract)]
pub enum DiedTo {
Execution {
day: NonZeroU8,
},
#[extract(source as killer)]
MapleWolf {
source: CharacterId,
night: NonZeroU8,
starves_if_fails: bool,
},
MapleWolfStarved {
night: NonZeroU8,
},
#[extract(killer as killer)]
Militia {
killer: CharacterId,
night: NonZeroU8,
},
#[extract(killing_wolf as killer)]
Wolfpack {
killing_wolf: CharacterId,
night: NonZeroU8,
},
#[extract(killer as killer)]
AlphaWolf {
killer: CharacterId,
night: NonZeroU8,
},
Shapeshift {
into: CharacterId,
night: NonZeroU8,
},
#[extract(killer as killer)]
Hunter {
killer: CharacterId,
night: NonZeroU8,
},
#[extract(source as killer)]
GuardianProtecting {
source: CharacterId,
protecting: CharacterId,
protecting_from: CharacterId,
protecting_from_cause: Box<DiedTo>,
night: NonZeroU8,
},
}
impl DiedTo {
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::Hunter { killer: _, night } => DateTime::Night {
number: night.get(),
},
}
}
}