atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
f3a1913c1299571fbfcb552007761bae715c4434
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git

Blame: src/game/travel.rs

782069860236atagen2026-10-10 12:44 UTC1
use super::{
8b8e83329a1datagen2026-10-12 12:01 UTC2
    Cause, Elder, Floor, FloorState, Notice, Outcome, Run,
0d604ee39751atagen2026-10-10 14:15 UTC3
    balance::{
6033b0db186catagen2026-10-13 12:44 UTC4
        EQ_BAND, FLOOR_ALLOWANCE, FLOOR_LIMIT, FLOOR_TURNS, FRICTION_FLOOR, LOCKER_ROOM_BAR,
6033b0db186catagen2026-10-13 12:44 UTC5
        LOCKER_ROOM_OTHERS, LOCKER_ROOM_SHAME, OVERSTAY_BUSTED, OVERSTAY_EQ, OVERSTAY_SHAME,
6033b0db186catagen2026-10-13 12:44 UTC6
        STARTING_EQ, ZIP,
0d604ee39751atagen2026-10-10 14:15 UTC7
    },
8b8e83329a1datagen2026-10-12 12:01 UTC8
    measure::round2,
782069860236atagen2026-10-10 12:44 UTC9
};
782069860236atagen2026-10-10 12:44 UTC10
use crate::problem::Problem;
8b8e83329a1datagen2026-10-12 12:01 UTC11
use axum::http::{StatusCode, header};
8b8e83329a1datagen2026-10-12 12:01 UTC12
use serde_json::{Value, json};
8b8e83329a1datagen2026-10-12 12:01 UTC13
8b8e83329a1datagen2026-10-12 12:01 UTC14
/// How a floor was left. Only a proper exit is paid.
8b8e83329a1datagen2026-10-12 12:01 UTC15
#[derive(Clone, Copy, PartialEq, Eq)]
8b8e83329a1datagen2026-10-12 12:01 UTC16
pub(super) enum Exit {
8b8e83329a1datagen2026-10-12 12:01 UTC17
    Proper,
8b8e83329a1datagen2026-10-12 12:01 UTC18
    Premature,
3ac624339c98atagen2026-10-13 12:21 UTC19
    Overstayed,
8b8e83329a1datagen2026-10-12 12:01 UTC20
}
782069860236atagen2026-10-10 12:44 UTC21
782069860236atagen2026-10-10 12:44 UTC22
impl Run {
8b8e83329a1datagen2026-10-12 12:01 UTC23
    pub(super) fn next_floor(&mut self, exit: Exit) {
782069860236atagen2026-10-10 12:44 UTC24
        let Some(next) = self.floor.next() else {
782069860236atagen2026-10-10 12:44 UTC25
            return;
782069860236atagen2026-10-10 12:44 UTC26
        };
8b8e83329a1datagen2026-10-12 12:01 UTC27
        let warm = EQ_BAND.contains(&self.body.eq);
782069860236atagen2026-10-10 12:44 UTC28
        self.floor = next;
4347977b8192atagen2026-10-11 04:56 UTC29
        self.here = FloorState {
4347977b8192atagen2026-10-11 04:56 UTC30
            warm_arrival: warm,
4347977b8192atagen2026-10-11 04:56 UTC31
            ..FloorState::default()
4347977b8192atagen2026-10-11 04:56 UTC32
        };
6033b0db186catagen2026-10-13 12:44 UTC33
        self.realise(true);
14de3e1e8dc2atagen2026-10-11 06:19 UTC34
        self.reset_eq(STARTING_EQ);
8b8e83329a1datagen2026-10-12 12:01 UTC35
        self.standing.suspicion = 0;
5dfebcc0ac43atagen2026-10-11 05:28 UTC36
        self.shed(FRICTION_FLOOR);
8b8e83329a1datagen2026-10-12 12:01 UTC37
        self.household.mum = None;
058650ec79d6atagen2026-10-12 10:49 UTC38
        if self.floor == Floor::ChangingRoom && !self.holds_own_in_the_locker_room() {
8b8e83329a1datagen2026-10-12 12:01 UTC39
            self.standing.shame += LOCKER_ROOM_SHAME;
8b8e83329a1datagen2026-10-12 12:01 UTC40
            self.notices.push(Notice::KevIsTheBar);
058650ec79d6atagen2026-10-12 10:49 UTC41
        }
8b8e83329a1datagen2026-10-12 12:01 UTC42
        if exit == Exit::Proper {
8b8e83329a1datagen2026-10-12 12:01 UTC43
            self.standing.cash += FLOOR_ALLOWANCE;
782069860236atagen2026-10-10 12:44 UTC44
        }
782069860236atagen2026-10-10 12:44 UTC45
        self.touch();
782069860236atagen2026-10-10 12:44 UTC46
    }
782069860236atagen2026-10-10 12:44 UTC47
6033b0db186catagen2026-10-13 12:44 UTC48
    pub(super) fn check_clock(&mut self) -> Result<(), Problem> {
6033b0db186catagen2026-10-13 12:44 UTC49
        if self.floor.timed() && self.here.turns + 1 >= FLOOR_LIMIT {
6033b0db186catagen2026-10-13 12:44 UTC50
            return Err(self.overstay());
6033b0db186catagen2026-10-13 12:44 UTC51
        }
6033b0db186catagen2026-10-13 12:44 UTC52
        Ok(())
6033b0db186catagen2026-10-13 12:44 UTC53
    }
6033b0db186catagen2026-10-13 12:44 UTC54
3ac624339c98atagen2026-10-13 12:21 UTC55
    /// A floor past its limit either ends the run or moves you along, shamed and deflated.
6033b0db186catagen2026-10-13 12:44 UTC56
    fn overstay(&mut self) -> Problem {
3ac624339c98atagen2026-10-13 12:21 UTC57
        self.touch();
3ac624339c98atagen2026-10-13 12:21 UTC58
        if self.chance(
3ac624339c98atagen2026-10-13 12:21 UTC59
            self.decision(
3ac624339c98atagen2026-10-13 12:21 UTC60
                "overstayed",
3ac624339c98atagen2026-10-13 12:21 UTC61
                "The floor has run long. Does somebody walk in?",
3ac624339c98atagen2026-10-13 12:21 UTC62
            ),
3ac624339c98atagen2026-10-13 12:21 UTC63
            OVERSTAY_BUSTED,
3ac624339c98atagen2026-10-13 12:21 UTC64
        ) {
3ac624339c98atagen2026-10-13 12:21 UTC65
            return self.end(Cause::Overstayed);
3ac624339c98atagen2026-10-13 12:21 UTC66
        }
3ac624339c98atagen2026-10-13 12:21 UTC67
        self.standing.shame += OVERSTAY_SHAME;
3ac624339c98atagen2026-10-13 12:21 UTC68
        self.next_floor(Exit::Overstayed);
3ac624339c98atagen2026-10-13 12:21 UTC69
        self.here.warm_arrival = false;
3ac624339c98atagen2026-10-13 12:21 UTC70
        self.reset_eq(OVERSTAY_EQ);
3ac624339c98atagen2026-10-13 12:21 UTC71
        Problem::new(
3ac624339c98atagen2026-10-13 12:21 UTC72
            StatusCode::REQUEST_TIMEOUT,
3ac624339c98atagen2026-10-13 12:21 UTC73
            "floor-timed-out",
3ac624339c98atagen2026-10-13 12:21 UTC74
            "The floor has timed out. You have been moved along.",
3ac624339c98atagen2026-10-13 12:21 UTC75
        )
3ac624339c98atagen2026-10-13 12:21 UTC76
        .header(header::CONNECTION, "close")
3ac624339c98atagen2026-10-13 12:21 UTC77
    }
3ac624339c98atagen2026-10-13 12:21 UTC78
782069860236atagen2026-10-10 12:44 UTC79
    pub fn advance(&mut self) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC80
        match self.floor {
782069860236atagen2026-10-10 12:44 UTC81
            Floor::Clinic => {
782069860236atagen2026-10-10 12:44 UTC82
                return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC83
                    StatusCode::CONFLICT,
782069860236atagen2026-10-10 12:44 UTC84
                    "no-further-floor",
782069860236atagen2026-10-10 12:44 UTC85
                    "There is no further floor. There is only the diagnosis.",
782069860236atagen2026-10-10 12:44 UTC86
                ));
782069860236atagen2026-10-10 12:44 UTC87
            }
