atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
bf5f8cb6f60f6e974991335cdfec63b7874a37bf
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/rest.rsRust94 lines3.2 KB
1
use super::{
2
    Notice, Outcome, Run, Story,
3
    balance::{
4
        DANGER_EQ, FRICTION_HOLD, FRICTION_MEDITATE, HOLD_EQ, MEDITATION_EQ, REFLECTION,
5
        RUPTURE_HOLD,
6
    },
7
};
8
use crate::problem::Problem;
9
use axum::http::StatusCode;
10
use serde_json::json;
11
12
impl Run {
13
    pub fn can_hold(&self) -> bool {
14
        self.body.eq > DANGER_EQ || self.body.stamina <= 2
15
    }
16
17
    pub fn hold(&mut self) -> Result<Outcome, Problem> {
18
        if self.online.story == Story::Pending {
19
            return Ok(self.branch_offer());
20
        }
21
        if self.items.kit.cage {
22
            return Err(Problem::new(
23
                StatusCode::LOCKED,
24
                "caged",
25
                "The cage is locked. The key is not in the box.",
26
            ));
27
        }
28
        self.begin_turn();
29
        if self.oracle.chance_not(
30
            self.decision("rupture", "The pause is uneventful"),
31
            RUPTURE_HOLD,
32
        ) {
33
            return Err(self.rupture());
34
        }
35
        if self.body.exhausted {
36
            self.recover();
37
            self.shed(FRICTION_HOLD);
38
            self.settle();
39
            let detail = if self.body.conditions.priapism_turns > 0 {
40
                "The count went well past ten. Stamina is back. It went down a little. Maybe. You hope."
41
            } else {
42
                "The count went well past ten. Stamina is back. Everything else has gone quiet, and you are cold again."
43
            };
44
            return Ok(Outcome::json(StatusCode::OK, json!({ "detail": detail })));
45
        }
46
        if self.chance(
47
            self.decision(
48
                "reflection",
49
                "In the quiet afterwards, have you caught your own eye in the mirror?",
50
            ),
51
            REFLECTION,
52
        ) {
53
            self.body.eq = 0;
54
            self.standing.shame += 1;
55
            self.notices.push(Notice::Reflection);
56
        } else {
57
            self.body.eq = (self.body.eq - HOLD_EQ).clamp(0, 100);
58
        }
59
        self.body.stamina = (self.body.stamina + 1).min(self.max_stamina());
60
        self.shed(FRICTION_HOLD);
61
        self.settle();
62
        Ok(Outcome::empty(StatusCode::NO_CONTENT))
63
    }
64
65
    /// The breathing technique from the forum's replies. It spends no stamina and the turn is
66
    /// not the floor's, but each floor allows it once.
67
    pub(super) fn meditate(&mut self) -> Result<Outcome, Problem> {
68
        if !self.online.meditation_taught {
69
            return Err(Problem::new(
70
                StatusCode::FORBIDDEN,
71
                "technique-locked",
72
                "Somebody on a forum knows how to breathe. You have not found the reply.",
73
            ));
74
        }
75
        if self.here.meditated {
76
            return Err(Problem::new(
77
                StatusCode::CONFLICT,
78
                "already-meditated",
79
                "This floor has had its meditation.",
80
            ));
81
        }
82
        self.here.meditated = true;
83
        self.step_away();
84
        self.reset_eq(self.body.eq - MEDITATION_EQ);
85
        self.shed(FRICTION_MEDITATE);
86
        self.touch();
87
        Ok(Outcome::json(
88
            StatusCode::OK,
89
            json!({
90
                "detail": "In through the nose, out through the mouth. EQ falls by ten.",
91
            }),
92
        ))
93
    }
94
}