atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
fa21a42ca0856e336f8217a763a57c0af40afc6d
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/inventory.rsRust139 lines4.4 KB
1
use super::{Item, Lube, balance::STARTING_ICE_PACKS};
2
3
#[derive(Default)]
4
pub struct Items {
5
    pub(crate) kit: Kit,
6
    pub(crate) stores: Stores,
7
    pub(crate) lubes: LubeStock,
8
}
9
10
#[derive(Default)]
11
pub struct Kit {
12
    pub(crate) ruler: bool,
13
    pub(crate) dnd_sign: bool,
14
    pub(crate) blinds: bool,
15
    pub(crate) pump_pro: bool,
16
    pub(crate) extender: bool,
17
    pub(crate) ring: bool,
18
    pub(crate) cage: bool,
19
    pub(crate) spreadsheet: bool,
20
    pub(crate) teapot_spout: bool,
21
}
22
23
pub struct Stores {
24
    pub(crate) ice_packs: u32,
25
    pub(crate) door_locks: u32,
26
    pub(crate) supplements: u32,
27
    pub(crate) energy_drinks: u32,
28
}
29
30
impl Default for Stores {
31
    fn default() -> Self {
32
        Self {
33
            ice_packs: STARTING_ICE_PACKS,
34
            door_locks: 0,
35
            supplements: 0,
36
            energy_drinks: 0,
37
        }
38
    }
39
}
40
41
#[derive(Default)]
42
pub struct LubeStock {
43
    pub(crate) baby_oil: u32,
44
    pub(crate) coconut_oil: u32,
45
    pub(crate) lotion: u32,
46
    pub(crate) vaseline: u32,
47
}
48
49
impl LubeStock {
50
    /// Spit is the only lubricant that never runs out, so it has no count.
51
    fn bottle(&mut self, lube: Lube) -> Option<&mut u32> {
52
        match lube {
53
            Lube::Spit => None,
54
            Lube::BabyOil => Some(&mut self.baby_oil),
55
            Lube::CoconutOil => Some(&mut self.coconut_oil),
56
            Lube::Lotion => Some(&mut self.lotion),
57
            Lube::Vaseline => Some(&mut self.vaseline),
58
        }
59
    }
60
61
    pub fn has(&self, lube: Lube) -> bool {
62
        match lube {
63
            Lube::Spit => true,
64
            Lube::BabyOil => self.baby_oil > 0,
65
            Lube::CoconutOil => self.coconut_oil > 0,
66
            Lube::Lotion => self.lotion > 0,
67
            Lube::Vaseline => self.vaseline > 0,
68
        }
69
    }
70
71
    pub fn take(&mut self, lube: Lube) {
72
        if let Some(bottle) = self.bottle(lube) {
73
            *bottle = bottle.saturating_sub(1);
74
        }
75
    }
76
77
    fn add(&mut self, lube: Lube) {
78
        if let Some(bottle) = self.bottle(lube) {
79
            *bottle += 1;
80
        }
81
    }
82
}
83
84
impl Items {
85
    pub fn has(&self, item: Item) -> bool {
86
        match item {
87
            Item::WarmTowel => true,
88
            Item::IcePack => self.stores.ice_packs > 0,
89
            Item::Ruler => self.kit.ruler,
90
            Item::DoorLock => self.stores.door_locks > 0,
91
            Item::DndSign => self.kit.dnd_sign,
92
            Item::Blinds => self.kit.blinds,
93
            Item::PumpPro => self.kit.pump_pro,
94
            Item::Extender => self.kit.extender,
95
            Item::Ring => self.kit.ring,
96
            Item::Supplement => self.stores.supplements > 0,
97
            Item::Cage => self.kit.cage,
98
            Item::Spreadsheet => self.kit.spreadsheet,
99
            Item::TeapotSpout => self.kit.teapot_spout,
100
            Item::EnergyDrink => self.stores.energy_drinks > 0,
101
            Item::BabyOil => self.lubes.has(Lube::BabyOil),
102
            Item::CoconutOil => self.lubes.has(Lube::CoconutOil),
103
            Item::Lotion => self.lubes.has(Lube::Lotion),
104
            Item::Vaseline => self.lubes.has(Lube::Vaseline),
105
            Item::Pump | Item::CageKey => false,
106
        }
107
    }
108
109
    pub fn owned(&self) -> Vec<Item> {
110
        Item::ALL
111
            .into_iter()
112
            .filter(|&item| self.has(item))
113
            .collect()
114
    }
115
116
    pub fn grant(&mut self, item: Item) {
117
        match item {
118
            Item::IcePack => self.stores.ice_packs += 1,
119
            Item::Ruler => self.kit.ruler = true,
120
            Item::DoorLock => self.stores.door_locks += 1,
121
            Item::DndSign => self.kit.dnd_sign = true,
122
            Item::Blinds => self.kit.blinds = true,
123
            Item::PumpPro => self.kit.pump_pro = true,
124
            Item::Extender => self.kit.extender = true,
125
            Item::Ring => self.kit.ring = true,
126
            Item::Supplement => self.stores.supplements += 1,
127
            Item::Cage => self.kit.cage = true,
128
            Item::CageKey => self.kit.cage = false,
129
            Item::Spreadsheet => self.kit.spreadsheet = true,
130
            Item::TeapotSpout => self.kit.teapot_spout = true,
131
            Item::EnergyDrink => self.stores.energy_drinks += 1,
132
            Item::BabyOil => self.lubes.add(Lube::BabyOil),
133
            Item::CoconutOil => self.lubes.add(Lube::CoconutOil),
134
            Item::Lotion => self.lubes.add(Lube::Lotion),
135
            Item::Vaseline => self.lubes.add(Lube::Vaseline),
136
            Item::WarmTowel | Item::Pump => {}
137
        }
138
    }
139
}