atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
f16ab17c8ff6e8e90a8d6658a1fa79039509d7d7
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,
8b8e83329a1datagen2026-10-12 12:01 UTC5
        LOCKER_ROOM_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,
8b8e83329a1datagen2026-10-12 12:01 UTC18
}
782069860236atagen2026-10-10 12:44 UTC19
782069860236atagen2026-10-10 12:44 UTC20
impl Run {
8b8e83329a1datagen2026-10-12 12:01 UTC21
    pub(super) fn next_floor(&mut self, exit: Exit) {
782069860236atagen2026-10-10 12:44 UTC22
        let Some(next) = self.floor.next() else {
782069860236atagen2026-10-10 12:44 UTC23
            return;
782069860236atagen2026-10-10 12:44 UTC24
        };
8b8e83329a1datagen2026-10-12 12:01 UTC25
        let warm = EQ_BAND.contains(&self.body.eq);
782069860236atagen2026-10-10 12:44 UTC26
        self.floor = next;
4347977b8192atagen2026-10-11 04:56 UTC27
        self.here = FloorState {
4347977b8192atagen2026-10-11 04:56 UTC28
            warm_arrival: warm,
4347977b8192atagen2026-10-11 04:56 UTC29
            ..FloorState::default()
4347977b8192atagen2026-10-11 04:56 UTC30
        };
8b8e83329a1datagen2026-10-12 12:01 UTC31
        self.body.warmed_up = false;
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
782069860236atagen2026-10-10 12:44 UTC46
    pub fn advance(&mut self) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC47
        match self.floor {
782069860236atagen2026-10-10 12:44 UTC48
            Floor::Clinic => {
782069860236atagen2026-10-10 12:44 UTC49
                return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC50
                    StatusCode::CONFLICT,
782069860236atagen2026-10-10 12:44 UTC51
                    "no-further-floor",
782069860236atagen2026-10-10 12:44 UTC52
                    "There is no further floor. There is only the diagnosis.",
782069860236atagen2026-10-10 12:44 UTC53
                ));
782069860236atagen2026-10-10 12:44 UTC54
            }
8b8e83329a1datagen2026-10-12 12:01 UTC55
            Floor::Forum if self.online.elder != Elder::Beaten => {
782069860236atagen2026-10-10 12:44 UTC56
                return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC57
                    StatusCode::CONFLICT,
782069860236atagen2026-10-10 12:44 UTC58
                    "elder-unaddressed",
782069860236atagen2026-10-10 12:44 UTC59
                    "The Elder has not been addressed.",
782069860236atagen2026-10-10 12:44 UTC60
                )
782069860236atagen2026-10-10 12:44 UTC61
                .with("elder", self.path("/elder")));
782069860236atagen2026-10-10 12:44 UTC62
            }
782069860236atagen2026-10-10 12:44 UTC63
            floor if floor.timed() && self.here.turns < FLOOR_TURNS => {
782069860236atagen2026-10-10 12:44 UTC64
                return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC65
                    StatusCode::TOO_EARLY,
782069860236atagen2026-10-10 12:44 UTC66
                    "floor-not-over",
782069860236atagen2026-10-10 12:44 UTC67
                    format!(
782069860236atagen2026-10-10 12:44 UTC68
                        "The floor is not over. {} turns remain.",
782069860236atagen2026-10-10 12:44 UTC69
                        FLOOR_TURNS - self.here.turns
782069860236atagen2026-10-10 12:44 UTC70
                    ),
782069860236atagen2026-10-10 12:44 UTC71
                ));
782069860236atagen2026-10-10 12:44 UTC72
            }
782069860236atagen2026-10-10 12:44 UTC73
            _ => {}
782069860236atagen2026-10-10 12:44 UTC74
        }
3f9091557ec3atagen2026-10-11 11:43 UTC75
        if self.chance(
3f9091557ec3atagen2026-10-11 11:43 UTC76
            self.decision(
3f9091557ec3atagen2026-10-11 11:43 UTC77
                "zip",
3f9091557ec3atagen2026-10-11 11:43 UTC78
                "As the floor ends and you put yourself away, does the zip catch?",
3f9091557ec3atagen2026-10-11 11:43 UTC79
            ),
3f9091557ec3atagen2026-10-11 11:43 UTC80
            ZIP,
3f9091557ec3atagen2026-10-11 11:43 UTC81
        ) {
9683736a2c5eatagen2026-10-10 13:15 UTC82
            return Err(self.end(Cause::Zip));
782069860236atagen2026-10-10 12:44 UTC83
        }
7d3fb63208bfatagen2026-10-11 04:38 UTC84
        let left = self.floor.name();
782069860236atagen2026-10-10 12:44 UTC85
        let reverted = self.here.temp_length;
8b8e83329a1datagen2026-10-12 12:01 UTC86
        self.next_floor(Exit::Proper);
4347977b8192atagen2026-10-11 04:56 UTC87
        let warm = if self.here.warm_arrival {
4347977b8192atagen2026-10-11 04:56 UTC88
            ", and the warmth came with you"
4347977b8192atagen2026-10-11 04:56 UTC89
        } else {
4347977b8192atagen2026-10-11 04:56 UTC90
            ""
4347977b8192atagen2026-10-11 04:56 UTC91
        };
