atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
4347977b819220280d64f9e914967717329b830a
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/techniques.rsRust237 lines6.5 KB
1
use axum::http::StatusCode;
2
use serde_json::{Value, json};
3
4
use crate::problem::Problem;
5
6
pub const LUBRICANTS: [&str; 5] = [
7
    "application/baby-oil",
8
    "application/coconut-oil",
9
    "application/lotion",
10
    "application/vaseline",
11
    "text/plain; charset=spit",
12
];
13
14
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
15
pub enum Lube {
16
    BabyOil,
17
    CoconutOil,
18
    Lotion,
19
    Vaseline,
20
    Spit,
21
}
22
23
impl Lube {
24
    pub fn from_content_type(content_type: Option<&str>) -> Result<Option<Self>, Problem> {
25
        let Some(raw) = content_type else {
26
            return Ok(None);
27
        };
28
        let lowered = raw.to_ascii_lowercase();
29
        let mut parts = lowered.split(';').map(str::trim);
30
        let essence = parts.next().unwrap_or_default();
31
        let spit = parts.any(|p| p.replace(' ', "") == "charset=spit");
32
        match essence {
33
            "application/baby-oil" => Ok(Some(Self::BabyOil)),
34
            "application/coconut-oil" => Ok(Some(Self::CoconutOil)),
35
            "application/lotion" => Ok(Some(Self::Lotion)),
36
            "application/vaseline" => Ok(Some(Self::Vaseline)),
37
            "text/plain" if spit => Ok(Some(Self::Spit)),
38
            e if e.starts_with("image/") || e.starts_with("video/") => Err(Problem::new(
39
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
40
                "no",
41
                "No.",
42
            )),
43
            _ => Err(Problem::new(
44
                StatusCode::UNSUPPORTED_MEDIA_TYPE,
45
                "unsupported-lubricant",
46
                format!("{essence} is not a lubricant."),
47
            )
48
            .with("lubricants", json!(LUBRICANTS))),
49
        }
50
    }
51
52
    pub fn modifier(self) -> i32 {
53
        match self {
54
            Self::BabyOil => 1,
55
            Self::CoconutOil => 3,
56
            Self::Lotion => 0,
57
            Self::Vaseline => 2,
58
            Self::Spit => -2,
59
        }
60
    }
61
}
62
63
/// Techniques that roll for gains.
64
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
65
pub enum Training {
66
    Wet,
67
    Dry,
68
    Stretch,
69
    Uli,
70
}
71
72
/// Techniques that change EQ or spend an item without rolling.
73
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
74
pub enum Utility {
75
    Warmup,
76
    Ice,
77
    Edge,
78
    Pump,
79
    Supplement,
80
    Meditate,
81
}
82
83
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
84
pub enum Technique {
85
    Training(Training),
86
    Utility(Utility),
87
}
88
89
#[derive(Clone, Copy)]
90
pub enum LubeRule {
91
    Required,
92
    Forbidden,
93
    Optional,
94
}
95
96
impl LubeRule {
97
    fn name(self) -> &'static str {
98
        match self {
99
            Self::Required => "required",
100
            Self::Forbidden => "forbidden",
101
            Self::Optional => "optional",
102
        }
103
    }
104
}
105
106
pub struct Profile {
107
    pub dc: i32,
108
    pub length: f64,
109
    pub girth: f64,
110
    /// Minimum and maximum foreskin the technique tolerates. A minimum above zero means it is used.
111
    pub foreskin: Option<(f64, f64)>,
112
    pub foreskin_growth: f64,
113
    pub lube: LubeRule,
114
}
115
116
impl Training {
117
    pub fn name(self) -> &'static str {
118
        match self {
119
            Self::Wet => "wet",
120
            Self::Dry => "dry",
121
            Self::Stretch => "stretch",
122
            Self::Uli => "uli",
123
        }
124
    }
