an http based roguelike rpg about jelqing
Blame: src/game/run.rs
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 1 | use std::{ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 2 | hash::{DefaultHasher, Hash, Hasher}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 3 | time::{Instant, SystemTime}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 4 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 5 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 6 | use axum::http::StatusCode; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 7 | use serde_json::{Value, json}; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 8 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 9 | use super::{ |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 10 | Body, Cause, Clinic, Ending, Floor, FloorState, Household, Item, Items, Notice, Observer, |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 11 | Online, RunStatus, Standing, Story, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | balance::{ |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 13 | BRANCH_TURN, FLOOR_LIMIT, MAX_STAMINA, PRIAPISM_EQ, PULLED_STAMINA, REFRACTORY_STAMINA, |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 14 | SECOND_WIND, SELF_REPORT_INFLATION, STARTING_BABY_OIL, STARTING_EQ, STARTING_LUBE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 15 | }, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 16 | measure::round2, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 17 | oracle::{Oracle, OracleTemplate, Roll}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 18 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 19 | use crate::problem::Problem; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 20 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 21 | pub struct Identity { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 22 | /// The private id in the run's URL. Knowing it is the only authorisation a run has. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 23 | pub(crate) id: String, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 24 | pub(crate) public_id: String, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 25 | pub(crate) seeded: bool, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 26 | etag_salt: u64, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 27 | pub(crate) version: u64, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 28 | pub(crate) last_seen: Instant, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 29 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 30 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 31 | pub struct Run { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 32 | pub(crate) ident: Identity, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 33 | pub(crate) body: Body, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 34 | pub(crate) standing: Standing, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 35 | pub(crate) household: Household, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 36 | pub(crate) online: Online, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 37 | pub(crate) items: Items, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 38 | pub(crate) clinic: Clinic, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 39 | pub(crate) turn: u32, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 40 | pub(crate) floor: Floor, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 41 | pub(crate) here: FloorState, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 42 | pub(crate) observed: Option<Observer>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 43 | pub(crate) notices: Vec<Notice>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 44 | pub(crate) ended: Option<Ending>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 45 | pub(super) oracle: Oracle, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 46 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 47 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 48 | impl Run { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 49 | #[cfg(test)] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 50 | pub fn new(id: String, public_id: String, seed: u64) -> Self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 51 | Self::with_oracle(id, public_id, seed, false, &OracleTemplate::Rng) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 52 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 53 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 54 | pub fn with_oracle( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | id: String, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 56 | public_id: String, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 57 | seed: u64, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 58 | seeded: bool, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 59 | template: &OracleTemplate, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 60 | ) -> Self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 61 | let mut oracle = Oracle::build(template, seed); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 62 | let length = round2(oracle.span( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 63 | Run::unborn("length", "How long is it, in inches?"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 64 | 4.5, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 65 | 6.5, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 66 | )); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 67 | let girth = round2(oracle.span( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 68 | Run::unborn("girth", "How thick is it, in inches?"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 69 | 4.0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 70 | 5.0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 71 | )); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 72 | let foreskin = round2(oracle.span( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 73 | Run::unborn("foreskin", "How much foreskin is there, in inches?"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 74 | 0.4, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 75 | 2.4, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 76 | )); |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 77 | let inflation = f64::from(oracle.span_int( |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 78 | Run::unborn( |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 79 | "inflation", |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 80 | "How far does the self-report round up, in tenths of an inch?", |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 81 | ), |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 82 | *SELF_REPORT_INFLATION.start(), |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 83 | *SELF_REPORT_INFLATION.end(), |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 84 | )) / 10.0; |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 85 | let mut items = Items::default(); |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 86 | if oracle.chance( |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 87 | Run::unborn( |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 88 | "starting-lube", |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 89 | "Is there a bottle of lube in the drawer already?", |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 90 | ), |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 91 | STARTING_LUBE, |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 92 | ) { |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 93 | let baby_oil = oracle.chance( |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 94 | Run::unborn( |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 95 | "starting-bottle", |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 96 | "Is the bottle baby oil, rather than lotion?", |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 97 | ), |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 98 | STARTING_BABY_OIL, |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 99 | ); |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 100 | items.grant(if baby_oil { |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 101 | Item::BabyOil |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 102 | } else { |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 103 | Item::Lotion |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 104 | }); |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 105 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 106 | let etag_salt = oracle.u64(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 107 | Self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 108 | ident: Identity { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 109 | id, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 110 | public_id, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 111 | seeded, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 112 | etag_salt, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 113 | version: 0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 114 | last_seen: Instant::now(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 115 | }, |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 116 | body: Body::new(length, girth, foreskin, inflation), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 117 | standing: Standing::default(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 118 | household: Household::default(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 119 | online: Online::default(), |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 120 | items, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 121 | clinic: Clinic::default(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 122 | turn: 0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 123 | floor: Floor::Bedroom, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 124 | here: FloorState::default(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 125 | observed: None, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 126 | notices: Vec::new(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 127 | ended: None, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 128 | oracle, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 129 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 130 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 131 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 132 | fn unborn(site: &'static str, ask: &'static str) -> Roll { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 133 | Roll { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 134 | state: "A new run is being created. No game has been played yet.".into(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 135 | site, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 136 | ask, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 137 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 138 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 139 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 140 | fn etag_at(&self, version: u64) -> String { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 141 | let mut hasher = DefaultHasher::new(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 142 | (self.ident.etag_salt, version).hash(&mut hasher); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 143 | format!("\"{:016x}\"", hasher.finish()) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 144 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 145 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 146 | pub fn etag(&self) -> String { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 147 | self.etag_at(self.ident.version) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 148 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 149 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 150 | /// The ETag the run had when it was created, which the true ending asks for. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 151 | pub fn origin_etag(&self) -> String { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 152 | self.etag_at(0) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 153 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 154 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 155 | pub fn touch(&mut self) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 156 | self.ident.version += 1; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 157 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 158 | |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 159 | pub(super) fn begin_turn(&mut self) -> Result<(), Problem> { |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 160 | self.check_clock()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 161 | self.touch(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 162 | self.turn += 1; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 163 | self.here.turns += 1; |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 164 | self.body.torn = 0.0; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 165 | self.standing.at_turn_start = self.standing.suspicion; |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 166 | self.realise(false); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 167 | if self.floor.timed() && self.here.turns + 2 == FLOOR_LIMIT { |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 168 | self.notices.push(Notice::RunningLong(self.floor)); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 169 | } else if self.floor.timed() && self.here.turns + 1 == FLOOR_LIMIT { |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 170 | self.notices.push(Notice::LastTurn); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 171 | } |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 172 | Ok(()) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 173 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 174 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 175 | pub(super) fn shed(&mut self, friction: i32) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 176 | self.body.friction = (self.body.friction - friction).max(0); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 177 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 178 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 179 | /// Priapism holds EQ up no matter what else moves it. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 180 | pub(super) fn reset_eq(&mut self, eq: i32) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 181 | let floor = if self.body.conditions.priapism_turns > 0 { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 182 | PRIAPISM_EQ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 183 | } else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 184 | 0 |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 185 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 186 | self.body.eq = eq.max(floor); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 187 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 188 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 189 | pub(super) fn end_kitchen_visit(&mut self) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 190 | self.here.kitchen.melon_offered = false; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 191 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 192 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 193 | /// Going back to the jelq walks away from both the fridge and Pump-Bro. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 194 | pub(super) fn step_away(&mut self) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 195 | self.end_kitchen_visit(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 196 | self.here.shopping = false; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 197 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 198 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 199 | pub(super) fn fresh_nonce(&mut self) -> String { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 200 | format!("{:016x}", self.oracle.u64()) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 201 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 202 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 203 | /// One game decision. The dice ignore the state prose, so it is only written for the model. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 204 | pub(super) fn decision(&self, site: &'static str, ask: &'static str) -> Roll { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 205 | Roll { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 206 | state: if self.oracle.listens() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 207 | self.oracle_state() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 208 | } else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 209 | String::new() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 210 | }, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 211 | site, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 212 | ask, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 213 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 214 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 215 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 216 | fn oracle_state(&self) -> String { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 217 | let mut s = format!( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 218 | "Floor {}, {}. Turn {}.\n\neq: {}\nstamina: {}\nfriction: {}\n", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 219 | self.floor.number(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 220 | self.floor.place(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 221 | self.turn, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 222 | self.body.eq, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 223 | self.body.stamina, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 224 | self.body.friction |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 225 | ); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 226 | let conditions = &self.body.conditions; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 227 | for (active, line) in [ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 228 | (conditions.friction_burn, "friction burn: yes, untreated\n"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 229 | (conditions.priapism_turns > 0, "priapism: yes\n"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 230 | (conditions.peyronie, "peyronie's disease: yes\n"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 231 | (conditions.pulled_muscle, "pulled muscle: yes\n"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 232 | ] { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 233 | if active { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 234 | s.push_str(line); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 235 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 236 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 237 | s.push_str(&format!( |
bf5f8cb6f60f | atagen | 2026-10-13 12:10 UTC | 238 | "suspicion: {}\nshame: {}\ngrip: {}\n", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 239 | self.standing.suspicion, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 240 | self.standing.shame, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 241 | self.body.grip.name(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 242 | )); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 243 | let held: Vec<&str> = self.items.owned().iter().map(|item| item.slug()).collect(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 244 | if !held.is_empty() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 245 | s.push_str(&format!("items: {}\n", held.join(", "))); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 246 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 247 | if self.household.mum.is_some() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 248 | s.push_str("Mum is at the door\n"); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 249 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 250 | s |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 251 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 252 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 253 | pub(super) fn chance(&mut self, roll: Roll, odds: u32) -> bool { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 254 | self.oracle.chance(roll, odds) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 255 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 256 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 257 | pub fn path(&self, sub: &str) -> String { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 258 | format!("/runs/{}{sub}", self.ident.id) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 259 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 260 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 261 | pub fn current_length(&self) -> f64 { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 262 | self.body.length + self.here.temp_length |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 263 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 264 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 265 | pub fn self_reported(&self) -> f64 { |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 266 | self.current_length() + self.body.inflation |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 267 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 268 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 269 | pub fn shown_length(&self) -> f64 { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 270 | if self.items.kit.ruler { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 271 | self.current_length() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 272 | } else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 273 | self.self_reported() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 274 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 275 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 276 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 277 | pub fn max_stamina(&self) -> i32 { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 278 | if self.body.conditions.pulled_muscle { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 279 | PULLED_STAMINA |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 280 | } else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 281 | MAX_STAMINA |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 282 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 283 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 284 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 285 | pub fn forum_read(&self) -> bool { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 286 | self.online.story == Story::ReadForum |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 287 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 288 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 289 | pub fn thread_reachable(&self) -> bool { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 290 | self.turn >= BRANCH_TURN |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 291 | || self.forum_read() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 292 | || self.floor.number() >= Floor::Forum.number() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 293 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 294 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 295 | pub fn footage(&self) -> Option<(SystemTime, u64)> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 296 | let filmed = self.online.filmed_at?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 297 | let age = filmed.elapsed().map_or(0, |d| d.as_secs()); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 298 | Some((filmed, age)) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 299 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 300 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 301 | pub fn status(&self) -> RunStatus { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 302 | if self.ended.is_some() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 303 | RunStatus::Gone |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 304 | } else if self.clinic.cured { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 305 | RunStatus::Normal |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 306 | } else if self.clinic.prescribed { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 307 | RunStatus::Prescribed |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 308 | } else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 309 | RunStatus::Alive |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 310 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 311 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 312 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 313 | /// The parts of the run that its response headers do not already carry. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 314 | pub fn view(&self) -> Value { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 315 | let conditions: Vec<&str> = [ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 316 | (self.here.teapot, "short and stout"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 317 | (self.body.conditions.peyronie, "curved"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 318 | (self.items.kit.cage, "caged"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 319 | (self.body.conditions.priapism_turns > 0, "priapism"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 320 | (self.body.conditions.pulled_muscle, "pulled muscle"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 321 | (self.online.filmed_at.is_some(), "viral"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 322 | ] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 323 | .into_iter() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 324 | .filter_map(|(active, name)| active.then_some(name)) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 325 | .collect(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 326 | json!({ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 327 | "public_id": self.ident.public_id, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 328 | "status": self.status().name(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 329 | "turn": self.turn, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 330 | "run_shame": self.standing.shame, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 331 | "grip": self.body.grip.name(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 332 | "ranked": !self.ident.seeded, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 333 | "conditions": conditions, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 334 | }) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 335 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 336 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 337 | pub fn end(&mut self, cause: Cause) -> Problem { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 338 | self.ended = Some(Ending { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 339 | cause, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 340 | turn: self.turn, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 341 | }); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 342 | cause.problem().with("turn", self.turn) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 343 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 344 | |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 345 | /// The refractory period is the next HOLD. Returns whether it rolled the second wind that refills stamina outright. |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 346 | pub(super) fn recover(&mut self) -> bool { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 347 | self.body.exhausted = false; |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 348 | let second_wind = self.chance( |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 349 | self.decision( |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 350 | "second-wind", |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 351 | "Does the refractory period end in a second wind?", |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 352 | ), |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 353 | SECOND_WIND, |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 354 | ); |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 355 | self.body.stamina = if second_wind { |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 356 | self.max_stamina() |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 357 | } else { |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 358 | let (lo, hi) = REFRACTORY_STAMINA; |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 359 | let back = self.oracle.span_int( |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 360 | self.decision( |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 361 | "refractory", |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 362 | "How much stamina comes back after the refractory period?", |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 363 | ), |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 364 | lo, |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 365 | hi, |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 366 | ); |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 367 | back.min(self.max_stamina()) |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 368 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 369 | self.reset_eq(STARTING_EQ); |
f48daa8adf59 | atagen | 2026-10-13 12:51 UTC | 370 | second_wind |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 371 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 372 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 373 | pub(super) fn check_exhausted(&self) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 374 | if !self.body.exhausted { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 375 | return Ok(()); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 376 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 377 | Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 378 | StatusCode::TOO_MANY_REQUESTS, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 379 | "overtrained", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 380 | "Stamina is exhausted. HOLD for the refractory period.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 381 | )) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 382 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 383 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 384 | pub(super) fn exhaust(&mut self) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 385 | self.body.stamina = 0; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 386 | self.body.exhausted = true; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 387 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 388 | |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 389 | /// Leaving a floor lets time pass, so everything still queued arrives at once. |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 390 | pub(super) fn realise(&mut self, everything: bool) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 391 | let (due, waiting): (Vec<_>, Vec<_>) = std::mem::take(&mut self.body.pending) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 392 | .into_iter() |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 393 | .partition(|p| everything || p.due <= self.turn); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 394 | self.body.pending = waiting; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 395 | for p in due { |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 396 | let foreskin = self.gain(p.length, p.girth, p.foreskin); |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 397 | let arrived = self.body.arrived.get_or_insert_default(); |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 398 | arrived.length += p.length; |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 399 | arrived.girth += p.girth; |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 400 | if let Some(grown) = foreskin { |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 401 | *arrived.foreskin.get_or_insert(0.0) += grown; |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 402 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 403 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 404 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 405 | |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 406 | /// The foreskin change it returns nets out whatever friction tore off this turn. |
97c05b741d8f | atagen | 2026-10-13 11:27 UTC | 407 | pub(super) fn gain(&mut self, length: f64, girth: f64, foreskin: f64) -> Option<f64> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 408 | self.body.length += length; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 409 | self.body.girth += girth; |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 410 | let torn = std::mem::take(&mut self.body.torn); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 411 | let grown = match &mut self.body.foreskin { |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 412 | Some(f) => { |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 413 | *f += foreskin; |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 414 | foreskin |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 415 | } |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 416 | None => 0.0, |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 417 | }; |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 418 | (grown != 0.0 || torn != 0.0).then_some(grown - torn) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 419 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 420 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 421 | pub(super) fn rupture(&mut self) -> Problem { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 422 | let cause = Cause::Ruptured { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 423 | ice_unused: self.items.stores.ice_packs > 0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 424 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 425 | self.end(cause) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 426 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 427 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 428 | /// A run whose lock was poisoned by a panic mid-turn cannot be trusted to carry on. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 429 | pub fn lose(&mut self) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 430 | if self.ended.is_none() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 431 | self.end(Cause::Lost); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 432 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 433 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 434 | } |