782069860236atagen2026-10-10 12:44 UTC92
        let mut body = json!({
4347977b8192atagen2026-10-11 04:56 UTC93
            "detail": format!("You leave {left}. You have arrived at {}{warm}.", self.floor.name()),
782069860236atagen2026-10-10 12:44 UTC94
            "note": self.floor.note(),
782069860236atagen2026-10-10 12:44 UTC95
        });
782069860236atagen2026-10-10 12:44 UTC96
        if reverted > 0.0 {
782069860236atagen2026-10-10 12:44 UTC97
            body["reverted"] = json!(round2(reverted));
782069860236atagen2026-10-10 12:44 UTC98
        }
782069860236atagen2026-10-10 12:44 UTC99
        Ok(
782069860236atagen2026-10-10 12:44 UTC100
            Outcome::json(StatusCode::SEE_OTHER, body)
782069860236atagen2026-10-10 12:44 UTC101
                .header(header::LOCATION, self.path("/floor")),
782069860236atagen2026-10-10 12:44 UTC102
        )
782069860236atagen2026-10-10 12:44 UTC103
    }
782069860236atagen2026-10-10 12:44 UTC104
782069860236atagen2026-10-10 12:44 UTC105
    pub fn floor_view(&self) -> Value {
782069860236atagen2026-10-10 12:44 UTC106
        let mut view = json!({
782069860236atagen2026-10-10 12:44 UTC107
            "name": self.floor.name(),
782069860236atagen2026-10-10 12:44 UTC108
            "note": self.floor.note(),
782069860236atagen2026-10-10 12:44 UTC109
            "turns": self.here.turns,
782069860236atagen2026-10-10 12:44 UTC110
            "turns_required": self.floor.timed().then_some(FLOOR_TURNS),
782069860236atagen2026-10-10 12:44 UTC111
            "exit": { "href": self.path("/floor"), "method": "POST" },
782069860236atagen2026-10-10 12:44 UTC112
        });
782069860236atagen2026-10-10 12:44 UTC113
        match self.floor {
9683736a2c5eatagen2026-10-10 13:15 UTC114
            Floor::ChangingRoom => {
8b8e83329a1datagen2026-10-12 12:01 UTC115
                let others: Vec<Value> = LOCKER_ROOM_OTHERS
8b8e83329a1datagen2026-10-12 12:01 UTC116
                    .into_iter()
8b8e83329a1datagen2026-10-12 12:01 UTC117
                    .chain([("Kev", LOCKER_ROOM_BAR)])
8b8e83329a1datagen2026-10-12 12:01 UTC118
                    .map(|(name, length)| json!({ "name": name, "self_reported_length": length }))
8b8e83329a1datagen2026-10-12 12:01 UTC119
                    .collect();
8b8e83329a1datagen2026-10-12 12:01 UTC120
                view["others"] = json!(others);
782069860236atagen2026-10-10 12:44 UTC121
            }
782069860236atagen2026-10-10 12:44 UTC122
            Floor::Hotel => view["portal"] = json!(self.path("/portal")),
782069860236atagen2026-10-10 12:44 UTC123
            Floor::Forum => {
782069860236atagen2026-10-10 12:44 UTC124
                view["thread"] = json!(super::FORUM_THREAD);
782069860236atagen2026-10-10 12:44 UTC125
                view["elder"] = json!(self.path("/elder"));
782069860236atagen2026-10-10 12:44 UTC126
            }
782069860236atagen2026-10-10 12:44 UTC127
            Floor::Clinic => view["diagnosis"] = json!(self.path("/diagnosis")),
782069860236atagen2026-10-10 12:44 UTC128
            _ => {}
782069860236atagen2026-10-10 12:44 UTC129
        }
782069860236atagen2026-10-10 12:44 UTC130
        if self.floor.shop_open() {
782069860236atagen2026-10-10 12:44 UTC131
            view["shop"] = json!(self.path("/shop"));
782069860236atagen2026-10-10 12:44 UTC132
        }
782069860236atagen2026-10-10 12:44 UTC133
        view
782069860236atagen2026-10-10 12:44 UTC134
    }
782069860236atagen2026-10-10 12:44 UTC135
782069860236atagen2026-10-10 12:44 UTC136
    pub fn accept_terms(&mut self) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC137
        if self.floor != Floor::Hotel {
782069860236atagen2026-10-10 12:44 UTC138
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC139
                StatusCode::NOT_FOUND,
782069860236atagen2026-10-10 12:44 UTC140
                "no-portal",
782069860236atagen2026-10-10 12:44 UTC141
                "There is no captive portal here. There is only the regular kind of captivity.",
782069860236atagen2026-10-10 12:44 UTC142
            ));
782069860236atagen2026-10-10 12:44 UTC143
        }
782069860236atagen2026-10-10 12:44 UTC144
        self.here.wifi_accepted = true;
782069860236atagen2026-10-10 12:44 UTC145
        self.touch();
782069860236atagen2026-10-10 12:44 UTC146
        Ok(Outcome::json(
782069860236atagen2026-10-10 12:44 UTC147
            StatusCode::SEE_OTHER,
782069860236atagen2026-10-10 12:44 UTC148
            json!({ "detail": "Connected. The hotel does not want to know." }),
782069860236atagen2026-10-10 12:44 UTC149
        )
782069860236atagen2026-10-10 12:44 UTC150
        .header(header::LOCATION, self.path("")))
782069860236atagen2026-10-10 12:44 UTC151
    }
782069860236atagen2026-10-10 12:44 UTC152
}