an http based roguelike rpg about jelqing
Blame: src/game/hazards.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use std::{ops::ControlFlow, time::SystemTime}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | use axum::http::{StatusCode, header}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | use rand::Rng; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | use serde_json::json; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | use super::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | Cause, Floor, Outcome, Run, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | balance::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | COLD_EQ, CURVE_MISSES, DANGER_EQ, DEGLOVING, DEGLOVING_INTENSITY, FRIEND, HOT_EQ, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | PREMATURE_EQ, RUPTURE_HOT, RUPTURE_IN_BAND, RUPTURE_PREMATURE, RUPTURE_WARM, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | SUSPICION_LIMIT, WANDERER_VISIT, WINDOW, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | techniques::Training, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | use crate::problem::Problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | type Interruption = Result<ControlFlow<Outcome>, Problem>; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | impl Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | /// Accidents tied to a specific technique. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | pub(super) fn mishaps(&mut self, training: Training, intensity: i32) -> Interruption { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | if training == Training::Dry && intensity >= DEGLOVING_INTENSITY && self.chance(DEGLOVING) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | return Err(self.end(Cause::Degloved)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | Ok(ControlFlow::Continue(())) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | /// Everything that can go wrong on a committed turn before the roll. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | pub(super) fn hazards(&mut self, intensity: i32) -> Interruption { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | let odds = if self.eq <= DANGER_EQ { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | RUPTURE_IN_BAND |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | } else if self.eq <= HOT_EQ { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | RUPTURE_WARM |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | RUPTURE_HOT |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | if self.chance(odds) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | return Err(self.rupture()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | if self.floor.has_window() && !self.items.blinds && self.chance(WINDOW) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | self.shame += 30; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | self.filmed_at.get_or_insert_with(SystemTime::now); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | return Ok(ControlFlow::Break( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | StatusCode::CREATED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | json!({ "detail": "A neighbour was at the window. A recording has been created. It has been shared." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | .header(header::LOCATION, self.path("/footage")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 52 | if self.floor == Floor::ChangingRoom && self.chance(FRIEND) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | self.shame += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | StatusCode::USE_PROXY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | "friend", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | "A friend has offered to help. Use Proxy is deprecated, and the server has declined on your behalf.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | if self.conditions.peyronie && self.chance(CURVE_MISSES) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | StatusCode::MISDIRECTED_REQUEST, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | "misdirected", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | "The technique landed slightly to the left. It was meant for a different server.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | if intensity <= 2 && self.eq < 50 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | self.eq = (self.eq - 10).max(0); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | StatusCode::REQUEST_TIMEOUT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 71 | "lost-it", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | "The request took too long. It was lost.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | .header(header::CONNECTION, "close")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | if self.eq > PREMATURE_EQ { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | if self.chance(RUPTURE_PREMATURE) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | return Err(self.rupture()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | self.next_floor(false); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | StatusCode::TOO_EARLY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | "premature", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | "The floor has ended early. Everyone involved has agreed not to discuss it.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 87 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | if self.eq < COLD_EQ { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | "cold", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | "The resource exists. It is cold.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | Ok(ControlFlow::Continue(())) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 98 | /// The enemies suspicion summons on floors without Mum. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | pub(super) fn floor_enemy(&mut self) -> Result<(), Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | let visits = u32::from(self.suspicion) + 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | let wanders_in = matches!(self.floor, Floor::Bathroom | Floor::Hotel) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | && self.rng.random_ratio(visits, WANDERER_VISIT); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | if self.suspicion < SUSPICION_LIMIT && !wanders_in { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | match self.floor { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | Floor::Bathroom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | if self.items.door_locks > 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | self.items.door_locks -= 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 114 | self.here.flatmate_told = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | StatusCode::CONFLICT, |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 117 | "flatmate", |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 118 | "The flatmate needs the bathroom. He will mention this to people.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 121 | Floor::ChangingRoom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | "gym-staff", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | "Gym staff have been notified. The server cannot serve this request for legal reasons.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | Floor::Hotel => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | if self.items.dnd_sign { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | self.shame += 3; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | StatusCode::UNAUTHORIZED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | "housekeeping", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | "Housekeeping has entered. Housekeeping accepts no excuses.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | .header(header::WWW_AUTHENTICATE, "Excuse realm=\"housekeeping\"")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | _ => Ok(()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | } |