atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
97c05b741d8f0a39cec7b9e24bf5491f18c819c5
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/cause.rsRust134 lines4.0 KB
1
use axum::http::StatusCode;
2
3
use crate::problem::Problem;
4
5
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
6
pub enum Cause {
7
    Ruptured { ice_unused: bool },
8
    Caught,
9
    Opened,
10
    Banned,
11
    Degloved,
12
    Zip,
13
    Meloned,
14
    Abandoned,
15
    Lost,
16
}
17
18
impl Cause {
19
    pub const ALL: [Self; 10] = [
20
        Self::Ruptured { ice_unused: true },
21
        Self::Ruptured { ice_unused: false },
22
        Self::Caught,
23
        Self::Opened,
24
        Self::Banned,
25
        Self::Degloved,
26
        Self::Zip,
27
        Self::Meloned,
28
        Self::Abandoned,
29
        Self::Lost,
30
    ];
31
32
    pub fn slug(self) -> &'static str {
33
        match self {
34
            Self::Ruptured { .. } => "vascular-event",
35
            Self::Caught => "caught",
36
            Self::Opened => "opened",
37
            Self::Banned => "banned",
38
            Self::Degloved => "degloved",
39
            Self::Zip => "zip",
40
            Self::Meloned => "watermelon",
41
            Self::Abandoned => "abandoned",
42
            Self::Lost => "lost",
43
        }
44
    }
45
46
    pub fn detail(self) -> &'static str {
47
        match self {
48
            Self::Ruptured { ice_unused: true } => {
49
                "A vessel has exceeded its rated pressure. The run has ended. An ice pack was available and was not used."
50
            }
51
            Self::Ruptured { ice_unused: false } => {
52
                "A vessel has exceeded its rated pressure. The run has ended."
53
            }
54
            Self::Caught => {
55
                "Mum has seen enough. The run has ended. Nobody will mention it at dinner."
56
            }
57
            Self::Opened => {
58
                "Mum has stopped knocking and opened the door. The run has ended. Nobody will mention it at dinner."
59
            }
60
            Self::Banned => "Your account has been banned. The forum can tell. The run has ended.",
61
            Self::Degloved => {
62
                "The outer layer has been removed in one piece. It will not be returning. The run has ended."
63
            }
64
            Self::Zip => {
65
                "The request conflicts with the current state of the zip. The run has ended."
66
            }
67
            Self::Meloned => {
68
                "You have been caught with the watermelon. Nobody will mention it at dinner. The run has ended."
69
            }
70
            Self::Abandoned => "The run was abandoned.",
71
            Self::Lost => {
72
                "The server fell over mid-stroke and the run went with it. Nobody will mention it at dinner."
73
            }
74
        }
75
    }
76
77
    /// The records keep the slug and the ice, which is all a cause needs to be told again.
78
    pub fn parse(slug: &str, ice_unused: bool) -> Option<Self> {
79
        Self::ALL.into_iter().find(|cause| {
80
            cause.slug() == slug
81
                && !matches!(cause, Self::Ruptured { ice_unused: unused } if *unused != ice_unused)
82
        })
83
    }
84
85
    fn status(self) -> StatusCode {
86
        match self {
87
            Self::Ruptured { .. } | Self::Lost => StatusCode::INTERNAL_SERVER_ERROR,
88
            Self::Caught | Self::Opened | Self::Degloved | Self::Abandoned | Self::Meloned => {
89
                StatusCode::GONE
90
            }
91
            Self::Banned => StatusCode::FORBIDDEN,
92
            Self::Zip => StatusCode::CONFLICT,
93
        }
94
    }
95
96
    pub fn problem(self) -> Problem {
97
        Problem::new(self.status(), self.slug(), self.detail())
98
    }
99
}
100
101
pub struct Ending {
102
    pub(crate) cause: Cause,
103
    pub(crate) turn: u32,
104
}
105
106
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
107
pub enum RunStatus {
108
    Alive,
109
    Prescribed,
110
    /// The true ending, the clinic's `304`.
111
    Normal,
112
    Gone,
113
}
114
115
impl RunStatus {
116
    pub const ALL: [Self; 4] = [Self::Alive, Self::Prescribed, Self::Normal, Self::Gone];
117
118
    pub fn name(self) -> &'static str {
119
        match self {
120
            Self::Alive => "alive",
121
            Self::Prescribed => "prescribed",
122
            Self::Normal => "normal",
123
            Self::Gone => "gone",
124
        }
125
    }
126
127
    pub fn parse(name: &str) -> Option<Self> {
128
        Self::ALL.into_iter().find(|status| status.name() == name)
129
    }
130
131
    pub fn finished(self) -> bool {
132
        self != Self::Alive
133
    }
134
}