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