atagen

jelq

public

an http based roguelike rpg about jelqing

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

Blame: src/game/turn.rs

782069860236atagen2026-10-10 12:44 UTC1
use std::{fmt::Write as _, ops::ControlFlow, time::Instant};
782069860236atagen2026-10-10 12:44 UTC2
782069860236atagen2026-10-10 12:44 UTC3
use axum::http::{StatusCode, header};
782069860236atagen2026-10-10 12:44 UTC4
use rand::Rng;
782069860236atagen2026-10-10 12:44 UTC5
use serde_json::json;
782069860236atagen2026-10-10 12:44 UTC6
782069860236atagen2026-10-10 12:44 UTC7
use super::{
782069860236atagen2026-10-10 12:44 UTC8
    Floor, Grip, LUBRICANTS, Lube, Outcome, Payload, Run, Story, Technique,
782069860236atagen2026-10-10 12:44 UTC9
    balance::{
5dfebcc0ac43atagen2026-10-11 05:28 UTC10
        ARRIVAL_BONUS, BAND_BONUS, BRANCH_TURN, BURN_RUPTURE, CAT_TAKES_TOWEL, CHANGING_ROOM_CHILL,
5dfebcc0ac43atagen2026-10-11 05:28 UTC11
        DANGER_EQ, EQ_BAND, EQ_WOBBLE, EXTENDER_GAIN, FRICTION_BURN, FRICTION_BURN_AT,
5dfebcc0ac43atagen2026-10-11 05:28 UTC12
        FRICTION_DRY, FRICTION_GRIP, FRICTION_HOLD, FRICTION_MAX, FRICTION_MEDITATE, FRICTION_SPIT,
5dfebcc0ac43atagen2026-10-11 05:28 UTC13
        GREED_HOT, GREED_WARM, HOLD_EQ, HOT_EQ, MEDITATION_EQ, OBSERVED, PRIAPISM_EQ,
5dfebcc0ac43atagen2026-10-11 05:28 UTC14
        PRIAPISM_TURNS, PULLED_MUSCLE, PULLED_MUSCLE_INTENSITY, REFLECTION, RING_PRIAPISM,
5dfebcc0ac43atagen2026-10-11 05:28 UTC15
        RING_RUPTURE_LINE, RUPTURE_LINE, STORAGE_GIRTH, SUSPICION_LIMIT,
782069860236atagen2026-10-10 12:44 UTC16
    },
782069860236atagen2026-10-10 12:44 UTC17
    not_extended, round3,
9683736a2c5eatagen2026-10-10 13:15 UTC18
    state::{MumVisit, Observer, Pending},
782069860236atagen2026-10-10 12:44 UTC19
    techniques::{LubeRule, Profile, Training, Utility},
782069860236atagen2026-10-10 12:44 UTC20
};
782069860236atagen2026-10-10 12:44 UTC21
use crate::{headers::SERVER_TIMING, problem::Problem};
782069860236atagen2026-10-10 12:44 UTC22
782069860236atagen2026-10-10 12:44 UTC23
impl Run {
782069860236atagen2026-10-10 12:44 UTC24
    pub fn jelq(
782069860236atagen2026-10-10 12:44 UTC25
        &mut self,
782069860236atagen2026-10-10 12:44 UTC26
        techniques: &[Technique],
782069860236atagen2026-10-10 12:44 UTC27
        intensity: i32,
782069860236atagen2026-10-10 12:44 UTC28
        lube: Option<Lube>,
782069860236atagen2026-10-10 12:44 UTC29
        now: Instant,
782069860236atagen2026-10-10 12:44 UTC30
    ) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC31
        self.check_refractory(now)?;
782069860236atagen2026-10-10 12:44 UTC32
        if self.story == Story::Pending {
782069860236atagen2026-10-10 12:44 UTC33
            return Ok(self.branch_offer());
782069860236atagen2026-10-10 12:44 UTC34
        }
782069860236atagen2026-10-10 12:44 UTC35
        if self.floor == Floor::Forum {
782069860236atagen2026-10-10 12:44 UTC36
            return Ok(Outcome::json(
782069860236atagen2026-10-10 12:44 UTC37
                StatusCode::SEE_OTHER,
782069860236atagen2026-10-10 12:44 UTC38
                json!({ "detail": "Refer to the forum." }),
782069860236atagen2026-10-10 12:44 UTC39
            )
782069860236atagen2026-10-10 12:44 UTC40
            .header(header::LOCATION, super::FORUM_THREAD));
782069860236atagen2026-10-10 12:44 UTC41
        }
782069860236atagen2026-10-10 12:44 UTC42
        if self.items.cage {
782069860236atagen2026-10-10 12:44 UTC43
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC44
                StatusCode::LOCKED,
782069860236atagen2026-10-10 12:44 UTC45
                "caged",
782069860236atagen2026-10-10 12:44 UTC46
                "The cage is locked. The key is not in the box.",
782069860236atagen2026-10-10 12:44 UTC47
            ));
782069860236atagen2026-10-10 12:44 UTC48
        }
0fdc47364c8catagen2026-10-11 04:45 UTC49
        self.here.shopping = false;
782069860236atagen2026-10-10 12:44 UTC50
        match *techniques {
782069860236atagen2026-10-10 12:44 UTC51
            [Technique::Utility(utility)] => self.utility(utility, lube, now),
782069860236atagen2026-10-10 12:44 UTC52
            [Technique::Training(training)] => self.single(training, intensity, lube, now),
782069860236atagen2026-10-10 12:44 UTC53
            [Technique::Training(a), Technique::Training(b)] => {
782069860236atagen2026-10-10 12:44 UTC54
                self.combo(a, b, intensity, lube, now)
782069860236atagen2026-10-10 12:44 UTC55
            }
782069860236atagen2026-10-10 12:44 UTC56
            [_, _] => Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC57
                StatusCode::BAD_REQUEST,
782069860236atagen2026-10-10 12:44 UTC58
                "combo-invalid",
782069860236atagen2026-10-10 12:44 UTC59
                "Only training techniques can be combined.",
782069860236atagen2026-10-10 12:44 UTC60
            )),
782069860236atagen2026-10-10 12:44 UTC61
            _ => Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC62
                StatusCode::BAD_REQUEST,
782069860236atagen2026-10-10 12:44 UTC63
                "too-many-techniques",
782069860236atagen2026-10-10 12:44 UTC64
                "Two techniques at most. The server has limits even if you do not.",
782069860236atagen2026-10-10 12:44 UTC65
            )),
782069860236atagen2026-10-10 12:44 UTC66
        }
782069860236atagen2026-10-10 12:44 UTC67
    }
782069860236atagen2026-10-10 12:44 UTC68
782069860236atagen2026-10-10 12:44 UTC69
    fn utility(
782069860236atagen2026-10-10 12:44 UTC70
        &mut self,
782069860236atagen2026-10-10 12:44 UTC71
        utility: Utility,
782069860236atagen2026-10-10 12:44 UTC72
        lube: Option<Lube>,
782069860236atagen2026-10-10 12:44 UTC73
        now: Instant,
782069860236atagen2026-10-10 12:44 UTC74
    ) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC75
        match utility {
782069860236atagen2026-10-10 12:44 UTC76
            Utility::Warmup => return self.warm_up(),
782069860236atagen2026-10-10 12:44 UTC77
            Utility::Ice => return self.ice(),
782069860236atagen2026-10-10 12:44 UTC78
            Utility::Supplement => return self.supplement(),
0fdc47364c8catagen2026-10-11 04:45 UTC79
            Utility::Meditate => return self.meditate(),
0a0bfee8329eatagen2026-10-11 05:11 UTC80
            Utility::Energy => return self.energy(),
782069860236atagen2026-10-10 12:44 UTC81
            Utility::Edge | Utility::Pump => {}
782069860236atagen2026-10-10 12:44 UTC82
        }
782069860236atagen2026-10-10 12:44 UTC83
        if utility == Utility::Pump {
782069860236atagen2026-10-10 12:44 UTC84
            self.here.edges = 0;
782069860236atagen2026-10-10 12:44 UTC85
        }
782069860236atagen2026-10-10 12:44 UTC86
        self.ready(Technique::Utility(utility), lube)?;
782069860236atagen2026-10-10 12:44 UTC87
        self.check_storage()?;
782069860236atagen2026-10-10 12:44 UTC88
        self.floor_enemy()?;
