atagen

jelq

public

an http based roguelike rpg about jelqing

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