atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
b85a0d4536c3b294547a682ac046d8a38beb47a3
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::{
b85a0d4536c3atagen2026-10-11 08:50 UTC10
        ARRIVAL_BONUS, BAND_BONUS, BRANCH_TURN, CAT_TAKES_TOWEL, CHANGING_ROOM_CHILL, DANGER_EQ,
b85a0d4536c3atagen2026-10-11 08:50 UTC11
        EQ_BAND, EQ_WOBBLE, EXTENDER_GAIN, FRICTION_BURN, FRICTION_BURN_AT, FRICTION_DRY,
b85a0d4536c3atagen2026-10-11 08:50 UTC12
        FRICTION_GRIP, FRICTION_HOLD, FRICTION_MAX, FRICTION_MEDITATE, FRICTION_SPIT, GREED_HOT,
b85a0d4536c3atagen2026-10-11 08:50 UTC13
        GREED_WARM, HOLD_EQ, HOT_EQ, MEDITATION_EQ, OBSERVED, PRIAPISM_EQ, PRIAPISM_TURNS,
b85a0d4536c3atagen2026-10-11 08:50 UTC14
        PULLED_MUSCLE, PULLED_MUSCLE_INTENSITY, REFLECTION, RING_PRIAPISM, RING_RUPTURE_LINE,
b85a0d4536c3atagen2026-10-11 08:50 UTC15
        RUPTURE_HOLD, 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> {
b85a0d4536c3atagen2026-10-11 08:50 UTC199
        if technique == Technique::Training(Training::Uli) && !self.uli_taught {
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",
b85a0d4536c3atagen2026-10-11 08:50 UTC203
                "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 UTC204
            ));
782069860236atagen2026-10-10 12:44 UTC205
        }
782069860236atagen2026-10-10 12:44 UTC206
        if !self.warmed_up {
782069860236atagen2026-10-10 12:44 UTC207
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC208
                StatusCode::PRECONDITION_FAILED,
782069860236atagen2026-10-10 12:44 UTC209
                "cold-start",
782069860236atagen2026-10-10 12:44 UTC210
                "Warm-up was skipped. The server has noted this.",
782069860236atagen2026-10-10 12:44 UTC211
            )
782069860236atagen2026-10-10 12:44 UTC212
            .with("technique", Utility::Warmup.name()));
782069860236atagen2026-10-10 12:44 UTC213
        }
58e1fb3943e6atagen2026-10-10 13:30 UTC214
        match technique {
58e1fb3943e6atagen2026-10-10 13:30 UTC215
            Technique::Utility(Utility::Pump) if !self.items.pump_pro => Err(Problem::new(
58e1fb3943e6atagen2026-10-10 13:30 UTC216
                StatusCode::FAILED_DEPENDENCY,
58e1fb3943e6atagen2026-10-10 13:30 UTC217
                "no-pump",
58e1fb3943e6atagen2026-10-10 13:30 UTC218
                "The pump technique depends on a pump.",
58e1fb3943e6atagen2026-10-10 13:30 UTC219
            )),
58e1fb3943e6atagen2026-10-10 13:30 UTC220
            Technique::Utility(_) => Ok(()),
58e1fb3943e6atagen2026-10-10 13:30 UTC221
            Technique::Training(training) => match training.profile().foreskin {
58e1fb3943e6atagen2026-10-10 13:30 UTC222
                Some((min, max)) => self.check_foreskin(min, max),
58e1fb3943e6atagen2026-10-10 13:30 UTC223
                None => Ok(()),
58e1fb3943e6atagen2026-10-10 13:30 UTC224
            },
782069860236atagen2026-10-10 12:44 UTC225
        }
58e1fb3943e6atagen2026-10-10 13:30 UTC226
    }
58e1fb3943e6atagen2026-10-10 13:30 UTC227
58e1fb3943e6atagen2026-10-10 13:30 UTC228
    fn check_lube(training: Training, lube: Option<Lube>) -> Result<(), Problem> {
58e1fb3943e6atagen2026-10-10 13:30 UTC229
        match (training.profile().lube, lube) {
58e1fb3943e6atagen2026-10-10 13:30 UTC230
            (LubeRule::Required, None) => Err(Problem::new(
58e1fb3943e6atagen2026-10-10 13:30 UTC231
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
58e1fb3943e6atagen2026-10-10 13:30 UTC232
                "lubricant-required",
58e1fb3943e6atagen2026-10-10 13:30 UTC233
                format!(
58e1fb3943e6atagen2026-10-10 13:30 UTC234
                    "The {} technique requires a lubricant. None was declared.",
58e1fb3943e6atagen2026-10-10 13:30 UTC235
                    training.name()
58e1fb3943e6atagen2026-10-10 13:30 UTC236
                ),
58e1fb3943e6atagen2026-10-10 13:30 UTC237
            )
58e1fb3943e6atagen2026-10-10 13:30 UTC238
            .with("lubricants", json!(LUBRICANTS))),
58e1fb3943e6atagen2026-10-10 13:30 UTC239
            (LubeRule::Forbidden, Some(_)) => Err(Problem::new(
58e1fb3943e6atagen2026-10-10 13:30 UTC240
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
58e1fb3943e6atagen2026-10-10 13:30 UTC241
                "lubricant-declared",
58e1fb3943e6atagen2026-10-10 13:30 UTC242
                format!(
58e1fb3943e6atagen2026-10-10 13:30 UTC243
                    "The {} technique was requested. A lubricant was declared.",
58e1fb3943e6atagen2026-10-10 13:30 UTC244
                    training.name()
58e1fb3943e6atagen2026-10-10 13:30 UTC245
                ),
58e1fb3943e6atagen2026-10-10 13:30 UTC246
            )),
58e1fb3943e6atagen2026-10-10 13:30 UTC247
            _ => Ok(()),
58e1fb3943e6atagen2026-10-10 13:30 UTC248
        }
58e1fb3943e6atagen2026-10-10 13:30 UTC249
    }
58e1fb3943e6atagen2026-10-10 13:30 UTC250
0a0bfee8329eatagen2026-10-11 05:11 UTC251
    /// One unit of whatever was declared. Spit is free and the tap is always on.
