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::{ |
139164489032 | atagen | 2026-10-11 05:46 UTC | 10 | BURN_RUPTURE, COLD_EQ, CURVE_MISSES, DANGER_EQ, DEGLOVING, DEGLOVING_INTENSITY, FRIEND, |
139164489032 | atagen | 2026-10-11 05:46 UTC | 11 | HOT_EQ, 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 { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 31 | let burn = if self.conditions.friction_burn { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 32 | BURN_RUPTURE |
139164489032 | atagen | 2026-10-11 05:46 UTC | 33 | } else { |
139164489032 | atagen | 2026-10-11 05:46 UTC | 34 | 0 |
139164489032 | atagen | 2026-10-11 05:46 UTC | 35 | }; |
139164489032 | atagen | 2026-10-11 05:46 UTC | 36 | let odds = if self.eq <= DANGER_EQ - burn { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | RUPTURE_IN_BAND |
139164489032 | atagen | 2026-10-11 05:46 UTC | 38 | } else if self.eq <= HOT_EQ - burn { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | RUPTURE_WARM |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | RUPTURE_HOT |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | if self.chance(odds) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | return Err(self.rupture()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | if self.floor.has_window() && !self.items.blinds && self.chance(WINDOW) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | self.shame += 30; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | self.filmed_at.get_or_insert_with(SystemTime::now); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | return Ok(ControlFlow::Break( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | StatusCode::CREATED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | 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 | 53 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | .header(header::LOCATION, self.path("/footage")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 57 | if self.floor == Floor::ChangingRoom && self.chance(FRIEND) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | self.shame += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | StatusCode::USE_PROXY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | "friend", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | "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 | 63 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | if self.conditions.peyronie && self.chance(CURVE_MISSES) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | StatusCode::MISDIRECTED_REQUEST, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | "misdirected", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | "The technique landed slightly to the left. It was meant for a different server.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 71 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | if intensity <= 2 && self.eq < 50 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | self.eq = (self.eq - 10).max(0); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | StatusCode::REQUEST_TIMEOUT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | "lost-it", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | "The request took too long. It was lost.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | .header(header::CONNECTION, "close")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | } |
139164489032 | atagen | 2026-10-11 05:46 UTC | 81 | if self.eq > PREMATURE_EQ - burn { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | if self.chance(RUPTURE_PREMATURE) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | return Err(self.rupture()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | self.next_floor(false); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 87 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | StatusCode::TOO_EARLY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | "premature", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | "The floor has ended early. Everyone involved has agreed not to discuss it.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | if self.eq < COLD_EQ { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | "cold", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | "The resource exists. It is cold.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | Ok(ControlFlow::Continue(())) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 103 | /// The enemies suspicion summons on floors without Mum. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | pub(super) fn floor_enemy(&mut self) -> Result<(), Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | let visits = u32::from(self.suspicion) + 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | let wanders_in = matches!(self.floor, Floor::Bathroom | Floor::Hotel) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | && self.rng.random_ratio(visits, WANDERER_VISIT); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | if self.suspicion < SUSPICION_LIMIT && !wanders_in { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | match self.floor { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | Floor::Bathroom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | if self.items.door_locks > 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | self.items.door_locks -= 1; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 117 | self.notices.push("your brother tried the door"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | } |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 120 | self.here.brother_told = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | StatusCode::CONFLICT, |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 123 | "brother", |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 124 | "Your brother needs the bathroom. He will tell Mum.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 127 | Floor::ChangingRoom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | "gym-staff", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | "Gym staff have been notified. The server cannot serve this request for legal reasons.", |
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 | Floor::Hotel => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | if self.items.dnd_sign { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 141 | self.notices.push("housekeeping read the sign"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | self.shame += 3; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | StatusCode::UNAUTHORIZED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | "housekeeping", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | "Housekeeping has entered. Housekeeping accepts no excuses.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | .header(header::WWW_AUTHENTICATE, "Excuse realm=\"housekeeping\"")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | _ => Ok(()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | } |