an http based roguelike rpg about jelqing
Blame: src/game/travel.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use super::{ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 2 | Cause, Elder, Floor, FloorState, Notice, Outcome, Run, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 3 | balance::{ |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 4 | EQ_BAND, FLOOR_ALLOWANCE, FLOOR_LIMIT, FLOOR_TURNS, FRICTION_FLOOR, LOCKER_ROOM_BAR, |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 5 | LOCKER_ROOM_OTHERS, LOCKER_ROOM_SHAME, OVERSTAY_BUSTED, OVERSTAY_EQ, OVERSTAY_SHAME, |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 6 | STARTING_EQ, ZIP, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 7 | }, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 8 | measure::round2, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | use crate::problem::Problem; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 11 | use axum::http::{StatusCode, header}; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | use serde_json::{Value, json}; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 13 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 14 | /// How a floor was left. Only a proper exit is paid. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 15 | #[derive(Clone, Copy, PartialEq, Eq)] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 16 | pub(super) enum Exit { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 17 | Proper, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 18 | Premature, |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 19 | Overstayed, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 20 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | impl Run { |
624fe9c09c8e | atagen | 2026-10-14 12:11 UTC | 23 | /// Whether enough turns have passed for a timed floor to let the player go. |
624fe9c09c8e | atagen | 2026-10-14 12:11 UTC | 24 | pub(super) fn served_floor(&self) -> bool { |
624fe9c09c8e | atagen | 2026-10-14 12:11 UTC | 25 | self.here.turns >= FLOOR_TURNS |
624fe9c09c8e | atagen | 2026-10-14 12:11 UTC | 26 | } |
624fe9c09c8e | atagen | 2026-10-14 12:11 UTC | 27 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 28 | pub(super) fn next_floor(&mut self, exit: Exit) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | let Some(next) = self.floor.next() else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | return; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 32 | let warm = EQ_BAND.contains(&self.body.eq); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | self.floor = next; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 34 | self.here = FloorState { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 35 | warm_arrival: warm, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 36 | ..FloorState::default() |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 37 | }; |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 38 | self.realise(true); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 39 | self.reset_eq(STARTING_EQ); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 40 | self.standing.suspicion = 0; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 41 | self.shed(FRICTION_FLOOR); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 42 | self.household.mum = None; |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 43 | if self.floor == Floor::ChangingRoom && !self.holds_own_in_the_locker_room() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 44 | self.standing.shame += LOCKER_ROOM_SHAME; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 45 | self.notices.push(Notice::KevIsTheBar); |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 46 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 47 | if exit == Exit::Proper { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 48 | self.standing.cash += FLOOR_ALLOWANCE; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 53 | pub(super) fn check_clock(&mut self) -> Result<(), Problem> { |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 54 | if self.floor.timed() && self.here.turns + 1 >= FLOOR_LIMIT { |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 55 | return Err(self.overstay()); |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 56 | } |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 57 | Ok(()) |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 58 | } |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 59 | |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 60 | /// A floor past its limit either ends the run or moves you along, shamed and deflated. |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 61 | fn overstay(&mut self) -> Problem { |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 62 | self.touch(); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 63 | if self.chance( |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 64 | self.decision( |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 65 | "overstayed", |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 66 | "The floor has run long. Does somebody walk in?", |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 67 | ), |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 68 | OVERSTAY_BUSTED, |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 69 | ) { |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 70 | return self.end(Cause::Overstayed); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 71 | } |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 72 | self.standing.shame += OVERSTAY_SHAME; |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 73 | self.next_floor(Exit::Overstayed); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 74 | self.here.warm_arrival = false; |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 75 | self.reset_eq(OVERSTAY_EQ); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 76 | Problem::new( |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 77 | StatusCode::REQUEST_TIMEOUT, |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 78 | "floor-timed-out", |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 79 | "The floor has timed out. You have been moved along.", |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 80 | ) |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 81 | .header(header::CONNECTION, "close") |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 82 | } |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 83 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | pub fn advance(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | match self.floor { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | Floor::Clinic => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 87 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | StatusCode::CONFLICT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | "no-further-floor", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | "There is no further floor. There is only the diagnosis.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 93 | Floor::Forum if self.online.elder != Elder::Beaten => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | StatusCode::CONFLICT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | "elder-unaddressed", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | "The Elder has not been addressed.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | .with("elder", self.path("/elder"))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | } |
624fe9c09c8e | atagen | 2026-10-14 12:11 UTC | 101 | floor if floor.timed() && !self.served_floor() => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | StatusCode::TOO_EARLY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | "floor-not-over", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | format!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | "The floor is not over. {} turns remain.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | FLOOR_TURNS - self.here.turns |
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 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | _ => {} |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | } |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 113 | if self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 114 | self.decision( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 115 | "zip", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 116 | "As the floor ends and you put yourself away, does the zip catch?", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 117 | ), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 118 | ZIP, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 119 | ) { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 120 | return Err(self.end(Cause::Zip)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | } |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 122 | let left = self.floor.name(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | let reverted = self.here.temp_length; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 124 | self.next_floor(Exit::Proper); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 125 | let warm = if self.here.warm_arrival { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 126 | ", and the warmth came with you" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 127 | } else { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 128 | "" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 129 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | let mut body = json!({ |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 131 | "detail": format!("You leave {left}. You have arrived at {}{warm}.", self.floor.name()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | "note": self.floor.note(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | if reverted > 0.0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | body["reverted"] = json!(round2(reverted)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | Ok( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | Outcome::json(StatusCode::SEE_OTHER, body) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | .header(header::LOCATION, self.path("/floor")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | ) |
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 | pub fn floor_view(&self) -> Value { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | let mut view = json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | "name": self.floor.name(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | "note": self.floor.note(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | "turns": self.here.turns, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | "turns_required": self.floor.timed().then_some(FLOOR_TURNS), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | "exit": { "href": self.path("/floor"), "method": "POST" }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | match self.floor { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 152 | Floor::ChangingRoom => { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 153 | let others: Vec<Value> = LOCKER_ROOM_OTHERS |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 154 | .into_iter() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 155 | .chain([("Kev", LOCKER_ROOM_BAR)]) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 156 | .map(|(name, length)| json!({ "name": name, "self_reported_length": length })) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 157 | .collect(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 158 | view["others"] = json!(others); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | Floor::Hotel => view["portal"] = json!(self.path("/portal")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | Floor::Forum => { |
a11497af08aa | atagen | 2026-10-13 12:04 UTC | 162 | view["thread"] = json!(self.path("/thread")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | view["elder"] = json!(self.path("/elder")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | Floor::Clinic => view["diagnosis"] = json!(self.path("/diagnosis")), |
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 | if self.floor.shop_open() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 169 | view["shop"] = json!(self.path("/shop")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 170 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 171 | view |
782069860236 | atagen | 2026-10-10 12:44 UTC | 172 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 173 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 174 | pub fn accept_terms(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 175 | if self.floor != Floor::Hotel { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 176 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 177 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 178 | "no-portal", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 179 | "There is no captive portal here. There is only the regular kind of captivity.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 180 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 181 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 182 | self.here.wifi_accepted = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 183 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 184 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 185 | StatusCode::SEE_OTHER, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 186 | json!({ "detail": "Connected. The hotel does not want to know." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 187 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | .header(header::LOCATION, self.path(""))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 189 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 190 | } |