782069860236atagen2026-10-10 12:44 UTC89
        match utility {
782069860236atagen2026-10-10 12:44 UTC90
            Utility::Edge => self.edge(now),
782069860236atagen2026-10-10 12:44 UTC91
            _ => self.pump(now),
782069860236atagen2026-10-10 12:44 UTC92
        }
782069860236atagen2026-10-10 12:44 UTC93
    }
782069860236atagen2026-10-10 12:44 UTC94
782069860236atagen2026-10-10 12:44 UTC95
    fn single(
782069860236atagen2026-10-10 12:44 UTC96
        &mut self,
782069860236atagen2026-10-10 12:44 UTC97
        training: Training,
782069860236atagen2026-10-10 12:44 UTC98
        intensity: i32,
782069860236atagen2026-10-10 12:44 UTC99
        lube: Option<Lube>,
782069860236atagen2026-10-10 12:44 UTC100
        now: Instant,
782069860236atagen2026-10-10 12:44 UTC101
    ) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC102
        self.here.edges = 0;
782069860236atagen2026-10-10 12:44 UTC103
        self.ready(Technique::Training(training), lube)?;
782069860236atagen2026-10-10 12:44 UTC104
        self.check_storage()?;
14de3e1e8dc2atagen2026-10-11 06:19 UTC105
        self.lube_available(lube)?;
782069860236atagen2026-10-10 12:44 UTC106
        self.floor_enemy()?;
139164489032atagen2026-10-11 05:46 UTC107
        self.take_lube(lube)?;
5dfebcc0ac43atagen2026-10-11 05:28 UTC108
        self.chafe(lube);
782069860236atagen2026-10-10 12:44 UTC109
        self.commit(intensity, lube, now, 1);
782069860236atagen2026-10-10 12:44 UTC110
        if let ControlFlow::Break(interrupted) = self.mishaps(training, intensity)? {
782069860236atagen2026-10-10 12:44 UTC111
            return Ok(interrupted);
782069860236atagen2026-10-10 12:44 UTC112
        }
782069860236atagen2026-10-10 12:44 UTC113
        if let ControlFlow::Break(interrupted) = self.hazards(intensity)? {
782069860236atagen2026-10-10 12:44 UTC114
            return Ok(interrupted);
782069860236atagen2026-10-10 12:44 UTC115
        }
782069860236atagen2026-10-10 12:44 UTC116
        let outcome = self.roll(training, intensity, lube)?;
782069860236atagen2026-10-10 12:44 UTC117
        Ok(self.gossip(outcome))
782069860236atagen2026-10-10 12:44 UTC118
    }
782069860236atagen2026-10-10 12:44 UTC119
782069860236atagen2026-10-10 12:44 UTC120
    fn combo(
782069860236atagen2026-10-10 12:44 UTC121
        &mut self,
782069860236atagen2026-10-10 12:44 UTC122
        a: Training,
782069860236atagen2026-10-10 12:44 UTC123
        b: Training,
782069860236atagen2026-10-10 12:44 UTC124
        intensity: i32,
782069860236atagen2026-10-10 12:44 UTC125
        lube: Option<Lube>,
782069860236atagen2026-10-10 12:44 UTC126
        now: Instant,
782069860236atagen2026-10-10 12:44 UTC127
    ) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC128
        if a == b {
782069860236atagen2026-10-10 12:44 UTC129
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC130
                StatusCode::BAD_REQUEST,
782069860236atagen2026-10-10 12:44 UTC131
                "combo-invalid",
782069860236atagen2026-10-10 12:44 UTC132
                "A technique cannot be combined with itself. The server has checked.",
782069860236atagen2026-10-10 12:44 UTC133
            ));
782069860236atagen2026-10-10 12:44 UTC134
        }
782069860236atagen2026-10-10 12:44 UTC135
        self.here.edges = 0;
782069860236atagen2026-10-10 12:44 UTC136
        self.ready(Technique::Training(a), lube)?;
782069860236atagen2026-10-10 12:44 UTC137
        self.ready(Technique::Training(b), lube)?;
782069860236atagen2026-10-10 12:44 UTC138
        self.check_storage()?;
14de3e1e8dc2atagen2026-10-11 06:19 UTC139
        self.lube_available(lube)?;
782069860236atagen2026-10-10 12:44 UTC140
        self.floor_enemy()?;
139164489032atagen2026-10-11 05:46 UTC141
        self.take_lube(lube)?;
5dfebcc0ac43atagen2026-10-11 05:28 UTC142
        self.chafe(lube);
782069860236atagen2026-10-10 12:44 UTC143
        self.commit(intensity, lube, now, 2);
782069860236atagen2026-10-10 12:44 UTC144
        for training in [a, b] {
782069860236atagen2026-10-10 12:44 UTC145
            if let ControlFlow::Break(interrupted) = self.mishaps(training, intensity)? {
782069860236atagen2026-10-10 12:44 UTC146
                return Ok(interrupted);
782069860236atagen2026-10-10 12:44 UTC147
            }
782069860236atagen2026-10-10 12:44 UTC148
        }
782069860236atagen2026-10-10 12:44 UTC149
        if let ControlFlow::Break(interrupted) = self.hazards(intensity)? {
782069860236atagen2026-10-10 12:44 UTC150
            return Ok(interrupted);
782069860236atagen2026-10-10 12:44 UTC151
        }
782069860236atagen2026-10-10 12:44 UTC152
782069860236atagen2026-10-10 12:44 UTC153
        let mut statuses = Vec::new();
782069860236atagen2026-10-10 12:44 UTC154
        for training in [a, b] {
782069860236atagen2026-10-10 12:44 UTC155
            let result = self.roll(training, intensity, lube);
782069860236atagen2026-10-10 12:44 UTC156
            if self.ended.is_some() {
782069860236atagen2026-10-10 12:44 UTC157
                return result;
782069860236atagen2026-10-10 12:44 UTC158
            }
782069860236atagen2026-10-10 12:44 UTC159
            let status = match result {
782069860236atagen2026-10-10 12:44 UTC160
                Ok(outcome) => self.gossip(outcome).status,
782069860236atagen2026-10-10 12:44 UTC161
                Err(problem) => problem.status(),
782069860236atagen2026-10-10 12:44 UTC162
            };
782069860236atagen2026-10-10 12:44 UTC163
            statuses.push((training, status));
782069860236atagen2026-10-10 12:44 UTC164
        }
782069860236atagen2026-10-10 12:44 UTC165
782069860236atagen2026-10-10 12:44 UTC166
        let mut xml = String::from(
782069860236atagen2026-10-10 12:44 UTC167
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<D:multistatus xmlns:D=\"DAV:\">\n",
782069860236atagen2026-10-10 12:44 UTC168
        );
782069860236atagen2026-10-10 12:44 UTC169
        for (training, status) in statuses {
782069860236atagen2026-10-10 12:44 UTC170
            let _ = write!(
782069860236atagen2026-10-10 12:44 UTC171
                xml,
782069860236atagen2026-10-10 12:44 UTC172
                "  <D:response>\n    <D:href>{}?technique={}</D:href>\n    <D:status>HTTP/1.1 {} {}</D:status>\n  </D:response>\n",
782069860236atagen2026-10-10 12:44 UTC173
                self.path(""),
782069860236atagen2026-10-10 12:44 UTC174
                training.name(),
782069860236atagen2026-10-10 12:44 UTC175
                status.as_u16(),
782069860236atagen2026-10-10 12:44 UTC176
                crate::problem::reason(status),
782069860236atagen2026-10-10 12:44 UTC177
            );
782069860236atagen2026-10-10 12:44 UTC178
        }
782069860236atagen2026-10-10 12:44 UTC179
        xml.push_str(
782069860236atagen2026-10-10 12:44 UTC180
            "  <D:responsedescription>Each technique has been reported separately.</D:responsedescription>\n</D:multistatus>\n",
782069860236atagen2026-10-10 12:44 UTC181
        );
782069860236atagen2026-10-10 12:44 UTC182
        Ok(Outcome::raw(
782069860236atagen2026-10-10 12:44 UTC183
            StatusCode::MULTI_STATUS,
782069860236atagen2026-10-10 12:44 UTC184
            "application/xml; charset=utf-8",
782069860236atagen2026-10-10 12:44 UTC185
            xml,
782069860236atagen2026-10-10 12:44 UTC186
        ))
