an http based roguelike rpg about jelqing
Blame: src/game/drawer.rs
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 1 | use super::{ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 2 | Floor, Item, Notice, Outcome, Run, |
56d34031c321 | atagen | 2026-10-14 09:23 UTC | 3 | balance::{ |
56d34031c321 | atagen | 2026-10-14 09:23 UTC | 4 | BATHROOM_VASELINE, DRAWER_JAMS, GREGS_LOCKER, KEY_IN_DRAWER, RULER_IN_DRAWER, RULER_SHAME, |
56d34031c321 | atagen | 2026-10-14 09:23 UTC | 5 | }, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 6 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 7 | use crate::problem::Problem; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 8 | use axum::http::{StatusCode, header}; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 9 | use serde_json::json; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 10 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 11 | fn nothing() -> Result<Outcome, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | Ok(Outcome::empty(StatusCode::NO_CONTENT)) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 13 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 14 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 15 | impl Run { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 16 | pub(super) fn found(&self, item: Item, detail: &str) -> Outcome { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 17 | Outcome::json(StatusCode::FOUND, json!({ "detail": detail })).header( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 18 | header::LOCATION, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 19 | self.path(&format!("/inventory/{}", item.slug())), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 20 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 21 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 22 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 23 | pub fn search_drawer(&mut self) -> Result<Outcome, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 24 | self.touch(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 25 | self.end_kitchen_visit(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 26 | if self.items.kit.cage { |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 27 | return self.rummage_for_key(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 28 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 29 | let first = !self.here.drawer.searched; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 30 | self.here.drawer.searched = true; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 31 | match self.floor { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 32 | Floor::Bedroom => self.search_bedroom(first), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 33 | Floor::Bathroom if first => Ok(self.search_bathroom()), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 34 | Floor::ChangingRoom => self.search_locker(first), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 35 | Floor::Nans if first => { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 36 | self.items.grant(Item::Cage); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 37 | self.standing.shame += 5; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 38 | Ok(self.found( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 39 | Item::Cage, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 40 | "A small box. Inside was a cage. It is now on. The key is not in the box.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 41 | )) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 42 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 43 | Floor::Hotel if first => { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 44 | for item in [Item::DndSign, Item::IcePack, Item::IcePack, Item::Lotion] { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 45 | self.items.grant(item); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 46 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 47 | Ok(self.found( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 48 | Item::DndSign, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 49 | "A Do Not Disturb sign, two ice packs from the machine down the hall, and a complimentary lotion.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 50 | )) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 51 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 52 | Floor::Forum if first => { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 53 | self.items.grant(Item::Spreadsheet); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 54 | Ok(self.found( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | Item::Spreadsheet, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 56 | "Your own spreadsheet. Every line is flat.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 57 | )) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 58 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 59 | Floor::Clinic => Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 60 | StatusCode::FORBIDDEN, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 61 | "doctors-drawer", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 62 | "That is the doctor's drawer.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 63 | )), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 64 | _ => nothing(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 65 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 66 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 67 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 68 | fn search_bedroom(&mut self, first: bool) -> Result<Outcome, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 69 | let ruler_here = self.chance( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 70 | self.decision("ruler", "Is there a ruler hiding in the drawer?"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 71 | RULER_IN_DRAWER, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 72 | ); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 73 | if !first || self.items.kit.ruler || !ruler_here { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 74 | return nothing(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 75 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 76 | self.items.grant(Item::Ruler); |
56d34031c321 | atagen | 2026-10-14 09:23 UTC | 77 | self.standing.shame += RULER_SHAME; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 78 | Ok(self.found( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 79 | Item::Ruler, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 80 | "You now know. This is the first honest measurement of the run.", |
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 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 84 | fn search_bathroom(&mut self) -> Outcome { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 85 | self.items.grant(Item::DoorLock); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 86 | let vaseline = self.chance( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 87 | self.decision( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 88 | "bathroom-vaseline", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 89 | "Is it the vaseline behind the door lock, rather than the lotion?", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 90 | ), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 91 | BATHROOM_VASELINE, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 92 | ); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 93 | let (lube, detail) = if vaseline { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 94 | ( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 95 | Item::Vaseline, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 96 | "A door lock, which works once, and a tub of vaseline behind it.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 97 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 98 | } else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 99 | ( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 100 | Item::Lotion, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 101 | "A door lock, which works once, and a bottle of lotion behind it.", |
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 | self.items.grant(lube); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 105 | self.found(Item::DoorLock, detail) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 106 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 107 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 108 | fn search_locker(&mut self, first: bool) -> Result<Outcome, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 109 | let open = first |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 110 | && self.chance( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 111 | self.decision("gregs-locker", "Has Greg left his locker open?"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 112 | GREGS_LOCKER, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 113 | ); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 114 | if open { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 115 | self.items.grant(Item::BabyOil); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 116 | return Ok(self.found( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 117 | Item::BabyOil, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 118 | "Greg has left his locker open. The baby oil is yours now, legally speaking.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 119 | )); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 120 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 121 | self.standing.shame += 3; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 122 | Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 123 | StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 124 | "not-your-locker", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 125 | "That locker belongs to Greg. The server cannot serve this request for legal reasons.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 126 | )) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 127 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 128 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 129 | /// Searching while caged is noisy, costs the floor turn, and the key only turns up some of |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 130 | /// the time. A jammed drawer takes a whole turn to work loose. |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 131 | pub(super) fn rummage_for_key(&mut self) -> Result<Outcome, Problem> { |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 132 | self.begin_turn()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 133 | self.add_suspicion(1); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 134 | self.maybe_summon_mum(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 135 | if self.here.drawer.jammed { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 136 | self.here.drawer.jammed = false; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 137 | self.notices.push(Notice::DrawerComesLoose); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 138 | return Ok(Outcome::empty(StatusCode::NO_CONTENT)); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 139 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 140 | if !self.chance( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 141 | self.decision("key", "Does the drawer finally give up the cage key?"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 142 | KEY_IN_DRAWER, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 143 | ) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 144 | if self.chance( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 145 | self.decision("drawer-jams", "Has the drawer jammed on its runners?"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 146 | DRAWER_JAMS, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 147 | ) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 148 | self.here.drawer.jammed = true; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 149 | self.notices.push(Notice::DrawerJammed); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 150 | } |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 151 | return Ok(Outcome::empty(StatusCode::NO_CONTENT)); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 152 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 153 | self.items.grant(Item::CageKey); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 154 | Ok(Outcome::json( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 155 | StatusCode::OK, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 156 | json!({ "detail": "The key was in the drawer. The cage is off." }), |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 157 | )) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 158 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 159 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 160 | pub fn drawer_worth_searching(&self) -> bool { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 161 | !self.here.drawer.searched || self.items.kit.cage |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 162 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 163 | } |