14de3e1e8dc2atagen2026-10-11 06:19 UTC252
    fn lube_available(&self, lube: Option<Lube>) -> Result<(), Problem> {
0a0bfee8329eatagen2026-10-11 05:11 UTC253
        let (held, name) = match lube {
0a0bfee8329eatagen2026-10-11 05:11 UTC254
            None | Some(Lube::Spit) => return Ok(()),
14de3e1e8dc2atagen2026-10-11 06:19 UTC255
            Some(Lube::BabyOil) => (&self.items.baby_oil, "baby-oil"),
14de3e1e8dc2atagen2026-10-11 06:19 UTC256
            Some(Lube::CoconutOil) => (&self.items.coconut_oil, "coconut-oil"),
14de3e1e8dc2atagen2026-10-11 06:19 UTC257
            Some(Lube::Lotion) => (&self.items.lotion, "lotion"),
14de3e1e8dc2atagen2026-10-11 06:19 UTC258
            Some(Lube::Vaseline) => (&self.items.vaseline, "vaseline"),
0a0bfee8329eatagen2026-10-11 05:11 UTC259
        };
0a0bfee8329eatagen2026-10-11 05:11 UTC260
        if *held == 0 {
0a0bfee8329eatagen2026-10-11 05:11 UTC261
            return Err(Problem::new(
139164489032atagen2026-10-11 05:46 UTC262
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
0a0bfee8329eatagen2026-10-11 05:11 UTC263
                "lubricant-exhausted",
0a0bfee8329eatagen2026-10-11 05:11 UTC264
                format!("{name} was declared, but the bottle is empty."),
0a0bfee8329eatagen2026-10-11 05:11 UTC265
            ));
0a0bfee8329eatagen2026-10-11 05:11 UTC266
        }
14de3e1e8dc2atagen2026-10-11 06:19 UTC267
        Ok(())
14de3e1e8dc2atagen2026-10-11 06:19 UTC268
    }
14de3e1e8dc2atagen2026-10-11 06:19 UTC269
14de3e1e8dc2atagen2026-10-11 06:19 UTC270
    fn take_lube(&mut self, lube: Option<Lube>) -> Result<(), Problem> {
14de3e1e8dc2atagen2026-10-11 06:19 UTC271
        self.lube_available(lube)?;
14de3e1e8dc2atagen2026-10-11 06:19 UTC272
        let held = match lube {
14de3e1e8dc2atagen2026-10-11 06:19 UTC273
            None | Some(Lube::Spit) => return Ok(()),
14de3e1e8dc2atagen2026-10-11 06:19 UTC274
            Some(Lube::BabyOil) => &mut self.items.baby_oil,
14de3e1e8dc2atagen2026-10-11 06:19 UTC275
            Some(Lube::CoconutOil) => &mut self.items.coconut_oil,
14de3e1e8dc2atagen2026-10-11 06:19 UTC276
            Some(Lube::Lotion) => &mut self.items.lotion,
14de3e1e8dc2atagen2026-10-11 06:19 UTC277
            Some(Lube::Vaseline) => &mut self.items.vaseline,
14de3e1e8dc2atagen2026-10-11 06:19 UTC278
        };
0a0bfee8329eatagen2026-10-11 05:11 UTC279
        *held -= 1;
0a0bfee8329eatagen2026-10-11 05:11 UTC280
        Ok(())
0a0bfee8329eatagen2026-10-11 05:11 UTC281
    }
0a0bfee8329eatagen2026-10-11 05:11 UTC282
58e1fb3943e6atagen2026-10-10 13:30 UTC283
    /// The techniques a JELQ could use right now without being refused before the roll.
58e1fb3943e6atagen2026-10-10 13:30 UTC284
    pub fn techniques_now(&self, now: Instant) -> Vec<Technique> {
58e1fb3943e6atagen2026-10-10 13:30 UTC285
        let blocked = !self.floor.timed()
58e1fb3943e6atagen2026-10-10 13:30 UTC286
            || self.items.cage
58e1fb3943e6atagen2026-10-10 13:30 UTC287
            || self.refractory_until.is_some_and(|until| now < until);
58e1fb3943e6atagen2026-10-10 13:30 UTC288
        if blocked {
58e1fb3943e6atagen2026-10-10 13:30 UTC289
            return Vec::new();
782069860236atagen2026-10-10 12:44 UTC290
        }
58e1fb3943e6atagen2026-10-10 13:30 UTC291
        Technique::ALL
58e1fb3943e6atagen2026-10-10 13:30 UTC292
            .into_iter()
58e1fb3943e6atagen2026-10-10 13:30 UTC293
            .filter(|&technique| match technique {
58e1fb3943e6atagen2026-10-10 13:30 UTC294
                Technique::Utility(Utility::Warmup) => true,
58e1fb3943e6atagen2026-10-10 13:30 UTC295
                Technique::Utility(Utility::Ice) => self.items.ice_packs > 0,
58e1fb3943e6atagen2026-10-10 13:30 UTC296
                Technique::Utility(Utility::Supplement) => self.items.supplements > 0,
b85a0d4536c3atagen2026-10-11 08:50 UTC297
                Technique::Utility(Utility::Meditate) => !self.here.meditated,
0a0bfee8329eatagen2026-10-11 05:11 UTC298
                Technique::Utility(Utility::Energy) => self.items.energy_drinks > 0,
58e1fb3943e6atagen2026-10-10 13:30 UTC299
                _ => self.access(technique).is_ok() && self.check_storage().is_ok(),
58e1fb3943e6atagen2026-10-10 13:30 UTC300
            })
58e1fb3943e6atagen2026-10-10 13:30 UTC301
            .collect()
782069860236atagen2026-10-10 12:44 UTC302
    }
