atagen

jelq

public

an http based roguelike rpg about jelqing

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

Blame: src/game/hazards.rs

782069860236atagen2026-10-10 12:44 UTC1
use std::{ops::ControlFlow, time::SystemTime};
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::{
8b8e83329a1datagen2026-10-12 12:01 UTC7
    Cause, Floor, Notice, Outcome, Run,
782069860236atagen2026-10-10 12:44 UTC8
    balance::{
4b1f5f88827datagen2026-10-13 10:18 UTC9
        BURN_RUPTURE, COLD_DEGLOVING, COLD_EQ, CURVE_MISSES, DANGER_EQ, DEGLOVING,
4b1f5f88827datagen2026-10-13 10:18 UTC10
        DEGLOVING_INTENSITY, EQ_BAND, FRIEND, HOT_EQ, LOST_IT_EQ, PREMATURE_EQ, RUPTURE_HOT,
4b1f5f88827datagen2026-10-13 10:18 UTC11
        RUPTURE_IN_BAND, RUPTURE_PREMATURE, RUPTURE_WARM, SOFT_INTENSITY, SUSPICION_LIMIT,
4b1f5f88827datagen2026-10-13 10:18 UTC12
        WANDERER_VISIT, WINDOW,
782069860236atagen2026-10-10 12:44 UTC13
    },
97c05b741d8fatagen2026-10-13 11:27 UTC14
    measure::round3,
782069860236atagen2026-10-10 12:44 UTC15
    techniques::Training,
8b8e83329a1datagen2026-10-12 12:01 UTC16
    travel::Exit,
782069860236atagen2026-10-10 12:44 UTC17
};
782069860236atagen2026-10-10 12:44 UTC18
use crate::problem::Problem;
782069860236atagen2026-10-10 12:44 UTC19
782069860236atagen2026-10-10 12:44 UTC20
type Interruption = Result<ControlFlow<Outcome>, Problem>;
782069860236atagen2026-10-10 12:44 UTC21
782069860236atagen2026-10-10 12:44 UTC22
impl Run {
8b8e83329a1datagen2026-10-12 12:01 UTC23
    /// Whether EQ is past `line`, with a friction burn dragging every line down.
8b8e83329a1datagen2026-10-12 12:01 UTC24
    pub(super) fn hotter_than(&self, line: i32) -> bool {
8b8e83329a1datagen2026-10-12 12:01 UTC25
        let burn = if self.body.conditions.friction_burn {
b85a0d4536c3atagen2026-10-11 08:50 UTC26
            BURN_RUPTURE
b85a0d4536c3atagen2026-10-11 08:50 UTC27
        } else {
b85a0d4536c3atagen2026-10-11 08:50 UTC28
            0
8b8e83329a1datagen2026-10-12 12:01 UTC29
        };
8b8e83329a1datagen2026-10-12 12:01 UTC30
        self.body.eq > line - burn
b85a0d4536c3atagen2026-10-11 08:50 UTC31
    }
b85a0d4536c3atagen2026-10-11 08:50 UTC32
b85a0d4536c3atagen2026-10-11 08:50 UTC33
    /// The rupture tier for any turn that is not a jelq, so never the premature band's 1 in 3.
b85a0d4536c3atagen2026-10-11 08:50 UTC34
    pub(super) fn rupture_odds(&self) -> u32 {
8b8e83329a1datagen2026-10-12 12:01 UTC35
        if !self.hotter_than(DANGER_EQ) {
b85a0d4536c3atagen2026-10-11 08:50 UTC36
            RUPTURE_IN_BAND
8b8e83329a1datagen2026-10-12 12:01 UTC37
        } else if !self.hotter_than(HOT_EQ) {
b85a0d4536c3atagen2026-10-11 08:50 UTC38
            RUPTURE_WARM
b85a0d4536c3atagen2026-10-11 08:50 UTC39
        } else {
b85a0d4536c3atagen2026-10-11 08:50 UTC40
            RUPTURE_HOT
b85a0d4536c3atagen2026-10-11 08:50 UTC41
        }
b85a0d4536c3atagen2026-10-11 08:50 UTC42
    }
b85a0d4536c3atagen2026-10-11 08:50 UTC43
bf5f8cb6f60fatagen2026-10-13 12:10 UTC44
    pub(super) fn cold(&self) -> bool {
bf5f8cb6f60fatagen2026-10-13 12:10 UTC45
        self.body.eq < COLD_EQ
bf5f8cb6f60fatagen2026-10-13 12:10 UTC46
    }
bf5f8cb6f60fatagen2026-10-13 12:10 UTC47
bf5f8cb6f60fatagen2026-10-13 12:10 UTC48
    pub(super) fn mishaps(
bf5f8cb6f60fatagen2026-10-13 12:10 UTC49
        &mut self,
bf5f8cb6f60fatagen2026-10-13 12:10 UTC50
        training: Training,
bf5f8cb6f60fatagen2026-10-13 12:10 UTC51
        intensity: i32,
bf5f8cb6f60fatagen2026-10-13 12:10 UTC52
        cold: bool,
bf5f8cb6f60fatagen2026-10-13 12:10 UTC53
    ) -> Interruption {
bf5f8cb6f60fatagen2026-10-13 12:10 UTC54
        if cold {
4b1f5f88827datagen2026-10-13 10:18 UTC55
            if !self.notices.contains(&Notice::ColdStart) {
4b1f5f88827datagen2026-10-13 10:18 UTC56
                self.notices.push(Notice::ColdStart);
4b1f5f88827datagen2026-10-13 10:18 UTC57
            }
4b1f5f88827datagen2026-10-13 10:18 UTC58
            if self.chance(
4b1f5f88827datagen2026-10-13 10:18 UTC59
                self.decision("cold-degloving", "Cold and unprepared, does the skin tear?"),
4b1f5f88827datagen2026-10-13 10:18 UTC60
                COLD_DEGLOVING,
4b1f5f88827datagen2026-10-13 10:18 UTC61
            ) {
97c05b741d8fatagen2026-10-13 11:27 UTC62
                return Err(self.deglove());
4b1f5f88827datagen2026-10-13 10:18 UTC63
            }
4b1f5f88827datagen2026-10-13 10:18 UTC64
        }
3f9091557ec3atagen2026-10-11 11:43 UTC65
        if training == Training::Dry
3f9091557ec3atagen2026-10-11 11:43 UTC66
            && intensity >= DEGLOVING_INTENSITY
3f9091557ec3atagen2026-10-11 11:43 UTC67
            && self.chance(
3f9091557ec3atagen2026-10-11 11:43 UTC68
                self.decision("degloving", "Dry at this intensity, does the skin tear?"),
3f9091557ec3atagen2026-10-11 11:43 UTC69
                DEGLOVING,
3f9091557ec3atagen2026-10-11 11:43 UTC70
            )
3f9091557ec3atagen2026-10-11 11:43 UTC71
        {
97c05b741d8fatagen2026-10-13 11:27 UTC72
            return Err(self.deglove());
782069860236atagen2026-10-10 12:44 UTC73
        }
782069860236atagen2026-10-10 12:44 UTC74
        Ok(ControlFlow::Continue(()))
782069860236atagen2026-10-10 12:44 UTC75
    }
782069860236atagen2026-10-10 12:44 UTC76
97c05b741d8fatagen2026-10-13 11:27 UTC77
    fn deglove(&mut self) -> Problem {
97c05b741d8fatagen2026-10-13 11:27 UTC78
        let lost = self.body.foreskin.take();
97c05b741d8fatagen2026-10-13 11:27 UTC79
        let problem = self.end(Cause::Degloved);
97c05b741d8fatagen2026-10-13 11:27 UTC80
        match lost {
97c05b741d8fatagen2026-10-13 11:27 UTC81
            Some(lost) => problem.with("foreskin", -round3(lost)),
97c05b741d8fatagen2026-10-13 11:27 UTC82
            None => problem,
97c05b741d8fatagen2026-10-13 11:27 UTC83
        }
97c05b741d8fatagen2026-10-13 11:27 UTC84
    }
97c05b741d8fatagen2026-10-13 11:27 UTC85
782069860236atagen2026-10-10 12:44 UTC86
    pub(super) fn hazards(&mut self, intensity: i32) -> Interruption {
8b8e83329a1datagen2026-10-12 12:01 UTC87
        if !self.hotter_than(PREMATURE_EQ)
3f9091557ec3atagen2026-10-11 11:43 UTC88
            && self.chance(
3f9091557ec3atagen2026-10-11 11:43 UTC89
                self.decision("rupture", "Does this jelq rupture something?"),
3f9091557ec3atagen2026-10-11 11:43 UTC90
                self.rupture_odds(),
3f9091557ec3atagen2026-10-11 11:43 UTC91
            )
3f9091557ec3atagen2026-10-11 11:43 UTC92
        {
782069860236atagen2026-10-10 12:44 UTC93
            return Err(self.rupture());
782069860236atagen2026-10-10 12:44 UTC94
        }
3f9091557ec3atagen2026-10-11 11:43 UTC95
        if self.floor.has_window()
8b8e83329a1datagen2026-10-12 12:01 UTC96
            && !self.items.kit.blinds
3f9091557ec3atagen2026-10-11 11:43 UTC97
            && self.oracle.chance_not(
3f9091557ec3atagen2026-10-11 11:43 UTC98
                self.decision("window", "Are the curtains still closed?"),
3f9091557ec3atagen2026-10-11 11:43 UTC99
                WINDOW,
3f9091557ec3atagen2026-10-11 11:43 UTC100
            )
3f9091557ec3atagen2026-10-11 11:43 UTC101
        {
8b8e83329a1datagen2026-10-12 12:01 UTC102
            self.standing.shame += 30;
8b8e83329a1datagen2026-10-12 12:01 UTC103
            self.online.filmed_at.get_or_insert_with(SystemTime::now);
782069860236atagen2026-10-10 12:44 UTC104
            return Ok(ControlFlow::Break(
782069860236atagen2026-10-10 12:44 UTC105
                Outcome::json(
782069860236atagen2026-10-10 12:44 UTC106
                    StatusCode::CREATED,
782069860236atagen2026-10-10 12:44 UTC107
                    json!({ "detail": "A neighbour was at the window. A recording has been created. It has been shared." }),
782069860236atagen2026-10-10 12:44 UTC108
                )
782069860236atagen2026-10-10 12:44 UTC109
                .header(header::LOCATION, self.path("/footage")),
782069860236atagen2026-10-10 12:44 UTC110
            ));
782069860236atagen2026-10-10 12:44 UTC111
        }
3f9091557ec3atagen2026-10-11 11:43 UTC112
        if self.floor == Floor::ChangingRoom
3f9091557ec3atagen2026-10-11 11:43 UTC113
            && self.chance(
3f9091557ec3atagen2026-10-11 11:43 UTC114
                self.decision("friend", "Does a friend walk in and offer to help?"),
3f9091557ec3atagen2026-10-11 11:43 UTC115
                FRIEND,
3f9091557ec3atagen2026-10-11 11:43 UTC116
            )
3f9091557ec3atagen2026-10-11 11:43 UTC117
        {
8b8e83329a1datagen2026-10-12 12:01 UTC118
            self.standing.shame += 1;
782069860236atagen2026-10-10 12:44 UTC119
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC120
                StatusCode::USE_PROXY,
782069860236atagen2026-10-10 12:44 UTC121
                "friend",
782069860236atagen2026-10-10 12:44 UTC122
                "A friend has offered to help. Use Proxy is deprecated, and the server has declined on your behalf.",
782069860236atagen2026-10-10 12:44 UTC123
            ));
782069860236atagen2026-10-10 12:44 UTC124
        }
8b8e83329a1datagen2026-10-12 12:01 UTC125
        if self.body.conditions.peyronie
3f9091557ec3atagen2026-10-11 11:43 UTC126
            && self.chance(
3f9091557ec3atagen2026-10-11 11:43 UTC127
                self.decision(
3f9091557ec3atagen2026-10-11 11:43 UTC128
                    "misdirected",
3f9091557ec3atagen2026-10-11 11:43 UTC129
                    "With the curve, does the stroke land sharply to the left?",
3f9091557ec3atagen2026-10-11 11:43 UTC130
                ),
3f9091557ec3atagen2026-10-11 11:43 UTC131
                CURVE_MISSES,
3f9091557ec3atagen2026-10-11 11:43 UTC132
            )
3f9091557ec3atagen2026-10-11 11:43 UTC133
        {
782069860236atagen2026-10-10 12:44 UTC134
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC135
                StatusCode::MISDIRECTED_REQUEST,
782069860236atagen2026-10-10 12:44 UTC136
                "misdirected",
782069860236atagen2026-10-10 12:44 UTC137
                "The technique landed slightly to the left. It was meant for a different server.",
782069860236atagen2026-10-10 12:44 UTC138
            ));
782069860236atagen2026-10-10 12:44 UTC139
        }
8b8e83329a1datagen2026-10-12 12:01 UTC140
        if intensity <= SOFT_INTENSITY && self.body.eq < *EQ_BAND.start() {
8b8e83329a1datagen2026-10-12 12:01 UTC141
            self.body.eq = (self.body.eq - LOST_IT_EQ).max(0);
782069860236atagen2026-10-10 12:44 UTC142
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC143
                StatusCode::REQUEST_TIMEOUT,
782069860236atagen2026-10-10 12:44 UTC144
                "lost-it",
782069860236atagen2026-10-10 12:44 UTC145
                "The request took too long. It was lost.",
782069860236atagen2026-10-10 12:44 UTC146
            )
