atagen

jelq

public

an http based roguelike rpg about jelqing

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