782069860236atagen2026-10-10 12:44 UTC303
782069860236atagen2026-10-10 12:44 UTC304
    fn check_foreskin(&self, min: f64, max: f64) -> Result<(), Problem> {
782069860236atagen2026-10-10 12:44 UTC305
        let Some(f) = self.foreskin else {
782069860236atagen2026-10-10 12:44 UTC306
            if min <= 0.0 {
782069860236atagen2026-10-10 12:44 UTC307
                return Ok(());
782069860236atagen2026-10-10 12:44 UTC308
            }
782069860236atagen2026-10-10 12:44 UTC309
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC310
                StatusCode::GONE,
782069860236atagen2026-10-10 12:44 UTC311
                "foreskin-gone",
782069860236atagen2026-10-10 12:44 UTC312
                "This technique requires a foreskin. The foreskin is gone.",
782069860236atagen2026-10-10 12:44 UTC313
            )
782069860236atagen2026-10-10 12:44 UTC314
            .header(header::CONTENT_LOCATION, self.path("/foreskin")));
782069860236atagen2026-10-10 12:44 UTC315
        };
782069860236atagen2026-10-10 12:44 UTC316
        if f < min {
782069860236atagen2026-10-10 12:44 UTC317
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC318
                StatusCode::LENGTH_REQUIRED,
782069860236atagen2026-10-10 12:44 UTC319
                "foreskin-insufficient",
782069860236atagen2026-10-10 12:44 UTC320
                format!(
782069860236atagen2026-10-10 12:44 UTC321
                    "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 UTC322
                ),
782069860236atagen2026-10-10 12:44 UTC323
            )
782069860236atagen2026-10-10 12:44 UTC324
            .with("required", min));
782069860236atagen2026-10-10 12:44 UTC325
        }
782069860236atagen2026-10-10 12:44 UTC326
        if f > max {
782069860236atagen2026-10-10 12:44 UTC327
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC328
                StatusCode::PAYLOAD_TOO_LARGE,
782069860236atagen2026-10-10 12:44 UTC329
                "foreskin-excessive",
782069860236atagen2026-10-10 12:44 UTC330
                format!(
782069860236atagen2026-10-10 12:44 UTC331
                    "The selected technique tolerates at most {max:.1} units of foreskin. {f:.2} units are present."
782069860236atagen2026-10-10 12:44 UTC332
                ),
782069860236atagen2026-10-10 12:44 UTC333
            )
782069860236atagen2026-10-10 12:44 UTC334
            .with("maximum", max));
782069860236atagen2026-10-10 12:44 UTC335
        }
782069860236atagen2026-10-10 12:44 UTC336
        Ok(())
782069860236atagen2026-10-10 12:44 UTC337
    }
782069860236atagen2026-10-10 12:44 UTC338
782069860236atagen2026-10-10 12:44 UTC339
    fn check_storage(&self) -> Result<(), Problem> {
782069860236atagen2026-10-10 12:44 UTC340
        if self.items.extender && self.girth > STORAGE_GIRTH {
782069860236atagen2026-10-10 12:44 UTC341
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC342
                StatusCode::INSUFFICIENT_STORAGE,
782069860236atagen2026-10-10 12:44 UTC343
                "jeans-full",
782069860236atagen2026-10-10 12:44 UTC344
                "The jeans are full. The extender is occupying the remaining storage.",
782069860236atagen2026-10-10 12:44 UTC345
            )
782069860236atagen2026-10-10 12:44 UTC346
            .with("extender", self.path("/inventory/extender")));
782069860236atagen2026-10-10 12:44 UTC347
        }
782069860236atagen2026-10-10 12:44 UTC348
        Ok(())
782069860236atagen2026-10-10 12:44 UTC349
    }
