an http based roguelike rpg about jelqing
Blame: src/game/body.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use axum::http::StatusCode; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | use super::{ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 4 | Outcome, Run, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 5 | balance::{GIRTH_RESPECTED, GIRTH_THICK, LOCKER_ROOM_BAR, MAX_STAMINA, STARTING_EQ}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 6 | credentials::etag_matches, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | use crate::problem::Problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 10 | pub struct Body { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 11 | pub(crate) length: f64, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | pub(crate) girth: f64, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 13 | pub(crate) foreskin: Option<f64>, |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 14 | pub(crate) inflation: f64, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 15 | pub(crate) eq: i32, |
53bce0d93000 | atagen | 2026-10-14 13:39 UTC | 16 | /// `heat` as the current turn began, so no rupture is judged hotter than the turn started. |
53bce0d93000 | atagen | 2026-10-14 13:39 UTC | 17 | pub(crate) heat_at_turn_start: i32, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 18 | pub(crate) stamina: i32, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 19 | pub(crate) friction: i32, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 20 | pub(crate) grip: Grip, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 21 | /// The grip of the last stroke, which decides whether this one gets the switching discount. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 22 | pub(crate) jelq_grip: Option<Grip>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 23 | pub(crate) exhausted: bool, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 24 | pub(crate) put_applied: bool, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 25 | pub(crate) conditions: Conditions, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 26 | pub(crate) pending: Vec<Pending>, |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 27 | pub(crate) arrived: Option<Arrival>, |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 28 | pub(crate) torn: f64, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 31 | impl Body { |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 32 | pub fn new(length: f64, girth: f64, foreskin: f64, inflation: f64) -> Self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 33 | Self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 34 | length, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 35 | girth, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 36 | foreskin: Some(foreskin), |
9adb509e6685 | atagen | 2026-10-14 08:54 UTC | 37 | inflation, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 38 | eq: STARTING_EQ, |
53bce0d93000 | atagen | 2026-10-14 13:39 UTC | 39 | heat_at_turn_start: STARTING_EQ, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 40 | stamina: MAX_STAMINA, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 41 | friction: 0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 42 | grip: Grip::Overhand, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 43 | jelq_grip: None, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 44 | exhausted: false, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 45 | put_applied: false, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 46 | conditions: Conditions::default(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 47 | pending: Vec::new(), |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 48 | arrived: None, |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 49 | torn: 0.0, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 50 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 51 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 54 | #[derive(Default)] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | pub struct Conditions { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 56 | pub(crate) peyronie: bool, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 57 | pub(crate) pulled_muscle: bool, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 58 | pub(crate) priapism_turns: u8, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 59 | pub(crate) friction_burn: bool, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 60 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 61 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 62 | /// Gains a `202` promised, due on a later turn. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 63 | pub struct Pending { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 64 | pub(crate) due: u32, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 65 | pub(crate) length: f64, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 66 | pub(crate) girth: f64, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 67 | pub(crate) foreskin: f64, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 68 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 69 | |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 70 | #[derive(Default)] |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 71 | pub struct Arrival { |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 72 | pub(crate) length: f64, |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 73 | pub(crate) girth: f64, |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 74 | pub(crate) foreskin: Option<f64>, |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 75 | } |
fcc6cf6d5edc | atagen | 2026-10-13 11:31 UTC | 76 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 77 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 78 | pub enum Grip { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 79 | Overhand, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 80 | Underhand, |
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 | impl Grip { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 84 | pub fn name(self) -> &'static str { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 85 | match self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 86 | Self::Overhand => "overhand", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 87 | Self::Underhand => "underhand", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 90 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 92 | impl std::str::FromStr for Grip { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 93 | type Err = (); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 94 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 95 | fn from_str(protocol: &str) -> Result<Self, ()> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 96 | match protocol.to_ascii_lowercase().as_str() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 97 | "overhand" => Ok(Self::Overhand), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 98 | "underhand" => Ok(Self::Underhand), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 99 | _ => Err(()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 102 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 104 | impl Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | pub fn delete_foreskin(&mut self, if_match: Option<&str>) -> Result<Outcome, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 106 | if self.body.foreskin.is_none() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | StatusCode::GONE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | "foreskin-gone", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | "The foreskin is gone. It will not be returning.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | let Some(if_match) = if_match else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | StatusCode::PRECONDITION_REQUIRED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | "confirmation-required", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | "The server requires you to be sure. Send If-Match.", |
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 | if !etag_matches(if_match, &self.etag()) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | StatusCode::PRECONDITION_FAILED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | "stale-foreskin", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | "The foreskin has changed since you last looked at it.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 127 | self.body.foreskin = None; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 128 | self.standing.shame += 20; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | Ok(Outcome::empty(StatusCode::NO_CONTENT)) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 133 | pub fn set_grip(&mut self, grip: Grip) -> Result<(), Problem> { |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 134 | self.grip_closes(grip)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 135 | self.body.grip = grip; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | self.touch(); |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 137 | Ok(()) |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 138 | } |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 139 | |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 140 | pub(super) fn grip_closes(&self, grip: Grip) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 141 | if grip == Grip::Underhand && self.body.girth > GIRTH_THICK { |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 142 | return Err(Problem::new( |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 143 | StatusCode::PAYLOAD_TOO_LARGE, |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 144 | "grip-too-small", |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 145 | format!( |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 146 | "The underhand grip no longer closes around {:.2} inches of girth.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 147 | self.body.girth |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 148 | ), |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 149 | ) |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 150 | .with("maximum", GIRTH_THICK)); |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 151 | } |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 152 | Ok(()) |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 153 | } |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 154 | |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 155 | /// Everyone in the changing room self-reports, so the comparison is self-report against self-report. |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 156 | pub fn holds_own_in_the_locker_room(&self) -> bool { |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 157 | self.self_reported() >= LOCKER_ROOM_BAR |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 158 | } |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 159 | |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 160 | pub fn girth_respected(&self) -> bool { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 161 | self.body.girth >= GIRTH_RESPECTED |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 162 | } |
159f0998263b | atagen | 2026-10-12 11:01 UTC | 163 | } |