an http based roguelike rpg about jelqing
Blame: src/game/jelq.rs
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 1 | use std::{ |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 2 | fmt::Write as _, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 3 | time::{Duration, Instant, SystemTime}, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 4 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 5 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 6 | use axum::http::{StatusCode, header}; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 7 | use rand::Rng; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 8 | use serde_json::json; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 9 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 10 | use super::{ |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 11 | CLINIC_ALLOW, FORUM_THREAD, Floor, Grip, Lube, Outcome, REFRACTORY, Run, SERVER_TIMING, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 12 | SUSPICION_LIMIT, Technique, catalog::LubeRule, catalog::Profile, not_extended, round3, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 13 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 14 | use crate::{game::LUBRICANTS, problem::Problem}; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 15 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 16 | const WEEK: Duration = Duration::from_secs(7 * 24 * 60 * 60); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 17 | const PRIAPISM_TURNS: u8 = 5; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 18 | const PRIAPISM_EQ: i32 = 75; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 19 | const DEGLOVED: &str = |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 20 | "The outer layer has been removed in one piece. It will not be returning. The run has ended."; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 21 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 22 | impl Run { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 23 | pub fn jelq( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 24 | &mut self, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 25 | techniques: &[Technique], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 26 | intensity: i32, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 27 | lube: Option<Lube>, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 28 | now: Instant, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 29 | ) -> Result<Outcome, Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 30 | self.check_refractory(now)?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 31 | if self.branch_pending { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 32 | return Ok(self.branch_offer()); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 33 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 34 | match self.floor { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 35 | Floor::Forum => { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 36 | return Ok(Outcome::json( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 37 | StatusCode::SEE_OTHER, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 38 | json!({ "detail": "Refer to the forum." }), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 39 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 40 | .header(header::LOCATION, FORUM_THREAD)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 41 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 42 | Floor::Clinic => { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 43 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 44 | StatusCode::METHOD_NOT_ALLOWED, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 45 | "not-in-the-clinic", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 46 | "JELQ is not performed in the clinic.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 47 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 48 | .header(header::ALLOW, CLINIC_ALLOW)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 49 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 50 | _ => {} |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 51 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 52 | if self.items.cage { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 53 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 54 | StatusCode::LOCKED, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 55 | "caged", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 56 | "The cage is locked. The key is not in the box.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 57 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 58 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 59 | match *techniques { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 60 | [technique] => self.single(technique, intensity, lube, now), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 61 | [a, b] => self.combo(a, b, intensity, lube, now), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 62 | _ => Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 63 | StatusCode::BAD_REQUEST, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 64 | "too-many-techniques", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 65 | "Two techniques at most. The server has limits even if you do not.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 66 | )), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 67 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 68 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 69 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 70 | fn single( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 71 | &mut self, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 72 | technique: Technique, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 73 | intensity: i32, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 74 | lube: Option<Lube>, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 75 | now: Instant, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 76 | ) -> Result<Outcome, Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 77 | match technique { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 78 | Technique::Warmup => return self.warm_up(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 79 | Technique::Ice => return self.ice(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 80 | Technique::Supplement => return self.supplement(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 81 | Technique::Edge => {} |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 82 | _ => self.edges = 0, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 83 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 84 | self.prepare(technique, lube)?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 85 | self.check_storage()?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 86 | self.floor_enemy()?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 87 | match technique { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 88 | Technique::Edge => return self.edge(now), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 89 | Technique::Pump => return self.pump(now), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 90 | _ => {} |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 91 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 92 | let profile = technique.profile().expect("training technique"); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 93 | self.commit(intensity, lube, now, 1); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 94 | if technique == Technique::Dry && intensity >= 8 && self.rng.random_ratio(1, 60) { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 95 | self.end("degloved", DEGLOVED); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 96 | return Err(Problem::new(StatusCode::GONE, "degloved", DEGLOVED)); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 97 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 98 | if let Some(interrupted) = self.hazards(intensity)? { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 99 | return Ok(interrupted); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 100 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 101 | let result = self.roll(technique, &profile, intensity, lube); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 102 | Ok(self.gossip(result?)) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 103 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 104 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 105 | fn combo( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 106 | &mut self, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 107 | a: Technique, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 108 | b: Technique, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 109 | intensity: i32, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 110 | lube: Option<Lube>, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 111 | now: Instant, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 112 | ) -> Result<Outcome, Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 113 | let (Some(first), Some(second)) = (a.profile(), b.profile()) else { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 114 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 115 | StatusCode::BAD_REQUEST, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 116 | "combo-invalid", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 117 | "Only training techniques can be combined.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 118 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 119 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 120 | if a == b { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 121 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 122 | StatusCode::BAD_REQUEST, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 123 | "combo-invalid", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 124 | "A technique cannot be combined with itself. The server has checked.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 125 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 126 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 127 | self.edges = 0; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 128 | self.prepare(a, lube)?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 129 | self.prepare(b, lube)?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 130 | self.check_storage()?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 131 | self.floor_enemy()?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 132 | self.commit(intensity, lube, now, 2); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 133 | if let Some(interrupted) = self.hazards(intensity)? { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 134 | return Ok(interrupted); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 135 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 136 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 137 | let mut statuses = Vec::new(); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 138 | for (technique, profile) in [(a, first), (b, second)] { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 139 | let result = self.roll(technique, &profile, intensity, lube); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 140 | if self.ended.is_some() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 141 | return result; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 142 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 143 | let status = match &result { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 144 | Ok(outcome) => outcome.status(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 145 | Err(problem) => problem.status(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 146 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 147 | statuses.push((technique, status)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 148 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 149 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 150 | let mut xml = String::from( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 151 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<D:multistatus xmlns:D=\"DAV:\">\n", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 152 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 153 | for (technique, status) in statuses { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 154 | let _ = write!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 155 | xml, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 156 | " <D:response>\n <D:href>/runs/{}?technique={}</D:href>\n <D:status>HTTP/1.1 {} {}</D:status>\n </D:response>\n", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 157 | self.id, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 158 | technique.name(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 159 | status.as_u16(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 160 | status.canonical_reason().unwrap_or_default(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 161 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 162 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 163 | xml.push_str( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 164 | " <D:responsedescription>Each technique has been reported separately.</D:responsedescription>\n</D:multistatus>\n", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 165 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 166 | Ok(Outcome::raw( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 167 | StatusCode::MULTI_STATUS, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 168 | "application/xml; charset=utf-8", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 169 | xml, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 170 | )) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 171 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 172 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 173 | fn prepare(&self, technique: Technique, lube: Option<Lube>) -> Result<(), Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 174 | if technique == Technique::Uli && !self.forum_read { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 175 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 176 | StatusCode::FORBIDDEN, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 177 | "technique-locked", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 178 | "This technique is discussed on the forum. You have not been to the forum.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 179 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 180 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 181 | if !self.warmed_up { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 182 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 183 | StatusCode::PRECONDITION_FAILED, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 184 | "cold-start", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 185 | "Warm-up was skipped. The server has noted this.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 186 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 187 | .with("technique", Technique::Warmup.name())); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 188 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 189 | if technique == Technique::Pump && !self.items.pump_pro { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 190 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 191 | StatusCode::FAILED_DEPENDENCY, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 192 | "no-pump", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 193 | "The pump technique depends on a pump.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 194 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 195 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 196 | let Some(profile) = technique.profile() else { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 197 | return Ok(()); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 198 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 199 | match (profile.lube, lube) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 200 | (LubeRule::Required, None) => { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 201 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 202 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 203 | "lubricant-required", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 204 | format!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 205 | "The {} technique requires a lubricant. None was declared.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 206 | technique.name() |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 207 | ), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 208 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 209 | .with("lubricants", json!(LUBRICANTS))); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 210 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 211 | (LubeRule::Forbidden, Some(_)) => { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 212 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 213 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 214 | "lubricant-declared", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 215 | "The dry technique was requested. A lubricant was declared.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 216 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 217 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 218 | _ => {} |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 219 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 220 | if let Some((min, max)) = profile.foreskin { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 221 | self.check_foreskin(min, max)?; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 222 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 223 | Ok(()) |
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 | fn check_foreskin(&self, min: f64, max: f64) -> Result<(), Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 227 | let Some(f) = self.foreskin else { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 228 | if min <= 0.0 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 229 | return Ok(()); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 230 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 231 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 232 | StatusCode::GONE, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 233 | "foreskin-gone", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 234 | "This technique requires a foreskin. The foreskin is gone.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 235 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 236 | .header( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 237 | header::CONTENT_LOCATION, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 238 | format!("/runs/{}/foreskin", self.id), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 239 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 240 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 241 | if f < min { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 242 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 243 | StatusCode::LENGTH_REQUIRED, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 244 | "foreskin-insufficient", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 245 | format!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 246 | "The selected technique requires {min:.1} units of foreskin. {f:.2} units are available. The server has noted the shortfall." |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 247 | ), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 248 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 249 | .with("required", min) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 250 | .with("available", super::round2(f))); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 251 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 252 | if f > max { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 253 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 254 | StatusCode::PAYLOAD_TOO_LARGE, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 255 | "foreskin-excessive", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 256 | format!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 257 | "The selected technique tolerates at most {max:.1} units of foreskin. {f:.2} units are present." |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 258 | ), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 259 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 260 | .with("maximum", max) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 261 | .with("present", super::round2(f))); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 262 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 263 | Ok(()) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 264 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 265 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 266 | fn check_storage(&self) -> Result<(), Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 267 | if self.items.extender && self.girth > 5.0 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 268 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 269 | StatusCode::INSUFFICIENT_STORAGE, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 270 | "jeans-full", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 271 | "The jeans are full. The extender is occupying the remaining storage.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 272 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 273 | .with("extender", format!("/runs/{}/inventory/extender", self.id))); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 274 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 275 | Ok(()) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 276 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 277 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 278 | fn commit(&mut self, intensity: i32, lube: Option<Lube>, now: Instant, cost: i32) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 279 | self.touch(); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 280 | self.turn += 1; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 281 | self.floor_turns += 1; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 282 | self.realize(); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 283 | if self.items.extender { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 284 | self.length += 0.004; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 285 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 286 | self.stamina -= cost + i32::from(lube == Some(Lube::Lotion)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 287 | if self.stamina <= 0 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 288 | self.stamina = 0; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 289 | self.refractory_until = Some(now + *REFRACTORY); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 290 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 291 | let chill = if self.floor == Floor::LockerRoom { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 292 | 8 |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 293 | } else { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 294 | 0 |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 295 | }; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 296 | let wobble = self.rng.random_range(-3..=3); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 297 | self.eq = (self.eq + intensity * 2 - 6 - chill + wobble).clamp(0, 100); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 298 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 299 | let mut suspicion = intensity / 5 + i32::from(lube == Some(Lube::Vaseline)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 300 | if matches!(self.floor, Floor::LockerRoom | Floor::Grandmas) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 301 | suspicion *= 2; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 302 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 303 | if self.floor == Floor::Grandmas && lube == Some(Lube::CoconutOil) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 304 | suspicion += 2; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 305 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 306 | let was_below = self.suspicion < SUSPICION_LIMIT; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 307 | self.suspicion = |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 308 | (i32::from(self.suspicion) + suspicion).min(i32::from(SUSPICION_LIMIT)) as u8; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 309 | if self.floor.has_mom() && !self.mom_present { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 310 | let summoned = was_below && self.suspicion == SUSPICION_LIMIT; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 311 | if summoned || self.rng.random_ratio(u32::from(self.suspicion) + 1, 16) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 312 | self.mom_present = true; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 313 | self.mom_strikes = 0; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 314 | self.mom_errand = self.errand(summoned); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 315 | self.nonce = self.fresh_nonce(); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 316 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 317 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 318 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 319 | if let Some(observer) = self.floor.observer() |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 320 | && self.rng.random_ratio(1, 6) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 321 | { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 322 | self.observed = Some(observer); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 323 | self.shame += 1; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 324 | if observer == "cat" && self.rng.random_ratio(1, 5) { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 325 | self.towel_stolen = true; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 326 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 327 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 328 | if intensity >= 9 && !self.pulled_muscle && self.rng.random_ratio(1, 12) { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 329 | self.pulled_muscle = true; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 330 | self.stamina = self.stamina.min(self.max_stamina()); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 331 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 332 | if self.items.ring && self.eq > 85 && self.rng.random_ratio(1, 10) { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 333 | self.priapism_turns = PRIAPISM_TURNS; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 334 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 335 | if self.priapism_turns > 0 { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 336 | self.priapism_turns -= 1; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 337 | self.eq = self.eq.max(PRIAPISM_EQ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 338 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 339 | if self.turn == super::BRANCH_TURN { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 340 | self.branch_pending = true; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 341 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 342 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 343 | |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 344 | fn hazards(&mut self, intensity: i32) -> Result<Option<Outcome>, Problem> { |
2ea5ef81f040 | atagen | 2026-10-10 11:24 UTC | 345 | let odds = match self.eq { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 346 | ..=70 => 300, |
2ea5ef81f040 | atagen | 2026-10-10 11:24 UTC | 347 | 71..=85 => 25, |
2ea5ef81f040 | atagen | 2026-10-10 11:24 UTC | 348 | _ => 10, |
2ea5ef81f040 | atagen | 2026-10-10 11:24 UTC | 349 | }; |
2ea5ef81f040 | atagen | 2026-10-10 11:24 UTC | 350 | if self.rng.random_ratio(1, odds) { |
2ea5ef81f040 | atagen | 2026-10-10 11:24 UTC | 351 | return Err(self.rupture()); |
2ea5ef81f040 | atagen | 2026-10-10 11:24 UTC | 352 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 353 | let windowed = matches!(self.floor, Floor::Bedroom | Floor::Grandmas | Floor::Hotel); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 354 | if windowed && !self.items.blinds && self.rng.random_ratio(1, 60) { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 355 | self.shame += 30; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 356 | self.filmed_at.get_or_insert_with(SystemTime::now); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 357 | return Ok(Some( |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 358 | Outcome::json( |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 359 | StatusCode::CREATED, |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 360 | json!({ "detail": "A neighbour was at the window. A recording has been created. It has been shared." }), |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 361 | ) |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 362 | .header(header::LOCATION, format!("/runs/{}/footage", self.id)), |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 363 | )); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 364 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 365 | if self.floor == Floor::LockerRoom && self.rng.random_ratio(1, 10) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 366 | self.shame += 1; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 367 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 368 | StatusCode::USE_PROXY, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 369 | "friend", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 370 | "A friend has offered to help. Use Proxy is deprecated, and the server has declined on your behalf.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 371 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 372 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 373 | if self.peyronie && self.rng.random_ratio(1, 3) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 374 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 375 | StatusCode::MISDIRECTED_REQUEST, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 376 | "misdirected", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 377 | "The technique landed slightly to the left. It was meant for a different server.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 378 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 379 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 380 | if intensity <= 2 && self.eq < 50 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 381 | self.eq = (self.eq - 10).max(0); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 382 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 383 | StatusCode::REQUEST_TIMEOUT, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 384 | "lost-it", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 385 | "The request took too long. It was lost.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 386 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 387 | .header(header::CONNECTION, "close")); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 388 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 389 | if self.eq > 95 { |
177535ac8abf | atagen | 2026-10-10 10:39 UTC | 390 | if self.rng.random_ratio(1, 3) { |
177535ac8abf | atagen | 2026-10-10 10:39 UTC | 391 | return Err(self.rupture()); |
177535ac8abf | atagen | 2026-10-10 10:39 UTC | 392 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 393 | self.shame += 5; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 394 | self.next_floor(false); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 395 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 396 | StatusCode::TOO_EARLY, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 397 | "premature", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 398 | "The floor has ended early. Everyone involved has agreed not to discuss it.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 399 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 400 | .with("floor", self.floor.number())); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 401 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 402 | if self.eq < 30 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 403 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 404 | StatusCode::NOT_FOUND, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 405 | "cold", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 406 | "The resource exists. It is cold.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 407 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 408 | .with("eq", self.eq)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 409 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 410 | Ok(None) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 411 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 412 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 413 | fn roll( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 414 | &mut self, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 415 | technique: Technique, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 416 | profile: &Profile, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 417 | intensity: i32, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 418 | lube: Option<Lube>, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 419 | ) -> Result<Outcome, Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 420 | let natural: i32 = self.rng.random_range(1..=20); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 421 | let band = if (50..=70).contains(&self.eq) { 2 } else { 0 }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 422 | let grip = match (self.grip, technique) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 423 | (Grip::Underhand, Technique::Stretch) => 2, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 424 | (Grip::Underhand, Technique::Wet) => -1, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 425 | _ => 0, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 426 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 427 | let modifier = lube.map_or(0, Lube::modifier) + band + grip; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 428 | let dc = profile.dc + intensity / 3; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 429 | let total = natural + modifier; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 430 | let timing = format!("roll;desc=\"d20{modifier:+} vs {dc}\";dur={natural}"); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 431 | let timed = |p: Problem| p.header(SERVER_TIMING, &timing); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 432 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 433 | let scale = f64::from(intensity); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 434 | let (mut length, mut girth) = (profile.length * scale, profile.girth * scale); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 435 | if self.teapot { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 436 | length *= 0.5; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 437 | girth *= 1.5; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 438 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 439 | if self.items.ring { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 440 | girth *= 2.0; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 441 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 442 | let rupture_eq = if self.items.ring { 80 } else { 90 }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 443 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 444 | if natural == 1 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 445 | let touches_foreskin = profile.foreskin.is_some_and(|(min, _)| min > 0.0); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 446 | if touches_foreskin && self.foreskin.is_some() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 447 | self.foreskin = None; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 448 | self.shame += 25; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 449 | return Err(timed( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 450 | Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 451 | StatusCode::GONE, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 452 | "foreskin-lost", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 453 | "The technique has removed the foreskin. It will not be returning.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 454 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 455 | .header( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 456 | header::CONTENT_LOCATION, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 457 | format!("/runs/{}/foreskin", self.id), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 458 | ), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 459 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 460 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 461 | if self.eq > 70 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 462 | return Err(timed(self.rupture())); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 463 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 464 | if technique == Technique::Stretch && !self.teapot { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 465 | self.teapot = true; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 466 | self.items.teapot_spout = true; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 467 | self.shame += 5; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 468 | return Err(timed(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 469 | StatusCode::IM_A_TEAPOT, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 470 | "teapot", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 471 | "The subject is now short and stout. Length gains are halved for the rest of the floor.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 472 | ))); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 473 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 474 | if technique == Technique::Uli && !self.peyronie { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 475 | self.peyronie = true; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 476 | self.shame += 5; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 477 | return Err(timed(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 478 | StatusCode::MISDIRECTED_REQUEST, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 479 | "curvature", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 480 | "A curvature has developed. Techniques will land slightly to the left until a professional is consulted.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 481 | ))); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 482 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 483 | return Err(timed(not_extended())); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 484 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 485 | if natural == 2 && self.eq > 70 { |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 486 | return Err(timed(self.rupture())); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 487 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 488 | if self.eq > rupture_eq && total < dc { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 489 | return Err(timed(self.rupture())); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 490 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 491 | if natural == 20 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 492 | self.gain(length * 2.0, girth * 2.0, profile.foreskin_growth); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 493 | return Ok(Outcome::json( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 494 | StatusCode::CREATED, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 495 | json!({ |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 496 | "detail": "A permanent gain has been created.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 497 | "length": round3(length * 2.0), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 498 | "girth": round3(girth * 2.0), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 499 | }), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 500 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 501 | .header(header::LOCATION, format!("/runs/{}/length", self.id)) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 502 | .header(SERVER_TIMING, timing)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 503 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 504 | if total < dc - 3 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 505 | return Err(timed(not_extended())); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 506 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 507 | if total < dc { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 508 | return Ok(Outcome::empty(StatusCode::NO_CONTENT).header(SERVER_TIMING, timing)); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 509 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 510 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 511 | let outcome = if self.eq < 50 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 512 | self.gain(length / 2.0, girth / 2.0, profile.foreskin_growth); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 513 | Outcome::json( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 514 | StatusCode::PARTIAL_CONTENT, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 515 | json!({ |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 516 | "detail": "Partial gains were applied. EQ was below the band.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 517 | "length": round3(length / 2.0), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 518 | "girth": round3(girth / 2.0), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 519 | }), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 520 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 521 | } else if total >= dc + 5 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 522 | self.gain(length, girth, profile.foreskin_growth); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 523 | Outcome::json( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 524 | StatusCode::OK, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 525 | json!({ |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 526 | "detail": "Gains were applied.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 527 | "length": round3(length), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 528 | "girth": round3(girth), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 529 | }), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 530 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 531 | } else { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 532 | let eta = self.rng.random_range(1..=4); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 533 | self.pending.push(super::Pending { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 534 | due: self.turn + eta, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 535 | length, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 536 | girth, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 537 | }); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 538 | self.gain(0.0, 0.0, profile.foreskin_growth); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 539 | Outcome::json( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 540 | StatusCode::ACCEPTED, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 541 | json!({ |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 542 | "detail": "Gains have been queued. They may arrive.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 543 | "eta_turns": eta, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 544 | }), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 545 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 546 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 547 | Ok(outcome.header(SERVER_TIMING, timing)) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 548 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 549 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 550 | fn gossip(&mut self, outcome: Outcome) -> Outcome { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 551 | let reportable = matches!(outcome.status.as_u16(), 200 | 202 | 206); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 552 | if !self.roommate_told || !reportable { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 553 | return outcome; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 554 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 555 | self.roommate_told = false; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 556 | let mut outcome = outcome; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 557 | outcome.status = StatusCode::ALREADY_REPORTED; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 558 | if let super::Payload::Json(body) = &mut outcome.payload { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 559 | body["detail"] = json!("The roommate has already told everyone."); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 560 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 561 | outcome |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 562 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 563 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 564 | fn warm_up(&mut self) -> Result<Outcome, Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 565 | if self.floor == Floor::Hotel && self.rng.random_ratio(1, 3) { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 566 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 567 | StatusCode::SERVICE_UNAVAILABLE, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 568 | "service-unavailable", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 569 | "Service is unavailable. The server estimates next week. The server is being pessimistic.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 570 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 571 | .header( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 572 | header::RETRY_AFTER, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 573 | httpdate::fmt_http_date(SystemTime::now() + WEEK), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 574 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 575 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 576 | let (boost, detail) = if self.floor == Floor::Bathroom { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 577 | ( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 578 | 35, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 579 | "Warmed up. The shower is hot. The roommate's will not be.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 580 | ) |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 581 | } else if self.towel_stolen { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 582 | (10, "Warmed up, poorly. The cat has the towel.") |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 583 | } else { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 584 | (25, "Warmed up. The towel has cooled.") |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 585 | }; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 586 | self.touch(); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 587 | self.warmed_up = true; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 588 | self.eq = (self.eq + boost).min(100); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 589 | Ok(Outcome::json(StatusCode::OK, json!({ "detail": detail }))) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 590 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 591 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 592 | fn ice(&mut self) -> Result<Outcome, Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 593 | if self.items.ice_packs == 0 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 594 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 595 | StatusCode::FAILED_DEPENDENCY, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 596 | "no-ice", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 597 | "The ice technique depends on an ice pack. There are none.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 598 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 599 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 600 | self.touch(); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 601 | self.items.ice_packs -= 1; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 602 | if self.priapism_turns > 0 { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 603 | return Ok(Outcome::json( |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 604 | StatusCode::OK, |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 605 | json!({ "detail": "The ice has no effect. The condition persists. The ice pack is gone." }), |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 606 | )); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 607 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 608 | self.eq = (self.eq - 40).max(0); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 609 | Ok(Outcome::json( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 610 | StatusCode::OK, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 611 | json!({ "detail": "EQ has been reduced. The ice pack is gone." }), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 612 | )) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 613 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 614 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 615 | fn supplement(&mut self) -> Result<Outcome, Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 616 | if self.items.supplements == 0 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 617 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 618 | StatusCode::FAILED_DEPENDENCY, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 619 | "no-supplement", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 620 | "The supplement technique depends on a supplement.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 621 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 622 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 623 | self.items.supplements -= 1; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 624 | self.touch(); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 625 | if self.rng.random_ratio(1, 5) { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 626 | self.priapism_turns = PRIAPISM_TURNS; |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 627 | self.eq = self.eq.max(PRIAPISM_EQ); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 628 | return Ok(Outcome::json( |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 629 | StatusCode::OK, |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 630 | json!({ "detail": "The upstream returned a valid response. It is still returning it." }), |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 631 | )); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 632 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 633 | Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 634 | StatusCode::BAD_GATEWAY, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 635 | "bad-gateway", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 636 | "The upstream returned an invalid response.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 637 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 638 | .with("upstream", "Pump-Bro")) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 639 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 640 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 641 | fn edge(&mut self, now: Instant) -> Result<Outcome, Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 642 | self.commit(5, None, now, 1); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 643 | self.edges += 1; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 644 | self.eq = (self.eq + 11).min(100); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 645 | self.girth += 0.004; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 646 | if self.edges >= 3 { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 647 | self.edges = 0; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 648 | self.stamina = 0; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 649 | self.refractory_until = Some(now + *REFRACTORY); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 650 | return Err(Problem::new( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 651 | StatusCode::LOOP_DETECTED, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 652 | "edging-loop", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 653 | "Edging has looped. The server detected an infinite loop and terminated it.", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 654 | )); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 655 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 656 | if let Some(interrupted) = self.hazards(5)? { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 657 | return Ok(interrupted); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 658 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 659 | Ok(Outcome::json( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 660 | StatusCode::OK, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 661 | json!({ "detail": "Edged. EQ is rising. Nothing else is.", "edges": self.edges }), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 662 | )) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 663 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 664 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 665 | fn pump(&mut self, now: Instant) -> Result<Outcome, Problem> { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 666 | self.commit(4, None, now, 1); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 667 | if let Some(interrupted) = self.hazards(4)? { |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 668 | return Ok(interrupted); |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 669 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 670 | self.temp_length += 0.5; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 671 | Ok(Outcome::json( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 672 | StatusCode::TEMPORARY_REDIRECT, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 673 | json!({ "detail": "Gains applied. They are temporary.", "length": 0.5 }), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 674 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 675 | .header(header::LOCATION, format!("/runs/{}/length", self.id))) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 676 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 677 | } |