an http based roguelike rpg about jelqing
Blame: src/game/floors.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use axum::http::{StatusCode, header}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | use serde_json::{Value, json}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | use super::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | Cause, Elder, Floor, FloorState, Item, Outcome, Run, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 6 | balance::{ |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 7 | EQ_BAND, FLOOR_ALLOWANCE, FLOOR_TURNS, FRICTION_FLOOR, KEY_IN_DRAWER, RULER_IN_DRAWER, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 8 | STARTING_EQ, SUSPICION_LIMIT, ZIP, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 9 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | round2, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | use crate::problem::Problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | impl Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | pub(super) fn next_floor(&mut self, paid: bool) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | let Some(next) = self.floor.next() else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | return; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | }; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 19 | let warm = EQ_BAND.contains(&self.eq); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | self.floor = next; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 21 | self.here = FloorState { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 22 | warm_arrival: warm, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 23 | ..FloorState::default() |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 24 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | self.warmed_up = false; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | self.eq = STARTING_EQ; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | self.suspicion = 0; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 28 | self.shed(FRICTION_FLOOR); |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 29 | self.mum = None; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | if paid { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | self.cash += FLOOR_ALLOWANCE; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | pub fn advance(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | match self.floor { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | Floor::Clinic => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | StatusCode::CONFLICT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | "no-further-floor", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | "There is no further floor. There is only the diagnosis.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | Floor::Forum if self.elder != Elder::Beaten => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | StatusCode::CONFLICT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | "elder-unaddressed", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | "The Elder has not been addressed.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | .with("elder", self.path("/elder"))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | floor if floor.timed() && self.here.turns < FLOOR_TURNS => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | StatusCode::TOO_EARLY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | "floor-not-over", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | format!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | "The floor is not over. {} turns remain.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | FLOOR_TURNS - self.here.turns |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | ), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | _ => {} |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 65 | if self.chance(ZIP) { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 66 | return Err(self.end(Cause::Zip)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | } |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 68 | let left = self.floor.name(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | let reverted = self.here.temp_length; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | self.next_floor(true); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 71 | let warm = if self.here.warm_arrival { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 72 | ", and the warmth came with you" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 73 | } else { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 74 | "" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 75 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | let mut body = json!({ |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 77 | "detail": format!("You leave {left}. You have arrived at {}{warm}.", self.floor.name()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | "note": self.floor.note(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | if reverted > 0.0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | body["reverted"] = json!(round2(reverted)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | Ok( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | Outcome::json(StatusCode::SEE_OTHER, body) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | .header(header::LOCATION, self.path("/floor")), |
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 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | pub fn floor_view(&self) -> Value { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | let mut view = json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | "name": self.floor.name(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | "note": self.floor.note(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | "turns": self.here.turns, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | "turns_required": self.floor.timed().then_some(FLOOR_TURNS), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | "exit": { "href": self.path("/floor"), "method": "POST" }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | match self.floor { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 98 | Floor::ChangingRoom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | view["others"] = json!([ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | { "name": "Greg", "self_reported_length": 9.5 }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | { "name": "Dmitri", "self_reported_length": 8.75 }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | { "name": "a man in a towel", "self_reported_length": 11.0 }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | ]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | Floor::Hotel => view["portal"] = json!(self.path("/portal")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | Floor::Forum => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | view["thread"] = json!(super::FORUM_THREAD); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | view["elder"] = json!(self.path("/elder")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | Floor::Clinic => view["diagnosis"] = json!(self.path("/diagnosis")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | _ => {} |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | if self.floor.shop_open() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | view["shop"] = json!(self.path("/shop")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | view |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | fn found(&self, item: Item, detail: &str) -> Outcome { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | Outcome::json(StatusCode::FOUND, json!({ "detail": detail })).header( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | header::LOCATION, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | self.path(&format!("/inventory/{}", item.slug())), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | pub fn search_drawer(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | self.here.drawer_searches += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | let first = self.here.drawer_searches == 1; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 130 | if self.items.cage { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 131 | return Ok(self.rummage_for_key()); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 132 | } |
ad00e0e051a1 | atagen | 2026-10-10 14:00 UTC | 133 | let ruler_here = self.floor == Floor::Bedroom && self.chance(RULER_IN_DRAWER); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | match self.floor { |
ad00e0e051a1 | atagen | 2026-10-10 14:00 UTC | 135 | Floor::Bedroom if first && !self.items.ruler && ruler_here => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | self.items.grant(Item::Ruler); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | self.shame += 10; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | Ok(self.found( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | Item::Ruler, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | "You now know. This is the first honest measurement of the run.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | Floor::Bathroom if first => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | self.items.grant(Item::DoorLock); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | Ok(self.found(Item::DoorLock, "A door lock. It works once.")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 147 | Floor::ChangingRoom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | self.shame += 3; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | "not-your-locker", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | "That locker belongs to Greg. The server cannot serve this request for legal reasons.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 155 | Floor::Nans if first => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | self.items.grant(Item::Cage); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | Ok(self.found( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | Item::Cage, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | "A small box. Inside was a cage. It is now on. The key is not in the box.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | Floor::Hotel if first => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | self.items.grant(Item::DndSign); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | self.items.grant(Item::IcePack); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | self.items.grant(Item::IcePack); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | Ok(self.found( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | Item::DndSign, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 169 | "A Do Not Disturb sign, and two ice packs from the machine down the hall.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 170 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 171 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 172 | Floor::Forum if first => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 173 | self.items.grant(Item::Spreadsheet); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 174 | Ok(self.found( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 175 | Item::Spreadsheet, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 176 | "Your own spreadsheet. Every line is flat.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 177 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 178 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 179 | Floor::Clinic => Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 180 | StatusCode::FORBIDDEN, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 181 | "doctors-drawer", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 182 | "That is the doctor's drawer.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 183 | )), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 184 | _ => Ok(Outcome::empty(StatusCode::NO_CONTENT)), |
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 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | pub fn accept_terms(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 189 | if self.floor != Floor::Hotel { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 190 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 191 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 192 | "no-portal", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 193 | "There is no captive portal here. There is only the regular kind of captivity.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 194 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 195 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 196 | self.here.wifi_accepted = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 197 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 198 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 199 | StatusCode::SEE_OTHER, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 200 | json!({ "detail": "Connected. The hotel does not want to know." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 201 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 202 | .header(header::LOCATION, self.path(""))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 203 | } |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 204 | |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 205 | /// Searching while caged is noisy, and the key only turns up some of the time. |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 206 | fn rummage_for_key(&mut self) -> Outcome { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 207 | let was_below = self.suspicion < SUSPICION_LIMIT; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 208 | self.suspicion = (self.suspicion + 1).min(SUSPICION_LIMIT); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 209 | self.maybe_summon_mum(was_below); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 210 | if !self.chance(KEY_IN_DRAWER) { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 211 | return Outcome::empty(StatusCode::NO_CONTENT); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 212 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 213 | self.items.grant(Item::CageKey); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 214 | Outcome::json( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 215 | StatusCode::OK, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 216 | json!({ "detail": "The key was in the drawer. The cage is off." }), |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 217 | ) |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 218 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 219 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 220 | /// Whether searching the drawer on this floor would turn anything up. |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 221 | pub fn drawer_worth_searching(&self) -> bool { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 222 | self.here.drawer_searches == 0 || self.items.cage |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 223 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 224 | } |