8b8e83329a1datagen2026-10-12 12:01 UTC88
            Floor::Forum if self.online.elder != Elder::Beaten => {
782069860236atagen2026-10-10 12:44 UTC89
                return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC90
                    StatusCode::CONFLICT,
782069860236atagen2026-10-10 12:44 UTC91
                    "elder-unaddressed",
782069860236atagen2026-10-10 12:44 UTC92
                    "The Elder has not been addressed.",
782069860236atagen2026-10-10 12:44 UTC93
                )
782069860236atagen2026-10-10 12:44 UTC94
                .with("elder", self.path("/elder")));
782069860236atagen2026-10-10 12:44 UTC95
            }
782069860236atagen2026-10-10 12:44 UTC96
            floor if floor.timed() && self.here.turns < FLOOR_TURNS => {
782069860236atagen2026-10-10 12:44 UTC97
                return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC98
                    StatusCode::TOO_EARLY,
782069860236atagen2026-10-10 12:44 UTC99
                    "floor-not-over",
782069860236atagen2026-10-10 12:44 UTC100
                    format!(
782069860236atagen2026-10-10 12:44 UTC101
                        "The floor is not over. {} turns remain.",
782069860236atagen2026-10-10 12:44 UTC102
                        FLOOR_TURNS - self.here.turns
782069860236atagen2026-10-10 12:44 UTC103
                    ),
782069860236atagen2026-10-10 12:44 UTC104
                ));
