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