atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
7d3fb63208bf5064f04782aac0c0273305f8f35f
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/techniques.rsRust233 lines6.3 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
}
81
82
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
83
pub enum Technique {
84
    Training(Training),
85
    Utility(Utility),
86
}
87
88
#[derive(Clone, Copy)]
89
pub enum LubeRule {
90
    Required,
91
    Forbidden,
92
    Optional,
93
}
94
95
impl LubeRule {
96
    fn name(self) -> &'static str {
97
        match self {
98
            Self::Required => "required",
99
            Self::Forbidden => "forbidden",
100
            Self::Optional => "optional",
101
        }
102
    }
103
}
104
105
pub struct Profile {
106
    pub dc: i32,
107
    pub length: f64,
108
    pub girth: f64,
109
    /// Minimum and maximum foreskin the technique tolerates. A minimum above zero means it is used.
110
    pub foreskin: Option<(f64, f64)>,
111
    pub foreskin_growth: f64,
112
    pub lube: LubeRule,
113
}
114
115
impl Training {
116
    pub fn name(self) -> &'static str {
117
        match self {
118
            Self::Wet => "wet",
119
            Self::Dry => "dry",
120
            Self::Stretch => "stretch",
121
            Self::Uli => "uli",
122
        }
123
    }
124
125
    pub fn profile(self) -> Profile {
126
        match self {
127
            Self::Wet => Profile {
128
                dc: 10,
129
                length: 0.010,
130
                girth: 0.005,
131
                foreskin: None,
132
                foreskin_growth: 0.0,
133
                lube: LubeRule::Required,
134
            },
135
            Self::Dry => Profile {
136
                dc: 12,
137
                length: 0.008,
138
                girth: 0.003,
139
                foreskin: Some((0.8, 2.0)),
140
                foreskin_growth: 0.01,
141
                lube: LubeRule::Forbidden,
142
            },
143
            Self::Stretch => Profile {
144
                dc: 11,
145
                length: 0.015,
146
                girth: 0.0,
147
                foreskin: Some((0.0, 1.8)),
148
                foreskin_growth: 0.03,
149
                lube: LubeRule::Optional,
150
            },
151
            Self::Uli => Profile {
152
                dc: 15,
153
                length: 0.002,
154
                girth: 0.020,
155
                foreskin: None,
156
                foreskin_growth: 0.0,
157
                lube: LubeRule::Optional,
158
            },
159
        }
160
    }
161
}
162
163
impl Utility {
164
    pub fn name(self) -> &'static str {
165
        match self {
166
            Self::Warmup => "warmup",
167
            Self::Ice => "ice",
168
            Self::Edge => "edge",
169
            Self::Pump => "pump",
170
            Self::Supplement => "supplement",
171
        }
172
    }
173
174
    fn effect(self) -> &'static str {
175
        match self {
176
            Self::Warmup => "EQ +25. Satisfies the warm-up precondition.",
177
            Self::Ice => "EQ -40. Consumes an ice pack.",
178
            Self::Edge => "EQ +15 and a little girth. Three in a row is a loop.",
179
            Self::Pump => "Large gains, all temporary. Requires a pump.",
180
            Self::Supplement => "Consumes a supplement.",
181
        }
182
    }
183
}
184
185
impl Technique {
186
    pub const ALL: [Self; 9] = [
187
        Self::Utility(Utility::Warmup),
188
        Self::Utility(Utility::Ice),
189
        Self::Utility(Utility::Edge),
190
        Self::Utility(Utility::Pump),
191
        Self::Utility(Utility::Supplement),
192
        Self::Training(Training::Wet),
193
        Self::Training(Training::Dry),
194
        Self::Training(Training::Stretch),
195
        Self::Training(Training::Uli),
196
    ];
197
198
    pub fn name(self) -> &'static str {
199
        match self {
200
            Self::Training(t) => t.name(),
201
            Self::Utility(u) => u.name(),
202
        }
203
    }
204
205
    pub fn parse(name: &str) -> Option<Self> {
206
        Self::ALL.into_iter().find(|t| t.name() == name)
207
    }
208
209
    pub fn lubricant(self) -> Option<&'static str> {
210
        match self {
211
            Self::Training(training) => Some(training.profile().lube.name()),
212
            Self::Utility(_) => None,
213
        }
214
    }
215
216
    pub fn describe(self, forum_read: bool) -> Value {
217
        let training = match self {
218
            Self::Utility(utility) => {
219
                return json!({ "name": utility.name(), "effect": utility.effect() });
220
            }
221
            Self::Training(training) => training,
222
        };
223
        let profile = training.profile();
224
        let lubricant = profile.lube.name();
225
        json!({
226
            "name": training.name(),
227
            "dc": profile.dc,
228
            "lubricant": lubricant,
229
            "foreskin": profile.foreskin.map(|(min, max)| json!({ "min": min, "max": max })),
230
            "locked": training == Training::Uli && !forum_read,
231
        })
232
    }
233
}