782069860236atagen2026-10-10 12:44 UTC105
            }
782069860236atagen2026-10-10 12:44 UTC106
            _ => {}
782069860236atagen2026-10-10 12:44 UTC107
        }
3f9091557ec3atagen2026-10-11 11:43 UTC108
        if self.chance(
3f9091557ec3atagen2026-10-11 11:43 UTC109
            self.decision(
3f9091557ec3atagen2026-10-11 11:43 UTC110
                "zip",
3f9091557ec3atagen2026-10-11 11:43 UTC111
                "As the floor ends and you put yourself away, does the zip catch?",
3f9091557ec3atagen2026-10-11 11:43 UTC112
            ),
3f9091557ec3atagen2026-10-11 11:43 UTC113
            ZIP,
3f9091557ec3atagen2026-10-11 11:43 UTC114
        ) {
9683736a2c5eatagen2026-10-10 13:15 UTC115
            return Err(self.end(Cause::Zip));
782069860236atagen2026-10-10 12:44 UTC116
        }
7d3fb63208bfatagen2026-10-11 04:38 UTC117
        let left = self.floor.name();
782069860236atagen2026-10-10 12:44 UTC118
        let reverted = self.here.temp_length;
8b8e83329a1datagen2026-10-12 12:01 UTC119
        self.next_floor(Exit::Proper);
4347977b8192atagen2026-10-11 04:56 UTC120
        let warm = if self.here.warm_arrival {
4347977b8192atagen2026-10-11 04:56 UTC121
            ", and the warmth came with you"
4347977b8192atagen2026-10-11 04:56 UTC122
        } else {
4347977b8192atagen2026-10-11 04:56 UTC123
            ""
4347977b8192atagen2026-10-11 04:56 UTC124
        };
782069860236atagen2026-10-10 12:44 UTC125
        let mut body = json!({
4347977b8192atagen2026-10-11 04:56 UTC126
            "detail": format!("You leave {left}. You have arrived at {}{warm}.", self.floor.name()),
782069860236atagen2026-10-10 12:44 UTC127
            "note": self.floor.note(),
782069860236atagen2026-10-10 12:44 UTC128
        });
782069860236atagen2026-10-10 12:44 UTC129
        if reverted > 0.0 {
782069860236atagen2026-10-10 12:44 UTC130
            body["reverted"] = json!(round2(reverted));
782069860236atagen2026-10-10 12:44 UTC131
        }
782069860236atagen2026-10-10 12:44 UTC132
        Ok(
782069860236atagen2026-10-10 12:44 UTC133
            Outcome::json(StatusCode::SEE_OTHER, body)
782069860236atagen2026-10-10 12:44 UTC134
                .header(header::LOCATION, self.path("/floor")),
782069860236atagen2026-10-10 12:44 UTC135
        )
782069860236atagen2026-10-10 12:44 UTC136
    }