782069860236atagen2026-10-10 12:44 UTC350
5dfebcc0ac43atagen2026-10-11 05:28 UTC351
    fn chafe(&mut self, lube: Option<Lube>) {
5dfebcc0ac43atagen2026-10-11 05:28 UTC352
        let mut friction = match lube {
5dfebcc0ac43atagen2026-10-11 05:28 UTC353
            None => FRICTION_DRY,
5dfebcc0ac43atagen2026-10-11 05:28 UTC354
            Some(Lube::Spit) => FRICTION_SPIT,
5dfebcc0ac43atagen2026-10-11 05:28 UTC355
            Some(_) => 0,
5dfebcc0ac43atagen2026-10-11 05:28 UTC356
        };
5dfebcc0ac43atagen2026-10-11 05:28 UTC357
        if friction > 0 && self.jelq_grip.is_some_and(|grip| grip != self.grip) {
5dfebcc0ac43atagen2026-10-11 05:28 UTC358
            friction -= FRICTION_GRIP;
5dfebcc0ac43atagen2026-10-11 05:28 UTC359
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC360
        self.jelq_grip = Some(self.grip);
5dfebcc0ac43atagen2026-10-11 05:28 UTC361
        self.friction = (self.friction + friction).min(FRICTION_MAX);
5dfebcc0ac43atagen2026-10-11 05:28 UTC362
        if self.friction >= FRICTION_BURN_AT
5dfebcc0ac43atagen2026-10-11 05:28 UTC363
            && !self.conditions.friction_burn
5dfebcc0ac43atagen2026-10-11 05:28 UTC364
            && self.chance(FRICTION_BURN)
5dfebcc0ac43atagen2026-10-11 05:28 UTC365
        {
5dfebcc0ac43atagen2026-10-11 05:28 UTC366
            self.conditions.friction_burn = true;
5dfebcc0ac43atagen2026-10-11 05:28 UTC367
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC368
    }
5dfebcc0ac43atagen2026-10-11 05:28 UTC369
782069860236atagen2026-10-10 12:44 UTC370
    pub(super) fn commit(&mut self, intensity: i32, lube: Option<Lube>, now: Instant, cost: i32) {
782069860236atagen2026-10-10 12:44 UTC371
        self.touch();
782069860236atagen2026-10-10 12:44 UTC372
        self.turn += 1;
782069860236atagen2026-10-10 12:44 UTC373
        self.here.turns += 1;
9683736a2c5eatagen2026-10-10 13:15 UTC374
        self.realise();
782069860236atagen2026-10-10 12:44 UTC375
        if self.items.extender {
782069860236atagen2026-10-10 12:44 UTC376
            self.length += EXTENDER_GAIN;
782069860236atagen2026-10-10 12:44 UTC377
        }
782069860236atagen2026-10-10 12:44 UTC378
        self.stamina -= cost + i32::from(lube == Some(Lube::Lotion));
782069860236atagen2026-10-10 12:44 UTC379
        if self.stamina <= 0 {
782069860236atagen2026-10-10 12:44 UTC380
            self.exhaust(now);
782069860236atagen2026-10-10 12:44 UTC381
        }
9683736a2c5eatagen2026-10-10 13:15 UTC382
        let chill = if self.floor == Floor::ChangingRoom {
9683736a2c5eatagen2026-10-10 13:15 UTC383
            CHANGING_ROOM_CHILL
782069860236atagen2026-10-10 12:44 UTC384
        } else {
782069860236atagen2026-10-10 12:44 UTC385
            0
782069860236atagen2026-10-10 12:44 UTC386
        };
782069860236atagen2026-10-10 12:44 UTC387
        let wobble = self.rng.random_range(-EQ_WOBBLE..=EQ_WOBBLE);
782069860236atagen2026-10-10 12:44 UTC388
        self.eq = (self.eq + intensity * 2 - 6 - chill + wobble).clamp(0, 100);
782069860236atagen2026-10-10 12:44 UTC389
782069860236atagen2026-10-10 12:44 UTC390
        let mut suspicion = intensity / 5 + i32::from(lube == Some(Lube::Vaseline));
9683736a2c5eatagen2026-10-10 13:15 UTC391
        if matches!(self.floor, Floor::ChangingRoom | Floor::Nans) {
782069860236atagen2026-10-10 12:44 UTC392
            suspicion *= 2;
782069860236atagen2026-10-10 12:44 UTC393
        }
9683736a2c5eatagen2026-10-10 13:15 UTC394
        if self.floor == Floor::Nans && lube == Some(Lube::CoconutOil) {
782069860236atagen2026-10-10 12:44 UTC395
            suspicion += 2;
782069860236atagen2026-10-10 12:44 UTC396
        }
782069860236atagen2026-10-10 12:44 UTC397
        let was_below = self.suspicion < SUSPICION_LIMIT;
782069860236atagen2026-10-10 12:44 UTC398
        self.suspicion =
782069860236atagen2026-10-10 12:44 UTC399
            u8::try_from((i32::from(self.suspicion) + suspicion).min(i32::from(SUSPICION_LIMIT)))
782069860236atagen2026-10-10 12:44 UTC400
                .unwrap_or(SUSPICION_LIMIT);
782069860236atagen2026-10-10 12:44 UTC401
4347977b8192atagen2026-10-11 04:56 UTC402
        if intensity >= PULLED_MUSCLE_INTENSITY
4347977b8192atagen2026-10-11 04:56 UTC403
            && !self.conditions.pulled_muscle
4347977b8192atagen2026-10-11 04:56 UTC404
            && self.chance(PULLED_MUSCLE)
4347977b8192atagen2026-10-11 04:56 UTC405
        {
4347977b8192atagen2026-10-11 04:56 UTC406
            self.conditions.pulled_muscle = true;
4347977b8192atagen2026-10-11 04:56 UTC407
            self.stamina = self.stamina.min(self.max_stamina());
4347977b8192atagen2026-10-11 04:56 UTC408
        }
4347977b8192atagen2026-10-11 04:56 UTC409
        self.settle(was_below);
4347977b8192atagen2026-10-11 04:56 UTC410
    }
4347977b8192atagen2026-10-11 04:56 UTC411
4347977b8192atagen2026-10-11 04:56 UTC412
    /// The part of a turn the house takes part in, whatever the action was.
0a0bfee8329eatagen2026-10-11 05:11 UTC413
    pub(super) fn settle(&mut self, was_below: bool) {
4347977b8192atagen2026-10-11 04:56 UTC414
        self.maybe_summon_mum(was_below);
782069860236atagen2026-10-10 12:44 UTC415
        if let Some(observer) = self.floor.observer()
782069860236atagen2026-10-10 12:44 UTC416
            && self.chance(OBSERVED)
782069860236atagen2026-10-10 12:44 UTC417
        {
782069860236atagen2026-10-10 12:44 UTC418
            self.observed = Some(observer);
782069860236atagen2026-10-10 12:44 UTC419
            self.shame += 1;
782069860236atagen2026-10-10 12:44 UTC420
            if observer == Observer::Cat && self.chance(CAT_TAKES_TOWEL) {
782069860236atagen2026-10-10 12:44 UTC421
                self.here.towel_stolen = true;
782069860236atagen2026-10-10 12:44 UTC422
            }
782069860236atagen2026-10-10 12:44 UTC423
        }
782069860236atagen2026-10-10 12:44 UTC424
        if self.items.ring && self.eq > HOT_EQ && self.chance(RING_PRIAPISM) {
782069860236atagen2026-10-10 12:44 UTC425
            self.conditions.priapism_turns = PRIAPISM_TURNS;
782069860236atagen2026-10-10 12:44 UTC426
        }
782069860236atagen2026-10-10 12:44 UTC427
        if self.conditions.priapism_turns > 0 {
782069860236atagen2026-10-10 12:44 UTC428
            self.conditions.priapism_turns -= 1;
782069860236atagen2026-10-10 12:44 UTC429
            self.eq = self.eq.max(PRIAPISM_EQ);
782069860236atagen2026-10-10 12:44 UTC430
        }
782069860236atagen2026-10-10 12:44 UTC431
        if self.turn == BRANCH_TURN && self.story == Story::Unopened {
782069860236atagen2026-10-10 12:44 UTC432
            self.story = Story::Pending;
0fdc47364c8catagen2026-10-11 04:45 UTC433
            self.notices
0fdc47364c8catagen2026-10-11 04:45 UTC434
                .push("Somewhere, a forum thread from 2009 still has replies.");
782069860236atagen2026-10-10 12:44 UTC435
        }
782069860236atagen2026-10-10 12:44 UTC436
    }
782069860236atagen2026-10-10 12:44 UTC437
4347977b8192atagen2026-10-11 04:56 UTC438
    /// HOLD. A pause between strokes, offered when the band has been left or the stamina is gone.
4347977b8192atagen2026-10-11 04:56 UTC439
    pub fn can_hold(&self) -> bool {
4347977b8192atagen2026-10-11 04:56 UTC440
        self.eq > DANGER_EQ || self.stamina <= 2
4347977b8192atagen2026-10-11 04:56 UTC441
    }
4347977b8192atagen2026-10-11 04:56 UTC442
4347977b8192atagen2026-10-11 04:56 UTC443
    pub fn hold(&mut self, now: Instant) -> Result<Outcome, Problem> {
4347977b8192atagen2026-10-11 04:56 UTC444
        self.check_refractory(now)?;
4347977b8192atagen2026-10-11 04:56 UTC445
        if self.story == Story::Pending {
4347977b8192atagen2026-10-11 04:56 UTC446
            return Ok(self.branch_offer());
4347977b8192atagen2026-10-11 04:56 UTC447
        }
4347977b8192atagen2026-10-11 04:56 UTC448
        if self.items.cage {
4347977b8192atagen2026-10-11 04:56 UTC449
            return Err(Problem::new(
4347977b8192atagen2026-10-11 04:56 UTC450
                StatusCode::LOCKED,
4347977b8192atagen2026-10-11 04:56 UTC451
                "caged",
4347977b8192atagen2026-10-11 04:56 UTC452
                "The cage is locked. The key is not in the box.",
4347977b8192atagen2026-10-11 04:56 UTC453
            ));
4347977b8192atagen2026-10-11 04:56 UTC454
        }
b85a0d4536c3atagen2026-10-11 08:50 UTC455
        if self.chance(RUPTURE_HOLD) {
b85a0d4536c3atagen2026-10-11 08:50 UTC456
            return Err(self.rupture());
b85a0d4536c3atagen2026-10-11 08:50 UTC457
        }
4347977b8192atagen2026-10-11 04:56 UTC458
        self.touch();
4347977b8192atagen2026-10-11 04:56 UTC459
        self.turn += 1;
4347977b8192atagen2026-10-11 04:56 UTC460
        self.here.turns += 1;
4347977b8192atagen2026-10-11 04:56 UTC461
        self.realise();
4347977b8192atagen2026-10-11 04:56 UTC462
        let was_below = self.suspicion < SUSPICION_LIMIT;
4347977b8192atagen2026-10-11 04:56 UTC463
        if self.chance(REFLECTION) {
4347977b8192atagen2026-10-11 04:56 UTC464
            self.eq = 0;
4347977b8192atagen2026-10-11 04:56 UTC465
            self.shame += 1;
4347977b8192atagen2026-10-11 04:56 UTC466
            self.notices
4347977b8192atagen2026-10-11 04:56 UTC467
                .push("the count reached ten, and then the reflection started");
4347977b8192atagen2026-10-11 04:56 UTC468
        } else {
4347977b8192atagen2026-10-11 04:56 UTC469
            self.eq = (self.eq - HOLD_EQ).clamp(0, 100);
4347977b8192atagen2026-10-11 04:56 UTC470
        }
4347977b8192atagen2026-10-11 04:56 UTC471
        self.stamina = (self.stamina + 1).min(self.max_stamina());
5dfebcc0ac43atagen2026-10-11 05:28 UTC472
        self.shed(FRICTION_HOLD);
4347977b8192atagen2026-10-11 04:56 UTC473
        self.settle(was_below);
4347977b8192atagen2026-10-11 04:56 UTC474
        Ok(Outcome::empty(StatusCode::NO_CONTENT))
4347977b8192atagen2026-10-11 04:56 UTC475
    }
4347977b8192atagen2026-10-11 04:56 UTC476
0fdc47364c8catagen2026-10-11 04:45 UTC477
    /// The breathing technique from the forum's replies. It spends no stamina and the turn is
0fdc47364c8catagen2026-10-11 04:45 UTC478
    /// not the floor's, but each floor allows it once.
0fdc47364c8catagen2026-10-11 04:45 UTC479
    fn meditate(&mut self) -> Result<Outcome, Problem> {
0fdc47364c8catagen2026-10-11 04:45 UTC480
        if self.here.meditated {
0fdc47364c8catagen2026-10-11 04:45 UTC481
            return Err(Problem::new(
0fdc47364c8catagen2026-10-11 04:45 UTC482
                StatusCode::CONFLICT,
0fdc47364c8catagen2026-10-11 04:45 UTC483
                "already-meditated",
0fdc47364c8catagen2026-10-11 04:45 UTC484
                "This floor has had its meditation.",
0fdc47364c8catagen2026-10-11 04:45 UTC485
            ));
0fdc47364c8catagen2026-10-11 04:45 UTC486
        }
0fdc47364c8catagen2026-10-11 04:45 UTC487
        self.here.meditated = true;
14de3e1e8dc2atagen2026-10-11 06:19 UTC488
        self.reset_eq(self.eq - MEDITATION_EQ);
5dfebcc0ac43atagen2026-10-11 05:28 UTC489
        self.shed(FRICTION_MEDITATE);
0fdc47364c8catagen2026-10-11 04:45 UTC490
        self.touch();
0fdc47364c8catagen2026-10-11 04:45 UTC491
        Ok(Outcome::json(
0fdc47364c8catagen2026-10-11 04:45 UTC492
            StatusCode::OK,
0fdc47364c8catagen2026-10-11 04:45 UTC493
            json!({
0fdc47364c8catagen2026-10-11 04:45 UTC494
                "detail": "In through the nose, out through the mouth. EQ falls by ten.",
0fdc47364c8catagen2026-10-11 04:45 UTC495
            }),
0fdc47364c8catagen2026-10-11 04:45 UTC496
        ))
0fdc47364c8catagen2026-10-11 04:45 UTC497
    }
0fdc47364c8catagen2026-10-11 04:45 UTC498
0d604ee39751atagen2026-10-10 14:15 UTC499
    pub(super) fn maybe_summon_mum(&mut self, was_below: bool) {
9683736a2c5eatagen2026-10-10 13:15 UTC500
        if !self.floor.has_mum() || self.mum.is_some() {
782069860236atagen2026-10-10 12:44 UTC501
            return;
782069860236atagen2026-10-10 12:44 UTC502
        }
782069860236atagen2026-10-10 12:44 UTC503
        let summoned = was_below && self.suspicion == SUSPICION_LIMIT;
7d3fb63208bfatagen2026-10-11 04:38 UTC504
        let mut visits = u32::from(self.suspicion) + 1;
7d3fb63208bfatagen2026-10-11 04:38 UTC505
        if self.here.brother_told {
7d3fb63208bfatagen2026-10-11 04:38 UTC506
            visits *= 2;
7d3fb63208bfatagen2026-10-11 04:38 UTC507
        }
9683736a2c5eatagen2026-10-10 13:15 UTC508
        if summoned || self.rng.random_ratio(visits, super::balance::MUM_VISIT) {
782069860236atagen2026-10-10 12:44 UTC509
            let errand = self.errand(summoned);
782069860236atagen2026-10-10 12:44 UTC510
            let nonce = self.fresh_nonce();
9683736a2c5eatagen2026-10-10 13:15 UTC511
            self.mum = Some(MumVisit {
782069860236atagen2026-10-10 12:44 UTC512
                errand,
782069860236atagen2026-10-10 12:44 UTC513
                nonce,
782069860236atagen2026-10-10 12:44 UTC514
                strikes: 0,
0d604ee39751atagen2026-10-10 14:15 UTC515
                knocked: false,
782069860236atagen2026-10-10 12:44 UTC516
            });
782069860236atagen2026-10-10 12:44 UTC517
        }
782069860236atagen2026-10-10 12:44 UTC518
    }
782069860236atagen2026-10-10 12:44 UTC519
782069860236atagen2026-10-10 12:44 UTC520
    fn roll(
782069860236atagen2026-10-10 12:44 UTC521
        &mut self,
782069860236atagen2026-10-10 12:44 UTC522
        training: Training,
782069860236atagen2026-10-10 12:44 UTC523
        intensity: i32,
782069860236atagen2026-10-10 12:44 UTC524
        lube: Option<Lube>,
782069860236atagen2026-10-10 12:44 UTC525
    ) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC526
        let profile = training.profile();
782069860236atagen2026-10-10 12:44 UTC527
        let natural: i32 = self.rng.random_range(1..=20);
782069860236atagen2026-10-10 12:44 UTC528
        let band = if EQ_BAND.contains(&self.eq) {
782069860236atagen2026-10-10 12:44 UTC529
            BAND_BONUS
782069860236atagen2026-10-10 12:44 UTC530
        } else {
782069860236atagen2026-10-10 12:44 UTC531
            0
782069860236atagen2026-10-10 12:44 UTC532
        };
782069860236atagen2026-10-10 12:44 UTC533
        let grip = match (self.grip, training) {
782069860236atagen2026-10-10 12:44 UTC534
            (Grip::Underhand, Training::Stretch) => 2,
782069860236atagen2026-10-10 12:44 UTC535
            (Grip::Underhand, Training::Wet) => -1,
782069860236atagen2026-10-10 12:44 UTC536
            _ => 0,
782069860236atagen2026-10-10 12:44 UTC537
        };
4347977b8192atagen2026-10-11 04:56 UTC538
        let arrival = if self.here.warm_arrival {
4347977b8192atagen2026-10-11 04:56 UTC539
            self.here.warm_arrival = false;
4347977b8192atagen2026-10-11 04:56 UTC540
            ARRIVAL_BONUS
4347977b8192atagen2026-10-11 04:56 UTC541
        } else {
4347977b8192atagen2026-10-11 04:56 UTC542
            0
4347977b8192atagen2026-10-11 04:56 UTC543
        };
4347977b8192atagen2026-10-11 04:56 UTC544
        let modifier = lube.map_or(0, Lube::modifier) + band + grip + arrival;
782069860236atagen2026-10-10 12:44 UTC545
        let dc = profile.dc + intensity / 3;
782069860236atagen2026-10-10 12:44 UTC546
        let total = natural + modifier;
782069860236atagen2026-10-10 12:44 UTC547
        let timing = format!("roll;desc=\"d20{modifier:+} vs {dc}\";dur={natural}");
782069860236atagen2026-10-10 12:44 UTC548
        let timed = |p: Problem| p.header(SERVER_TIMING, &timing);
782069860236atagen2026-10-10 12:44 UTC549
782069860236atagen2026-10-10 12:44 UTC550
        let (length, girth) = self.scaled_gains(&profile, intensity);
b85a0d4536c3atagen2026-10-11 08:50 UTC551
        let burn = self.burn();
782069860236atagen2026-10-10 12:44 UTC552
        let rupture_line = if self.items.ring {
782069860236atagen2026-10-10 12:44 UTC553
            RING_RUPTURE_LINE
782069860236atagen2026-10-10 12:44 UTC554
        } else {
782069860236atagen2026-10-10 12:44 UTC555
            RUPTURE_LINE
782069860236atagen2026-10-10 12:44 UTC556
        };
782069860236atagen2026-10-10 12:44 UTC557
782069860236atagen2026-10-10 12:44 UTC558
        if natural == 1 {
782069860236atagen2026-10-10 12:44 UTC559
            return Err(timed(self.critical_failure(training, &profile)));
782069860236atagen2026-10-10 12:44 UTC560
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC561
        if natural == 2 && self.eq > DANGER_EQ - burn {
782069860236atagen2026-10-10 12:44 UTC562
            return Err(timed(self.rupture()));
782069860236atagen2026-10-10 12:44 UTC563
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC564
        if self.eq > rupture_line - burn && total < dc {
782069860236atagen2026-10-10 12:44 UTC565
            return Err(timed(self.rupture()));
782069860236atagen2026-10-10 12:44 UTC566
        }
782069860236atagen2026-10-10 12:44 UTC567
        if natural == 20 {
782069860236atagen2026-10-10 12:44 UTC568
            self.gain(length * 2.0, girth * 2.0, profile.foreskin_growth);
782069860236atagen2026-10-10 12:44 UTC569
            return Ok(Outcome::json(
782069860236atagen2026-10-10 12:44 UTC570
                StatusCode::PERMANENT_REDIRECT,
782069860236atagen2026-10-10 12:44 UTC571
                json!({
782069860236atagen2026-10-10 12:44 UTC572
                    "detail": "Your length has moved permanently.",
782069860236atagen2026-10-10 12:44 UTC573
                    "length": round3(length * 2.0),
782069860236atagen2026-10-10 12:44 UTC574
                    "girth": round3(girth * 2.0),
782069860236atagen2026-10-10 12:44 UTC575
                }),
782069860236atagen2026-10-10 12:44 UTC576
            )
782069860236atagen2026-10-10 12:44 UTC577
            .header(header::LOCATION, self.path("/length"))
782069860236atagen2026-10-10 12:44 UTC578
            .header(SERVER_TIMING, timing));
782069860236atagen2026-10-10 12:44 UTC579
        }
782069860236atagen2026-10-10 12:44 UTC580
        if total < dc - 3 {
782069860236atagen2026-10-10 12:44 UTC581
            return Err(timed(not_extended()));
782069860236atagen2026-10-10 12:44 UTC582
        }
782069860236atagen2026-10-10 12:44 UTC583
        if total < dc {
782069860236atagen2026-10-10 12:44 UTC584
            return Ok(Outcome::empty(StatusCode::NO_CONTENT).header(SERVER_TIMING, timing));
782069860236atagen2026-10-10 12:44 UTC585
        }
782069860236atagen2026-10-10 12:44 UTC586
782069860236atagen2026-10-10 12:44 UTC587
        let outcome = if self.eq < *EQ_BAND.start() {
782069860236atagen2026-10-10 12:44 UTC588
            self.gain(length / 2.0, girth / 2.0, profile.foreskin_growth);
782069860236atagen2026-10-10 12:44 UTC589
            Outcome::json(
782069860236atagen2026-10-10 12:44 UTC590
                StatusCode::PARTIAL_CONTENT,
782069860236atagen2026-10-10 12:44 UTC591
                json!({
782069860236atagen2026-10-10 12:44 UTC592
                    "detail": "Partial gains were applied. EQ was below the band.",
782069860236atagen2026-10-10 12:44 UTC593
                    "length": round3(length / 2.0),
782069860236atagen2026-10-10 12:44 UTC594
                    "girth": round3(girth / 2.0),
782069860236atagen2026-10-10 12:44 UTC595
                }),
782069860236atagen2026-10-10 12:44 UTC596
            )
782069860236atagen2026-10-10 12:44 UTC597
        } else if total >= dc + 5 {
782069860236atagen2026-10-10 12:44 UTC598
            self.gain(length, girth, profile.foreskin_growth);
782069860236atagen2026-10-10 12:44 UTC599
            Outcome::json(
782069860236atagen2026-10-10 12:44 UTC600
                StatusCode::OK,
782069860236atagen2026-10-10 12:44 UTC601
                json!({
782069860236atagen2026-10-10 12:44 UTC602
                    "detail": "Gains were applied.",
782069860236atagen2026-10-10 12:44 UTC603
                    "length": round3(length),
782069860236atagen2026-10-10 12:44 UTC604
                    "girth": round3(girth),
782069860236atagen2026-10-10 12:44 UTC605
                }),
782069860236atagen2026-10-10 12:44 UTC606
            )
782069860236atagen2026-10-10 12:44 UTC607
        } else {
782069860236atagen2026-10-10 12:44 UTC608
            let eta = self.rng.random_range(1..=4);
782069860236atagen2026-10-10 12:44 UTC609
            self.pending.push(Pending {
782069860236atagen2026-10-10 12:44 UTC610
                due: self.turn + eta,
782069860236atagen2026-10-10 12:44 UTC611
                length,
782069860236atagen2026-10-10 12:44 UTC612
                girth,
782069860236atagen2026-10-10 12:44 UTC613
            });
782069860236atagen2026-10-10 12:44 UTC614
            self.gain(0.0, 0.0, profile.foreskin_growth);
782069860236atagen2026-10-10 12:44 UTC615
            Outcome::json(
782069860236atagen2026-10-10 12:44 UTC616
                StatusCode::ACCEPTED,
782069860236atagen2026-10-10 12:44 UTC617
                json!({
782069860236atagen2026-10-10 12:44 UTC618
                    "detail": "Gains have been queued. They may arrive.",
782069860236atagen2026-10-10 12:44 UTC619
                    "eta_turns": eta,
782069860236atagen2026-10-10 12:44 UTC620
                }),
782069860236atagen2026-10-10 12:44 UTC621
            )
782069860236atagen2026-10-10 12:44 UTC622
        };
782069860236atagen2026-10-10 12:44 UTC623
        Ok(outcome.header(SERVER_TIMING, timing))
782069860236atagen2026-10-10 12:44 UTC624
    }
782069860236atagen2026-10-10 12:44 UTC625
782069860236atagen2026-10-10 12:44 UTC626
    fn scaled_gains(&self, profile: &Profile, intensity: i32) -> (f64, f64) {
782069860236atagen2026-10-10 12:44 UTC627
        let scale = f64::from(intensity);
782069860236atagen2026-10-10 12:44 UTC628
        let (mut length, mut girth) = (profile.length * scale, profile.girth * scale);
4347977b8192atagen2026-10-11 04:56 UTC629
        let greed = if self.eq > HOT_EQ {
4347977b8192atagen2026-10-11 04:56 UTC630
            GREED_HOT
4347977b8192atagen2026-10-11 04:56 UTC631
        } else if self.eq > DANGER_EQ {
4347977b8192atagen2026-10-11 04:56 UTC632
            GREED_WARM
4347977b8192atagen2026-10-11 04:56 UTC633
        } else {
4347977b8192atagen2026-10-11 04:56 UTC634
            1.0
4347977b8192atagen2026-10-11 04:56 UTC635
        };
4347977b8192atagen2026-10-11 04:56 UTC636
        length *= greed;
4347977b8192atagen2026-10-11 04:56 UTC637
        girth *= greed;
782069860236atagen2026-10-10 12:44 UTC638
        if self.here.teapot {
782069860236atagen2026-10-10 12:44 UTC639
            length *= 0.5;
782069860236atagen2026-10-10 12:44 UTC640
            girth *= 1.5;
782069860236atagen2026-10-10 12:44 UTC641
        }
782069860236atagen2026-10-10 12:44 UTC642
        if self.items.ring {
782069860236atagen2026-10-10 12:44 UTC643
            girth *= 2.0;
782069860236atagen2026-10-10 12:44 UTC644
        }
5dfebcc0ac43atagen2026-10-11 05:28 UTC645
        if self.conditions.friction_burn {
5dfebcc0ac43atagen2026-10-11 05:28 UTC646
            length *= 0.5;
5dfebcc0ac43atagen2026-10-11 05:28 UTC647
            girth *= 0.5;
5dfebcc0ac43atagen2026-10-11 05:28 UTC648
        }
782069860236atagen2026-10-10 12:44 UTC649
        (length, girth)
782069860236atagen2026-10-10 12:44 UTC650
    }
782069860236atagen2026-10-10 12:44 UTC651
782069860236atagen2026-10-10 12:44 UTC652
    fn critical_failure(&mut self, training: Training, profile: &Profile) -> Problem {
782069860236atagen2026-10-10 12:44 UTC653
        let uses_foreskin = profile.foreskin.is_some_and(|(min, _)| min > 0.0);
782069860236atagen2026-10-10 12:44 UTC654
        if uses_foreskin && self.foreskin.is_some() {
782069860236atagen2026-10-10 12:44 UTC655
            self.foreskin = None;
782069860236atagen2026-10-10 12:44 UTC656
            self.shame += 25;
782069860236atagen2026-10-10 12:44 UTC657
            return Problem::new(
782069860236atagen2026-10-10 12:44 UTC658
                StatusCode::GONE,
782069860236atagen2026-10-10 12:44 UTC659
                "foreskin-lost",
782069860236atagen2026-10-10 12:44 UTC660
                "The technique has removed the foreskin. It will not be returning.",
782069860236atagen2026-10-10 12:44 UTC661
            )
782069860236atagen2026-10-10 12:44 UTC662
            .header(header::CONTENT_LOCATION, self.path("/foreskin"));
782069860236atagen2026-10-10 12:44 UTC663
        }
b85a0d4536c3atagen2026-10-11 08:50 UTC664
        if self.eq > DANGER_EQ - self.burn() {
782069860236atagen2026-10-10 12:44 UTC665
            return self.rupture();
782069860236atagen2026-10-10 12:44 UTC666
        }
782069860236atagen2026-10-10 12:44 UTC667
        if training == Training::Stretch && !self.here.teapot {
782069860236atagen2026-10-10 12:44 UTC668
            self.here.teapot = true;
782069860236atagen2026-10-10 12:44 UTC669
            self.items.teapot_spout = true;
782069860236atagen2026-10-10 12:44 UTC670
            self.shame += 5;
782069860236atagen2026-10-10 12:44 UTC671
            return Problem::new(
782069860236atagen2026-10-10 12:44 UTC672
                StatusCode::IM_A_TEAPOT,
782069860236atagen2026-10-10 12:44 UTC673
                "teapot",
782069860236atagen2026-10-10 12:44 UTC674
                "The subject is now short and stout. Length gains are halved for the rest of the floor.",
782069860236atagen2026-10-10 12:44 UTC675
            );
782069860236atagen2026-10-10 12:44 UTC676
        }
782069860236atagen2026-10-10 12:44 UTC677
        if training == Training::Uli && !self.conditions.peyronie {
782069860236atagen2026-10-10 12:44 UTC678
            self.conditions.peyronie = true;
782069860236atagen2026-10-10 12:44 UTC679
            self.shame += 5;
782069860236atagen2026-10-10 12:44 UTC680
            return Problem::new(
782069860236atagen2026-10-10 12:44 UTC681
                StatusCode::MISDIRECTED_REQUEST,
782069860236atagen2026-10-10 12:44 UTC682
                "curvature",
782069860236atagen2026-10-10 12:44 UTC683
                "A curvature has developed. Techniques will land slightly to the left until a professional is consulted.",
782069860236atagen2026-10-10 12:44 UTC684
            );
782069860236atagen2026-10-10 12:44 UTC685
        }
782069860236atagen2026-10-10 12:44 UTC686
        not_extended()
782069860236atagen2026-10-10 12:44 UTC687
    }
782069860236atagen2026-10-10 12:44 UTC688
782069860236atagen2026-10-10 12:44 UTC689
    fn gossip(&mut self, mut outcome: Outcome) -> Outcome {
782069860236atagen2026-10-10 12:44 UTC690
        let reportable = matches!(outcome.status.as_u16(), 200 | 202 | 206);
7d3fb63208bfatagen2026-10-11 04:38 UTC691
        if !self.here.brother_told || !reportable {
782069860236atagen2026-10-10 12:44 UTC692
            return outcome;
782069860236atagen2026-10-10 12:44 UTC693
        }
7d3fb63208bfatagen2026-10-11 04:38 UTC694
        self.here.brother_told = false;
782069860236atagen2026-10-10 12:44 UTC695
        outcome.status = StatusCode::ALREADY_REPORTED;
782069860236atagen2026-10-10 12:44 UTC696
        if let Payload::Json(body) = &mut outcome.payload {
7d3fb63208bfatagen2026-10-11 04:38 UTC697
            body["detail"] = json!("Your brother has already told Mum.");
782069860236atagen2026-10-10 12:44 UTC698
        }
782069860236atagen2026-10-10 12:44 UTC699
        outcome
782069860236atagen2026-10-10 12:44 UTC700
    }
782069860236atagen2026-10-10 12:44 UTC701
}