an http based roguelike rpg about jelqing
Blame: src/game/utility.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use std::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | ops::ControlFlow, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | time::{Duration, Instant, SystemTime}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | use axum::http::{StatusCode, header}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | use serde_json::json; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | use super::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | Floor, Outcome, Run, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | balance::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | EDGE_EQ, EDGE_GIRTH, EDGE_LOOP, HOTEL_STRESS, ICE_EQ, PRIAPISM_EQ, PRIAPISM_TURNS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | PUMP_GAIN, SHOWER_EQ, SUPPLEMENT_WORKS, TOWELLESS_EQ, WARMUP_EQ, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | use crate::problem::Problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | const WEEK: Duration = Duration::from_secs(7 * 24 * 60 * 60); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | impl Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | pub(super) fn warm_up(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | if self.floor == Floor::Hotel && self.chance(HOTEL_STRESS) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | StatusCode::SERVICE_UNAVAILABLE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | "service-unavailable", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | "Service is unavailable. The server estimates next week. The server is being pessimistic.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | .header( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | header::RETRY_AFTER, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | httpdate::fmt_http_date(SystemTime::now() + WEEK), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | let (boost, detail) = if self.floor == Floor::Bathroom { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | SHOWER_EQ, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | "Warmed up. The shower is hot. The roommate's will not be.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | } else if self.here.towel_stolen { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | (TOWELLESS_EQ, "Warmed up, poorly. The cat has the towel.") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | (WARMUP_EQ, "Warmed up. The towel has cooled.") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | self.warmed_up = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | self.eq = (self.eq + boost).min(100); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | Ok(Outcome::json(StatusCode::OK, json!({ "detail": detail }))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | pub(super) fn ice(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | if self.items.ice_packs == 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | StatusCode::FAILED_DEPENDENCY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | "no-ice", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | "The ice technique depends on an ice pack. There are none.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | self.items.ice_packs -= 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | if self.conditions.priapism_turns > 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | return Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | json!({ "detail": "The ice has no effect. The condition persists. The ice pack is gone." }), |
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 | self.eq = (self.eq - ICE_EQ).max(0); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | json!({ "detail": "EQ has been reduced. The ice pack is gone." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 71 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | pub(super) fn supplement(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | if self.items.supplements == 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | StatusCode::FAILED_DEPENDENCY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | "no-supplement", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | "The supplement technique depends on a supplement.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | self.items.supplements -= 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | if self.chance(SUPPLEMENT_WORKS) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | self.conditions.priapism_turns = PRIAPISM_TURNS; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | self.eq = self.eq.max(PRIAPISM_EQ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | return Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 87 | json!({ "detail": "The upstream returned a valid response. It is still returning it." }), |
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 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | StatusCode::BAD_GATEWAY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | "bad-gateway", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | "The upstream returned an invalid response.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | .with("upstream", "Pump-Bro")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | pub(super) fn edge(&mut self, now: Instant) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | self.commit(5, None, now, 1); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | self.here.edges += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | self.eq = (self.eq + EDGE_EQ).min(100); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | self.girth += EDGE_GIRTH; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | if self.here.edges >= EDGE_LOOP { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | self.here.edges = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | self.exhaust(now); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | StatusCode::LOOP_DETECTED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | "edging-loop", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | "Edging has looped. The server detected an infinite loop and terminated it.", |
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 | if let ControlFlow::Break(interrupted) = self.hazards(5)? { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | return Ok(interrupted); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | json!({ "detail": "Edged. EQ is rising. Nothing else is.", "edges": self.here.edges }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | pub(super) fn pump(&mut self, now: Instant) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | self.commit(4, None, now, 1); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | if let ControlFlow::Break(interrupted) = self.hazards(4)? { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | return Ok(interrupted); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | self.here.temp_length += PUMP_GAIN; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | StatusCode::TEMPORARY_REDIRECT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | json!({ "detail": "Gains applied. They are temporary.", "length": PUMP_GAIN }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | .header(header::LOCATION, self.path("/length"))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | } |