atagen

jelq

public

an http based roguelike rpg about jelqing

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

Blame: src/game/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 rand::Rng;
782069860236atagen2026-10-10 12:44 UTC5
use serde_json::json;
782069860236atagen2026-10-10 12:44 UTC6
782069860236atagen2026-10-10 12:44 UTC7
use super::{
782069860236atagen2026-10-10 12:44 UTC8
    Cause, Floor, Outcome, Run,
782069860236atagen2026-10-10 12:44 UTC9
    balance::{
139164489032atagen2026-10-11 05:46 UTC10
        BURN_RUPTURE, COLD_EQ, CURVE_MISSES, DANGER_EQ, DEGLOVING, DEGLOVING_INTENSITY, FRIEND,
139164489032atagen2026-10-11 05:46 UTC11
        HOT_EQ, PREMATURE_EQ, RUPTURE_HOT, RUPTURE_IN_BAND, RUPTURE_PREMATURE, RUPTURE_WARM,
782069860236atagen2026-10-10 12:44 UTC12
        SUSPICION_LIMIT, WANDERER_VISIT, WINDOW,
782069860236atagen2026-10-10 12:44 UTC13
    },
782069860236atagen2026-10-10 12:44 UTC14
    techniques::Training,
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 {
b85a0d4536c3atagen2026-10-11 08:50 UTC21
    /// How far the friction burn drags the rupture tiers down.
b85a0d4536c3atagen2026-10-11 08:50 UTC22
    pub(super) fn burn(&self) -> i32 {
b85a0d4536c3atagen2026-10-11 08:50 UTC23
        if self.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
b85a0d4536c3atagen2026-10-11 08:50 UTC27
        }
b85a0d4536c3atagen2026-10-11 08:50 UTC28
    }
b85a0d4536c3atagen2026-10-11 08:50 UTC29
b85a0d4536c3atagen2026-10-11 08:50 UTC30
    /// 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 UTC31
    pub(super) fn rupture_odds(&self) -> u32 {
b85a0d4536c3atagen2026-10-11 08:50 UTC32
        if self.eq <= DANGER_EQ - self.burn() {
b85a0d4536c3atagen2026-10-11 08:50 UTC33
            RUPTURE_IN_BAND
b85a0d4536c3atagen2026-10-11 08:50 UTC34
        } else if self.eq <= HOT_EQ - self.burn() {
b85a0d4536c3atagen2026-10-11 08:50 UTC35
            RUPTURE_WARM
b85a0d4536c3atagen2026-10-11 08:50 UTC36
        } else {
b85a0d4536c3atagen2026-10-11 08:50 UTC37
            RUPTURE_HOT
b85a0d4536c3atagen2026-10-11 08:50 UTC38
        }
b85a0d4536c3atagen2026-10-11 08:50 UTC39
    }
b85a0d4536c3atagen2026-10-11 08:50 UTC40
782069860236atagen2026-10-10 12:44 UTC41
    /// Accidents tied to a specific technique.
782069860236atagen2026-10-10 12:44 UTC42
    pub(super) fn mishaps(&mut self, training: Training, intensity: i32) -> Interruption {
782069860236atagen2026-10-10 12:44 UTC43
        if training == Training::Dry && intensity >= DEGLOVING_INTENSITY && self.chance(DEGLOVING) {
782069860236atagen2026-10-10 12:44 UTC44
            return Err(self.end(Cause::Degloved));
782069860236atagen2026-10-10 12:44 UTC45
        }
782069860236atagen2026-10-10 12:44 UTC46
        Ok(ControlFlow::Continue(()))
782069860236atagen2026-10-10 12:44 UTC47
    }
782069860236atagen2026-10-10 12:44 UTC48
782069860236atagen2026-10-10 12:44 UTC49
    /// Everything that can go wrong on a committed turn before the roll.
782069860236atagen2026-10-10 12:44 UTC50
    pub(super) fn hazards(&mut self, intensity: i32) -> Interruption {
b85a0d4536c3atagen2026-10-11 08:50 UTC51
        let burn = self.burn();
b85a0d4536c3atagen2026-10-11 08:50 UTC52
        if self.eq <= PREMATURE_EQ - burn && self.chance(self.rupture_odds()) {
782069860236atagen2026-10-10 12:44 UTC53
            return Err(self.rupture());
782069860236atagen2026-10-10 12:44 UTC54
        }
782069860236atagen2026-10-10 12:44 UTC55
        if self.floor.has_window() && !self.items.blinds && self.chance(WINDOW) {
782069860236atagen2026-10-10 12:44 UTC56
            self.shame += 30;
782069860236atagen2026-10-10 12:44 UTC57
            self.filmed_at.get_or_insert_with(SystemTime::now);
782069860236atagen2026-10-10 12:44 UTC58
            return Ok(ControlFlow::Break(
782069860236atagen2026-10-10 12:44 UTC59
                Outcome::json(
782069860236atagen2026-10-10 12:44 UTC60
                    StatusCode::CREATED,
782069860236atagen2026-10-10 12:44 UTC61
                    json!({ "detail": "A neighbour was at the window. A recording has been created. It has been shared." }),
782069860236atagen2026-10-10 12:44 UTC62
                )
782069860236atagen2026-10-10 12:44 UTC63
                .header(header::LOCATION, self.path("/footage")),
782069860236atagen2026-10-10 12:44 UTC64
            ));
782069860236atagen2026-10-10 12:44 UTC65
        }
9683736a2c5eatagen2026-10-10 13:15 UTC66
        if self.floor == Floor::ChangingRoom && self.chance(FRIEND) {
782069860236atagen2026-10-10 12:44 UTC67
            self.shame += 1;
782069860236atagen2026-10-10 12:44 UTC68
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC69
                StatusCode::USE_PROXY,
782069860236atagen2026-10-10 12:44 UTC70
                "friend",
782069860236atagen2026-10-10 12:44 UTC71
                "A friend has offered to help. Use Proxy is deprecated, and the server has declined on your behalf.",
782069860236atagen2026-10-10 12:44 UTC72
            ));
782069860236atagen2026-10-10 12:44 UTC73
        }