782069860236atagen2026-10-10 12:44 UTC187
    }
782069860236atagen2026-10-10 12:44 UTC188
782069860236atagen2026-10-10 12:44 UTC189
    fn ready(&self, technique: Technique, lube: Option<Lube>) -> Result<(), Problem> {
58e1fb3943e6atagen2026-10-10 13:30 UTC190
        self.access(technique)?;
58e1fb3943e6atagen2026-10-10 13:30 UTC191
        match technique {
58e1fb3943e6atagen2026-10-10 13:30 UTC192
            Technique::Training(training) => Self::check_lube(training, lube),
58e1fb3943e6atagen2026-10-10 13:30 UTC193
            Technique::Utility(_) => Ok(()),
58e1fb3943e6atagen2026-10-10 13:30 UTC194
        }
58e1fb3943e6atagen2026-10-10 13:30 UTC195
    }
58e1fb3943e6atagen2026-10-10 13:30 UTC196
58e1fb3943e6atagen2026-10-10 13:30 UTC197
    /// Whether the run could attempt the technique now, ignoring the lubricant.
58e1fb3943e6atagen2026-10-10 13:30 UTC198
    fn access(&self, technique: Technique) -> Result<(), Problem> {
782069860236atagen2026-10-10 12:44 UTC199
        if technique == Technique::Training(Training::Uli) && !self.forum_read() {
782069860236atagen2026-10-10 12:44 UTC200
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC201
                StatusCode::FORBIDDEN,
782069860236atagen2026-10-10 12:44 UTC202
                "technique-locked",
0fdc47364c8catagen2026-10-11 04:45 UTC203
                "uli is discussed on the forum, in a thread from 2009, by a man who never posted again. You have not been to the forum.",
782069860236atagen2026-10-10 12:44 UTC204
            ));
782069860236atagen2026-10-10 12:44 UTC205
        }
0fdc47364c8catagen2026-10-11 04:45 UTC206
        if technique == Technique::Utility(Utility::Meditate) {
0fdc47364c8catagen2026-10-11 04:45 UTC207
            return if self.meditation_taught {
0fdc47364c8catagen2026-10-11 04:45 UTC208
                Ok(())
0fdc47364c8catagen2026-10-11 04:45 UTC209
            } else {
0fdc47364c8catagen2026-10-11 04:45 UTC210
                Err(Problem::new(
0fdc47364c8catagen2026-10-11 04:45 UTC211
                    StatusCode::FORBIDDEN,
0fdc47364c8catagen2026-10-11 04:45 UTC212
                    "technique-locked",
0fdc47364c8catagen2026-10-11 04:45 UTC213
                    "The breathing technique is described in one of the forum's replies. You have not found it.",
0fdc47364c8catagen2026-10-11 04:45 UTC214
                ))
0fdc47364c8catagen2026-10-11 04:45 UTC215
            };
0fdc47364c8catagen2026-10-11 04:45 UTC216
        }
782069860236atagen2026-10-10 12:44 UTC217
        if !self.warmed_up {
782069860236atagen2026-10-10 12:44 UTC218
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC219
                StatusCode::PRECONDITION_FAILED,
782069860236atagen2026-10-10 12:44 UTC220
                "cold-start",
782069860236atagen2026-10-10 12:44 UTC221
                "Warm-up was skipped. The server has noted this.",
782069860236atagen2026-10-10 12:44 UTC222
            )
782069860236atagen2026-10-10 12:44 UTC223
            .with("technique", Utility::Warmup.name()));
782069860236atagen2026-10-10 12:44 UTC224
        }
58e1fb3943e6atagen2026-10-10 13:30 UTC225
        match technique {
58e1fb3943e6atagen2026-10-10 13:30 UTC226
            Technique::Utility(Utility::Pump) if !self.items.pump_pro => Err(Problem::new(
58e1fb3943e6atagen2026-10-10 13:30 UTC227
                StatusCode::FAILED_DEPENDENCY,
58e1fb3943e6atagen2026-10-10 13:30 UTC228
                "no-pump",
58e1fb3943e6atagen2026-10-10 13:30 UTC229
                "The pump technique depends on a pump.",
58e1fb3943e6atagen2026-10-10 13:30 UTC230
            )),
58e1fb3943e6atagen2026-10-10 13:30 UTC231
            Technique::Utility(_) => Ok(()),
58e1fb3943e6atagen2026-10-10 13:30 UTC232
            Technique::Training(training) => match training.profile().foreskin {
58e1fb3943e6atagen2026-10-10 13:30 UTC233
                Some((min, max)) => self.check_foreskin(min, max),
58e1fb3943e6atagen2026-10-10 13:30 UTC234
                None => Ok(()),
58e1fb3943e6atagen2026-10-10 13:30 UTC235
            },
782069860236atagen2026-10-10 12:44 UTC236
        }
58e1fb3943e6atagen2026-10-10 13:30 UTC237
    }
58e1fb3943e6atagen2026-10-10 13:30 UTC238
58e1fb3943e6atagen2026-10-10 13:30 UTC239
    fn check_lube(training: Training, lube: Option<Lube>) -> Result<(), Problem> {
58e1fb3943e6atagen2026-10-10 13:30 UTC240
        match (training.profile().lube, lube) {
58e1fb3943e6atagen2026-10-10 13:30 UTC241
            (LubeRule::Required, None) => Err(Problem::new(
58e1fb3943e6atagen2026-10-10 13:30 UTC242
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
58e1fb3943e6atagen2026-10-10 13:30 UTC243
                "lubricant-required",
58e1fb3943e6atagen2026-10-10 13:30 UTC244
                format!(
58e1fb3943e6atagen2026-10-10 13:30 UTC245
                    "The {} technique requires a lubricant. None was declared.",
58e1fb3943e6atagen2026-10-10 13:30 UTC246
                    training.name()
58e1fb3943e6atagen2026-10-10 13:30 UTC247
                ),
58e1fb3943e6atagen2026-10-10 13:30 UTC248
            )
58e1fb3943e6atagen2026-10-10 13:30 UTC249
            .with("lubricants", json!(LUBRICANTS))),
58e1fb3943e6atagen2026-10-10 13:30 UTC250
            (LubeRule::Forbidden, Some(_)) => Err(Problem::new(
58e1fb3943e6atagen2026-10-10 13:30 UTC251
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
58e1fb3943e6atagen2026-10-10 13:30 UTC252
                "lubricant-declared",
58e1fb3943e6atagen2026-10-10 13:30 UTC253
                format!(
58e1fb3943e6atagen2026-10-10 13:30 UTC254
                    "The {} technique was requested. A lubricant was declared.",
58e1fb3943e6atagen2026-10-10 13:30 UTC255
                    training.name()
58e1fb3943e6atagen2026-10-10 13:30 UTC256
                ),
58e1fb3943e6atagen2026-10-10 13:30 UTC257
            )),
58e1fb3943e6atagen2026-10-10 13:30 UTC258
            _ => Ok(()),
58e1fb3943e6atagen2026-10-10 13:30 UTC259
        }
58e1fb3943e6atagen2026-10-10 13:30 UTC260
    }
58e1fb3943e6atagen2026-10-10 13:30 UTC261
0a0bfee8329eatagen2026-10-11 05:11 UTC262
    /// One unit of whatever was declared. Spit is free and the tap is always on.
14de3e1e8dc2atagen2026-10-11 06:19 UTC263
    fn lube_available(&self, lube: Option<Lube>) -> Result<(), Problem> {
0a0bfee8329eatagen2026-10-11 05:11 UTC264
        let (held, name) = match lube {
0a0bfee8329eatagen2026-10-11 05:11 UTC265
            None | Some(Lube::Spit) => return Ok(()),
14de3e1e8dc2atagen2026-10-11 06:19 UTC266
            Some(Lube::BabyOil) => (&self.items.baby_oil, "baby-oil"),
14de3e1e8dc2atagen2026-10-11 06:19 UTC267
            Some(Lube::CoconutOil) => (&self.items.coconut_oil, "coconut-oil"),
14de3e1e8dc2atagen2026-10-11 06:19 UTC268
            Some(Lube::Lotion) => (&self.items.lotion, "lotion"),
14de3e1e8dc2atagen2026-10-11 06:19 UTC269
            Some(Lube::Vaseline) => (&self.items.vaseline, "vaseline"),
0a0bfee8329eatagen2026-10-11 05:11 UTC270
        };
0a0bfee8329eatagen2026-10-11 05:11 UTC271
        if *held == 0 {
0a0bfee8329eatagen2026-10-11 05:11 UTC272
            return Err(Problem::new(
139164489032atagen2026-10-11 05:46 UTC273
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
0a0bfee8329eatagen2026-10-11 05:11 UTC274
                "lubricant-exhausted",
0a0bfee8329eatagen2026-10-11 05:11 UTC275
                format!("{name} was declared, but the bottle is empty."),
0a0bfee8329eatagen2026-10-11 05:11 UTC276
            ));
0a0bfee8329eatagen2026-10-11 05:11 UTC277
        }
14de3e1e8dc2atagen2026-10-11 06:19 UTC278
        Ok(())
14de3e1e8dc2atagen2026-10-11 06:19 UTC279
    }
