atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
f39b10e20a0b672c83264ded097f223a248730bd
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git

Blame: src/game/mod.rs

782069860236atagen2026-10-10 12:44 UTC1
pub mod balance;
782069860236atagen2026-10-10 12:44 UTC2
mod body;
782069860236atagen2026-10-10 12:44 UTC3
mod clinic;
782069860236atagen2026-10-10 12:44 UTC4
mod floors;
782069860236atagen2026-10-10 12:44 UTC5
mod forum;
782069860236atagen2026-10-10 12:44 UTC6
mod hazards;
782069860236atagen2026-10-10 12:44 UTC7
mod household;
782069860236atagen2026-10-10 12:44 UTC8
mod items;
782069860236atagen2026-10-10 12:44 UTC9
mod outcome;
782069860236atagen2026-10-10 12:44 UTC10
mod shop;
782069860236atagen2026-10-10 12:44 UTC11
mod state;
782069860236atagen2026-10-10 12:44 UTC12
mod techniques;
782069860236atagen2026-10-10 12:44 UTC13
mod turn;
782069860236atagen2026-10-10 12:44 UTC14
mod utility;
782069860236atagen2026-10-10 12:44 UTC15
782069860236atagen2026-10-10 12:44 UTC16
pub use body::PatchOp;
782069860236atagen2026-10-10 12:44 UTC17
pub use forum::{ELDER_LAST_MODIFIED, FORUM_THREAD, forum_thread};
782069860236atagen2026-10-10 12:44 UTC18
pub use items::{Item, Items};
782069860236atagen2026-10-10 12:44 UTC19
pub use outcome::{Outcome, Payload};
782069860236atagen2026-10-10 12:44 UTC20
pub use state::{
9683736a2c5eatagen2026-10-10 13:15 UTC21
    Cause, Clinic, Conditions, Elder, Ending, Floor, FloorState, Grip, MumVisit, Observer, Story,
782069860236atagen2026-10-10 12:44 UTC22
};
782069860236atagen2026-10-10 12:44 UTC23
pub use techniques::{LUBRICANTS, Lube, Technique};
dfa38cf4cd4batagen2026-10-10 09:17 UTC24
99524cf9f17catagen2026-10-10 10:53 UTC25
use std::{
782069860236atagen2026-10-10 12:44 UTC26
    hash::{DefaultHasher, Hash, Hasher},
c3e0c27cf8fdatagen2026-10-10 11:28 UTC27
    time::{Duration, Instant, SystemTime},
99524cf9f17catagen2026-10-10 10:53 UTC28
};
dfa38cf4cd4batagen2026-10-10 09:17 UTC29
782069860236atagen2026-10-10 12:44 UTC30
use axum::http::{StatusCode, header};
dfa38cf4cd4batagen2026-10-10 09:17 UTC31
use rand::{Rng, SeedableRng, rngs::StdRng};
dfa38cf4cd4batagen2026-10-10 09:17 UTC32
use serde_json::{Value, json};
dfa38cf4cd4batagen2026-10-10 09:17 UTC33
dfa38cf4cd4batagen2026-10-10 09:17 UTC34
use crate::problem::Problem;
782069860236atagen2026-10-10 12:44 UTC35
use balance::{
782069860236atagen2026-10-10 12:44 UTC36
    HONEST_TOLERANCE, MAX_STAMINA, PULLED_STAMINA, SELF_REPORT_INFLATION, STARTING_CASH,
782069860236atagen2026-10-10 12:44 UTC37
    STARTING_EQ,
782069860236atagen2026-10-10 12:44 UTC38
};
782069860236atagen2026-10-10 12:44 UTC39
use state::Pending;
dfa38cf4cd4batagen2026-10-10 09:17 UTC40
dfa38cf4cd4batagen2026-10-10 09:17 UTC41
pub struct Run {
9683736a2c5eatagen2026-10-10 13:15 UTC42
    /// The private id in the run's URL. Knowing it is the only authorisation a run has.
dfa38cf4cd4batagen2026-10-10 09:17 UTC43
    pub id: String,
782069860236atagen2026-10-10 12:44 UTC44
    pub public_id: String,
782069860236atagen2026-10-10 12:44 UTC45
    etag_salt: u64,
dfa38cf4cd4batagen2026-10-10 09:17 UTC46
    pub version: u64,
dfa38cf4cd4batagen2026-10-10 09:17 UTC47
    pub turn: u32,
dfa38cf4cd4batagen2026-10-10 09:17 UTC48
    pub floor: Floor,
782069860236atagen2026-10-10 12:44 UTC49
    pub here: FloorState,
dfa38cf4cd4batagen2026-10-10 09:17 UTC50
    pub length: f64,
dfa38cf4cd4batagen2026-10-10 09:17 UTC51
    pub girth: f64,
dfa38cf4cd4batagen2026-10-10 09:17 UTC52
    pub foreskin: Option<f64>,
dfa38cf4cd4batagen2026-10-10 09:17 UTC53
    pub eq: i32,
dfa38cf4cd4batagen2026-10-10 09:17 UTC54
    pub stamina: i32,
dfa38cf4cd4batagen2026-10-10 09:17 UTC55
    pub suspicion: u8,
dfa38cf4cd4batagen2026-10-10 09:17 UTC56
    pub shame: u32,
782069860236atagen2026-10-10 12:44 UTC57
    pub shame_reported: u32,
782069860236atagen2026-10-10 12:44 UTC58
    pub shame_total: u32,
dfa38cf4cd4batagen2026-10-10 09:17 UTC59
    pub cash: u32,
dfa38cf4cd4batagen2026-10-10 09:17 UTC60
    pub grip: Grip,
dfa38cf4cd4batagen2026-10-10 09:17 UTC61
    pub items: Items,
782069860236atagen2026-10-10 12:44 UTC62
    pub conditions: Conditions,
dfa38cf4cd4batagen2026-10-10 09:17 UTC63
    pub warmed_up: bool,
dfa38cf4cd4batagen2026-10-10 09:17 UTC64
    pub put_applied: bool,
782069860236atagen2026-10-10 12:44 UTC65
    pub story: Story,
9683736a2c5eatagen2026-10-10 13:15 UTC66
    pub mum: Option<MumVisit>,
782069860236atagen2026-10-10 12:44 UTC67
    pub heard: Vec<String>,
782069860236atagen2026-10-10 12:44 UTC68
    pub elder: Elder,
782069860236atagen2026-10-10 12:44 UTC69
    pub clinic: Clinic,
99524cf9f17catagen2026-10-10 10:53 UTC70
    pub seeded: bool,
c3e0c27cf8fdatagen2026-10-10 11:28 UTC71
    pub filmed_at: Option<SystemTime>,
782069860236atagen2026-10-10 12:44 UTC72
    pub observed: Option<Observer>,
782069860236atagen2026-10-10 12:44 UTC73
    pub refractory: Duration,
dfa38cf4cd4batagen2026-10-10 09:17 UTC74
    pub refractory_until: Option<Instant>,
dfa38cf4cd4batagen2026-10-10 09:17 UTC75
    pub pending: Vec<Pending>,
dfa38cf4cd4batagen2026-10-10 09:17 UTC76
    pub ended: Option<Ending>,
782069860236atagen2026-10-10 12:44 UTC77
    pub last_seen: Instant,
dfa38cf4cd4batagen2026-10-10 09:17 UTC78
    rng: StdRng,
dfa38cf4cd4batagen2026-10-10 09:17 UTC79
}
dfa38cf4cd4batagen2026-10-10 09:17 UTC80
dfa38cf4cd4batagen2026-10-10 09:17 UTC81
pub fn round2(x: f64) -> f64 {
dfa38cf4cd4batagen2026-10-10 09:17 UTC82
    (x * 100.0).round() / 100.0
dfa38cf4cd4batagen2026-10-10 09:17 UTC83
}
dfa38cf4cd4batagen2026-10-10 09:17 UTC84
dfa38cf4cd4batagen2026-10-10 09:17 UTC85
fn round3(x: f64) -> f64 {
dfa38cf4cd4batagen2026-10-10 09:17 UTC86
    (x * 1000.0).round() / 1000.0
dfa38cf4cd4batagen2026-10-10 09:17 UTC87
}
dfa38cf4cd4batagen2026-10-10 09:17 UTC88
177535ac8abfatagen2026-10-10 10:39 UTC89
fn honest(claimed: f64, actual: f64) -> bool {
782069860236atagen2026-10-10 12:44 UTC90
    (claimed - actual).abs() < HONEST_TOLERANCE
dfa38cf4cd4batagen2026-10-10 09:17 UTC91
}
dfa38cf4cd4batagen2026-10-10 09:17 UTC92
dfa38cf4cd4batagen2026-10-10 09:17 UTC93
fn not_extended() -> Problem {
dfa38cf4cd4batagen2026-10-10 09:17 UTC94
    Problem::new(
dfa38cf4cd4batagen2026-10-10 09:17 UTC95
        StatusCode::NOT_EXTENDED,
dfa38cf4cd4batagen2026-10-10 09:17 UTC96
        "not-extended",
dfa38cf4cd4batagen2026-10-10 09:17 UTC97
        "The requested extension was not applied. The server has recorded the attempt.",
dfa38cf4cd4batagen2026-10-10 09:17 UTC98
    )
dfa38cf4cd4batagen2026-10-10 09:17 UTC99
}
dfa38cf4cd4batagen2026-10-10 09:17 UTC100
dfa38cf4cd4batagen2026-10-10 09:17 UTC101
pub fn parse_credentials<'a>(authorization: &'a str, scheme: &str) -> Option<&'a str> {
dfa38cf4cd4batagen2026-10-10 09:17 UTC102
    let (given, rest) = authorization.trim().split_once(' ')?;
