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