14de3e1e8dc2atagen2026-10-11 06:19 UTC280
14de3e1e8dc2atagen2026-10-11 06:19 UTC281
    fn take_lube(&mut self, lube: Option<Lube>) -> Result<(), Problem> {
14de3e1e8dc2atagen2026-10-11 06:19 UTC282
        self.lube_available(lube)?;
14de3e1e8dc2atagen2026-10-11 06:19 UTC283
        let held = match lube {
14de3e1e8dc2atagen2026-10-11 06:19 UTC284
            None | Some(Lube::Spit) => return Ok(()),
14de3e1e8dc2atagen2026-10-11 06:19 UTC285
            Some(Lube::BabyOil) => &mut self.items.baby_oil,
14de3e1e8dc2atagen2026-10-11 06:19 UTC286
            Some(Lube::CoconutOil) => &mut self.items.coconut_oil,
14de3e1e8dc2atagen2026-10-11 06:19 UTC287
            Some(Lube::Lotion) => &mut self.items.lotion,
14de3e1e8dc2atagen2026-10-11 06:19 UTC288
            Some(Lube::Vaseline) => &mut self.items.vaseline,
14de3e1e8dc2atagen2026-10-11 06:19 UTC289
        };
0a0bfee8329eatagen2026-10-11 05:11 UTC290
        *held -= 1;
0a0bfee8329eatagen2026-10-11 05:11 UTC291
        Ok(())
0a0bfee8329eatagen2026-10-11 05:11 UTC292
    }
0a0bfee8329eatagen2026-10-11 05:11 UTC293
58e1fb3943e6atagen2026-10-10 13:30 UTC294
    /// The techniques a JELQ could use right now without being refused before the roll.
58e1fb3943e6atagen2026-10-10 13:30 UTC295
    pub fn techniques_now(&self, now: Instant) -> Vec<Technique> {
58e1fb3943e6atagen2026-10-10 13:30 UTC296
        let blocked = !self.floor.timed()
58e1fb3943e6atagen2026-10-10 13:30 UTC297
            || self.items.cage
58e1fb3943e6atagen2026-10-10 13:30 UTC298
            || self.refractory_until.is_some_and(|until| now < until);
58e1fb3943e6atagen2026-10-10 13:30 UTC299
        if blocked {
58e1fb3943e6atagen2026-10-10 13:30 UTC300
            return Vec::new();
782069860236atagen2026-10-10 12:44 UTC301
        }
58e1fb3943e6atagen2026-10-10 13:30 UTC302
        Technique::ALL
58e1fb3943e6atagen2026-10-10 13:30 UTC303
            .into_iter()
58e1fb3943e6atagen2026-10-10 13:30 UTC304
            .filter(|&technique| match technique {
58e1fb3943e6atagen2026-10-10 13:30 UTC305
                Technique::Utility(Utility::Warmup) => true,
58e1fb3943e6atagen2026-10-10 13:30 UTC306
                Technique::Utility(Utility::Ice) => self.items.ice_packs > 0,
58e1fb3943e6atagen2026-10-10 13:30 UTC307
                Technique::Utility(Utility::Supplement) => self.items.supplements > 0,
0fdc47364c8catagen2026-10-11 04:45 UTC308
                Technique::Utility(Utility::Meditate) => {
0fdc47364c8catagen2026-10-11 04:45 UTC309
                    self.meditation_taught && !self.here.meditated
0fdc47364c8catagen2026-10-11 04:45 UTC310
                }
0a0bfee8329eatagen2026-10-11 05:11 UTC311
                Technique::Utility(Utility::Energy) => self.items.energy_drinks > 0,
58e1fb3943e6atagen2026-10-10 13:30 UTC312
                _ => self.access(technique).is_ok() && self.check_storage().is_ok(),
58e1fb3943e6atagen2026-10-10 13:30 UTC313
            })
58e1fb3943e6atagen2026-10-10 13:30 UTC314
            .collect()
782069860236atagen2026-10-10 12:44 UTC315
    }
782069860236atagen2026-10-10 12:44 UTC316
782069860236atagen2026-10-10 12:44 UTC317
    fn check_foreskin(&self, min: f64, max: f64) -> Result<(), Problem> {
782069860236atagen2026-10-10 12:44 UTC318
        let Some(f) = self.foreskin else {
782069860236atagen2026-10-10 12:44 UTC319
            if min <= 0.0 {
782069860236atagen2026-10-10 12:44 UTC320
                return Ok(());
782069860236atagen2026-10-10 12:44 UTC321
            }
782069860236atagen2026-10-10 12:44 UTC322
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC323
                StatusCode::GONE,
782069860236atagen2026-10-10 12:44 UTC324
                "foreskin-gone",
782069860236atagen2026-10-10 12:44 UTC325
                "This technique requires a foreskin. The foreskin is gone.",
782069860236atagen2026-10-10 12:44 UTC326
            )
782069860236atagen2026-10-10 12:44 UTC327
            .header(header::CONTENT_LOCATION, self.path("/foreskin")));
782069860236atagen2026-10-10 12:44 UTC328
        };
782069860236atagen2026-10-10 12:44 UTC329
        if f < min {
782069860236atagen2026-10-10 12:44 UTC330
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC331
                StatusCode::LENGTH_REQUIRED,
782069860236atagen2026-10-10 12:44 UTC332
                "foreskin-insufficient",
782069860236atagen2026-10-10 12:44 UTC333
                format!(
782069860236atagen2026-10-10 12:44 UTC334
                    "The selected technique requires {min:.1} units of foreskin. {f:.2} units are available. The server has noted the shortfall."
782069860236atagen2026-10-10 12:44 UTC335
                ),
782069860236atagen2026-10-10 12:44 UTC336
            )
782069860236atagen2026-10-10 12:44 UTC337
            .with("required", min));
782069860236atagen2026-10-10 12:44 UTC338
        }
782069860236atagen2026-10-10 12:44 UTC339
        if f > max {
782069860236atagen2026-10-10 12:44 UTC340
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC341
                StatusCode::PAYLOAD_TOO_LARGE,
782069860236atagen2026-10-10 12:44 UTC342
                "foreskin-excessive",
782069860236atagen2026-10-10 12:44 UTC343
                format!(
782069860236atagen2026-10-10 12:44 UTC344
                    "The selected technique tolerates at most {max:.1} units of foreskin. {f:.2} units are present."
782069860236atagen2026-10-10 12:44 UTC345
                ),
782069860236atagen2026-10-10 12:44 UTC346
            )
782069860236atagen2026-10-10 12:44 UTC347
            .with("maximum", max));
782069860236atagen2026-10-10 12:44 UTC348
        }
782069860236atagen2026-10-10 12:44 UTC349
        Ok(())
782069860236atagen2026-10-10 12:44 UTC350
    }
782069860236atagen2026-10-10 12:44 UTC351
782069860236atagen2026-10-10 12:44 UTC352
    fn check_storage(&self) -> Result<(), Problem> {
782069860236atagen2026-10-10 12:44 UTC353
        if self.items.extender && self.girth > STORAGE_GIRTH {
782069860236atagen2026-10-10 12:44 UTC354
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC355
                StatusCode::INSUFFICIENT_STORAGE,
782069860236atagen2026-10-10 12:44 UTC356
                "jeans-full",
782069860236atagen2026-10-10 12:44 UTC357
                "The jeans are full. The extender is occupying the remaining storage.",
782069860236atagen2026-10-10 12:44 UTC358
            )
782069860236atagen2026-10-10 12:44 UTC359
            .with("extender", self.path("/inventory/extender")));
