an http based roguelike rpg about jelqing
Blame: src/game/turn.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use std::{fmt::Write as _, ops::ControlFlow, time::Instant}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | use axum::http::{StatusCode, header}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | use rand::Rng; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | use serde_json::json; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | use super::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | Floor, Grip, LUBRICANTS, Lube, Outcome, Payload, Run, Story, Technique, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | balance::{ |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 10 | BAND_BONUS, BRANCH_TURN, CAT_TAKES_TOWEL, CHANGING_ROOM_CHILL, DANGER_EQ, EQ_BAND, |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 11 | EQ_WOBBLE, EXTENDER_GAIN, HOT_EQ, OBSERVED, PRIAPISM_EQ, PRIAPISM_TURNS, PULLED_MUSCLE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | PULLED_MUSCLE_INTENSITY, RING_PRIAPISM, RING_RUPTURE_LINE, RUPTURE_LINE, STORAGE_GIRTH, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | SUSPICION_LIMIT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | not_extended, round3, |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 16 | state::{MumVisit, Observer, Pending}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | techniques::{LubeRule, Profile, Training, Utility}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | use crate::{headers::SERVER_TIMING, problem::Problem}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | impl Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | pub fn jelq( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | &mut self, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | techniques: &[Technique], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | intensity: i32, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | lube: Option<Lube>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | now: Instant, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | ) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | self.check_refractory(now)?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | if self.story == Story::Pending { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | return Ok(self.branch_offer()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | if self.floor == Floor::Forum { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | return Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | StatusCode::SEE_OTHER, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | json!({ "detail": "Refer to the forum." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | .header(header::LOCATION, super::FORUM_THREAD)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | if self.items.cage { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | StatusCode::LOCKED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | "caged", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | "The cage is locked. The key is not in the box.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | match *techniques { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | [Technique::Utility(utility)] => self.utility(utility, lube, now), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | [Technique::Training(training)] => self.single(training, intensity, lube, now), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | [Technique::Training(a), Technique::Training(b)] => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | self.combo(a, b, intensity, lube, now) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | [_, _] => Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | StatusCode::BAD_REQUEST, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | "combo-invalid", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | "Only training techniques can be combined.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | )), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | _ => Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | StatusCode::BAD_REQUEST, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | "too-many-techniques", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | "Two techniques at most. The server has limits even if you do not.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | )), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | fn utility( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | &mut self, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | utility: Utility, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | lube: Option<Lube>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | now: Instant, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 71 | ) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | match utility { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | Utility::Warmup => return self.warm_up(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | Utility::Ice => return self.ice(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | Utility::Supplement => return self.supplement(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | Utility::Edge | Utility::Pump => {} |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | if utility == Utility::Pump { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | self.here.edges = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | self.ready(Technique::Utility(utility), lube)?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | self.check_storage()?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | self.floor_enemy()?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | match utility { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | Utility::Edge => self.edge(now), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | _ => self.pump(now), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 87 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | fn single( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | &mut self, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | training: Training, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | intensity: i32, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | lube: Option<Lube>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | now: Instant, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | ) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | self.here.edges = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | self.ready(Technique::Training(training), lube)?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | self.check_storage()?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | self.floor_enemy()?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | self.commit(intensity, lube, now, 1); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | if let ControlFlow::Break(interrupted) = self.mishaps(training, intensity)? { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | return Ok(interrupted); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | if let ControlFlow::Break(interrupted) = self.hazards(intensity)? { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | return Ok(interrupted); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | let outcome = self.roll(training, intensity, lube)?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | Ok(self.gossip(outcome)) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | fn combo( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | &mut self, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | a: Training, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | b: Training, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | intensity: i32, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | lube: Option<Lube>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | now: Instant, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | ) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | if a == b { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | StatusCode::BAD_REQUEST, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | "combo-invalid", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | "A technique cannot be combined with itself. The server has checked.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | self.here.edges = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | self.ready(Technique::Training(a), lube)?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | self.ready(Technique::Training(b), lube)?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | self.check_storage()?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | self.floor_enemy()?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | self.commit(intensity, lube, now, 2); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | for training in [a, b] { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | if let ControlFlow::Break(interrupted) = self.mishaps(training, intensity)? { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | return Ok(interrupted); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | if let ControlFlow::Break(interrupted) = self.hazards(intensity)? { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | return Ok(interrupted); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | let mut statuses = Vec::new(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | for training in [a, b] { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | let result = self.roll(training, intensity, lube); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | if self.ended.is_some() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | return result; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | let status = match result { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | Ok(outcome) => self.gossip(outcome).status, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | Err(problem) => problem.status(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | statuses.push((training, status)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | let mut xml = String::from( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<D:multistatus xmlns:D=\"DAV:\">\n", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | for (training, status) in statuses { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | let _ = write!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | xml, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | " <D:response>\n <D:href>{}?technique={}</D:href>\n <D:status>HTTP/1.1 {} {}</D:status>\n </D:response>\n", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | self.path(""), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | training.name(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | status.as_u16(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | crate::problem::reason(status), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | xml.push_str( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 169 | " <D:responsedescription>Each technique has been reported separately.</D:responsedescription>\n</D:multistatus>\n", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 170 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 171 | Ok(Outcome::raw( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 172 | StatusCode::MULTI_STATUS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 173 | "application/xml; charset=utf-8", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 174 | xml, |
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 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 178 | fn ready(&self, technique: Technique, lube: Option<Lube>) -> Result<(), Problem> { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 179 | self.access(technique)?; |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 180 | match technique { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 181 | Technique::Training(training) => Self::check_lube(training, lube), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 182 | Technique::Utility(_) => Ok(()), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 183 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 184 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 185 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 186 | /// Whether the run could attempt the technique now, ignoring the lubricant. |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 187 | fn access(&self, technique: Technique) -> Result<(), Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | if technique == Technique::Training(Training::Uli) && !self.forum_read() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 189 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 190 | StatusCode::FORBIDDEN, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 191 | "technique-locked", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 192 | "This technique is discussed on the forum. You have not been to the forum.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 193 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 194 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 195 | if !self.warmed_up { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 196 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 197 | StatusCode::PRECONDITION_FAILED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 198 | "cold-start", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 199 | "Warm-up was skipped. The server has noted this.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 200 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 201 | .with("technique", Utility::Warmup.name())); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 202 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 203 | match technique { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 204 | Technique::Utility(Utility::Pump) if !self.items.pump_pro => Err(Problem::new( |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 205 | StatusCode::FAILED_DEPENDENCY, |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 206 | "no-pump", |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 207 | "The pump technique depends on a pump.", |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 208 | )), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 209 | Technique::Utility(_) => Ok(()), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 210 | Technique::Training(training) => match training.profile().foreskin { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 211 | Some((min, max)) => self.check_foreskin(min, max), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 212 | None => Ok(()), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 213 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 214 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 215 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 216 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 217 | fn check_lube(training: Training, lube: Option<Lube>) -> Result<(), Problem> { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 218 | match (training.profile().lube, lube) { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 219 | (LubeRule::Required, None) => Err(Problem::new( |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 220 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 221 | "lubricant-required", |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 222 | format!( |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 223 | "The {} technique requires a lubricant. None was declared.", |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 224 | training.name() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 225 | ), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 226 | ) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 227 | .with("lubricants", json!(LUBRICANTS))), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 228 | (LubeRule::Forbidden, Some(_)) => Err(Problem::new( |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 229 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 230 | "lubricant-declared", |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 231 | format!( |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 232 | "The {} technique was requested. A lubricant was declared.", |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 233 | training.name() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 234 | ), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 235 | )), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 236 | _ => Ok(()), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 237 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 238 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 239 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 240 | /// The techniques a JELQ could use right now without being refused before the roll. |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 241 | pub fn techniques_now(&self, now: Instant) -> Vec<Technique> { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 242 | let blocked = !self.floor.timed() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 243 | || self.items.cage |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 244 | || self.story == Story::Pending |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 245 | || self.refractory_until.is_some_and(|until| now < until); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 246 | if blocked { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 247 | return Vec::new(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 248 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 249 | let rested = self.refractory_until.is_some(); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 250 | Technique::ALL |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 251 | .into_iter() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 252 | .filter(|&technique| match technique { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 253 | Technique::Utility(Utility::Warmup) => true, |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 254 | Technique::Utility(Utility::Ice) => self.items.ice_packs > 0, |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 255 | Technique::Utility(Utility::Supplement) => self.items.supplements > 0, |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 256 | _ if rested => false, |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 257 | _ => self.access(technique).is_ok() && self.check_storage().is_ok(), |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 258 | }) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 259 | .collect() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 260 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 261 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 262 | fn check_foreskin(&self, min: f64, max: f64) -> Result<(), Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 263 | let Some(f) = self.foreskin else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 264 | if min <= 0.0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 265 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 266 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 267 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 268 | StatusCode::GONE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 269 | "foreskin-gone", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 270 | "This technique requires a foreskin. The foreskin is gone.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 271 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 272 | .header(header::CONTENT_LOCATION, self.path("/foreskin"))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 273 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 274 | if f < min { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 275 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 276 | StatusCode::LENGTH_REQUIRED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 277 | "foreskin-insufficient", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 278 | format!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 279 | "The selected technique requires {min:.1} units of foreskin. {f:.2} units are available. The server has noted the shortfall." |
782069860236 | atagen | 2026-10-10 12:44 UTC | 280 | ), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 281 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 282 | .with("required", min)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 283 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 284 | if f > max { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 285 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 286 | StatusCode::PAYLOAD_TOO_LARGE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 287 | "foreskin-excessive", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 288 | format!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 289 | "The selected technique tolerates at most {max:.1} units of foreskin. {f:.2} units are present." |
782069860236 | atagen | 2026-10-10 12:44 UTC | 290 | ), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 291 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 292 | .with("maximum", max)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 293 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 294 | Ok(()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 295 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 296 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 297 | fn check_storage(&self) -> Result<(), Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 298 | if self.items.extender && self.girth > STORAGE_GIRTH { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 299 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 300 | StatusCode::INSUFFICIENT_STORAGE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 301 | "jeans-full", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 302 | "The jeans are full. The extender is occupying the remaining storage.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 303 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 304 | .with("extender", self.path("/inventory/extender"))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 305 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 306 | Ok(()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 307 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 308 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 309 | pub(super) fn commit(&mut self, intensity: i32, lube: Option<Lube>, now: Instant, cost: i32) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 310 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 311 | self.turn += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 312 | self.here.turns += 1; |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 313 | self.realise(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 314 | if self.items.extender { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 315 | self.length += EXTENDER_GAIN; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 316 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 317 | self.stamina -= cost + i32::from(lube == Some(Lube::Lotion)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 318 | if self.stamina <= 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 319 | self.exhaust(now); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 320 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 321 | let chill = if self.floor == Floor::ChangingRoom { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 322 | CHANGING_ROOM_CHILL |
782069860236 | atagen | 2026-10-10 12:44 UTC | 323 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 324 | 0 |
782069860236 | atagen | 2026-10-10 12:44 UTC | 325 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 326 | let wobble = self.rng.random_range(-EQ_WOBBLE..=EQ_WOBBLE); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 327 | self.eq = (self.eq + intensity * 2 - 6 - chill + wobble).clamp(0, 100); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 328 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 329 | let mut suspicion = intensity / 5 + i32::from(lube == Some(Lube::Vaseline)); |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 330 | if matches!(self.floor, Floor::ChangingRoom | Floor::Nans) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 331 | suspicion *= 2; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 332 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 333 | if self.floor == Floor::Nans && lube == Some(Lube::CoconutOil) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 334 | suspicion += 2; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 335 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 336 | let was_below = self.suspicion < SUSPICION_LIMIT; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 337 | self.suspicion = |
782069860236 | atagen | 2026-10-10 12:44 UTC | 338 | u8::try_from((i32::from(self.suspicion) + suspicion).min(i32::from(SUSPICION_LIMIT))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 339 | .unwrap_or(SUSPICION_LIMIT); |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 340 | self.maybe_summon_mum(was_below); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 341 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 342 | if let Some(observer) = self.floor.observer() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 343 | && self.chance(OBSERVED) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 344 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 345 | self.observed = Some(observer); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 346 | self.shame += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 347 | if observer == Observer::Cat && self.chance(CAT_TAKES_TOWEL) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 348 | self.here.towel_stolen = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 349 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 350 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 351 | if intensity >= PULLED_MUSCLE_INTENSITY |
782069860236 | atagen | 2026-10-10 12:44 UTC | 352 | && !self.conditions.pulled_muscle |
782069860236 | atagen | 2026-10-10 12:44 UTC | 353 | && self.chance(PULLED_MUSCLE) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 354 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 355 | self.conditions.pulled_muscle = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 356 | self.stamina = self.stamina.min(self.max_stamina()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 357 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 358 | if self.items.ring && self.eq > HOT_EQ && self.chance(RING_PRIAPISM) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 359 | self.conditions.priapism_turns = PRIAPISM_TURNS; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 360 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 361 | if self.conditions.priapism_turns > 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 362 | self.conditions.priapism_turns -= 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 363 | self.eq = self.eq.max(PRIAPISM_EQ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 364 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 365 | if self.turn == BRANCH_TURN && self.story == Story::Unopened { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 366 | self.story = Story::Pending; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 367 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 368 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 369 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 370 | fn maybe_summon_mum(&mut self, was_below: bool) { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 371 | if !self.floor.has_mum() || self.mum.is_some() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 372 | return; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 373 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 374 | let summoned = was_below && self.suspicion == SUSPICION_LIMIT; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 375 | let visits = u32::from(self.suspicion) + 1; |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 376 | if summoned || self.rng.random_ratio(visits, super::balance::MUM_VISIT) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 377 | let errand = self.errand(summoned); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 378 | let nonce = self.fresh_nonce(); |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 379 | self.mum = Some(MumVisit { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 380 | errand, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 381 | nonce, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 382 | strikes: 0, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 383 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 384 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 385 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 386 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 387 | fn roll( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 388 | &mut self, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 389 | training: Training, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 390 | intensity: i32, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 391 | lube: Option<Lube>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 392 | ) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 393 | let profile = training.profile(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 394 | let natural: i32 = self.rng.random_range(1..=20); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 395 | let band = if EQ_BAND.contains(&self.eq) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 396 | BAND_BONUS |
782069860236 | atagen | 2026-10-10 12:44 UTC | 397 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 398 | 0 |
782069860236 | atagen | 2026-10-10 12:44 UTC | 399 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 400 | let grip = match (self.grip, training) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 401 | (Grip::Underhand, Training::Stretch) => 2, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 402 | (Grip::Underhand, Training::Wet) => -1, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 403 | _ => 0, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 404 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 405 | let modifier = lube.map_or(0, Lube::modifier) + band + grip; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 406 | let dc = profile.dc + intensity / 3; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 407 | let total = natural + modifier; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 408 | let timing = format!("roll;desc=\"d20{modifier:+} vs {dc}\";dur={natural}"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 409 | let timed = |p: Problem| p.header(SERVER_TIMING, &timing); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 410 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 411 | let (length, girth) = self.scaled_gains(&profile, intensity); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 412 | let rupture_line = if self.items.ring { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 413 | RING_RUPTURE_LINE |
782069860236 | atagen | 2026-10-10 12:44 UTC | 414 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 415 | RUPTURE_LINE |
782069860236 | atagen | 2026-10-10 12:44 UTC | 416 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 417 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 418 | if natural == 1 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 419 | return Err(timed(self.critical_failure(training, &profile))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 420 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 421 | if natural == 2 && self.eq > DANGER_EQ { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 422 | return Err(timed(self.rupture())); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 423 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 424 | if self.eq > rupture_line && total < dc { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 425 | return Err(timed(self.rupture())); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 426 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 427 | if natural == 20 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 428 | self.gain(length * 2.0, girth * 2.0, profile.foreskin_growth); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 429 | return Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 430 | StatusCode::PERMANENT_REDIRECT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 431 | json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 432 | "detail": "Your length has moved permanently.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 433 | "length": round3(length * 2.0), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 434 | "girth": round3(girth * 2.0), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 435 | }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 436 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 437 | .header(header::LOCATION, self.path("/length")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 438 | .header(SERVER_TIMING, timing)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 439 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 440 | if total < dc - 3 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 441 | return Err(timed(not_extended())); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 442 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 443 | if total < dc { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 444 | return Ok(Outcome::empty(StatusCode::NO_CONTENT).header(SERVER_TIMING, timing)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 445 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 446 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 447 | let outcome = if self.eq < *EQ_BAND.start() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 448 | self.gain(length / 2.0, girth / 2.0, profile.foreskin_growth); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 449 | Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 450 | StatusCode::PARTIAL_CONTENT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 451 | json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 452 | "detail": "Partial gains were applied. EQ was below the band.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 453 | "length": round3(length / 2.0), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 454 | "girth": round3(girth / 2.0), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 455 | }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 456 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 457 | } else if total >= dc + 5 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 458 | self.gain(length, girth, profile.foreskin_growth); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 459 | Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 460 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 461 | json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 462 | "detail": "Gains were applied.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 463 | "length": round3(length), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 464 | "girth": round3(girth), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 465 | }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 466 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 467 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 468 | let eta = self.rng.random_range(1..=4); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 469 | self.pending.push(Pending { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 470 | due: self.turn + eta, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 471 | length, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 472 | girth, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 473 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 474 | self.gain(0.0, 0.0, profile.foreskin_growth); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 475 | Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 476 | StatusCode::ACCEPTED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 477 | json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 478 | "detail": "Gains have been queued. They may arrive.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 479 | "eta_turns": eta, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 480 | }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 481 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 482 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 483 | Ok(outcome.header(SERVER_TIMING, timing)) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 484 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 485 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 486 | fn scaled_gains(&self, profile: &Profile, intensity: i32) -> (f64, f64) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 487 | let scale = f64::from(intensity); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 488 | let (mut length, mut girth) = (profile.length * scale, profile.girth * scale); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 489 | if self.here.teapot { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 490 | length *= 0.5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 491 | girth *= 1.5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 492 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 493 | if self.items.ring { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 494 | girth *= 2.0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 495 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 496 | (length, girth) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 497 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 498 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 499 | fn critical_failure(&mut self, training: Training, profile: &Profile) -> Problem { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 500 | let uses_foreskin = profile.foreskin.is_some_and(|(min, _)| min > 0.0); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 501 | if uses_foreskin && self.foreskin.is_some() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 502 | self.foreskin = None; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 503 | self.shame += 25; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 504 | return Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 505 | StatusCode::GONE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 506 | "foreskin-lost", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 507 | "The technique has removed the foreskin. It will not be returning.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 508 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 509 | .header(header::CONTENT_LOCATION, self.path("/foreskin")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 510 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 511 | if self.eq > DANGER_EQ { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 512 | return self.rupture(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 513 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 514 | if training == Training::Stretch && !self.here.teapot { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 515 | self.here.teapot = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 516 | self.items.teapot_spout = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 517 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 518 | return Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 519 | StatusCode::IM_A_TEAPOT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 520 | "teapot", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 521 | "The subject is now short and stout. Length gains are halved for the rest of the floor.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 522 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 523 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 524 | if training == Training::Uli && !self.conditions.peyronie { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 525 | self.conditions.peyronie = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 526 | self.shame += 5; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 527 | return Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 528 | StatusCode::MISDIRECTED_REQUEST, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 529 | "curvature", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 530 | "A curvature has developed. Techniques will land slightly to the left until a professional is consulted.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 531 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 532 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 533 | not_extended() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 534 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 535 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 536 | fn gossip(&mut self, mut outcome: Outcome) -> Outcome { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 537 | let reportable = matches!(outcome.status.as_u16(), 200 | 202 | 206); |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 538 | if !self.here.flatmate_told || !reportable { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 539 | return outcome; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 540 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 541 | self.here.flatmate_told = false; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 542 | outcome.status = StatusCode::ALREADY_REPORTED; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 543 | if let Payload::Json(body) = &mut outcome.payload { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 544 | body["detail"] = json!("The flatmate has already told everyone."); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 545 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 546 | outcome |
782069860236 | atagen | 2026-10-10 12:44 UTC | 547 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 548 | } |