782069860236atagen2026-10-10 12:44 UTC147
            .header(header::CONNECTION, "close"));
782069860236atagen2026-10-10 12:44 UTC148
        }
8b8e83329a1datagen2026-10-12 12:01 UTC149
        if self.hotter_than(PREMATURE_EQ) {
3f9091557ec3atagen2026-10-11 11:43 UTC150
            if self.chance(
3f9091557ec3atagen2026-10-11 11:43 UTC151
                self.decision(
3f9091557ec3atagen2026-10-11 11:43 UTC152
                    "rupture",
3f9091557ec3atagen2026-10-11 11:43 UTC153
                    "Right at the edge of finishing, does it rupture instead?",
3f9091557ec3atagen2026-10-11 11:43 UTC154
                ),
3f9091557ec3atagen2026-10-11 11:43 UTC155
                RUPTURE_PREMATURE,
3f9091557ec3atagen2026-10-11 11:43 UTC156
            ) {
782069860236atagen2026-10-10 12:44 UTC157
                return Err(self.rupture());
782069860236atagen2026-10-10 12:44 UTC158
            }
8b8e83329a1datagen2026-10-12 12:01 UTC159
            self.standing.shame += 5;
8b8e83329a1datagen2026-10-12 12:01 UTC160
            self.next_floor(Exit::Premature);
782069860236atagen2026-10-10 12:44 UTC161
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC162
                StatusCode::TOO_EARLY,
782069860236atagen2026-10-10 12:44 UTC163
                "premature",
782069860236atagen2026-10-10 12:44 UTC164
                "The floor has ended early. Everyone involved has agreed not to discuss it.",
782069860236atagen2026-10-10 12:44 UTC165
            ));
782069860236atagen2026-10-10 12:44 UTC166
        }
782069860236atagen2026-10-10 12:44 UTC167
        Ok(ControlFlow::Continue(()))
782069860236atagen2026-10-10 12:44 UTC168
    }
782069860236atagen2026-10-10 12:44 UTC169
9683736a2c5eatagen2026-10-10 13:15 UTC170
    /// The enemies suspicion summons on floors without Mum.
782069860236atagen2026-10-10 12:44 UTC171
    pub(super) fn floor_enemy(&mut self) -> Result<(), Problem> {
8b8e83329a1datagen2026-10-12 12:01 UTC172
        let visits = u32::from(self.standing.suspicion) + 1;
782069860236atagen2026-10-10 12:44 UTC173
        let wanders_in = matches!(self.floor, Floor::Bathroom | Floor::Hotel)
3f9091557ec3atagen2026-10-11 11:43 UTC174
            && self.oracle.ratio_choice(
3f9091557ec3atagen2026-10-11 11:43 UTC175
                self.decision("wanderer", "Does anyone else come through the door?"),
3f9091557ec3atagen2026-10-11 11:43 UTC176
                visits,
3f9091557ec3atagen2026-10-11 11:43 UTC177
                WANDERER_VISIT,
3f9091557ec3atagen2026-10-11 11:43 UTC178
                "No",
3f9091557ec3atagen2026-10-11 11:43 UTC179
                "Yes",
3f9091557ec3atagen2026-10-11 11:43 UTC180
            );
8b8e83329a1datagen2026-10-12 12:01 UTC181
        if self.standing.suspicion < SUSPICION_LIMIT && !wanders_in {
782069860236atagen2026-10-10 12:44 UTC182
            return Ok(());
782069860236atagen2026-10-10 12:44 UTC183
        }
782069860236atagen2026-10-10 12:44 UTC184
        match self.floor {
782069860236atagen2026-10-10 12:44 UTC185
            Floor::Bathroom => {
8b8e83329a1datagen2026-10-12 12:01 UTC186
                self.standing.suspicion = 0;
782069860236atagen2026-10-10 12:44 UTC187
                self.touch();
8b8e83329a1datagen2026-10-12 12:01 UTC188
                if self.items.stores.door_locks > 0 {
8b8e83329a1datagen2026-10-12 12:01 UTC189
                    self.items.stores.door_locks -= 1;
8b8e83329a1datagen2026-10-12 12:01 UTC190
                    self.notices.push(Notice::BrotherTriedTheDoor);
782069860236atagen2026-10-10 12:44 UTC191
                    return Ok(());
782069860236atagen2026-10-10 12:44 UTC192
                }
7d3fb63208bfatagen2026-10-11 04:38 UTC193
                self.here.brother_told = true;
782069860236atagen2026-10-10 12:44 UTC194
                Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC195
                    StatusCode::CONFLICT,
7d3fb63208bfatagen2026-10-11 04:38 UTC196
                    "brother",
7d3fb63208bfatagen2026-10-11 04:38 UTC197
                    "Your brother needs the bathroom. He will tell Mum.",
782069860236atagen2026-10-10 12:44 UTC198
                ))
782069860236atagen2026-10-10 12:44 UTC199
            }
