atagen

jelq

public

an http based roguelike rpg about jelqing

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