782069860236atagen2026-10-10 12:44 UTC74
        if self.conditions.peyronie && self.chance(CURVE_MISSES) {
782069860236atagen2026-10-10 12:44 UTC75
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC76
                StatusCode::MISDIRECTED_REQUEST,
782069860236atagen2026-10-10 12:44 UTC77
                "misdirected",
782069860236atagen2026-10-10 12:44 UTC78
                "The technique landed slightly to the left. It was meant for a different server.",
782069860236atagen2026-10-10 12:44 UTC79
            ));
782069860236atagen2026-10-10 12:44 UTC80
        }
782069860236atagen2026-10-10 12:44 UTC81
        if intensity <= 2 && self.eq < 50 {
782069860236atagen2026-10-10 12:44 UTC82
            self.eq = (self.eq - 10).max(0);
782069860236atagen2026-10-10 12:44 UTC83
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC84
                StatusCode::REQUEST_TIMEOUT,
782069860236atagen2026-10-10 12:44 UTC85
                "lost-it",
782069860236atagen2026-10-10 12:44 UTC86
                "The request took too long. It was lost.",
782069860236atagen2026-10-10 12:44 UTC87
            )
782069860236atagen2026-10-10 12:44 UTC88
            .header(header::CONNECTION, "close"));
782069860236atagen2026-10-10 12:44 UTC89
        }
139164489032atagen2026-10-11 05:46 UTC90
        if self.eq > PREMATURE_EQ - burn {
782069860236atagen2026-10-10 12:44 UTC91
            if self.chance(RUPTURE_PREMATURE) {
782069860236atagen2026-10-10 12:44 UTC92
                return Err(self.rupture());
782069860236atagen2026-10-10 12:44 UTC93
            }
782069860236atagen2026-10-10 12:44 UTC94
            self.shame += 5;
782069860236atagen2026-10-10 12:44 UTC95
            self.next_floor(false);
782069860236atagen2026-10-10 12:44 UTC96
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC97
                StatusCode::TOO_EARLY,
782069860236atagen2026-10-10 12:44 UTC98
                "premature",
782069860236atagen2026-10-10 12:44 UTC99
                "The floor has ended early. Everyone involved has agreed not to discuss it.",
782069860236atagen2026-10-10 12:44 UTC100
            ));
782069860236atagen2026-10-10 12:44 UTC101
        }
782069860236atagen2026-10-10 12:44 UTC102
        if self.eq < COLD_EQ {
782069860236atagen2026-10-10 12:44 UTC103
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC104
                StatusCode::NOT_FOUND,
782069860236atagen2026-10-10 12:44 UTC105
                "cold",
782069860236atagen2026-10-10 12:44 UTC106
                "The resource exists. It is cold.",
782069860236atagen2026-10-10 12:44 UTC107
            ));
782069860236atagen2026-10-10 12:44 UTC108
        }
782069860236atagen2026-10-10 12:44 UTC109
        Ok(ControlFlow::Continue(()))
782069860236atagen2026-10-10 12:44 UTC110
    }
782069860236atagen2026-10-10 12:44 UTC111
9683736a2c5eatagen2026-10-10 13:15 UTC112
    /// The enemies suspicion summons on floors without Mum.