782069860236atagen2026-10-10 12:44 UTC137
782069860236atagen2026-10-10 12:44 UTC138
    pub fn floor_view(&self) -> Value {
782069860236atagen2026-10-10 12:44 UTC139
        let mut view = json!({
782069860236atagen2026-10-10 12:44 UTC140
            "name": self.floor.name(),
782069860236atagen2026-10-10 12:44 UTC141
            "note": self.floor.note(),
782069860236atagen2026-10-10 12:44 UTC142
            "turns": self.here.turns,
782069860236atagen2026-10-10 12:44 UTC143
            "turns_required": self.floor.timed().then_some(FLOOR_TURNS),
782069860236atagen2026-10-10 12:44 UTC144
            "exit": { "href": self.path("/floor"), "method": "POST" },
782069860236atagen2026-10-10 12:44 UTC145
        });
782069860236atagen2026-10-10 12:44 UTC146
        match self.floor {
9683736a2c5eatagen2026-10-10 13:15 UTC147
            Floor::ChangingRoom => {
8b8e83329a1datagen2026-10-12 12:01 UTC148
                let others: Vec<Value> = LOCKER_ROOM_OTHERS
8b8e83329a1datagen2026-10-12 12:01 UTC149
                    .into_iter()
8b8e83329a1datagen2026-10-12 12:01 UTC150
                    .chain([("Kev", LOCKER_ROOM_BAR)])
8b8e83329a1datagen2026-10-12 12:01 UTC151
                    .map(|(name, length)| json!({ "name": name, "self_reported_length": length }))
8b8e83329a1datagen2026-10-12 12:01 UTC152
                    .collect();
8b8e83329a1datagen2026-10-12 12:01 UTC153
                view["others"] = json!(others);
782069860236atagen2026-10-10 12:44 UTC154
            }
782069860236atagen2026-10-10 12:44 UTC155
            Floor::Hotel => view["portal"] = json!(self.path("/portal")),
782069860236atagen2026-10-10 12:44 UTC156
            Floor::Forum => {
a11497af08aaatagen2026-10-13 12:04 UTC157
                view["thread"] = json!(self.path("/thread"));
782069860236atagen2026-10-10 12:44 UTC158
                view["elder"] = json!(self.path("/elder"));
782069860236atagen2026-10-10 12:44 UTC159
            }
782069860236atagen2026-10-10 12:44 UTC160
            Floor::Clinic => view["diagnosis"] = json!(self.path("/diagnosis")),
782069860236atagen2026-10-10 12:44 UTC161
            _ => {}
782069860236atagen2026-10-10 12:44 UTC162
        }
782069860236atagen2026-10-10 12:44 UTC163
        if self.floor.shop_open() {
782069860236atagen2026-10-10 12:44 UTC164
            view["shop"] = json!(self.path("/shop"));
782069860236atagen2026-10-10 12:44 UTC165
        }
782069860236atagen2026-10-10 12:44 UTC166
        view
782069860236atagen2026-10-10 12:44 UTC167
    }
782069860236atagen2026-10-10 12:44 UTC168
782069860236atagen2026-10-10 12:44 UTC169
    pub fn accept_terms(&mut self) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC170
        if self.floor != Floor::Hotel {
782069860236atagen2026-10-10 12:44 UTC171
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC172
                StatusCode::NOT_FOUND,
782069860236atagen2026-10-10 12:44 UTC173
                "no-portal",
782069860236atagen2026-10-10 12:44 UTC174
                "There is no captive portal here. There is only the regular kind of captivity.",
782069860236atagen2026-10-10 12:44 UTC175
            ));
782069860236atagen2026-10-10 12:44 UTC176
        }
782069860236atagen2026-10-10 12:44 UTC177
        self.here.wifi_accepted = true;
782069860236atagen2026-10-10 12:44 UTC178
        self.touch();
782069860236atagen2026-10-10 12:44 UTC179
        Ok(Outcome::json(
782069860236atagen2026-10-10 12:44 UTC180
            StatusCode::SEE_OTHER,
782069860236atagen2026-10-10 12:44 UTC181
            json!({ "detail": "Connected. The hotel does not want to know." }),
782069860236atagen2026-10-10 12:44 UTC182
        )
782069860236atagen2026-10-10 12:44 UTC183
        .header(header::LOCATION, self.path("")))
782069860236atagen2026-10-10 12:44 UTC184
    }
782069860236atagen2026-10-10 12:44 UTC185
}