782069860236atagen2026-10-10 12:44 UTC360
        }
782069860236atagen2026-10-10 12:44 UTC361
        Ok(())
782069860236atagen2026-10-10 12:44 UTC362
    }
782069860236atagen2026-10-10 12:44 UTC363
5dfebcc0ac43atagen2026-10-11 05:28 UTC364
    fn chafe(&mut self, lube: Option<Lube>) {
5dfebcc0ac43atagen2026-10-11 05:28 UTC365
        let mut friction = match lube {
5dfebcc0ac43atagen2026-10-11 05:28 UTC366
            None => FRICTION_DRY,
5dfebcc0ac43atagen2026-10-11 05:28 UTC367
            Some(Lube::Spit) => FRICTION_SPIT,
5dfebcc0ac43atagen2026-10-11 05:28 UTC368
            Some(_) => 0,
5dfebcc0ac43atagen2026-10-11 05:28 UTC369
        };
5dfebcc0ac43atagen2026-10-11 05:28 UTC370
        if friction > 0 && self.jelq_grip.is_some_and(|grip| grip != self.grip) {
5dfebcc0ac43atagen2026-10-11 05:28 UTC371
            friction -= FRICTION_GRIP;
5dfebcc0ac43atagen2026-10-11 05:28 UTC372
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC373
        self.jelq_grip = Some(self.grip);
5dfebcc0ac43atagen2026-10-11 05:28 UTC374
        self.friction = (self.friction + friction).min(FRICTION_MAX);
5dfebcc0ac43atagen2026-10-11 05:28 UTC375
        if self.friction >= FRICTION_BURN_AT
5dfebcc0ac43atagen2026-10-11 05:28 UTC376
            && !self.conditions.friction_burn
5dfebcc0ac43atagen2026-10-11 05:28 UTC377
            && self.chance(FRICTION_BURN)
5dfebcc0ac43atagen2026-10-11 05:28 UTC378
        {
5dfebcc0ac43atagen2026-10-11 05:28 UTC379
            self.conditions.friction_burn = true;
5dfebcc0ac43atagen2026-10-11 05:28 UTC380
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC381
    }
5dfebcc0ac43atagen2026-10-11 05:28 UTC382
782069860236atagen2026-10-10 12:44 UTC383
    pub(super) fn commit(&mut self, intensity: i32, lube: Option<Lube>, now: Instant, cost: i32) {
782069860236atagen2026-10-10 12:44 UTC384
        self.touch();
782069860236atagen2026-10-10 12:44 UTC385
        self.turn += 1;
782069860236atagen2026-10-10 12:44 UTC386
        self.here.turns += 1;
9683736a2c5eatagen2026-10-10 13:15 UTC387
        self.realise();
782069860236atagen2026-10-10 12:44 UTC388
        if self.items.extender {
782069860236atagen2026-10-10 12:44 UTC389
            self.length += EXTENDER_GAIN;
782069860236atagen2026-10-10 12:44 UTC390
        }
782069860236atagen2026-10-10 12:44 UTC391
        self.stamina -= cost + i32::from(lube == Some(Lube::Lotion));
782069860236atagen2026-10-10 12:44 UTC392
        if self.stamina <= 0 {
782069860236atagen2026-10-10 12:44 UTC393
            self.exhaust(now);
782069860236atagen2026-10-10 12:44 UTC394
        }
9683736a2c5eatagen2026-10-10 13:15 UTC395
        let chill = if self.floor == Floor::ChangingRoom {
9683736a2c5eatagen2026-10-10 13:15 UTC396
            CHANGING_ROOM_CHILL
782069860236atagen2026-10-10 12:44 UTC397
        } else {
782069860236atagen2026-10-10 12:44 UTC398
            0
782069860236atagen2026-10-10 12:44 UTC399
        };
782069860236atagen2026-10-10 12:44 UTC400
        let wobble = self.rng.random_range(-EQ_WOBBLE..=EQ_WOBBLE);
782069860236atagen2026-10-10 12:44 UTC401
        self.eq = (self.eq + intensity * 2 - 6 - chill + wobble).clamp(0, 100);
782069860236atagen2026-10-10 12:44 UTC402
782069860236atagen2026-10-10 12:44 UTC403
        let mut suspicion = intensity / 5 + i32::from(lube == Some(Lube::Vaseline));
9683736a2c5eatagen2026-10-10 13:15 UTC404
        if matches!(self.floor, Floor::ChangingRoom | Floor::Nans) {
782069860236atagen2026-10-10 12:44 UTC405
            suspicion *= 2;
782069860236atagen2026-10-10 12:44 UTC406
        }
9683736a2c5eatagen2026-10-10 13:15 UTC407
        if self.floor == Floor::Nans && lube == Some(Lube::CoconutOil) {
782069860236atagen2026-10-10 12:44 UTC408
            suspicion += 2;
782069860236atagen2026-10-10 12:44 UTC409
        }
782069860236atagen2026-10-10 12:44 UTC410
        let was_below = self.suspicion < SUSPICION_LIMIT;
782069860236atagen2026-10-10 12:44 UTC411
        self.suspicion =
782069860236atagen2026-10-10 12:44 UTC412
            u8::try_from((i32::from(self.suspicion) + suspicion).min(i32::from(SUSPICION_LIMIT)))
782069860236atagen2026-10-10 12:44 UTC413
                .unwrap_or(SUSPICION_LIMIT);
782069860236atagen2026-10-10 12:44 UTC414
4347977b8192atagen2026-10-11 04:56 UTC415
        if intensity >= PULLED_MUSCLE_INTENSITY
4347977b8192atagen2026-10-11 04:56 UTC416
            && !self.conditions.pulled_muscle
4347977b8192atagen2026-10-11 04:56 UTC417
            && self.chance(PULLED_MUSCLE)
4347977b8192atagen2026-10-11 04:56 UTC418
        {
4347977b8192atagen2026-10-11 04:56 UTC419
            self.conditions.pulled_muscle = true;
4347977b8192atagen2026-10-11 04:56 UTC420
            self.stamina = self.stamina.min(self.max_stamina());
4347977b8192atagen2026-10-11 04:56 UTC421
        }
4347977b8192atagen2026-10-11 04:56 UTC422
        self.settle(was_below);
4347977b8192atagen2026-10-11 04:56 UTC423
    }
4347977b8192atagen2026-10-11 04:56 UTC424
4347977b8192atagen2026-10-11 04:56 UTC425
    /// The part of a turn the house takes part in, whatever the action was.
0a0bfee8329eatagen2026-10-11 05:11 UTC426
    pub(super) fn settle(&mut self, was_below: bool) {
4347977b8192atagen2026-10-11 04:56 UTC427
        self.maybe_summon_mum(was_below);
782069860236atagen2026-10-10 12:44 UTC428
        if let Some(observer) = self.floor.observer()
782069860236atagen2026-10-10 12:44 UTC429
            && self.chance(OBSERVED)
782069860236atagen2026-10-10 12:44 UTC430
        {
782069860236atagen2026-10-10 12:44 UTC431
            self.observed = Some(observer);
782069860236atagen2026-10-10 12:44 UTC432
            self.shame += 1;
782069860236atagen2026-10-10 12:44 UTC433
            if observer == Observer::Cat && self.chance(CAT_TAKES_TOWEL) {
782069860236atagen2026-10-10 12:44 UTC434
                self.here.towel_stolen = true;
782069860236atagen2026-10-10 12:44 UTC435
            }
782069860236atagen2026-10-10 12:44 UTC436
        }
782069860236atagen2026-10-10 12:44 UTC437
        if self.items.ring && self.eq > HOT_EQ && self.chance(RING_PRIAPISM) {
782069860236atagen2026-10-10 12:44 UTC438
            self.conditions.priapism_turns = PRIAPISM_TURNS;
782069860236atagen2026-10-10 12:44 UTC439
        }
782069860236atagen2026-10-10 12:44 UTC440
        if self.conditions.priapism_turns > 0 {
782069860236atagen2026-10-10 12:44 UTC441
            self.conditions.priapism_turns -= 1;
782069860236atagen2026-10-10 12:44 UTC442
            self.eq = self.eq.max(PRIAPISM_EQ);
782069860236atagen2026-10-10 12:44 UTC443
        }
782069860236atagen2026-10-10 12:44 UTC444
        if self.turn == BRANCH_TURN && self.story == Story::Unopened {
782069860236atagen2026-10-10 12:44 UTC445
            self.story = Story::Pending;
0fdc47364c8catagen2026-10-11 04:45 UTC446
            self.notices
0fdc47364c8catagen2026-10-11 04:45 UTC447
                .push("Somewhere, a forum thread from 2009 still has replies.");
782069860236atagen2026-10-10 12:44 UTC448
        }
782069860236atagen2026-10-10 12:44 UTC449
    }
782069860236atagen2026-10-10 12:44 UTC450
4347977b8192atagen2026-10-11 04:56 UTC451
    /// HOLD. A pause between strokes, offered when the band has been left or the stamina is gone.
4347977b8192atagen2026-10-11 04:56 UTC452
    pub fn can_hold(&self) -> bool {
4347977b8192atagen2026-10-11 04:56 UTC453
        self.eq > DANGER_EQ || self.stamina <= 2
4347977b8192atagen2026-10-11 04:56 UTC454
    }
4347977b8192atagen2026-10-11 04:56 UTC455
4347977b8192atagen2026-10-11 04:56 UTC456
    pub fn hold(&mut self, now: Instant) -> Result<Outcome, Problem> {
4347977b8192atagen2026-10-11 04:56 UTC457
        self.check_refractory(now)?;
4347977b8192atagen2026-10-11 04:56 UTC458
        if self.story == Story::Pending {
4347977b8192atagen2026-10-11 04:56 UTC459
            return Ok(self.branch_offer());
4347977b8192atagen2026-10-11 04:56 UTC460
        }
4347977b8192atagen2026-10-11 04:56 UTC461
        if self.items.cage {
4347977b8192atagen2026-10-11 04:56 UTC462
            return Err(Problem::new(
4347977b8192atagen2026-10-11 04:56 UTC463
                StatusCode::LOCKED,
4347977b8192atagen2026-10-11 04:56 UTC464
                "caged",
4347977b8192atagen2026-10-11 04:56 UTC465
                "The cage is locked. The key is not in the box.",
4347977b8192atagen2026-10-11 04:56 UTC466
            ));
4347977b8192atagen2026-10-11 04:56 UTC467
        }
4347977b8192atagen2026-10-11 04:56 UTC468
        self.touch();
4347977b8192atagen2026-10-11 04:56 UTC469
        self.turn += 1;
4347977b8192atagen2026-10-11 04:56 UTC470
        self.here.turns += 1;
4347977b8192atagen2026-10-11 04:56 UTC471
        self.realise();
4347977b8192atagen2026-10-11 04:56 UTC472
        let was_below = self.suspicion < SUSPICION_LIMIT;
4347977b8192atagen2026-10-11 04:56 UTC473
        if self.chance(REFLECTION) {
4347977b8192atagen2026-10-11 04:56 UTC474
            self.eq = 0;
4347977b8192atagen2026-10-11 04:56 UTC475
            self.shame += 1;
4347977b8192atagen2026-10-11 04:56 UTC476
            self.notices
4347977b8192atagen2026-10-11 04:56 UTC477
                .push("the count reached ten, and then the reflection started");
4347977b8192atagen2026-10-11 04:56 UTC478
        } else {
4347977b8192atagen2026-10-11 04:56 UTC479
            self.eq = (self.eq - HOLD_EQ).clamp(0, 100);
4347977b8192atagen2026-10-11 04:56 UTC480
        }
4347977b8192atagen2026-10-11 04:56 UTC481
        self.stamina = (self.stamina + 1).min(self.max_stamina());
5dfebcc0ac43atagen2026-10-11 05:28 UTC482
        self.shed(FRICTION_HOLD);
4347977b8192atagen2026-10-11 04:56 UTC483
        self.settle(was_below);
4347977b8192atagen2026-10-11 04:56 UTC484
        Ok(Outcome::empty(StatusCode::NO_CONTENT))
4347977b8192atagen2026-10-11 04:56 UTC485
    }
4347977b8192atagen2026-10-11 04:56 UTC486
0fdc47364c8catagen2026-10-11 04:45 UTC487
    /// The breathing technique from the forum's replies. It spends no stamina and the turn is
0fdc47364c8catagen2026-10-11 04:45 UTC488
    /// not the floor's, but each floor allows it once.
0fdc47364c8catagen2026-10-11 04:45 UTC489
    fn meditate(&mut self) -> Result<Outcome, Problem> {
0fdc47364c8catagen2026-10-11 04:45 UTC490
        self.access(Technique::Utility(Utility::Meditate))?;
0fdc47364c8catagen2026-10-11 04:45 UTC491
        if self.here.meditated {
0fdc47364c8catagen2026-10-11 04:45 UTC492
            return Err(Problem::new(
0fdc47364c8catagen2026-10-11 04:45 UTC493
                StatusCode::CONFLICT,
0fdc47364c8catagen2026-10-11 04:45 UTC494
                "already-meditated",
0fdc47364c8catagen2026-10-11 04:45 UTC495
                "This floor has had its meditation.",
0fdc47364c8catagen2026-10-11 04:45 UTC496
            ));
0fdc47364c8catagen2026-10-11 04:45 UTC497
        }
0fdc47364c8catagen2026-10-11 04:45 UTC498
        self.here.meditated = true;
14de3e1e8dc2atagen2026-10-11 06:19 UTC499
        self.reset_eq(self.eq - MEDITATION_EQ);
5dfebcc0ac43atagen2026-10-11 05:28 UTC500
        self.shed(FRICTION_MEDITATE);
0fdc47364c8catagen2026-10-11 04:45 UTC501
        self.touch();
0fdc47364c8catagen2026-10-11 04:45 UTC502
        Ok(Outcome::json(
0fdc47364c8catagen2026-10-11 04:45 UTC503
            StatusCode::OK,
0fdc47364c8catagen2026-10-11 04:45 UTC504
            json!({
0fdc47364c8catagen2026-10-11 04:45 UTC505
                "detail": "In through the nose, out through the mouth. EQ falls by ten.",
0fdc47364c8catagen2026-10-11 04:45 UTC506
            }),
0fdc47364c8catagen2026-10-11 04:45 UTC507
        ))
0fdc47364c8catagen2026-10-11 04:45 UTC508
    }
0fdc47364c8catagen2026-10-11 04:45 UTC509
0d604ee39751atagen2026-10-10 14:15 UTC510
    pub(super) fn maybe_summon_mum(&mut self, was_below: bool) {
9683736a2c5eatagen2026-10-10 13:15 UTC511
        if !self.floor.has_mum() || self.mum.is_some() {
782069860236atagen2026-10-10 12:44 UTC512
            return;
782069860236atagen2026-10-10 12:44 UTC513
        }
782069860236atagen2026-10-10 12:44 UTC514
        let summoned = was_below && self.suspicion == SUSPICION_LIMIT;
7d3fb63208bfatagen2026-10-11 04:38 UTC515
        let mut visits = u32::from(self.suspicion) + 1;
7d3fb63208bfatagen2026-10-11 04:38 UTC516
        if self.here.brother_told {
7d3fb63208bfatagen2026-10-11 04:38 UTC517
            visits *= 2;
7d3fb63208bfatagen2026-10-11 04:38 UTC518
        }
9683736a2c5eatagen2026-10-10 13:15 UTC519
        if summoned || self.rng.random_ratio(visits, super::balance::MUM_VISIT) {
782069860236atagen2026-10-10 12:44 UTC520
            let errand = self.errand(summoned);
782069860236atagen2026-10-10 12:44 UTC521
            let nonce = self.fresh_nonce();
9683736a2c5eatagen2026-10-10 13:15 UTC522
            self.mum = Some(MumVisit {
782069860236atagen2026-10-10 12:44 UTC523
                errand,
782069860236atagen2026-10-10 12:44 UTC524
                nonce,
782069860236atagen2026-10-10 12:44 UTC525
                strikes: 0,
0d604ee39751atagen2026-10-10 14:15 UTC526
                knocked: false,
782069860236atagen2026-10-10 12:44 UTC527
            });
782069860236atagen2026-10-10 12:44 UTC528
        }
782069860236atagen2026-10-10 12:44 UTC529
    }
782069860236atagen2026-10-10 12:44 UTC530
782069860236atagen2026-10-10 12:44 UTC531
    fn roll(
782069860236atagen2026-10-10 12:44 UTC532
        &mut self,
782069860236atagen2026-10-10 12:44 UTC533
        training: Training,
782069860236atagen2026-10-10 12:44 UTC534
        intensity: i32,
782069860236atagen2026-10-10 12:44 UTC535
        lube: Option<Lube>,
782069860236atagen2026-10-10 12:44 UTC536
    ) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC537
        let profile = training.profile();
782069860236atagen2026-10-10 12:44 UTC538
        let natural: i32 = self.rng.random_range(1..=20);
782069860236atagen2026-10-10 12:44 UTC539
        let band = if EQ_BAND.contains(&self.eq) {
782069860236atagen2026-10-10 12:44 UTC540
            BAND_BONUS
782069860236atagen2026-10-10 12:44 UTC541
        } else {
782069860236atagen2026-10-10 12:44 UTC542
            0
782069860236atagen2026-10-10 12:44 UTC543
        };
782069860236atagen2026-10-10 12:44 UTC544
        let grip = match (self.grip, training) {
782069860236atagen2026-10-10 12:44 UTC545
            (Grip::Underhand, Training::Stretch) => 2,
782069860236atagen2026-10-10 12:44 UTC546
            (Grip::Underhand, Training::Wet) => -1,
782069860236atagen2026-10-10 12:44 UTC547
            _ => 0,
782069860236atagen2026-10-10 12:44 UTC548
        };
4347977b8192atagen2026-10-11 04:56 UTC549
        let arrival = if self.here.warm_arrival {
4347977b8192atagen2026-10-11 04:56 UTC550
            self.here.warm_arrival = false;
4347977b8192atagen2026-10-11 04:56 UTC551
            ARRIVAL_BONUS
4347977b8192atagen2026-10-11 04:56 UTC552
        } else {
4347977b8192atagen2026-10-11 04:56 UTC553
            0
4347977b8192atagen2026-10-11 04:56 UTC554
        };
4347977b8192atagen2026-10-11 04:56 UTC555
        let modifier = lube.map_or(0, Lube::modifier) + band + grip + arrival;
782069860236atagen2026-10-10 12:44 UTC556
        let dc = profile.dc + intensity / 3;
782069860236atagen2026-10-10 12:44 UTC557
        let total = natural + modifier;
782069860236atagen2026-10-10 12:44 UTC558
        let timing = format!("roll;desc=\"d20{modifier:+} vs {dc}\";dur={natural}");
782069860236atagen2026-10-10 12:44 UTC559
        let timed = |p: Problem| p.header(SERVER_TIMING, &timing);
782069860236atagen2026-10-10 12:44 UTC560
782069860236atagen2026-10-10 12:44 UTC561
        let (length, girth) = self.scaled_gains(&profile, intensity);
5dfebcc0ac43atagen2026-10-11 05:28 UTC562
        let burn = if self.conditions.friction_burn {
5dfebcc0ac43atagen2026-10-11 05:28 UTC563
            BURN_RUPTURE
5dfebcc0ac43atagen2026-10-11 05:28 UTC564
        } else {
5dfebcc0ac43atagen2026-10-11 05:28 UTC565
            0
5dfebcc0ac43atagen2026-10-11 05:28 UTC566
        };
782069860236atagen2026-10-10 12:44 UTC567
        let rupture_line = if self.items.ring {
782069860236atagen2026-10-10 12:44 UTC568
            RING_RUPTURE_LINE
782069860236atagen2026-10-10 12:44 UTC569
        } else {
782069860236atagen2026-10-10 12:44 UTC570
            RUPTURE_LINE
782069860236atagen2026-10-10 12:44 UTC571
        };
782069860236atagen2026-10-10 12:44 UTC572
782069860236atagen2026-10-10 12:44 UTC573
        if natural == 1 {
782069860236atagen2026-10-10 12:44 UTC574
            return Err(timed(self.critical_failure(training, &profile)));
782069860236atagen2026-10-10 12:44 UTC575
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC576
        if natural == 2 && self.eq > DANGER_EQ - burn {
782069860236atagen2026-10-10 12:44 UTC577
            return Err(timed(self.rupture()));
782069860236atagen2026-10-10 12:44 UTC578
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC579
        if self.eq > rupture_line - burn && total < dc {
782069860236atagen2026-10-10 12:44 UTC580
            return Err(timed(self.rupture()));
782069860236atagen2026-10-10 12:44 UTC581
        }
782069860236atagen2026-10-10 12:44 UTC582
        if natural == 20 {
782069860236atagen2026-10-10 12:44 UTC583
            self.gain(length * 2.0, girth * 2.0, profile.foreskin_growth);
782069860236atagen2026-10-10 12:44 UTC584
            return Ok(Outcome::json(
782069860236atagen2026-10-10 12:44 UTC585
                StatusCode::PERMANENT_REDIRECT,
782069860236atagen2026-10-10 12:44 UTC586
                json!({
782069860236atagen2026-10-10 12:44 UTC587
                    "detail": "Your length has moved permanently.",
782069860236atagen2026-10-10 12:44 UTC588
                    "length": round3(length * 2.0),
782069860236atagen2026-10-10 12:44 UTC589
                    "girth": round3(girth * 2.0),
782069860236atagen2026-10-10 12:44 UTC590
                }),
782069860236atagen2026-10-10 12:44 UTC591
            )
782069860236atagen2026-10-10 12:44 UTC592
            .header(header::LOCATION, self.path("/length"))
782069860236atagen2026-10-10 12:44 UTC593
            .header(SERVER_TIMING, timing));
782069860236atagen2026-10-10 12:44 UTC594
        }
782069860236atagen2026-10-10 12:44 UTC595
        if total < dc - 3 {
782069860236atagen2026-10-10 12:44 UTC596
            return Err(timed(not_extended()));
782069860236atagen2026-10-10 12:44 UTC597
        }
782069860236atagen2026-10-10 12:44 UTC598
        if total < dc {
782069860236atagen2026-10-10 12:44 UTC599
            return Ok(Outcome::empty(StatusCode::NO_CONTENT).header(SERVER_TIMING, timing));
782069860236atagen2026-10-10 12:44 UTC600
        }
782069860236atagen2026-10-10 12:44 UTC601
782069860236atagen2026-10-10 12:44 UTC602
        let outcome = if self.eq < *EQ_BAND.start() {
782069860236atagen2026-10-10 12:44 UTC603
            self.gain(length / 2.0, girth / 2.0, profile.foreskin_growth);
782069860236atagen2026-10-10 12:44 UTC604
            Outcome::json(
782069860236atagen2026-10-10 12:44 UTC605
                StatusCode::PARTIAL_CONTENT,
782069860236atagen2026-10-10 12:44 UTC606
                json!({
782069860236atagen2026-10-10 12:44 UTC607
                    "detail": "Partial gains were applied. EQ was below the band.",
782069860236atagen2026-10-10 12:44 UTC608
                    "length": round3(length / 2.0),
782069860236atagen2026-10-10 12:44 UTC609
                    "girth": round3(girth / 2.0),
782069860236atagen2026-10-10 12:44 UTC610
                }),
782069860236atagen2026-10-10 12:44 UTC611
            )
782069860236atagen2026-10-10 12:44 UTC612
        } else if total >= dc + 5 {
782069860236atagen2026-10-10 12:44 UTC613
            self.gain(length, girth, profile.foreskin_growth);
782069860236atagen2026-10-10 12:44 UTC614
            Outcome::json(
782069860236atagen2026-10-10 12:44 UTC615
                StatusCode::OK,
782069860236atagen2026-10-10 12:44 UTC616
                json!({
782069860236atagen2026-10-10 12:44 UTC617
                    "detail": "Gains were applied.",
782069860236atagen2026-10-10 12:44 UTC618
                    "length": round3(length),
782069860236atagen2026-10-10 12:44 UTC619
                    "girth": round3(girth),
782069860236atagen2026-10-10 12:44 UTC620
                }),
782069860236atagen2026-10-10 12:44 UTC621
            )
782069860236atagen2026-10-10 12:44 UTC622
        } else {
782069860236atagen2026-10-10 12:44 UTC623
            let eta = self.rng.random_range(1..=4);
782069860236atagen2026-10-10 12:44 UTC624
            self.pending.push(Pending {
782069860236atagen2026-10-10 12:44 UTC625
                due: self.turn + eta,
782069860236atagen2026-10-10 12:44 UTC626
                length,
782069860236atagen2026-10-10 12:44 UTC627
                girth,
782069860236atagen2026-10-10 12:44 UTC628
            });
782069860236atagen2026-10-10 12:44 UTC629
            self.gain(0.0, 0.0, profile.foreskin_growth);
782069860236atagen2026-10-10 12:44 UTC630
            Outcome::json(
782069860236atagen2026-10-10 12:44 UTC631
                StatusCode::ACCEPTED,
782069860236atagen2026-10-10 12:44 UTC632
                json!({
782069860236atagen2026-10-10 12:44 UTC633
                    "detail": "Gains have been queued. They may arrive.",
782069860236atagen2026-10-10 12:44 UTC634
                    "eta_turns": eta,
782069860236atagen2026-10-10 12:44 UTC635
                }),
782069860236atagen2026-10-10 12:44 UTC636
            )
782069860236atagen2026-10-10 12:44 UTC637
        };
782069860236atagen2026-10-10 12:44 UTC638
        Ok(outcome.header(SERVER_TIMING, timing))
782069860236atagen2026-10-10 12:44 UTC639
    }
782069860236atagen2026-10-10 12:44 UTC640
782069860236atagen2026-10-10 12:44 UTC641
    fn scaled_gains(&self, profile: &Profile, intensity: i32) -> (f64, f64) {
782069860236atagen2026-10-10 12:44 UTC642
        let scale = f64::from(intensity);
782069860236atagen2026-10-10 12:44 UTC643
        let (mut length, mut girth) = (profile.length * scale, profile.girth * scale);
4347977b8192atagen2026-10-11 04:56 UTC644
        let greed = if self.eq > HOT_EQ {
4347977b8192atagen2026-10-11 04:56 UTC645
            GREED_HOT
4347977b8192atagen2026-10-11 04:56 UTC646
        } else if self.eq > DANGER_EQ {
4347977b8192atagen2026-10-11 04:56 UTC647
            GREED_WARM
4347977b8192atagen2026-10-11 04:56 UTC648
        } else {
4347977b8192atagen2026-10-11 04:56 UTC649
            1.0
4347977b8192atagen2026-10-11 04:56 UTC650
        };
4347977b8192atagen2026-10-11 04:56 UTC651
        length *= greed;
4347977b8192atagen2026-10-11 04:56 UTC652
        girth *= greed;
782069860236atagen2026-10-10 12:44 UTC653
        if self.here.teapot {
782069860236atagen2026-10-10 12:44 UTC654
            length *= 0.5;
782069860236atagen2026-10-10 12:44 UTC655
            girth *= 1.5;
782069860236atagen2026-10-10 12:44 UTC656
        }
782069860236atagen2026-10-10 12:44 UTC657
        if self.items.ring {
782069860236atagen2026-10-10 12:44 UTC658
            girth *= 2.0;
782069860236atagen2026-10-10 12:44 UTC659
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC660
        if self.conditions.friction_burn {
5dfebcc0ac43atagen2026-10-11 05:28 UTC661
            length *= 0.5;
5dfebcc0ac43atagen2026-10-11 05:28 UTC662
            girth *= 0.5;
5dfebcc0ac43atagen2026-10-11 05:28 UTC663
        }
782069860236atagen2026-10-10 12:44 UTC664
        (length, girth)
782069860236atagen2026-10-10 12:44 UTC665
    }
782069860236atagen2026-10-10 12:44 UTC666
782069860236atagen2026-10-10 12:44 UTC667
    fn critical_failure(&mut self, training: Training, profile: &Profile) -> Problem {
782069860236atagen2026-10-10 12:44 UTC668
        let uses_foreskin = profile.foreskin.is_some_and(|(min, _)| min > 0.0);
782069860236atagen2026-10-10 12:44 UTC669
        if uses_foreskin && self.foreskin.is_some() {
782069860236atagen2026-10-10 12:44 UTC670
            self.foreskin = None;
782069860236atagen2026-10-10 12:44 UTC671
            self.shame += 25;
782069860236atagen2026-10-10 12:44 UTC672
            return Problem::new(
782069860236atagen2026-10-10 12:44 UTC673
                StatusCode::GONE,
782069860236atagen2026-10-10 12:44 UTC674
                "foreskin-lost",
782069860236atagen2026-10-10 12:44 UTC675
                "The technique has removed the foreskin. It will not be returning.",
782069860236atagen2026-10-10 12:44 UTC676
            )
782069860236atagen2026-10-10 12:44 UTC677
            .header(header::CONTENT_LOCATION, self.path("/foreskin"));
782069860236atagen2026-10-10 12:44 UTC678
        }
139164489032atagen2026-10-11 05:46 UTC679
        let burn = if self.conditions.friction_burn {
139164489032atagen2026-10-11 05:46 UTC680
            BURN_RUPTURE
139164489032atagen2026-10-11 05:46 UTC681
        } else {
139164489032atagen2026-10-11 05:46 UTC682
            0
139164489032atagen2026-10-11 05:46 UTC683
        };
139164489032atagen2026-10-11 05:46 UTC684
        if self.eq > DANGER_EQ - burn {
782069860236atagen2026-10-10 12:44 UTC685
            return self.rupture();
782069860236atagen2026-10-10 12:44 UTC686
        }
782069860236atagen2026-10-10 12:44 UTC687
        if training == Training::Stretch && !self.here.teapot {
782069860236atagen2026-10-10 12:44 UTC688
            self.here.teapot = true;
782069860236atagen2026-10-10 12:44 UTC689
            self.items.teapot_spout = true;
782069860236atagen2026-10-10 12:44 UTC690
            self.shame += 5;
782069860236atagen2026-10-10 12:44 UTC691
            return Problem::new(
782069860236atagen2026-10-10 12:44 UTC692
                StatusCode::IM_A_TEAPOT,
782069860236atagen2026-10-10 12:44 UTC693
                "teapot",
782069860236atagen2026-10-10 12:44 UTC694
                "The subject is now short and stout. Length gains are halved for the rest of the floor.",
782069860236atagen2026-10-10 12:44 UTC695
            );
782069860236atagen2026-10-10 12:44 UTC696
        }
782069860236atagen2026-10-10 12:44 UTC697
        if training == Training::Uli && !self.conditions.peyronie {
782069860236atagen2026-10-10 12:44 UTC698
            self.conditions.peyronie = true;
782069860236atagen2026-10-10 12:44 UTC699
            self.shame += 5;
782069860236atagen2026-10-10 12:44 UTC700
            return Problem::new(
782069860236atagen2026-10-10 12:44 UTC701
                StatusCode::MISDIRECTED_REQUEST,
782069860236atagen2026-10-10 12:44 UTC702
                "curvature",
782069860236atagen2026-10-10 12:44 UTC703
                "A curvature has developed. Techniques will land slightly to the left until a professional is consulted.",
782069860236atagen2026-10-10 12:44 UTC704
            );
782069860236atagen2026-10-10 12:44 UTC705
        }
782069860236atagen2026-10-10 12:44 UTC706
        not_extended()
782069860236atagen2026-10-10 12:44 UTC707
    }
782069860236atagen2026-10-10 12:44 UTC708
782069860236atagen2026-10-10 12:44 UTC709
    fn gossip(&mut self, mut outcome: Outcome) -> Outcome {
782069860236atagen2026-10-10 12:44 UTC710
        let reportable = matches!(outcome.status.as_u16(), 200 | 202 | 206);
7d3fb63208bfatagen2026-10-11 04:38 UTC711
        if !self.here.brother_told || !reportable {
782069860236atagen2026-10-10 12:44 UTC712
            return outcome;
782069860236atagen2026-10-10 12:44 UTC713
        }
7d3fb63208bfatagen2026-10-11 04:38 UTC714
        self.here.brother_told = false;
782069860236atagen2026-10-10 12:44 UTC715
        outcome.status = StatusCode::ALREADY_REPORTED;
782069860236atagen2026-10-10 12:44 UTC716
        if let Payload::Json(body) = &mut outcome.payload {
7d3fb63208bfatagen2026-10-11 04:38 UTC717
            body["detail"] = json!("Your brother has already told Mum.");
782069860236atagen2026-10-10 12:44 UTC718
        }
782069860236atagen2026-10-10 12:44 UTC719
        outcome
782069860236atagen2026-10-10 12:44 UTC720
    }
782069860236atagen2026-10-10 12:44 UTC721
}