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