atagen

jelq

public

an http based roguelike rpg about jelqing

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