782069860236atagen2026-10-10 12:44 UTC113
    pub(super) fn floor_enemy(&mut self) -> Result<(), Problem> {
782069860236atagen2026-10-10 12:44 UTC114
        let visits = u32::from(self.suspicion) + 1;
782069860236atagen2026-10-10 12:44 UTC115
        let wanders_in = matches!(self.floor, Floor::Bathroom | Floor::Hotel)
782069860236atagen2026-10-10 12:44 UTC116
            && self.rng.random_ratio(visits, WANDERER_VISIT);
782069860236atagen2026-10-10 12:44 UTC117
        if self.suspicion < SUSPICION_LIMIT && !wanders_in {
782069860236atagen2026-10-10 12:44 UTC118
            return Ok(());
782069860236atagen2026-10-10 12:44 UTC119
        }
782069860236atagen2026-10-10 12:44 UTC120
        match self.floor {
782069860236atagen2026-10-10 12:44 UTC121
            Floor::Bathroom => {
782069860236atagen2026-10-10 12:44 UTC122
                self.suspicion = 0;
782069860236atagen2026-10-10 12:44 UTC123
                self.touch();
782069860236atagen2026-10-10 12:44 UTC124
                if self.items.door_locks > 0 {
782069860236atagen2026-10-10 12:44 UTC125
                    self.items.door_locks -= 1;
7d3fb63208bfatagen2026-10-11 04:38 UTC126
                    self.notices.push("your brother tried the door");
782069860236atagen2026-10-10 12:44 UTC127
                    return Ok(());
782069860236atagen2026-10-10 12:44 UTC128
                }
7d3fb63208bfatagen2026-10-11 04:38 UTC129
                self.here.brother_told = true;
782069860236atagen2026-10-10 12:44 UTC130
                Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC131
                    StatusCode::CONFLICT,
7d3fb63208bfatagen2026-10-11 04:38 UTC132
                    "brother",
7d3fb63208bfatagen2026-10-11 04:38 UTC133
                    "Your brother needs the bathroom. He will tell Mum.",
782069860236atagen2026-10-10 12:44 UTC134
                ))
782069860236atagen2026-10-10 12:44 UTC135
            }
9683736a2c5eatagen2026-10-10 13:15 UTC136
            Floor::ChangingRoom => {
782069860236atagen2026-10-10 12:44 UTC137
                self.suspicion = 0;
782069860236atagen2026-10-10 12:44 UTC138
                self.shame += 5;
782069860236atagen2026-10-10 12:44 UTC139
                self.touch();
782069860236atagen2026-10-10 12:44 UTC140
                Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC141
                    StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS,
782069860236atagen2026-10-10 12:44 UTC142
                    "gym-staff",
782069860236atagen2026-10-10 12:44 UTC143
                    "Gym staff have been notified. The server cannot serve this request for legal reasons.",
782069860236atagen2026-10-10 12:44 UTC144
                ))
782069860236atagen2026-10-10 12:44 UTC145
            }
782069860236atagen2026-10-10 12:44 UTC146
            Floor::Hotel => {
782069860236atagen2026-10-10 12:44 UTC147
                self.suspicion = 0;
782069860236atagen2026-10-10 12:44 UTC148
                self.touch();
782069860236atagen2026-10-10 12:44 UTC149
                if self.items.dnd_sign {
d46f9d0b953aatagen2026-10-10 14:41 UTC150
                    self.notices.push("housekeeping read the sign");
782069860236atagen2026-10-10 12:44 UTC151
                    return Ok(());
782069860236atagen2026-10-10 12:44 UTC152
                }
782069860236atagen2026-10-10 12:44 UTC153
                self.shame += 3;
782069860236atagen2026-10-10 12:44 UTC154
                Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC155
                    StatusCode::UNAUTHORIZED,
782069860236atagen2026-10-10 12:44 UTC156
                    "housekeeping",
782069860236atagen2026-10-10 12:44 UTC157
                    "Housekeeping has entered. Housekeeping accepts no excuses.",
782069860236atagen2026-10-10 12:44 UTC158
                )
782069860236atagen2026-10-10 12:44 UTC159
                .header(header::WWW_AUTHENTICATE, "Excuse realm=\"housekeeping\""))
782069860236atagen2026-10-10 12:44 UTC160
            }
782069860236atagen2026-10-10 12:44 UTC161
            _ => Ok(()),
782069860236atagen2026-10-10 12:44 UTC162
        }
782069860236atagen2026-10-10 12:44 UTC163
    }
782069860236atagen2026-10-10 12:44 UTC164
}