atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
53bce0d930007b21fb1f130865979bbd959edcc5
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/danger.rsRust61 lines1.8 KB
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 | Self::Ruptured => {
27
                Some(Danger::Critical)
28
            }
29
            Self::Flaccid | Self::Warm | Self::Ideal => None,
30
        }
31
    }
32
}
33
34
impl Run {
35
    pub(super) fn dangers(&self) -> Vec<(&'static str, Danger)> {
36
        let friction = if self.body.friction >= FRICTION_MAX || self.body.conditions.friction_burn {
37
            Some(Danger::Critical)
38
        } else {
39
            (self.body.friction >= FRICTION_BURN_AT).then_some(Danger::Dangerous)
40
        };
41
        let stamina = if self.body.stamina <= 0 {
42
            Some(Danger::Critical)
43
        } else {
44
            (self.body.stamina <= LOW_STAMINA).then_some(Danger::Dangerous)
45
        };
46
        let suspicion = if self.standing.suspicion + 1 >= SUSPICION_LIMIT {
47
            Some(Danger::Critical)
48
        } else {
49
            (self.standing.suspicion + 2 >= SUSPICION_LIMIT).then_some(Danger::Dangerous)
50
        };
51
        [
52
            ("friction", friction),
53
            ("eq", self.arousal().danger()),
54
            ("stamina", stamina),
55
            ("suspicion", suspicion),
56
        ]
57
        .into_iter()
58
        .filter_map(|(gauge, danger)| Some((gauge, danger?)))
59
        .collect()
60
    }
61
}