atagen

jelq

public

an http based roguelike rpg about jelqing

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

Blame: src/game/turn.rs

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