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 serde_json::json; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | use super::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | Cause, Floor, Outcome, Run, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | balance::{ |
139164489032 | atagen | 2026-10-11 05:46 UTC | 9 | BURN_RUPTURE, COLD_EQ, CURVE_MISSES, DANGER_EQ, DEGLOVING, DEGLOVING_INTENSITY, FRIEND, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 10 | HOT_EQ, PREMATURE_EQ, RUPTURE_HOT, RUPTURE_IN_BAND, RUPTURE_PREMATURE, RUPTURE_WARM, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | SUSPICION_LIMIT, WANDERER_VISIT, WINDOW, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | techniques::Training, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | use crate::problem::Problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | type Interruption = Result<ControlFlow<Outcome>, Problem>; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | impl Run { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 20 | /// How far the friction burn drags the rupture tiers down. |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 21 | pub(super) fn burn(&self) -> i32 { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 22 | if self.conditions.friction_burn { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 23 | BURN_RUPTURE |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 24 | } else { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 25 | 0 |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 26 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 27 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 28 | |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 29 | /// The rupture tier for any turn that is not a jelq, so never the premature band's 1 in 3. |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 30 | pub(super) fn rupture_odds(&self) -> u32 { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 31 | if self.eq <= DANGER_EQ - self.burn() { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 32 | RUPTURE_IN_BAND |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 33 | } else if self.eq <= HOT_EQ - self.burn() { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 34 | RUPTURE_WARM |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 35 | } else { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 36 | RUPTURE_HOT |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 37 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 38 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 39 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | /// Accidents tied to a specific technique. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | pub(super) fn mishaps(&mut self, training: Training, intensity: i32) -> Interruption { |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 42 | if training == Training::Dry |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 43 | && intensity >= DEGLOVING_INTENSITY |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 44 | && self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 45 | self.decision("degloving", "Dry at this intensity, does the skin tear?"), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 46 | DEGLOVING, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 47 | ) |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 48 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | return Err(self.end(Cause::Degloved)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | Ok(ControlFlow::Continue(())) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | /// Everything that can go wrong on a committed turn before the roll. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | pub(super) fn hazards(&mut self, intensity: i32) -> Interruption { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 56 | let burn = self.burn(); |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 57 | if self.eq <= PREMATURE_EQ - burn |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 58 | && self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 59 | self.decision("rupture", "Does this jelq rupture something?"), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 60 | self.rupture_odds(), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 61 | ) |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 62 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | return Err(self.rupture()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | } |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 65 | if self.floor.has_window() |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 66 | && !self.items.blinds |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 67 | && self.oracle.chance_not( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 68 | self.decision("window", "Are the curtains still closed?"), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 69 | WINDOW, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 70 | ) |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 71 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | self.shame += 30; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | self.filmed_at.get_or_insert_with(SystemTime::now); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | return Ok(ControlFlow::Break( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | StatusCode::CREATED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | 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 | 78 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | .header(header::LOCATION, self.path("/footage")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | } |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 82 | if self.floor == Floor::ChangingRoom |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 83 | && self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 84 | self.decision("friend", "Does a friend walk in and offer to help?"), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 85 | FRIEND, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 86 | ) |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 87 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | self.shame += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | StatusCode::USE_PROXY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | "friend", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | "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 | 93 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | } |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 95 | if self.conditions.peyronie |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 96 | && self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 97 | self.decision( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 98 | "misdirected", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 99 | "With the curve, does the stroke land sharply to the left?", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 100 | ), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 101 | CURVE_MISSES, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 102 | ) |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 103 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | StatusCode::MISDIRECTED_REQUEST, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | "misdirected", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | "The technique landed slightly to the left. It was meant for a different server.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | if intensity <= 2 && self.eq < 50 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | self.eq = (self.eq - 10).max(0); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | StatusCode::REQUEST_TIMEOUT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | "lost-it", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | "The request took too long. It was lost.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | .header(header::CONNECTION, "close")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 119 | if self.eq > PREMATURE_EQ - burn { |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 120 | if self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 121 | self.decision( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 122 | "rupture", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 123 | "Right at the edge of finishing, does it rupture instead?", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 124 | ), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 125 | RUPTURE_PREMATURE, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 126 | ) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | return Err(self.rupture()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | self.next_floor(false); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | StatusCode::TOO_EARLY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | "premature", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | "The floor has ended early. Everyone involved has agreed not to discuss it.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | if self.eq < COLD_EQ { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | "cold", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | "The resource exists. It is cold.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | Ok(ControlFlow::Continue(())) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 147 | /// The enemies suspicion summons on floors without Mum. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | pub(super) fn floor_enemy(&mut self) -> Result<(), Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | let visits = u32::from(self.suspicion) + 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | let wanders_in = matches!(self.floor, Floor::Bathroom | Floor::Hotel) |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 151 | && self.oracle.ratio_choice( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 152 | self.decision("wanderer", "Does anyone else come through the door?"), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 153 | visits, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 154 | WANDERER_VISIT, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 155 | "No", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 156 | "Yes", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 157 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | if self.suspicion < SUSPICION_LIMIT && !wanders_in { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | match self.floor { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | Floor::Bathroom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | if self.items.door_locks > 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | self.items.door_locks -= 1; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 167 | self.notices.push("your brother tried the door"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 169 | } |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 170 | self.here.brother_told = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 171 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 172 | StatusCode::CONFLICT, |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 173 | "brother", |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 174 | "Your brother needs the bathroom. He will tell Mum.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 175 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 176 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 177 | Floor::ChangingRoom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 178 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 179 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 180 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 181 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 182 | StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 183 | "gym-staff", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 184 | "Gym staff have been notified. The server cannot serve this request for legal reasons.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 185 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 186 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 187 | Floor::Hotel => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 189 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 190 | if self.items.dnd_sign { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 191 | self.notices.push("housekeeping read the sign"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 192 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 193 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 194 | self.shame += 3; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 195 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 196 | StatusCode::UNAUTHORIZED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 197 | "housekeeping", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 198 | "Housekeeping has entered. Housekeeping accepts no excuses.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 199 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 200 | .header(header::WWW_AUTHENTICATE, "Excuse realm=\"housekeeping\"")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 201 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 202 | _ => Ok(()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 203 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 204 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 205 | } |