dfa38cf4cd4batagen2026-10-10 09:17 UTC103
    given
dfa38cf4cd4batagen2026-10-10 09:17 UTC104
        .eq_ignore_ascii_case(scheme)
dfa38cf4cd4batagen2026-10-10 09:17 UTC105
        .then(|| rest.trim().trim_matches('"'))
dfa38cf4cd4batagen2026-10-10 09:17 UTC106
}
dfa38cf4cd4batagen2026-10-10 09:17 UTC107
dfa38cf4cd4batagen2026-10-10 09:17 UTC108
pub fn etag_matches(condition: &str, etag: &str) -> bool {
dfa38cf4cd4batagen2026-10-10 09:17 UTC109
    condition
dfa38cf4cd4batagen2026-10-10 09:17 UTC110
        .split(',')
dfa38cf4cd4batagen2026-10-10 09:17 UTC111
        .map(str::trim)
dfa38cf4cd4batagen2026-10-10 09:17 UTC112
        .any(|tag| tag == "*" || tag.trim_start_matches("W/") == etag)
dfa38cf4cd4batagen2026-10-10 09:17 UTC113
}
dfa38cf4cd4batagen2026-10-10 09:17 UTC114
dfa38cf4cd4batagen2026-10-10 09:17 UTC115
pub fn shaft(mm: usize) -> String {
dfa38cf4cd4batagen2026-10-10 09:17 UTC116
    format!("8{}D", "=".repeat(mm.saturating_sub(2)))
dfa38cf4cd4batagen2026-10-10 09:17 UTC117
}
dfa38cf4cd4batagen2026-10-10 09:17 UTC118
dfa38cf4cd4batagen2026-10-10 09:17 UTC119
impl Run {
782069860236atagen2026-10-10 12:44 UTC120
    pub fn new(id: String, public_id: String, seed: u64) -> Self {
dfa38cf4cd4batagen2026-10-10 09:17 UTC121
        let mut rng = StdRng::seed_from_u64(seed);
dfa38cf4cd4batagen2026-10-10 09:17 UTC122
        let length = round2(rng.random_range(4.5..6.5));
dfa38cf4cd4batagen2026-10-10 09:17 UTC123
        let girth = round2(rng.random_range(4.0..5.0));
dfa38cf4cd4batagen2026-10-10 09:17 UTC124
        let foreskin = round2(rng.random_range(0.4..2.4));
782069860236atagen2026-10-10 12:44 UTC125
        let etag_salt = rng.random();
782069860236atagen2026-10-10 12:44 UTC126
        Self {
dfa38cf4cd4batagen2026-10-10 09:17 UTC127
            id,
782069860236atagen2026-10-10 12:44 UTC128
            public_id,
782069860236atagen2026-10-10 12:44 UTC129
            etag_salt,
dfa38cf4cd4batagen2026-10-10 09:17 UTC130
            version: 0,
dfa38cf4cd4batagen2026-10-10 09:17 UTC131
            turn: 0,
dfa38cf4cd4batagen2026-10-10 09:17 UTC132
            floor: Floor::Bedroom,
782069860236atagen2026-10-10 12:44 UTC133
            here: FloorState::default(),
dfa38cf4cd4batagen2026-10-10 09:17 UTC134
            length,
dfa38cf4cd4batagen2026-10-10 09:17 UTC135
            girth,
dfa38cf4cd4batagen2026-10-10 09:17 UTC136
            foreskin: Some(foreskin),
782069860236atagen2026-10-10 12:44 UTC137
            eq: STARTING_EQ,
dfa38cf4cd4batagen2026-10-10 09:17 UTC138
            stamina: MAX_STAMINA,
dfa38cf4cd4batagen2026-10-10 09:17 UTC139
            suspicion: 0,
dfa38cf4cd4batagen2026-10-10 09:17 UTC140
            shame: 0,
782069860236atagen2026-10-10 12:44 UTC141
            shame_reported: 0,
782069860236atagen2026-10-10 12:44 UTC142
            shame_total: 0,
dfa38cf4cd4batagen2026-10-10 09:17 UTC143
            cash: STARTING_CASH,
dfa38cf4cd4batagen2026-10-10 09:17 UTC144
            grip: Grip::Overhand,
782069860236atagen2026-10-10 12:44 UTC145
            items: Items::default(),
782069860236atagen2026-10-10 12:44 UTC146
            conditions: Conditions::default(),
dfa38cf4cd4batagen2026-10-10 09:17 UTC147
            warmed_up: false,
dfa38cf4cd4batagen2026-10-10 09:17 UTC148
            put_applied: false,
782069860236atagen2026-10-10 12:44 UTC149
            story: Story::Unopened,
9683736a2c5eatagen2026-10-10 13:15 UTC150
            mum: None,
782069860236atagen2026-10-10 12:44 UTC151
            heard: Vec::new(),
782069860236atagen2026-10-10 12:44 UTC152
            elder: Elder::Unverified { strikes: 0 },
782069860236atagen2026-10-10 12:44 UTC153
            clinic: Clinic::default(),
99524cf9f17catagen2026-10-10 10:53 UTC154
            seeded: false,
c3e0c27cf8fdatagen2026-10-10 11:28 UTC155
            filmed_at: None,
dfa38cf4cd4batagen2026-10-10 09:17 UTC156
            observed: None,
782069860236atagen2026-10-10 12:44 UTC157
            refractory: Duration::from_secs(30),
dfa38cf4cd4batagen2026-10-10 09:17 UTC158
            refractory_until: None,
dfa38cf4cd4batagen2026-10-10 09:17 UTC159
            pending: Vec::new(),
dfa38cf4cd4batagen2026-10-10 09:17 UTC160
            ended: None,
782069860236atagen2026-10-10 12:44 UTC161
            last_seen: Instant::now(),
dfa38cf4cd4batagen2026-10-10 09:17 UTC162
            rng,
782069860236atagen2026-10-10 12:44 UTC163
        }
782069860236atagen2026-10-10 12:44 UTC164
    }
782069860236atagen2026-10-10 12:44 UTC165
782069860236atagen2026-10-10 12:44 UTC166
    fn etag_at(&self, version: u64) -> String {
782069860236atagen2026-10-10 12:44 UTC167
        let mut hasher = DefaultHasher::new();
782069860236atagen2026-10-10 12:44 UTC168
        (self.etag_salt, version).hash(&mut hasher);
782069860236atagen2026-10-10 12:44 UTC169
        format!("\"{:016x}\"", hasher.finish())
dfa38cf4cd4batagen2026-10-10 09:17 UTC170
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC171
dfa38cf4cd4batagen2026-10-10 09:17 UTC172
    pub fn etag(&self) -> String {
782069860236atagen2026-10-10 12:44 UTC173
        self.etag_at(self.version)
782069860236atagen2026-10-10 12:44 UTC174
    }
782069860236atagen2026-10-10 12:44 UTC175
782069860236atagen2026-10-10 12:44 UTC176
    /// The ETag the run had when it was created, which the true ending asks for.
782069860236atagen2026-10-10 12:44 UTC177
    pub fn origin_etag(&self) -> String {
782069860236atagen2026-10-10 12:44 UTC178
        self.etag_at(0)
dfa38cf4cd4batagen2026-10-10 09:17 UTC179
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC180
dfa38cf4cd4batagen2026-10-10 09:17 UTC181
    pub fn touch(&mut self) {
dfa38cf4cd4batagen2026-10-10 09:17 UTC182
        self.version += 1;
dfa38cf4cd4batagen2026-10-10 09:17 UTC183
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC184
dfa38cf4cd4batagen2026-10-10 09:17 UTC185
    fn fresh_nonce(&mut self) -> String {
dfa38cf4cd4batagen2026-10-10 09:17 UTC186
        format!("{:016x}", self.rng.random::<u64>())
dfa38cf4cd4batagen2026-10-10 09:17 UTC187
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC188
782069860236atagen2026-10-10 12:44 UTC189
    fn chance(&mut self, odds: u32) -> bool {
782069860236atagen2026-10-10 12:44 UTC190
        self.rng.random_ratio(1, odds)
782069860236atagen2026-10-10 12:44 UTC191
    }
782069860236atagen2026-10-10 12:44 UTC192
782069860236atagen2026-10-10 12:44 UTC193
    pub fn path(&self, sub: &str) -> String {
782069860236atagen2026-10-10 12:44 UTC194
        format!("/runs/{}{sub}", self.id)
782069860236atagen2026-10-10 12:44 UTC195
    }
782069860236atagen2026-10-10 12:44 UTC196
dfa38cf4cd4batagen2026-10-10 09:17 UTC197
    pub fn current_length(&self) -> f64 {
782069860236atagen2026-10-10 12:44 UTC198
        self.length + self.here.temp_length
dfa38cf4cd4batagen2026-10-10 09:17 UTC199
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC200
dfa38cf4cd4batagen2026-10-10 09:17 UTC201
    pub fn self_reported(&self) -> f64 {
dfa38cf4cd4batagen2026-10-10 09:17 UTC202
        self.current_length() + SELF_REPORT_INFLATION
dfa38cf4cd4batagen2026-10-10 09:17 UTC203
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC204
c3e0c27cf8fdatagen2026-10-10 11:28 UTC205
    pub fn max_stamina(&self) -> i32 {
782069860236atagen2026-10-10 12:44 UTC206
        if self.conditions.pulled_muscle {
782069860236atagen2026-10-10 12:44 UTC207
            PULLED_STAMINA
782069860236atagen2026-10-10 12:44 UTC208
        } else {
782069860236atagen2026-10-10 12:44 UTC209
            MAX_STAMINA
782069860236atagen2026-10-10 12:44 UTC210
        }
782069860236atagen2026-10-10 12:44 UTC211
    }
782069860236atagen2026-10-10 12:44 UTC212
782069860236atagen2026-10-10 12:44 UTC213
    pub fn forum_read(&self) -> bool {
782069860236atagen2026-10-10 12:44 UTC214
        self.story == Story::ReadForum
c3e0c27cf8fdatagen2026-10-10 11:28 UTC215
    }
c3e0c27cf8fdatagen2026-10-10 11:28 UTC216
c3e0c27cf8fdatagen2026-10-10 11:28 UTC217
    pub fn footage(&self) -> Option<(SystemTime, u64)> {
c3e0c27cf8fdatagen2026-10-10 11:28 UTC218
        let filmed = self.filmed_at?;
c3e0c27cf8fdatagen2026-10-10 11:28 UTC219
        let age = filmed.elapsed().map_or(0, |d| d.as_secs());
c3e0c27cf8fdatagen2026-10-10 11:28 UTC220
        Some((filmed, age))
c3e0c27cf8fdatagen2026-10-10 11:28 UTC221
    }
c3e0c27cf8fdatagen2026-10-10 11:28 UTC222
dfa38cf4cd4batagen2026-10-10 09:17 UTC223
    pub fn status(&self) -> &'static str {
782069860236atagen2026-10-10 12:44 UTC224
        match (&self.ended, self.clinic.cured) {
dfa38cf4cd4batagen2026-10-10 09:17 UTC225
            (Some(_), _) => "gone",
dfa38cf4cd4batagen2026-10-10 09:17 UTC226
            (None, true) => "normal",
dfa38cf4cd4batagen2026-10-10 09:17 UTC227
            (None, false) => "alive",
dfa38cf4cd4batagen2026-10-10 09:17 UTC228
        }
dfa38cf4cd4batagen2026-10-10 09:17 UTC229
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC230
782069860236atagen2026-10-10 12:44 UTC231
    /// The parts of the run that its response headers do not already carry.
dfa38cf4cd4batagen2026-10-10 09:17 UTC232
    pub fn view(&self) -> Value {
dfa38cf4cd4batagen2026-10-10 09:17 UTC233
        let conditions: Vec<&str> = [
782069860236atagen2026-10-10 12:44 UTC234
            (self.here.teapot, "short and stout"),
782069860236atagen2026-10-10 12:44 UTC235
            (self.conditions.peyronie, "curved"),
dfa38cf4cd4batagen2026-10-10 09:17 UTC236
            (self.items.cage, "caged"),
782069860236atagen2026-10-10 12:44 UTC237
            (self.conditions.priapism_turns > 0, "priapism"),
782069860236atagen2026-10-10 12:44 UTC238
            (self.conditions.pulled_muscle, "pulled muscle"),
c3e0c27cf8fdatagen2026-10-10 11:28 UTC239
            (self.filmed_at.is_some(), "viral"),
dfa38cf4cd4batagen2026-10-10 09:17 UTC240
        ]
dfa38cf4cd4batagen2026-10-10 09:17 UTC241
        .into_iter()
dfa38cf4cd4batagen2026-10-10 09:17 UTC242
        .filter_map(|(active, name)| active.then_some(name))
dfa38cf4cd4batagen2026-10-10 09:17 UTC243
        .collect();
782069860236atagen2026-10-10 12:44 UTC244
        json!({
782069860236atagen2026-10-10 12:44 UTC245
            "public_id": self.public_id,
dfa38cf4cd4batagen2026-10-10 09:17 UTC246
            "status": self.status(),
dfa38cf4cd4batagen2026-10-10 09:17 UTC247
            "turn": self.turn,
782069860236atagen2026-10-10 12:44 UTC248
            "run_shame": self.shame,
dfa38cf4cd4batagen2026-10-10 09:17 UTC249
            "grip": self.grip.name(),
dfa38cf4cd4batagen2026-10-10 09:17 UTC250
            "warmed_up": self.warmed_up,
99524cf9f17catagen2026-10-10 10:53 UTC251
            "ranked": !self.seeded,
dfa38cf4cd4batagen2026-10-10 09:17 UTC252
            "conditions": conditions,
782069860236atagen2026-10-10 12:44 UTC253
        })
dfa38cf4cd4batagen2026-10-10 09:17 UTC254
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC255
782069860236atagen2026-10-10 12:44 UTC256
    pub fn end(&mut self, cause: Cause) -> Problem {
dfa38cf4cd4batagen2026-10-10 09:17 UTC257
        self.ended = Some(Ending {
dfa38cf4cd4batagen2026-10-10 09:17 UTC258
            cause,
dfa38cf4cd4batagen2026-10-10 09:17 UTC259
            turn: self.turn,
dfa38cf4cd4batagen2026-10-10 09:17 UTC260
        });
782069860236atagen2026-10-10 12:44 UTC261
        cause.problem().with("turn", self.turn)
dfa38cf4cd4batagen2026-10-10 09:17 UTC262
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC263
e76ab808e7adatagen2026-10-10 13:46 UTC264
    /// Ends the refractory period once it has run out, whatever the request.
e76ab808e7adatagen2026-10-10 13:46 UTC265
    pub fn recover(&mut self, now: Instant) {
e76ab808e7adatagen2026-10-10 13:46 UTC266
        if self.refractory_until.is_some_and(|until| now >= until) {
e76ab808e7adatagen2026-10-10 13:46 UTC267
            self.refractory_until = None;
e76ab808e7adatagen2026-10-10 13:46 UTC268
            self.stamina = self.max_stamina();
e76ab808e7adatagen2026-10-10 13:46 UTC269
            self.eq = STARTING_EQ;
e76ab808e7adatagen2026-10-10 13:46 UTC270
            self.warmed_up = false;
e76ab808e7adatagen2026-10-10 13:46 UTC271
            self.touch();
e76ab808e7adatagen2026-10-10 13:46 UTC272
        }
e76ab808e7adatagen2026-10-10 13:46 UTC273
    }
e76ab808e7adatagen2026-10-10 13:46 UTC274
dfa38cf4cd4batagen2026-10-10 09:17 UTC275
    fn check_refractory(&mut self, now: Instant) -> Result<(), Problem> {
e76ab808e7adatagen2026-10-10 13:46 UTC276
        self.recover(now);
dfa38cf4cd4batagen2026-10-10 09:17 UTC277
        let Some(until) = self.refractory_until else {
dfa38cf4cd4batagen2026-10-10 09:17 UTC278
            return Ok(());
dfa38cf4cd4batagen2026-10-10 09:17 UTC279
        };
e76ab808e7adatagen2026-10-10 13:46 UTC280
        let seconds = until.saturating_duration_since(now).as_secs() + 1;
e76ab808e7adatagen2026-10-10 13:46 UTC281
        Err(Problem::new(
e76ab808e7adatagen2026-10-10 13:46 UTC282
            StatusCode::TOO_MANY_REQUESTS,
e76ab808e7adatagen2026-10-10 13:46 UTC283
            "overtrained",
e76ab808e7adatagen2026-10-10 13:46 UTC284
            "Stamina is exhausted. The refractory period is in effect.",
e76ab808e7adatagen2026-10-10 13:46 UTC285
        )
e76ab808e7adatagen2026-10-10 13:46 UTC286
        .header(header::RETRY_AFTER, seconds.to_string()))
dfa38cf4cd4batagen2026-10-10 09:17 UTC287
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC288
782069860236atagen2026-10-10 12:44 UTC289
    fn exhaust(&mut self, now: Instant) {
782069860236atagen2026-10-10 12:44 UTC290
        self.stamina = 0;
782069860236atagen2026-10-10 12:44 UTC291
        self.refractory_until = Some(now + self.refractory);
782069860236atagen2026-10-10 12:44 UTC292
    }
782069860236atagen2026-10-10 12:44 UTC293
9683736a2c5eatagen2026-10-10 13:15 UTC294
    fn realise(&mut self) {
dfa38cf4cd4batagen2026-10-10 09:17 UTC295
        let (due, waiting): (Vec<_>, Vec<_>) = std::mem::take(&mut self.pending)
dfa38cf4cd4batagen2026-10-10 09:17 UTC296
            .into_iter()
dfa38cf4cd4batagen2026-10-10 09:17 UTC297
            .partition(|p| p.due <= self.turn);
dfa38cf4cd4batagen2026-10-10 09:17 UTC298
        self.pending = waiting;
dfa38cf4cd4batagen2026-10-10 09:17 UTC299
        for p in due {
dfa38cf4cd4batagen2026-10-10 09:17 UTC300
            self.length += p.length;
dfa38cf4cd4batagen2026-10-10 09:17 UTC301
            self.girth += p.girth;
dfa38cf4cd4batagen2026-10-10 09:17 UTC302
        }
dfa38cf4cd4batagen2026-10-10 09:17 UTC303
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC304
dfa38cf4cd4batagen2026-10-10 09:17 UTC305
    fn gain(&mut self, length: f64, girth: f64, foreskin: f64) {
dfa38cf4cd4batagen2026-10-10 09:17 UTC306
        self.length += length;
dfa38cf4cd4batagen2026-10-10 09:17 UTC307
        self.girth += girth;
dfa38cf4cd4batagen2026-10-10 09:17 UTC308
        if let Some(f) = &mut self.foreskin {
dfa38cf4cd4batagen2026-10-10 09:17 UTC309
            *f += foreskin;
dfa38cf4cd4batagen2026-10-10 09:17 UTC310
        }
dfa38cf4cd4batagen2026-10-10 09:17 UTC311
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC312
dfa38cf4cd4batagen2026-10-10 09:17 UTC313
    fn rupture(&mut self) -> Problem {
782069860236atagen2026-10-10 12:44 UTC314
        let cause = Cause::Ruptured {
782069860236atagen2026-10-10 12:44 UTC315
            ice_unused: self.items.ice_packs > 0,
dfa38cf4cd4batagen2026-10-10 09:17 UTC316
        };
782069860236atagen2026-10-10 12:44 UTC317
        self.end(cause)
dfa38cf4cd4batagen2026-10-10 09:17 UTC318
    }
dfa38cf4cd4batagen2026-10-10 09:17 UTC319
}