125
126
    pub fn profile(self) -> Profile {
127
        match self {
128
            Self::Wet => Profile {
129
                dc: 10,
130
                length: 0.010,
131
                girth: 0.005,
132
                foreskin: None,
133
                foreskin_growth: 0.0,
134
                lube: LubeRule::Required,
135
            },
136
            Self::Dry => Profile {
137
                dc: 12,
138
                length: 0.008,
139
                girth: 0.003,
140
                foreskin: Some((0.8, 2.0)),
141
                foreskin_growth: 0.01,
142
                lube: LubeRule::Forbidden,
143
            },
144
            Self::Stretch => Profile {
145
                dc: 11,
146
                length: 0.015,
147
                girth: 0.0,
148
                foreskin: Some((0.0, 1.8)),
149
                foreskin_growth: 0.03,
150
                lube: LubeRule::Optional,
151
            },
152
            Self::Uli => Profile {
153
                dc: 15,
154
                length: 0.002,
155
                girth: 0.020,
156
                foreskin: None,
157
                foreskin_growth: 0.0,
158
                lube: LubeRule::Optional,
159
            },
160
        }
161
    }
162
}
163
164
impl Utility {
165
    pub fn name(self) -> &'static str {
166
        match self {
167
            Self::Warmup => "warmup",
168
            Self::Ice => "ice",
169
            Self::Edge => "edge",
170
            Self::Pump => "pump",
171
            Self::Supplement => "supplement",
172
            Self::Meditate => "meditate",
173
        }
174
    }
175
176
    fn effect(self) -> &'static str {
177
        match self {
178
            Self::Warmup => "EQ +25. Satisfies the warm-up precondition.",
179
            Self::Ice => "EQ -40. Consumes an ice pack.",
180
            Self::Edge => "EQ +15 and a little girth. Three in a row is a loop.",
181
            Self::Pump => "Large gains, all temporary. Requires a pump.",
182
            Self::Supplement => "Consumes a supplement.",
183
            Self::Meditate => "EQ -10. Taught by the forum. Once per floor, no stamina.",
184
        }
185
    }
186
}
187
188
impl Technique {
189
    pub const ALL: [Self; 10] = [
190
        Self::Utility(Utility::Warmup),
191
        Self::Utility(Utility::Ice),
192
        Self::Utility(Utility::Edge),
193
        Self::Utility(Utility::Pump),
194
        Self::Utility(Utility::Supplement),
195
        Self::Utility(Utility::Meditate),
196
        Self::Training(Training::Wet),
197
        Self::Training(Training::Dry),
198
        Self::Training(Training::Stretch),
199
        Self::Training(Training::Uli),
200
    ];
201
202
    pub fn name(self) -> &'static str {
203
        match self {
204
            Self::Training(t) => t.name(),
205
            Self::Utility(u) => u.name(),
206
        }
207
    }
208
209
    pub fn parse(name: &str) -> Option<Self> {
210
        Self::ALL.into_iter().find(|t| t.name() == name)
211
    }
212
213
    pub fn lubricant(self) -> Option<&'static str> {
214
        match self {
215
            Self::Training(training) => Some(training.profile().lube.name()),
216
            Self::Utility(_) => None,
217
        }
218
    }
219
220
    pub fn describe(self, forum_read: bool) -> Value {
221
        let training = match self {
222
            Self::Utility(utility) => {
223
                return json!({ "name": utility.name(), "effect": utility.effect() });
224
            }
225
            Self::Training(training) => training,
226
        };
227
        let profile = training.profile();
228
        let lubricant = profile.lube.name();
229
        json!({
230
            "name": training.name(),
231
            "dc": profile.dc,
232
            "lubricant": lubricant,
233
            "foreskin": profile.foreskin.map(|(min, max)| json!({ "min": min, "max": max })),
234
            "locked": training == Training::Uli && !forum_read,
235
        })
236
    }
237
}