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