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, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 5 | LOCKER_ROOM_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, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 18 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | impl Run { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 21 | pub(super) fn next_floor(&mut self, exit: Exit) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | let Some(next) = self.floor.next() else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | return; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 25 | let warm = EQ_BAND.contains(&self.body.eq); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | self.floor = next; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 27 | self.here = FloorState { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 28 | warm_arrival: warm, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 29 | ..FloorState::default() |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 30 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 31 | self.body.warmed_up = false; |
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 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | pub fn advance(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | match self.floor { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | Floor::Clinic => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | StatusCode::CONFLICT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | "no-further-floor", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | "There is no further floor. There is only the diagnosis.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | Floor::Forum if self.online.elder != Elder::Beaten => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | StatusCode::CONFLICT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | "elder-unaddressed", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | "The Elder has not been addressed.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | .with("elder", self.path("/elder"))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | floor if floor.timed() && self.here.turns < FLOOR_TURNS => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | StatusCode::TOO_EARLY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | "floor-not-over", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | format!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | "The floor is not over. {} turns remain.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | FLOOR_TURNS - self.here.turns |
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 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | _ => {} |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | } |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 75 | if self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 76 | self.decision( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 77 | "zip", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 78 | "As the floor ends and you put yourself away, does the zip catch?", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 79 | ), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 80 | ZIP, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 81 | ) { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 82 | return Err(self.end(Cause::Zip)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | } |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 84 | let left = self.floor.name(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | let reverted = self.here.temp_length; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 86 | self.next_floor(Exit::Proper); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 87 | let warm = if self.here.warm_arrival { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 88 | ", and the warmth came with you" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 89 | } else { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 90 | "" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 91 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | let mut body = json!({ |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 93 | "detail": format!("You leave {left}. You have arrived at {}{warm}.", self.floor.name()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | "note": self.floor.note(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | if reverted > 0.0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | body["reverted"] = json!(round2(reverted)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | Ok( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | Outcome::json(StatusCode::SEE_OTHER, body) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | .header(header::LOCATION, self.path("/floor")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | ) |
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 | pub fn floor_view(&self) -> Value { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | let mut view = json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | "name": self.floor.name(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | "note": self.floor.note(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | "turns": self.here.turns, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | "turns_required": self.floor.timed().then_some(FLOOR_TURNS), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | "exit": { "href": self.path("/floor"), "method": "POST" }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | match self.floor { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 114 | Floor::ChangingRoom => { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 115 | let others: Vec<Value> = LOCKER_ROOM_OTHERS |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 116 | .into_iter() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 117 | .chain([("Kev", LOCKER_ROOM_BAR)]) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 118 | .map(|(name, length)| json!({ "name": name, "self_reported_length": length })) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 119 | .collect(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 120 | view["others"] = json!(others); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | Floor::Hotel => view["portal"] = json!(self.path("/portal")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | Floor::Forum => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | view["thread"] = json!(super::FORUM_THREAD); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | view["elder"] = json!(self.path("/elder")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | Floor::Clinic => view["diagnosis"] = json!(self.path("/diagnosis")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | _ => {} |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | if self.floor.shop_open() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | view["shop"] = json!(self.path("/shop")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | view |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | pub fn accept_terms(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | if self.floor != Floor::Hotel { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | "no-portal", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | "There is no captive portal here. There is only the regular kind of captivity.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | self.here.wifi_accepted = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | StatusCode::SEE_OTHER, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | json!({ "detail": "Connected. The hotel does not want to know." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | .header(header::LOCATION, self.path(""))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | } |