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::{ |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 12 | EDGE_EQ, EDGE_GIRTH, EDGE_LOOP, ENERGY_STAMINA, HOTEL_STRESS, ICE_EQ, PRIAPISM_EQ, |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 13 | PRIAPISM_TURNS, 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> { |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 22 | if self.floor == Floor::Hotel |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 23 | && self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 24 | self.decision( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 25 | "hotel-stress", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 26 | "Has the hotel's plumbing given up for the week?", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 27 | ), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 28 | HOTEL_STRESS, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 29 | ) |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 30 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | StatusCode::SERVICE_UNAVAILABLE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | "service-unavailable", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | "Service is unavailable. The server estimates next week. The server is being pessimistic.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | .header( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | header::RETRY_AFTER, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | httpdate::fmt_http_date(SystemTime::now() + WEEK), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | let (boost, detail) = if self.floor == Floor::Bathroom { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | SHOWER_EQ, |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 44 | "Warmed up. The shower is hot. Your brother's will not be.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | } else if self.here.towel_stolen { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | (TOWELLESS_EQ, "Warmed up, poorly. The cat has the towel.") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | (WARMUP_EQ, "Warmed up. The towel has cooled.") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | self.touch(); |
e807266c323b | atagen | 2026-10-12 09:46 UTC | 52 | self.step_away(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | self.warmed_up = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | self.eq = (self.eq + boost).min(100); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | Ok(Outcome::json(StatusCode::OK, json!({ "detail": detail }))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | pub(super) fn ice(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | if self.items.ice_packs == 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | StatusCode::FAILED_DEPENDENCY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | "no-ice", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | "The ice technique depends on an ice pack. There are none.", |
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 | self.touch(); |
e807266c323b | atagen | 2026-10-12 09:46 UTC | 67 | self.step_away(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | self.items.ice_packs -= 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | if self.conditions.priapism_turns > 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | return Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 71 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | json!({ "detail": "The ice has no effect. The condition persists. The ice pack is gone." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | self.eq = (self.eq - ICE_EQ).max(0); |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 76 | let detail = if self.conditions.friction_burn { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 77 | self.conditions.friction_burn = false; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 78 | "The friction burn is treated. EQ has been reduced. The ice pack is gone." |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 79 | } else { |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 80 | "EQ has been reduced. The ice pack is gone." |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 81 | }; |
5dfebcc0ac43 | atagen | 2026-10-11 05:28 UTC | 82 | Ok(Outcome::json(StatusCode::OK, json!({ "detail": detail }))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 85 | pub(super) fn energy(&mut self) -> Result<Outcome, Problem> { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 86 | if self.items.energy_drinks == 0 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 87 | return Err(Problem::new( |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 88 | StatusCode::FAILED_DEPENDENCY, |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 89 | "no-energy-drink", |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 90 | "The energy technique depends on an energy drink.", |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 91 | )); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 92 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 93 | self.items.energy_drinks -= 1; |
e807266c323b | atagen | 2026-10-12 09:46 UTC | 94 | self.step_away(); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 95 | self.stamina = (self.stamina + ENERGY_STAMINA).min(self.max_stamina()); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 96 | self.touch(); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 97 | Ok(Outcome::json( |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 98 | StatusCode::OK, |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 99 | json!({ "detail": "The energy arrives before the regret. Stamina +3." }), |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 100 | )) |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 101 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 102 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | pub(super) fn supplement(&mut self) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | if self.items.supplements == 0 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | StatusCode::FAILED_DEPENDENCY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | "no-supplement", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | "The supplement technique depends on a supplement.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | self.items.supplements -= 1; |
e807266c323b | atagen | 2026-10-12 09:46 UTC | 112 | self.step_away(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | self.touch(); |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 114 | if self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 115 | self.decision( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 116 | "supplement", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 117 | "Does the supplement from Pump-Bro actually work?", |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 118 | ), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 119 | SUPPLEMENT_WORKS, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 120 | ) { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 121 | self.stamina = self.max_stamina(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | self.conditions.priapism_turns = PRIAPISM_TURNS; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | self.eq = self.eq.max(PRIAPISM_EQ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | return Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | StatusCode::OK, |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 126 | json!({ "detail": "The upstream returned a valid response. It is still returning it. Stamina is fully restored." }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | StatusCode::BAD_GATEWAY, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | "bad-gateway", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | "The upstream returned an invalid response.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | .with("upstream", "Pump-Bro")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | pub(super) fn edge(&mut self, now: Instant) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | self.commit(5, None, now, 1); |
e807266c323b | atagen | 2026-10-12 09:46 UTC | 139 | if let ControlFlow::Break(interrupted) = self.hazards(5)? { |
e807266c323b | atagen | 2026-10-12 09:46 UTC | 140 | return Ok(interrupted); |
e807266c323b | atagen | 2026-10-12 09:46 UTC | 141 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | self.here.edges += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | self.eq = (self.eq + EDGE_EQ).min(100); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | self.girth += EDGE_GIRTH; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | if self.here.edges >= EDGE_LOOP { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | self.here.edges = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | self.exhaust(now); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | StatusCode::LOOP_DETECTED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | "edging-loop", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | "Edging has looped. The server detected an infinite loop and terminated it.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | json!({ "detail": "Edged. EQ is rising. Nothing else is.", "edges": self.here.edges }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | pub(super) fn pump(&mut self, now: Instant) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | self.commit(4, None, now, 1); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | if let ControlFlow::Break(interrupted) = self.hazards(4)? { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | return Ok(interrupted); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | self.here.temp_length += PUMP_GAIN; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | Ok(Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | StatusCode::TEMPORARY_REDIRECT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | json!({ "detail": "Gains applied. They are temporary.", "length": PUMP_GAIN }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 169 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 170 | .header(header::LOCATION, self.path("/length"))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 171 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 172 | } |