atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
97c05b741d8f0a39cec7b9e24bf5491f18c819c5
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/gauges.rsRust178 lines5.3 KB
1
use std::time::Instant;
2
3
use serde_json::{Value, json};
4
5
use super::{
6
    Elder, Excuse, Floor, Grip, Item, Observer, Run, Story, Technique,
7
    balance::DANGER_EQ,
8
    techniques::{Training, Utility},
9
};
10
11
pub enum Shown {
12
    Measured(f64),
13
    SelfReported(f64),
14
}
15
16
pub struct Gauges {
17
    pub(crate) length: Shown,
18
    pub(crate) girth: f64,
19
    pub(crate) foreskin: Option<f64>,
20
    pub(crate) friction: i32,
21
    pub(crate) eq: i32,
22
    pub(crate) stamina: i32,
23
    pub(crate) max_stamina: i32,
24
    pub(crate) suspicion: u8,
25
    pub(crate) cash: u32,
26
    pub(crate) floor: u8,
27
    pub(crate) observed: Option<Observer>,
28
    pub(crate) mum_at_door: bool,
29
    pub(crate) warnings: Vec<&'static str>,
30
    pub(crate) ruler: bool,
31
    pub(crate) ring: bool,
32
}
33
34
pub struct Reach {
35
    pub(crate) foreskin: bool,
36
    pub(crate) drawer: bool,
37
    pub(crate) kitchen: bool,
38
    pub(crate) thread: bool,
39
    pub(crate) shop: bool,
40
    pub(crate) portal: bool,
41
    pub(crate) elder: bool,
42
    pub(crate) footage: bool,
43
    pub(crate) diagnosis: bool,
44
    pub(crate) branch_pending: bool,
45
    pub(crate) shopping: bool,
46
}
47
48
impl Run {
49
    /// Drains the notices, so call it once per response.
50
    pub fn gauges(&mut self) -> Gauges {
51
        let conditions = &self.body.conditions;
52
        let mut warnings = Vec::new();
53
        if conditions.pulled_muscle {
54
            warnings.push("a muscle has been pulled");
55
        }
56
        if conditions.friction_burn {
57
            warnings.push("friction burn");
58
        }
59
        warnings.extend(self.notices.drain(..).map(|notice| notice.text()));
60
        if self.body.eq > DANGER_EQ && self.ended.is_none() {
61
            warnings.push("it is turning purple");
62
        }
63
        Gauges {
64
            length: if self.items.kit.ruler {
65
                Shown::Measured(self.current_length())
66
            } else {
67
                Shown::SelfReported(self.self_reported())
68
            },
69
            girth: self.body.girth,
70
            foreskin: self.body.foreskin,
71
            friction: self.body.friction,
72
            eq: self.body.eq,
73
            stamina: self.body.stamina,
74
            max_stamina: self.max_stamina(),
75
            suspicion: self.standing.suspicion,
76
            cash: self.standing.cash,
77
            floor: self.floor.number(),
78
            observed: self.observed,
79
            mum_at_door: self.household.mum.is_some(),
80
            warnings,
81
            ruler: self.items.kit.ruler,
82
            ring: self.items.kit.ring,
83
        }
84
    }
85
86
    pub fn reach(&self) -> Reach {
87
        Reach {
88
            foreskin: self.body.foreskin.is_some(),
89
            drawer: self.drawer_worth_searching(),
90
            kitchen: self.floor.has_kitchen() && !self.here.kitchen.closed,
91
            thread: self.thread_reachable(),
92
            shop: self.floor.shop_open(),
93
            portal: self.needs_portal(),
94
            elder: self.floor == Floor::Forum && self.online.elder != Elder::Beaten,
95
            footage: self.online.filmed_at.is_some(),
96
            diagnosis: self.floor == Floor::Clinic,
97
            branch_pending: self.online.story == Story::Pending,
98
            shopping: self.here.shopping,
99
        }
100
    }
101
102
    pub fn needs_portal(&self) -> bool {
103
        self.floor == Floor::Hotel && !self.here.wifi_accepted
104
    }
105
106
    /// Shame follows the player across runs in a signed cookie. Each response adds this run's new
107
    /// shame to whatever total the client presents, so two runs at once both count.
108
    pub fn settle_shame(&mut self, presented: Option<u32>) -> u32 {
109
        let standing = &mut self.standing;
110
        let total =
111
            presented.unwrap_or(standing.shame_total) + (standing.shame - standing.shame_reported);
112
        standing.shame_reported = standing.shame;
113
        standing.shame_total = total;
114
        total
115
    }
116
117
    pub fn trace(&mut self) {
118
        self.standing.shame += 1;
119
    }
120
121
    pub fn measured(&self) -> bool {
122
        self.items.kit.ruler
123
    }
124
125
    pub fn id(&self) -> &str {
126
        &self.ident.id
127
    }
128
129
    pub fn last_seen(&self) -> Instant {
130
        self.ident.last_seen
131
    }
132
133
    /// A request has arrived. Whoever was watching last time has looked away.
134
    pub fn seen(&mut self, now: Instant) {
135
        self.ident.last_seen = now;
136
        self.observed = None;
137
    }
138
139
    pub fn foreskin(&self) -> Option<f64> {
140
        self.body.foreskin
141
    }
142
143
    pub fn grip(&self) -> Grip {
144
        self.body.grip
145
    }
146
147
    pub fn knows(&self, technique: Technique) -> bool {
148
        match technique {
149
            Technique::Training(Training::Uli) => self.online.uli_taught,
150
            Technique::Utility(Utility::Meditate) => self.online.meditation_taught,
151
            _ => true,
152
        }
153
    }
154
155
    pub fn holds(&self, item: Item) -> bool {
156
        self.items.has(item)
157
    }
158
159
    pub fn inventory_view(&self) -> Value {
160
        let items: Vec<Value> = self
161
            .items
162
            .owned()
163
            .into_iter()
164
            .map(|item| {
165
                json!({
166
                    "name": item.slug(),
167
                    "href": self.path(&format!("/inventory/{}", item.slug())),
168
                })
169
            })
170
            .collect();
171
        json!({
172
            "items": items,
173
            "ice_packs": self.items.stores.ice_packs,
174
            "supplements": self.items.stores.supplements,
175
            "excuses": self.excuses().into_iter().map(Excuse::phrase).collect::<Vec<_>>(),
176
        })
177
    }
178
}