atagen

jelq

public

an http based roguelike rpg about jelqing

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