atagen

jelq

public

an http based roguelike rpg about jelqing

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