atagen

jelq

public

an http based roguelike rpg about jelqing

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