an http based roguelike rpg about jelqing
Blame: src/game/mod.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | pub mod balance; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | mod body; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | mod clinic; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | mod floors; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | mod forum; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | mod hazards; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | mod household; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | mod items; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 9 | mod kitchen; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | mod outcome; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | mod shop; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | mod state; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | mod techniques; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | mod turn; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | mod utility; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | pub use body::PatchOp; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | pub use forum::{ELDER_LAST_MODIFIED, FORUM_THREAD, forum_thread}; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 19 | pub use items::{Item, Items, SHOP}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | pub use outcome::{Outcome, Payload}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | pub use state::{ |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 22 | Cause, Clinic, Conditions, Elder, Ending, Floor, FloorState, Grip, MumVisit, Observer, Story, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | pub use techniques::{LUBRICANTS, Lube, Technique}; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 25 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 26 | use std::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | hash::{DefaultHasher, Hash, Hasher}, |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 28 | time::{Duration, Instant, SystemTime}, |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 29 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 30 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | use axum::http::{StatusCode, header}; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 32 | use rand::{Rng, SeedableRng, rngs::StdRng}; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 33 | use serde_json::{Value, json}; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 34 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 35 | use crate::problem::Problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | use balance::{ |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 37 | HONEST_TOLERANCE, MAX_STAMINA, PRIAPISM_EQ, PULLED_STAMINA, SELF_REPORT_INFLATION, |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 38 | STARTING_CASH, STARTING_EQ, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | use state::Pending; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 41 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 42 | pub struct Run { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 43 | /// The private id in the run's URL. Knowing it is the only authorisation a run has. |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 44 | pub id: String, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | pub public_id: String, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | etag_salt: u64, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 47 | pub version: u64, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 48 | pub turn: u32, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 49 | pub floor: Floor, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | pub here: FloorState, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 51 | pub length: f64, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 52 | pub girth: f64, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 53 | pub foreskin: Option<f64>, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 54 | pub eq: i32, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 55 | pub stamina: i32, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 56 | pub suspicion: u8, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 57 | pub shame: u32, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | pub shame_reported: u32, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | pub shame_total: u32, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 60 | pub cash: u32, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 61 | pub grip: Grip, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 62 | pub friction: i32, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 63 | pub jelq_grip: Option<Grip>, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 64 | pub items: Items, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | pub conditions: Conditions, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 66 | pub warmed_up: bool, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 67 | pub put_applied: bool, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | pub story: Story, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 69 | pub meditation_taught: bool, |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 70 | pub kitchen_tellings: u8, |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 71 | pub mum: Option<MumVisit>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | pub heard: Vec<String>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | pub elder: Elder, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | pub clinic: Clinic, |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 75 | pub seeded: bool, |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 76 | pub filmed_at: Option<SystemTime>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | pub observed: Option<Observer>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | pub refractory: Duration, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 79 | pub refractory_until: Option<Instant>, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 80 | pub pending: Vec<Pending>, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 81 | pub notices: Vec<&'static str>, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 82 | pub ended: Option<Ending>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | pub last_seen: Instant, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 84 | rng: StdRng, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 85 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 86 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 87 | pub fn round2(x: f64) -> f64 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 88 | (x * 100.0).round() / 100.0 |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 89 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 90 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 91 | fn round3(x: f64) -> f64 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 92 | (x * 1000.0).round() / 1000.0 |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 93 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 94 | |
177535ac8abf | atagen | 2026-10-10 10:39 UTC | 95 | fn honest(claimed: f64, actual: f64) -> bool { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | (claimed - actual).abs() < HONEST_TOLERANCE |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 97 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 98 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 99 | fn not_extended() -> Problem { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 100 | Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 101 | StatusCode::NOT_EXTENDED, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 102 | "not-extended", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 103 | "The requested extension was not applied. The server has recorded the attempt.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 104 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 105 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 106 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 107 | pub fn parse_credentials<'a>(authorization: &'a str, scheme: &str) -> Option<&'a str> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 108 | let (given, rest) = authorization.trim().split_once(' ')?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 109 | given |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 110 | .eq_ignore_ascii_case(scheme) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 111 | .then(|| rest.trim().trim_matches('"')) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 112 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 113 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 114 | pub fn etag_matches(condition: &str, etag: &str) -> bool { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 115 | condition |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 116 | .split(',') |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 117 | .map(str::trim) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 118 | .any(|tag| tag == "*" || tag.trim_start_matches("W/") == etag) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 119 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 120 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 121 | pub fn shaft(mm: usize) -> String { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 122 | format!("8{}D", "=".repeat(mm.saturating_sub(2))) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 123 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 124 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 125 | impl Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | pub fn new(id: String, public_id: String, seed: u64) -> Self { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 127 | let mut rng = StdRng::seed_from_u64(seed); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 128 | let length = round2(rng.random_range(4.5..6.5)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 129 | let girth = round2(rng.random_range(4.0..5.0)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 130 | let foreskin = round2(rng.random_range(0.4..2.4)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | let etag_salt = rng.random(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | Self { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 133 | id, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | public_id, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | etag_salt, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 136 | version: 0, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 137 | turn: 0, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 138 | floor: Floor::Bedroom, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | here: FloorState::default(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 140 | length, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 141 | girth, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 142 | foreskin: Some(foreskin), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | eq: STARTING_EQ, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 144 | stamina: MAX_STAMINA, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 145 | suspicion: 0, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 146 | shame: 0, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | shame_reported: 0, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | shame_total: 0, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 149 | cash: STARTING_CASH, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 150 | grip: Grip::Overhand, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 151 | friction: 0, |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 152 | jelq_grip: None, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | items: Items::default(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | conditions: Conditions::default(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 155 | warmed_up: false, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 156 | put_applied: false, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | story: Story::Unopened, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 158 | meditation_taught: false, |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 159 | kitchen_tellings: 0, |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 160 | mum: None, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | heard: Vec::new(), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 162 | notices: Vec::new(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | elder: Elder::Unverified { strikes: 0 }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | clinic: Clinic::default(), |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 165 | seeded: false, |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 166 | filmed_at: None, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 167 | observed: None, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | refractory: Duration::from_secs(30), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 169 | refractory_until: None, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 170 | pending: Vec::new(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 171 | ended: None, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 172 | last_seen: Instant::now(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 173 | rng, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 174 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 175 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 176 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 177 | fn etag_at(&self, version: u64) -> String { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 178 | let mut hasher = DefaultHasher::new(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 179 | (self.etag_salt, version).hash(&mut hasher); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 180 | format!("\"{:016x}\"", hasher.finish()) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 181 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 182 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 183 | pub fn etag(&self) -> String { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 184 | self.etag_at(self.version) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 185 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 186 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 187 | /// The ETag the run had when it was created, which the true ending asks for. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | pub fn origin_etag(&self) -> String { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 189 | self.etag_at(0) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 190 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 191 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 192 | pub fn touch(&mut self) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 193 | self.version += 1; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 194 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 195 | |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 196 | pub(super) fn shed(&mut self, friction: i32) { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 197 | self.friction = (self.friction - friction).max(0); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 198 | } |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 199 | |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 200 | /// Priapism holds EQ up no matter what else moves it. |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 201 | pub(super) fn reset_eq(&mut self, eq: i32) { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 202 | let floor = if self.conditions.priapism_turns > 0 { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 203 | PRIAPISM_EQ |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 204 | } else { |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 205 | 0 |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 206 | }; |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 207 | self.eq = eq.max(floor); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 208 | } |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 209 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 210 | fn fresh_nonce(&mut self) -> String { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 211 | format!("{:016x}", self.rng.random::<u64>()) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 212 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 213 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 214 | fn chance(&mut self, odds: u32) -> bool { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 215 | self.rng.random_ratio(1, odds) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 216 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 217 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 218 | pub fn path(&self, sub: &str) -> String { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 219 | format!("/runs/{}{sub}", self.id) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 220 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 221 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 222 | pub fn current_length(&self) -> f64 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 223 | self.length + self.here.temp_length |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 224 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 225 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 226 | pub fn self_reported(&self) -> f64 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 227 | self.current_length() + SELF_REPORT_INFLATION |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 228 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 229 | |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 230 | pub fn max_stamina(&self) -> i32 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 231 | if self.conditions.pulled_muscle { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 232 | PULLED_STAMINA |
782069860236 | atagen | 2026-10-10 12:44 UTC | 233 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 234 | MAX_STAMINA |
782069860236 | atagen | 2026-10-10 12:44 UTC | 235 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 236 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 237 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 238 | pub fn forum_read(&self) -> bool { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 239 | self.story == Story::ReadForum |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 240 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 241 | |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 242 | pub fn footage(&self) -> Option<(SystemTime, u64)> { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 243 | let filmed = self.filmed_at?; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 244 | let age = filmed.elapsed().map_or(0, |d| d.as_secs()); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 245 | Some((filmed, age)) |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 246 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 247 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 248 | pub fn status(&self) -> &'static str { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 249 | match (&self.ended, self.clinic.cured) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 250 | (Some(_), _) => "gone", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 251 | (None, true) => "normal", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 252 | (None, false) => "alive", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 253 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 254 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 255 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 256 | /// The parts of the run that its response headers do not already carry. |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 257 | pub fn view(&self) -> Value { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 258 | let conditions: Vec<&str> = [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 259 | (self.here.teapot, "short and stout"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 260 | (self.conditions.peyronie, "curved"), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 261 | (self.items.cage, "caged"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 262 | (self.conditions.priapism_turns > 0, "priapism"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 263 | (self.conditions.pulled_muscle, "pulled muscle"), |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 264 | (self.filmed_at.is_some(), "viral"), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 265 | ] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 266 | .into_iter() |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 267 | .filter_map(|(active, name)| active.then_some(name)) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 268 | .collect(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 269 | json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 270 | "public_id": self.public_id, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 271 | "status": self.status(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 272 | "turn": self.turn, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 273 | "run_shame": self.shame, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 274 | "grip": self.grip.name(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 275 | "warmed_up": self.warmed_up, |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 276 | "ranked": !self.seeded, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 277 | "conditions": conditions, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 278 | }) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 279 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 280 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 281 | pub fn end(&mut self, cause: Cause) -> Problem { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 282 | self.ended = Some(Ending { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 283 | cause, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 284 | turn: self.turn, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 285 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 286 | cause.problem().with("turn", self.turn) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 287 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 288 | |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 289 | /// Ends the refractory period once it has run out, whatever the request. |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 290 | pub fn recover(&mut self, now: Instant) { |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 291 | if self.refractory_until.is_some_and(|until| now >= until) { |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 292 | self.refractory_until = None; |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 293 | self.stamina = self.max_stamina(); |
14de3e1e8dc2 | atagen | 2026-10-11 06:19 UTC | 294 | self.reset_eq(STARTING_EQ); |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 295 | self.warmed_up = false; |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 296 | self.touch(); |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 297 | } |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 298 | } |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 299 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 300 | fn check_refractory(&mut self, now: Instant) -> Result<(), Problem> { |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 301 | self.recover(now); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 302 | let Some(until) = self.refractory_until else { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 303 | return Ok(()); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 304 | }; |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 305 | let seconds = until.saturating_duration_since(now).as_secs() + 1; |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 306 | Err(Problem::new( |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 307 | StatusCode::TOO_MANY_REQUESTS, |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 308 | "overtrained", |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 309 | "Stamina is exhausted. The refractory period is in effect.", |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 310 | ) |
e76ab808e7ad | atagen | 2026-10-10 13:46 UTC | 311 | .header(header::RETRY_AFTER, seconds.to_string())) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 312 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 313 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 314 | fn exhaust(&mut self, now: Instant) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 315 | self.stamina = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 316 | self.refractory_until = Some(now + self.refractory); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 317 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 318 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 319 | fn realise(&mut self) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 320 | let (due, waiting): (Vec<_>, Vec<_>) = std::mem::take(&mut self.pending) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 321 | .into_iter() |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 322 | .partition(|p| p.due <= self.turn); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 323 | self.pending = waiting; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 324 | for p in due { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 325 | self.length += p.length; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 326 | self.girth += p.girth; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 327 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 328 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 329 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 330 | fn gain(&mut self, length: f64, girth: f64, foreskin: f64) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 331 | self.length += length; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 332 | self.girth += girth; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 333 | if let Some(f) = &mut self.foreskin { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 334 | *f += foreskin; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 335 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 336 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 337 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 338 | fn rupture(&mut self) -> Problem { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 339 | let cause = Cause::Ruptured { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 340 | ice_unused: self.items.ice_packs > 0, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 341 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 342 | self.end(cause) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 343 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 344 | } |