an http based roguelike rpg about jelqing
| 1 | use super::{ |
| 2 | Arousal, Run, |
| 3 | balance::{FRICTION_BURN_AT, FRICTION_MAX, LOW_STAMINA, SUSPICION_LIMIT}, |
| 4 | }; |
| 5 | |
| 6 | /// How close a gauge is to hurting the run, so a client can flag it without knowing the balance. |
| 7 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 8 | pub enum Danger { |
| 9 | Dangerous, |
| 10 | Critical, |
| 11 | } |
| 12 | |
| 13 | impl Danger { |
| 14 | pub fn name(self) -> &'static str { |
| 15 | match self { |
| 16 | Self::Dangerous => "dangerous", |
| 17 | Self::Critical => "critical", |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | impl Arousal { |
| 23 | fn danger(self) -> Option<Danger> { |
| 24 | match self { |
| 25 | Self::Cold | Self::Swollen | Self::Throbbing => Some(Danger::Dangerous), |
| 26 | Self::Straining | Self::Imminent | Self::Priapic => Some(Danger::Critical), |
| 27 | Self::Flaccid | Self::Warm | Self::Ideal => None, |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl Run { |
| 33 | pub(super) fn dangers(&self) -> Vec<(&'static str, Danger)> { |
| 34 | let friction = if self.body.friction >= FRICTION_MAX || self.body.conditions.friction_burn { |
| 35 | Some(Danger::Critical) |
| 36 | } else { |
| 37 | (self.body.friction >= FRICTION_BURN_AT).then_some(Danger::Dangerous) |
| 38 | }; |
| 39 | let stamina = if self.body.stamina <= 0 { |
| 40 | Some(Danger::Critical) |
| 41 | } else { |
| 42 | (self.body.stamina <= LOW_STAMINA).then_some(Danger::Dangerous) |
| 43 | }; |
| 44 | let suspicion = if self.standing.suspicion + 1 >= SUSPICION_LIMIT { |
| 45 | Some(Danger::Critical) |
| 46 | } else { |
| 47 | (self.standing.suspicion + 2 >= SUSPICION_LIMIT).then_some(Danger::Dangerous) |
| 48 | }; |
| 49 | [ |
| 50 | ("friction", friction), |
| 51 | ("eq", self.arousal().danger()), |
| 52 | ("stamina", stamina), |
| 53 | ("suspicion", suspicion), |
| 54 | ] |
| 55 | .into_iter() |
| 56 | .filter_map(|(gauge, danger)| Some((gauge, danger?))) |
| 57 | .collect() |
| 58 | } |
| 59 | } |