9683736a2c5eatagen2026-10-10 13:15 UTC200
            Floor::ChangingRoom => {
8b8e83329a1datagen2026-10-12 12:01 UTC201
                self.standing.suspicion = 0;
782069860236atagen2026-10-10 12:44 UTC202
                self.touch();
058650ec79d6atagen2026-10-12 10:49 UTC203
                if self.girth_respected() {
8b8e83329a1datagen2026-10-12 12:01 UTC204
                    self.notices.push(Notice::GymStaffLeaveIt);
058650ec79d6atagen2026-10-12 10:49 UTC205
                    return Ok(());
058650ec79d6atagen2026-10-12 10:49 UTC206
                }
8b8e83329a1datagen2026-10-12 12:01 UTC207
                self.standing.shame += 5;
782069860236atagen2026-10-10 12:44 UTC208
                Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC209
                    StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS,
782069860236atagen2026-10-10 12:44 UTC210
                    "gym-staff",
782069860236atagen2026-10-10 12:44 UTC211
                    "Gym staff have been notified. The server cannot serve this request for legal reasons.",
782069860236atagen2026-10-10 12:44 UTC212
                ))
782069860236atagen2026-10-10 12:44 UTC213
            }
782069860236atagen2026-10-10 12:44 UTC214
            Floor::Hotel => {
8b8e83329a1datagen2026-10-12 12:01 UTC215
                self.standing.suspicion = 0;
782069860236atagen2026-10-10 12:44 UTC216
                self.touch();
8b8e83329a1datagen2026-10-12 12:01 UTC217
                if self.items.kit.dnd_sign {
8b8e83329a1datagen2026-10-12 12:01 UTC218
                    self.notices.push(Notice::HousekeepingReadTheSign);
782069860236atagen2026-10-10 12:44 UTC219
                    return Ok(());
782069860236atagen2026-10-10 12:44 UTC220
                }
8b8e83329a1datagen2026-10-12 12:01 UTC221
                self.standing.shame += 3;
782069860236atagen2026-10-10 12:44 UTC222
                Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC223
                    StatusCode::UNAUTHORIZED,
782069860236atagen2026-10-10 12:44 UTC224
                    "housekeeping",
782069860236atagen2026-10-10 12:44 UTC225
                    "Housekeeping has entered. Housekeeping accepts no excuses.",
782069860236atagen2026-10-10 12:44 UTC226
                )
782069860236atagen2026-10-10 12:44 UTC227
                .header(header::WWW_AUTHENTICATE, "Excuse realm=\"housekeeping\""))
782069860236atagen2026-10-10 12:44 UTC228
            }
782069860236atagen2026-10-10 12:44 UTC229
            _ => Ok(()),
782069860236atagen2026-10-10 12:44 UTC230
        }
782069860236atagen2026-10-10 12:44 UTC231
    }
782069860236atagen2026-10-10 12:44 UTC232
}