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