atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
5cc6ab966f30f5bc5611ddefd166242a46ff3954
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/turn.rsRust703 lines25.0 KB
1
use std::{fmt::Write as _, ops::ControlFlow, time::Instant};
2
3
use axum::http::{StatusCode, header};
4
use rand::Rng;
5
use serde_json::json;
6
7
use super::{
8
    Floor, Grip, LUBRICANTS, Lube, Outcome, Payload, Run, Story, Technique,
9
    balance::{
10
        ARRIVAL_BONUS, BAND_BONUS, BRANCH_TURN, CAT_TAKES_TOWEL, CHANGING_ROOM_CHILL, DANGER_EQ,
11
        EQ_BAND, EQ_WOBBLE, EXTENDER_GAIN, FRICTION_BURN, FRICTION_BURN_AT, FRICTION_DRY,
12
        FRICTION_GRIP, FRICTION_HOLD, FRICTION_MAX, FRICTION_MEDITATE, FRICTION_SPIT, GREED_HOT,
13
        GREED_WARM, HOLD_EQ, HOT_EQ, MEDITATION_EQ, OBSERVED, PRIAPISM_EQ, PRIAPISM_TURNS,
14
        PULLED_MUSCLE, PULLED_MUSCLE_INTENSITY, REFLECTION, RING_PRIAPISM, RING_RUPTURE_LINE,
15
        RUPTURE_HOLD, RUPTURE_LINE, STORAGE_GIRTH, SUSPICION_LIMIT,
16
    },
17
    not_extended, round3,
18
    state::{MumVisit, Observer, Pending},
19
    techniques::{LubeRule, Profile, Training, Utility},
20
};
21
use crate::{headers::SERVER_TIMING, problem::Problem};
22
23
impl Run {
24
    pub fn jelq(
25
        &mut self,
26
        techniques: &[Technique],
27
        intensity: i32,
28
        lube: Option<Lube>,
29
        now: Instant,
30
    ) -> Result<Outcome, Problem> {
31
        self.check_refractory(now)?;
32
        if self.story == Story::Pending {
33
            return Ok(self.branch_offer());
34
        }
35
        if self.floor == Floor::Forum {
36
            return Ok(Outcome::json(
37
                StatusCode::SEE_OTHER,
38
                json!({ "detail": "Refer to the forum." }),
39
            )
40
            .header(header::LOCATION, super::FORUM_THREAD));
41
        }
42
        if self.items.cage {
43
            return Err(Problem::new(
44
                StatusCode::LOCKED,
45
                "caged",
46
                "The cage is locked. The key is not in the box.",
47
            ));
48
        }
49
        self.here.shopping = false;
50
        match *techniques {
51
            [Technique::Utility(utility)] => self.utility(utility, lube, now),
52
            [Technique::Training(training)] => self.single(training, intensity, lube, now),
53
            [Technique::Training(a), Technique::Training(b)] => {
54
                self.combo(a, b, intensity, lube, now)
55
            }
56
            [_, _] => Err(Problem::new(
57
                StatusCode::BAD_REQUEST,
58
                "combo-invalid",
59
                "Only training techniques can be combined.",
60
            )),
61
            _ => Err(Problem::new(
62
                StatusCode::BAD_REQUEST,
63
                "too-many-techniques",
64
                "Two techniques at most. The server has limits even if you do not.",
65
            )),
66
        }
67
    }
68
69
    fn utility(
70
        &mut self,
71
        utility: Utility,
72
        lube: Option<Lube>,
73
        now: Instant,
74
    ) -> Result<Outcome, Problem> {
75
        match utility {
76
            Utility::Warmup => return self.warm_up(),
77
            Utility::Ice => return self.ice(),
78
            Utility::Supplement => return self.supplement(),
79
            Utility::Meditate => return self.meditate(),
80
            Utility::Energy => return self.energy(),
81
            Utility::Edge | Utility::Pump => {}
82
        }
83
        if utility == Utility::Pump {
84
            self.here.edges = 0;
85
        }
86
        self.ready(Technique::Utility(utility), lube)?;
87
        self.check_storage()?;
88
        self.floor_enemy()?;
89
        match utility {
90
            Utility::Edge => self.edge(now),
91
            _ => self.pump(now),
92
        }
93
    }
94
95
    fn single(
96
        &mut self,
97
        training: Training,
98
        intensity: i32,
99
        lube: Option<Lube>,
100
        now: Instant,
101
    ) -> Result<Outcome, Problem> {
102
        self.here.edges = 0;
103
        self.ready(Technique::Training(training), lube)?;
104
        self.check_storage()?;
105
        self.lube_available(lube)?;
106
        self.floor_enemy()?;
107
        self.take_lube(lube)?;
108
        self.chafe(lube);
109
        self.commit(intensity, lube, now, 1);
110
        if let ControlFlow::Break(interrupted) = self.mishaps(training, intensity)? {
111
            return Ok(interrupted);
112
        }
113
        if let ControlFlow::Break(interrupted) = self.hazards(intensity)? {
114
            return Ok(interrupted);
115
        }
116
        let outcome = self.roll(training, intensity, lube)?;
117
        Ok(self.gossip(outcome))
118
    }
119
120
    fn combo(
121
        &mut self,
122
        a: Training,
123
        b: Training,
124
        intensity: i32,
125
        lube: Option<Lube>,
126
        now: Instant,
127
    ) -> Result<Outcome, Problem> {
128
        if a == b {
129
            return Err(Problem::new(
130
                StatusCode::BAD_REQUEST,
131
                "combo-invalid",
132
                "A technique cannot be combined with itself. The server has checked.",
133
            ));
134
        }
135
        self.here.edges = 0;
136
        self.ready(Technique::Training(a), lube)?;
137
        self.ready(Technique::Training(b), lube)?;
138
        self.check_storage()?;
139
        self.lube_available(lube)?;
140
        self.floor_enemy()?;
141
        self.take_lube(lube)?;
142
        self.chafe(lube);
143
        self.commit(intensity, lube, now, 2);
144
        for training in [a, b] {
145
            if let ControlFlow::Break(interrupted) = self.mishaps(training, intensity)? {
146
                return Ok(interrupted);
147
            }
148
        }
149
        if let ControlFlow::Break(interrupted) = self.hazards(intensity)? {
150
            return Ok(interrupted);
151
        }
152
153
        let mut statuses = Vec::new();
154
        for training in [a, b] {
155
            let result = self.roll(training, intensity, lube);
156
            if self.ended.is_some() {
157
                return result;
158
            }
159
            let status = match result {
160
                Ok(outcome) => self.gossip(outcome).status,
161
                Err(problem) => problem.status(),
162
            };
163
            statuses.push((training, status));
164
        }
165
166
        let mut xml = String::from(
167
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<D:multistatus xmlns:D=\"DAV:\">\n",
168
        );
169
        for (training, status) in statuses {
170
            let _ = write!(
171
                xml,
172
                "  <D:response>\n    <D:href>{}?technique={}</D:href>\n    <D:status>HTTP/1.1 {} {}</D:status>\n  </D:response>\n",
173
                self.path(""),
174
                training.name(),
175
                status.as_u16(),
176
                crate::problem::reason(status),
177
            );
178
        }
179
        xml.push_str(
180
            "  <D:responsedescription>Each technique has been reported separately.</D:responsedescription>\n</D:multistatus>\n",
181
        );
182
        Ok(Outcome::raw(
183
            StatusCode::MULTI_STATUS,
184
            "application/xml; charset=utf-8",
185
            xml,
186
        ))
187
    }
188
189
    fn ready(&self, technique: Technique, lube: Option<Lube>) -> Result<(), Problem> {
190
        self.access(technique)?;
191
        match technique {
192
            Technique::Training(training) => Self::check_lube(training, lube),
193
            Technique::Utility(_) => Ok(()),
194
        }
195
    }
196
197
    /// Whether the run could attempt the technique now, ignoring the lubricant.
198
    fn access(&self, technique: Technique) -> Result<(), Problem> {
199
        if technique == Technique::Training(Training::Uli) && !self.uli_taught {
200
            return Err(Problem::new(
201
                StatusCode::FORBIDDEN,
202
                "technique-locked",
203
                "uli is discussed on the forum, in a thread from 2009, by a man who never posted again. You have not found the reply.",
204
            ));
205
        }
206
        if !self.warmed_up {
207
            return Err(Problem::new(
208
                StatusCode::PRECONDITION_FAILED,
209
                "cold-start",
210
                "Warm-up was skipped. The server has noted this.",
211
            )
212
            .with("technique", Utility::Warmup.name()));
213
        }
214
        match technique {
215
            Technique::Utility(Utility::Pump) if !self.items.pump_pro => Err(Problem::new(
216
                StatusCode::FAILED_DEPENDENCY,
217
                "no-pump",
218
                "The pump technique depends on a pump.",
219
            )),
220
            Technique::Utility(_) => Ok(()),
221
            Technique::Training(training) => match training.profile().foreskin {
222
                Some((min, max)) => self.check_foreskin(min, max),
223
                None => Ok(()),
224
            },
225
        }
226
    }
227
228
    fn check_lube(training: Training, lube: Option<Lube>) -> Result<(), Problem> {
229
        match (training.profile().lube, lube) {
230
            (LubeRule::Required, None) => Err(Problem::new(
231
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
232
                "lubricant-required",
233
                format!(
234
                    "The {} technique requires a lubricant. None was declared.",
235
                    training.name()
236
                ),
237
            )
238
            .with("lubricants", json!(LUBRICANTS))),
239
            (LubeRule::Forbidden, Some(_)) => Err(Problem::new(
240
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
241
                "lubricant-declared",
242
                format!(
243
                    "The {} technique was requested. A lubricant was declared.",
244
                    training.name()
245
                ),
246
            )),
247
            _ => Ok(()),
248
        }
249
    }
250
251
    /// One unit of whatever was declared. Spit is free and the tap is always on.
252
    fn lube_available(&self, lube: Option<Lube>) -> Result<(), Problem> {
253
        let (held, name) = match lube {
254
            None | Some(Lube::Spit) => return Ok(()),
255
            Some(Lube::BabyOil) => (&self.items.baby_oil, "baby-oil"),
256
            Some(Lube::CoconutOil) => (&self.items.coconut_oil, "coconut-oil"),
257
            Some(Lube::Lotion) => (&self.items.lotion, "lotion"),
258
            Some(Lube::Vaseline) => (&self.items.vaseline, "vaseline"),
259
        };
260
        if *held == 0 {
261
            return Err(Problem::new(
262
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
263
                "lubricant-exhausted",
264
                format!("{name} was declared, but the bottle is empty."),
265
            ));
266
        }
267
        Ok(())
268
    }
269
270
    fn take_lube(&mut self, lube: Option<Lube>) -> Result<(), Problem> {
271
        self.lube_available(lube)?;
272
        let held = match lube {
273
            None | Some(Lube::Spit) => return Ok(()),
274
            Some(Lube::BabyOil) => &mut self.items.baby_oil,
275
            Some(Lube::CoconutOil) => &mut self.items.coconut_oil,
276
            Some(Lube::Lotion) => &mut self.items.lotion,
277
            Some(Lube::Vaseline) => &mut self.items.vaseline,
278
        };
279
        *held -= 1;
280
        Ok(())
281
    }
282
283
    /// The techniques a JELQ could use right now without being refused before the roll.
284
    pub fn techniques_now(&self, now: Instant) -> Vec<Technique> {
285
        let blocked = !self.floor.timed()
286
            || self.items.cage
287
            || self.refractory_until.is_some_and(|until| now < until);
288
        if blocked {
289
            return Vec::new();
290
        }
291
        Technique::ALL
292
            .into_iter()
293
            .filter(|&technique| match technique {
294
                Technique::Utility(Utility::Warmup) => true,
295
                Technique::Utility(Utility::Ice) => self.items.ice_packs > 0,
296
                Technique::Utility(Utility::Supplement) => self.items.supplements > 0,
297
                Technique::Utility(Utility::Meditate) => !self.here.meditated,
298
                Technique::Utility(Utility::Energy) => self.items.energy_drinks > 0,
299
                _ => self.access(technique).is_ok() && self.check_storage().is_ok(),
300
            })
301
            .collect()
302
    }
303
304
    fn check_foreskin(&self, min: f64, max: f64) -> Result<(), Problem> {
305
        let Some(f) = self.foreskin else {
306
            if min <= 0.0 {
307
                return Ok(());
308
            }
309
            return Err(Problem::new(
310
                StatusCode::GONE,
311
                "foreskin-gone",
312
                "This technique requires a foreskin. The foreskin is gone.",
313
            )
314
            .header(header::CONTENT_LOCATION, self.path("/foreskin")));
315
        };
316
        if f < min {
317
            return Err(Problem::new(
318
                StatusCode::LENGTH_REQUIRED,
319
                "foreskin-insufficient",
320
                format!(
321
                    "The selected technique requires {min:.1} units of foreskin. {f:.2} units are available. The server has noted the shortfall."
322
                ),
323
            )
324
            .with("required", min));
325
        }
326
        if f > max {
327
            return Err(Problem::new(
328
                StatusCode::PAYLOAD_TOO_LARGE,
329
                "foreskin-excessive",
330
                format!(
331
                    "The selected technique tolerates at most {max:.1} units of foreskin. {f:.2} units are present."
332
                ),
333
            )
334
            .with("maximum", max));
335
        }
336
        Ok(())
337
    }
338
339
    fn check_storage(&self) -> Result<(), Problem> {
340
        if self.items.extender && self.girth > STORAGE_GIRTH {
341
            return Err(Problem::new(
342
                StatusCode::INSUFFICIENT_STORAGE,
343
                "jeans-full",
344
                "The jeans are full. The extender is occupying the remaining storage.",
345
            )
346
            .with("extender", self.path("/inventory/extender")));
347
        }
348
        Ok(())
349
    }
350
351
    fn chafe(&mut self, lube: Option<Lube>) {
352
        let mut friction = match lube {
353
            None => FRICTION_DRY,
354
            Some(Lube::Spit) => FRICTION_SPIT,
355
            Some(_) => 0,
356
        };
357
        if friction > 0 && self.jelq_grip.is_some_and(|grip| grip != self.grip) {
358
            friction -= FRICTION_GRIP;
359
        }
360
        self.jelq_grip = Some(self.grip);
361
        self.friction = (self.friction + friction).min(FRICTION_MAX);
362
        if self.friction >= FRICTION_BURN_AT
363
            && !self.conditions.friction_burn
364
            && self.chance(FRICTION_BURN)
365
        {
366
            self.conditions.friction_burn = true;
367
        }
368
    }
369
370
    pub(super) fn commit(&mut self, intensity: i32, lube: Option<Lube>, now: Instant, cost: i32) {
371
        self.touch();
372
        self.turn += 1;
373
        self.here.turns += 1;
374
        self.end_kitchen_visit();
375
        self.realise();
376
        if self.items.extender {
377
            self.length += EXTENDER_GAIN;
378
        }
379
        self.stamina -= cost + i32::from(lube == Some(Lube::Lotion));
380
        if self.stamina <= 0 {
381
            self.exhaust(now);
382
        }
383
        let chill = if self.floor == Floor::ChangingRoom {
384
            CHANGING_ROOM_CHILL
385
        } else {
386
            0
387
        };
388
        let wobble = self.rng.random_range(-EQ_WOBBLE..=EQ_WOBBLE);
389
        self.eq = (self.eq + intensity * 2 - 6 - chill + wobble).clamp(0, 100);
390
391
        let mut suspicion = intensity / 5 + i32::from(lube == Some(Lube::Vaseline));
392
        if matches!(self.floor, Floor::ChangingRoom | Floor::Nans) {
393
            suspicion *= 2;
394
        }
395
        if self.floor == Floor::Nans && lube == Some(Lube::CoconutOil) {
396
            suspicion += 2;
397
        }
398
        let was_below = self.suspicion < SUSPICION_LIMIT;
399
        self.suspicion =
400
            u8::try_from((i32::from(self.suspicion) + suspicion).min(i32::from(SUSPICION_LIMIT)))
401
                .unwrap_or(SUSPICION_LIMIT);
402
403
        if intensity >= PULLED_MUSCLE_INTENSITY
404
            && !self.conditions.pulled_muscle
405
            && self.chance(PULLED_MUSCLE)
406
        {
407
            self.conditions.pulled_muscle = true;
408
            self.stamina = self.stamina.min(self.max_stamina());
409
        }
410
        self.settle(was_below);
411
    }
412
413
    /// The part of a turn the house takes part in, whatever the action was.
414
    pub(super) fn settle(&mut self, was_below: bool) {
415
        self.maybe_summon_mum(was_below);
416
        if let Some(observer) = self.floor.observer()
417
            && self.chance(OBSERVED)
418
        {
419
            self.observed = Some(observer);
420
            self.shame += 1;
421
            if observer == Observer::Cat && self.chance(CAT_TAKES_TOWEL) {
422
                self.here.towel_stolen = true;
423
            }
424
        }
425
        if self.items.ring && self.eq > HOT_EQ && self.chance(RING_PRIAPISM) {
426
            self.conditions.priapism_turns = PRIAPISM_TURNS;
427
        }
428
        if self.conditions.priapism_turns > 0 {
429
            self.conditions.priapism_turns -= 1;
430
            self.eq = self.eq.max(PRIAPISM_EQ);
431
        }
432
        if self.turn == BRANCH_TURN && self.story == Story::Unopened {
433
            self.story = Story::Pending;
434
            self.notices
435
                .push("Somewhere, a forum thread from 2009 still has replies.");
436
        }
437
    }
438
439
    /// HOLD. A pause between strokes, offered when the band has been left or the stamina is gone.
440
    pub fn can_hold(&self) -> bool {
441
        self.eq > DANGER_EQ || self.stamina <= 2
442
    }
443
444
    pub fn hold(&mut self, now: Instant) -> Result<Outcome, Problem> {
445
        self.check_refractory(now)?;
446
        if self.story == Story::Pending {
447
            return Ok(self.branch_offer());
448
        }
449
        if self.items.cage {
450
            return Err(Problem::new(
451
                StatusCode::LOCKED,
452
                "caged",
453
                "The cage is locked. The key is not in the box.",
454
            ));
455
        }
456
        if self.chance(RUPTURE_HOLD) {
457
            return Err(self.rupture());
458
        }
459
        self.touch();
460
        self.turn += 1;
461
        self.here.turns += 1;
462
        self.end_kitchen_visit();
463
        self.realise();
464
        let was_below = self.suspicion < SUSPICION_LIMIT;
465
        if self.chance(REFLECTION) {
466
            self.eq = 0;
467
            self.shame += 1;
468
            self.notices
469
                .push("the count reached ten, and then the reflection started");
470
        } else {
471
            self.eq = (self.eq - HOLD_EQ).clamp(0, 100);
472
        }
473
        self.stamina = (self.stamina + 1).min(self.max_stamina());
474
        self.shed(FRICTION_HOLD);
475
        self.settle(was_below);
476
        Ok(Outcome::empty(StatusCode::NO_CONTENT))
477
    }
478
479
    /// The breathing technique from the forum's replies. It spends no stamina and the turn is
480
    /// not the floor's, but each floor allows it once.
481
    fn meditate(&mut self) -> Result<Outcome, Problem> {
482
        if self.here.meditated {
483
            return Err(Problem::new(
484
                StatusCode::CONFLICT,
485
                "already-meditated",
486
                "This floor has had its meditation.",
487
            ));
488
        }
489
        self.here.meditated = true;
490
        self.reset_eq(self.eq - MEDITATION_EQ);
491
        self.shed(FRICTION_MEDITATE);
492
        self.touch();
493
        Ok(Outcome::json(
494
            StatusCode::OK,
495
            json!({
496
                "detail": "In through the nose, out through the mouth. EQ falls by ten.",
497
            }),
498
        ))
499
    }
500
501
    pub(super) fn maybe_summon_mum(&mut self, was_below: bool) {
502
        if !self.floor.has_mum() || self.mum.is_some() {
503
            return;
504
        }
505
        let summoned = was_below && self.suspicion == SUSPICION_LIMIT;
506
        let mut visits = u32::from(self.suspicion) + 1;
507
        if self.here.brother_told {
508
            visits *= 2;
509
        }
510
        if summoned || self.rng.random_ratio(visits, super::balance::MUM_VISIT) {
511
            let errand = self.errand(summoned);
512
            let nonce = self.fresh_nonce();
513
            self.mum = Some(MumVisit {
514
                errand,
515
                nonce,
516
                strikes: 0,
517
                knocked: false,
518
            });
519
        }
520
    }
521
522
    fn roll(
523
        &mut self,
524
        training: Training,
525
        intensity: i32,
526
        lube: Option<Lube>,
527
    ) -> Result<Outcome, Problem> {
528
        let profile = training.profile();
529
        let natural: i32 = self.rng.random_range(1..=20);
530
        let band = if EQ_BAND.contains(&self.eq) {
531
            BAND_BONUS
532
        } else {
533
            0
534
        };
535
        let grip = match (self.grip, training) {
536
            (Grip::Underhand, Training::Stretch) => 2,
537
            (Grip::Underhand, Training::Wet) => -1,
538
            _ => 0,
539
        };
540
        let arrival = if self.here.warm_arrival {
541
            self.here.warm_arrival = false;
542
            ARRIVAL_BONUS
543
        } else {
544
            0
545
        };
546
        let modifier = lube.map_or(0, Lube::modifier) + band + grip + arrival;
547
        let dc = profile.dc + intensity / 3;
548
        let total = natural + modifier;
549
        let timing = format!("roll;desc=\"d20{modifier:+} vs {dc}\";dur={natural}");
550
        let timed = |p: Problem| p.header(SERVER_TIMING, &timing);
551
552
        let (length, girth) = self.scaled_gains(&profile, intensity);
553
        let burn = self.burn();
554
        let rupture_line = if self.items.ring {
555
            RING_RUPTURE_LINE
556
        } else {
557
            RUPTURE_LINE
558
        };
559
560
        if natural == 1 {
561
            return Err(timed(self.critical_failure(training, &profile)));
562
        }
563
        if natural == 2 && self.eq > DANGER_EQ - burn {
564
            return Err(timed(self.rupture()));
565
        }
566
        if self.eq > rupture_line - burn && total < dc {
567
            return Err(timed(self.rupture()));
568
        }
569
        if natural == 20 {
570
            self.gain(length * 2.0, girth * 2.0, profile.foreskin_growth);
571
            return Ok(Outcome::json(
572
                StatusCode::PERMANENT_REDIRECT,
573
                json!({
574
                    "detail": "Your length has moved permanently.",
575
                    "length": round3(length * 2.0),
576
                    "girth": round3(girth * 2.0),
577
                }),
578
            )
579
            .header(header::LOCATION, self.path("/length"))
580
            .header(SERVER_TIMING, timing));
581
        }
582
        if total < dc - 3 {
583
            return Err(timed(not_extended()));
584
        }
585
        if total < dc {
586
            return Ok(Outcome::empty(StatusCode::NO_CONTENT).header(SERVER_TIMING, timing));
587
        }
588
589
        let outcome = if self.eq < *EQ_BAND.start() {
590
            self.gain(length / 2.0, girth / 2.0, profile.foreskin_growth);
591
            Outcome::json(
592
                StatusCode::PARTIAL_CONTENT,
593
                json!({
594
                    "detail": "Partial gains were applied. EQ was below the band.",
595
                    "length": round3(length / 2.0),
596
                    "girth": round3(girth / 2.0),
597
                }),
598
            )
599
        } else if total >= dc + 5 {
600
            self.gain(length, girth, profile.foreskin_growth);
601
            Outcome::json(
602
                StatusCode::OK,
603
                json!({
604
                    "detail": "Gains were applied.",
605
                    "length": round3(length),
606
                    "girth": round3(girth),
607
                }),
608
            )
609
        } else {
610
            let eta = self.rng.random_range(1..=4);
611
            self.pending.push(Pending {
612
                due: self.turn + eta,
613
                length,
614
                girth,
615
            });
616
            self.gain(0.0, 0.0, profile.foreskin_growth);
617
            Outcome::json(
618
                StatusCode::ACCEPTED,
619
                json!({
620
                    "detail": "Gains have been queued. They may arrive.",
621
                    "eta_turns": eta,
622
                }),
623
            )
624
        };
625
        Ok(outcome.header(SERVER_TIMING, timing))
626
    }
627
628
    fn scaled_gains(&self, profile: &Profile, intensity: i32) -> (f64, f64) {
629
        let scale = f64::from(intensity);
630
        let (mut length, mut girth) = (profile.length * scale, profile.girth * scale);
631
        let greed = if self.eq > HOT_EQ {
632
            GREED_HOT
633
        } else if self.eq > DANGER_EQ {
634
            GREED_WARM
635
        } else {
636
            1.0
637
        };
638
        length *= greed;
639
        girth *= greed;
640
        if self.here.teapot {
641
            length *= 0.5;
642
            girth *= 1.5;
643
        }
644
        if self.items.ring {
645
            girth *= 2.0;
646
        }
647
        if self.conditions.friction_burn {
648
            length *= 0.5;
649
            girth *= 0.5;
650
        }
651
        (length, girth)
652
    }
653
654
    fn critical_failure(&mut self, training: Training, profile: &Profile) -> Problem {
655
        let uses_foreskin = profile.foreskin.is_some_and(|(min, _)| min > 0.0);
656
        if uses_foreskin && self.foreskin.is_some() {
657
            self.foreskin = None;
658
            self.shame += 25;
659
            return Problem::new(
660
                StatusCode::GONE,
661
                "foreskin-lost",
662
                "The technique has removed the foreskin. It will not be returning.",
663
            )
664
            .header(header::CONTENT_LOCATION, self.path("/foreskin"));
665
        }
666
        if self.eq > DANGER_EQ - self.burn() {
667
            return self.rupture();
668
        }
669
        if training == Training::Stretch && !self.here.teapot {
670
            self.here.teapot = true;
671
            self.items.teapot_spout = true;
672
            self.shame += 5;
673
            return Problem::new(
674
                StatusCode::IM_A_TEAPOT,
675
                "teapot",
676
                "The subject is now short and stout. Length gains are halved for the rest of the floor.",
677
            );
678
        }
679
        if training == Training::Uli && !self.conditions.peyronie {
680
            self.conditions.peyronie = true;
681
            self.shame += 5;
682
            return Problem::new(
683
                StatusCode::MISDIRECTED_REQUEST,
684
                "curvature",
685
                "A curvature has developed. Techniques will land slightly to the left until a professional is consulted.",
686
            );
687
        }
688
        not_extended()
689
    }
690
691
    fn gossip(&mut self, mut outcome: Outcome) -> Outcome {
692
        let reportable = matches!(outcome.status.as_u16(), 200 | 202 | 206);
693
        if !self.here.brother_told || !reportable {
694
            return outcome;
695
        }
696
        self.here.brother_told = false;
697
        outcome.status = StatusCode::ALREADY_REPORTED;
698
        if let Payload::Json(body) = &mut outcome.payload {
699
            body["detail"] = json!("Your brother has already told Mum.");
700
        }
701
        outcome
702
    }
703
}