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, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | balance::{FLOOR_ALLOWANCE, FLOOR_TURNS, STARTING_EQ, ZIPPER}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | round2, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | use crate::problem::Problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | impl Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | pub(super) fn next_floor(&mut self, paid: bool) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | let Some(next) = self.floor.next() else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | return; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | self.floor = next; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | self.here = FloorState::default(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | self.warmed_up = false; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | self.eq = STARTING_EQ; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | self.mom = None; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | if paid { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | self.cash += FLOOR_ALLOWANCE; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | pub fn advance(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | match self.floor { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | Floor::Clinic => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | StatusCode::CONFLICT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | "no-further-floor", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | "There is no further floor. There is only the diagnosis.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | Floor::Forum if self.elder != Elder::Beaten => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | StatusCode::CONFLICT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | "elder-unaddressed", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | "The Elder has not been addressed.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | .with("elder", self.path("/elder"))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | floor if floor.timed() && self.here.turns < FLOOR_TURNS => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | StatusCode::TOO_EARLY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | "floor-not-over", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | format!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | "The floor is not over. {} turns remain.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | FLOOR_TURNS - self.here.turns |
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 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | _ => {} |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | if self.chance(ZIPPER) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | return Err(self.end(Cause::Zipper)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | let reverted = self.here.temp_length; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | self.next_floor(true); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | let mut body = json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | "detail": format!("You have arrived at {}.", self.floor.name()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | "note": self.floor.note(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | if reverted > 0.0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | body["reverted"] = json!(round2(reverted)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | Ok( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | Outcome::json(StatusCode::SEE_OTHER, body) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 71 | .header(header::LOCATION, self.path("/floor")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | pub fn floor_view(&self) -> Value { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | let mut view = json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | "name": 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 | "turns": self.here.turns, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | "turns_required": self.floor.timed().then_some(FLOOR_TURNS), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | "exit": { "href": self.path("/floor"), "method": "POST" }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | match self.floor { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | Floor::LockerRoom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | view["others"] = json!([ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | { "name": "Greg", "self_reported_length": 9.5 }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 87 | { "name": "Dmitri", "self_reported_length": 8.75 }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | { "name": "a man in a towel", "self_reported_length": 11.0 }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | ]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | Floor::Hotel => view["portal"] = json!(self.path("/portal")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | Floor::Forum => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | view["thread"] = json!(super::FORUM_THREAD); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | view["elder"] = json!(self.path("/elder")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | Floor::Clinic => view["diagnosis"] = json!(self.path("/diagnosis")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | _ => {} |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | if self.floor.shop_open() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | view["shop"] = json!(self.path("/shop")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | view |
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 | fn found(&self, item: Item, detail: &str) -> Outcome { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | Outcome::json(StatusCode::FOUND, json!({ "detail": detail })).header( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | header::LOCATION, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | self.path(&format!("/inventory/{}", item.slug())), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | pub fn search_drawer(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | self.here.drawer_searches += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | let first = self.here.drawer_searches == 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | match self.floor { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | Floor::Bedroom if first && !self.items.ruler => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | self.items.grant(Item::Ruler); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | self.shame += 10; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | Ok(self.found( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | Item::Ruler, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | "You now know. This is the first honest measurement of the run.", |
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 | Floor::Bathroom if first => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | self.items.grant(Item::DoorLock); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | Ok(self.found(Item::DoorLock, "A door lock. It works once.")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | Floor::LockerRoom => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | self.shame += 3; |
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 | "not-your-locker", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | "That locker belongs to Greg. 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::Grandmas if first => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | self.items.grant(Item::Cage); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | Ok(self.found( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | Item::Cage, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | "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 | 143 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | Floor::Grandmas if self.items.cage => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | self.items.grant(Item::CageKey); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | json!({ "detail": "The key was under where the box had been. The cage is off." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | Floor::Hotel if first => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | self.items.grant(Item::DndSign); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | self.items.grant(Item::IcePack); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | self.items.grant(Item::IcePack); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | Ok(self.found( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | Item::DndSign, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | "A Do Not Disturb sign, and two ice packs from the machine down the hall.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | Floor::Forum if first => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | self.items.grant(Item::Spreadsheet); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | Ok(self.found( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | Item::Spreadsheet, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | "Your own spreadsheet. Every line is flat.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | Floor::Clinic => Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 169 | StatusCode::FORBIDDEN, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 170 | "doctors-drawer", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 171 | "That is the doctor's drawer.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 172 | )), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 173 | _ => Ok(Outcome::empty(StatusCode::NO_CONTENT)), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 174 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 175 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 176 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 177 | pub fn accept_terms(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 178 | if self.floor != Floor::Hotel { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 179 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 180 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 181 | "no-portal", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 182 | "There is no captive portal here. There is only the regular kind of captivity.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 183 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 184 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 185 | self.here.wifi_accepted = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 186 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 187 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | StatusCode::SEE_OTHER, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 189 | json!({ "detail": "Connected. The hotel does not want to know." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 190 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 191 | .header(header::LOCATION, self.path(""))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 192 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 193 | } |