an http based roguelike rpg about jelqing
Blame: src/game/checks.rs
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 1 | use super::{ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 2 | LUBRICANTS, Lube, Run, Technique, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 3 | balance::STORAGE_BULK, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 4 | lube::LubeRule, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 5 | techniques::{Training, Utility}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 6 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 7 | use crate::problem::Problem; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 8 | use axum::http::{StatusCode, header}; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 9 | use serde_json::json; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 10 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 11 | impl Run { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | pub(super) fn ready(&self, technique: Technique, lube: Option<Lube>) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 13 | self.access(technique)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 14 | match technique { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 15 | Technique::Training(training) => Self::check_lube(training, lube), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 16 | Technique::Utility(_) => Ok(()), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 17 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 18 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 19 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 20 | pub(super) fn access(&self, technique: Technique) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 21 | if technique == Technique::Training(Training::Uli) && !self.online.uli_taught { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 22 | return Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 23 | StatusCode::FORBIDDEN, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 24 | "technique-locked", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 25 | "uli is discussed on the forum, in a thread from 2009, by a man who never posted again. You have not found the reply.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 26 | )); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 27 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 28 | if matches!(technique, Technique::Training(_)) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 29 | self.grip_closes(self.body.grip)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 30 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 31 | match technique { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 32 | Technique::Utility(Utility::Pump) if !self.items.kit.pump_pro => Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 33 | StatusCode::FAILED_DEPENDENCY, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 34 | "no-pump", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 35 | "The pump technique depends on a pump.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 36 | )), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 37 | Technique::Utility(_) => Ok(()), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 38 | Technique::Training(training) => match training.profile().foreskin { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 39 | Some((min, max)) => self.check_foreskin(min, max), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 40 | None => Ok(()), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 41 | }, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 42 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 43 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 44 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 45 | pub(super) fn check_lube(training: Training, lube: Option<Lube>) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 46 | match (training.profile().lube, lube) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 47 | (LubeRule::Required, None) => Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 48 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 49 | "lubricant-required", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 50 | format!( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 51 | "The {} technique requires a lubricant. None was declared.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 52 | training.name() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 53 | ), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 54 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | .with("lubricants", json!(LUBRICANTS))), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 56 | (LubeRule::Forbidden, Some(_)) => Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 57 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 58 | "lubricant-declared", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 59 | format!( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 60 | "The {} technique was requested. A lubricant was declared.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 61 | training.name() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 62 | ), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 63 | )), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 64 | _ => Ok(()), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 65 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 66 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 67 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 68 | /// One unit of whatever was declared. Spit is free and the tap is always on. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 69 | pub(super) fn lube_available(&self, lube: Option<Lube>) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 70 | let Some(bottle) = lube.and_then(Lube::item) else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 71 | return Ok(()); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 72 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 73 | if !self.items.has(bottle) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 74 | return Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 75 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 76 | "lubricant-exhausted", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 77 | format!("{} was declared, but the bottle is empty.", bottle.slug()), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 78 | )); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 79 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 80 | Ok(()) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 81 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 82 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 83 | pub(super) fn take_lube(&mut self, lube: Option<Lube>) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 84 | self.lube_available(lube)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 85 | if let Some(lube) = lube { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 86 | self.items.lubes.take(lube); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 87 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 88 | Ok(()) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 89 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 90 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 91 | pub fn techniques_now(&self) -> impl Iterator<Item = Technique> + '_ { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 92 | let blocked = !self.floor.timed() || self.items.kit.cage || self.body.exhausted; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 93 | Technique::ALL |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 94 | .into_iter() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 95 | .filter(move |_| !blocked) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 96 | .filter(|&technique| match technique { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 97 | Technique::Utility(Utility::Warmup) => { |
4b1f5f88827d | atagen | 2026-10-13 10:18 UTC | 98 | !self.here.towel_warmed || self.here.kitchen.kettle_boiled |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 99 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 100 | Technique::Utility(Utility::Ice) => self.items.stores.ice_packs > 0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 101 | Technique::Utility(Utility::Supplement) => self.items.stores.supplements > 0, |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 102 | Technique::Utility(Utility::Meditate) => { |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 103 | self.online.meditation_taught && !self.here.meditated |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 104 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 105 | Technique::Utility(Utility::Energy) => self.items.stores.energy_drinks > 0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 106 | _ => self.access(technique).is_ok() && self.check_storage().is_ok(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 107 | }) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 108 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 109 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 110 | pub(super) fn check_foreskin(&self, min: f64, max: f64) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 111 | let Some(f) = self.body.foreskin else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 112 | if min <= 0.0 { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 113 | return Ok(()); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 114 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 115 | return Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 116 | StatusCode::GONE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 117 | "foreskin-gone", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 118 | "This technique requires a foreskin. The foreskin is gone.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 119 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 120 | .header(header::CONTENT_LOCATION, self.path("/foreskin"))); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 121 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 122 | if f < min { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 123 | return Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 124 | StatusCode::LENGTH_REQUIRED, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 125 | "foreskin-insufficient", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 126 | format!( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 127 | "The selected technique requires {min:.1} units of foreskin. {f:.2} units are available. The server has noted the shortfall." |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 128 | ), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 129 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 130 | .with("required", min)); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 131 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 132 | if f > max { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 133 | return Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 134 | StatusCode::PAYLOAD_TOO_LARGE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 135 | "foreskin-excessive", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 136 | format!( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 137 | "The selected technique tolerates at most {max:.1} units of foreskin. {f:.2} units are present." |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 138 | ), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 139 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 140 | .with("maximum", max)); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 141 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 142 | Ok(()) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 143 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 144 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 145 | pub(super) fn check_storage(&self) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 146 | if self.items.kit.extender && self.body.girth + self.current_length() / 4.0 > STORAGE_BULK { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 147 | return Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 148 | StatusCode::INSUFFICIENT_STORAGE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 149 | "jeans-full", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 150 | "The jeans are full. The extender is occupying the remaining storage.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 151 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 152 | .with("extender", self.path("/inventory/extender"))); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 153 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 154 | Ok(()) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 155 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 156 | } |