atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
727d064fae3881054441752bc0a2afb71e1e63dd
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/game/inventory.rsRust149 lines4.5 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
pub struct LubeStock {
42
    pub(crate) baby_oil: u32,
43
    pub(crate) coconut_oil: u32,
44
    pub(crate) lotion: u32,
45
    pub(crate) vaseline: u32,
46
}
47
48
impl Default for LubeStock {
49
    fn default() -> Self {
50
        Self {
51
            baby_oil: 1,
52
            coconut_oil: 0,
53
            lotion: 1,
54
            vaseline: 0,
55
        }
56
    }
57
}
58
59
impl LubeStock {
60
    /// Spit is the only lubricant that never runs out, so it has no count.
61
    fn bottle(&mut self, lube: Lube) -> Option<&mut u32> {
62
        match lube {
63
            Lube::Spit => None,
64
            Lube::BabyOil => Some(&mut self.baby_oil),
65
            Lube::CoconutOil => Some(&mut self.coconut_oil),
66
            Lube::Lotion => Some(&mut self.lotion),
67
            Lube::Vaseline => Some(&mut self.vaseline),
68
        }
69
    }
70
71
    pub fn has(&self, lube: Lube) -> bool {
72
        match lube {
73
            Lube::Spit => true,
74
            Lube::BabyOil => self.baby_oil > 0,
75
            Lube::CoconutOil => self.coconut_oil > 0,
76
            Lube::Lotion => self.lotion > 0,
77
            Lube::Vaseline => self.vaseline > 0,
78
        }
79
    }
80
81
    pub fn take(&mut self, lube: Lube) {
82
        if let Some(bottle) = self.bottle(lube) {
83
            *bottle = bottle.saturating_sub(1);
84
        }
85
    }
86
87
    fn add(&mut self, lube: Lube) {
88
        if let Some(bottle) = self.bottle(lube) {
89
            *bottle += 1;
90
        }
91
    }
92
}
93
94
impl Items {
95
    pub fn has(&self, item: Item) -> bool {
96
        match item {
97
            Item::WarmTowel => true,
98
            Item::IcePack => self.stores.ice_packs > 0,
99
            Item::Ruler => self.kit.ruler,
100
            Item::DoorLock => self.stores.door_locks > 0,
101
            Item::DndSign => self.kit.dnd_sign,
102
            Item::Blinds => self.kit.blinds,
103
            Item::PumpPro => self.kit.pump_pro,
104
            Item::Extender => self.kit.extender,
105
            Item::Ring => self.kit.ring,
106
            Item::Supplement => self.stores.supplements > 0,
107
            Item::Cage => self.kit.cage,
108
            Item::Spreadsheet => self.kit.spreadsheet,
109
            Item::TeapotSpout => self.kit.teapot_spout,
110
            Item::EnergyDrink => self.stores.energy_drinks > 0,
111
            Item::BabyOil => self.lubes.has(Lube::BabyOil),
112
            Item::CoconutOil => self.lubes.has(Lube::CoconutOil),
113
            Item::Lotion => self.lubes.has(Lube::Lotion),
114
            Item::Vaseline => self.lubes.has(Lube::Vaseline),
115
            Item::Pump | Item::CageKey => false,
116
        }
117
    }
118
119
    pub fn owned(&self) -> Vec<Item> {
120
        Item::ALL
121
            .into_iter()
122
            .filter(|&item| self.has(item))
123
            .collect()
124
    }
125
126
    pub fn grant(&mut self, item: Item) {
127
        match item {
128
            Item::IcePack => self.stores.ice_packs += 1,
129
            Item::Ruler => self.kit.ruler = true,
130
            Item::DoorLock => self.stores.door_locks += 1,
131
            Item::DndSign => self.kit.dnd_sign = true,
132
            Item::Blinds => self.kit.blinds = true,
133
            Item::PumpPro => self.kit.pump_pro = true,
134
            Item::Extender => self.kit.extender = true,
135
            Item::Ring => self.kit.ring = true,
136
            Item::Supplement => self.stores.supplements += 1,
137
            Item::Cage => self.kit.cage = true,
138
            Item::CageKey => self.kit.cage = false,
139
            Item::Spreadsheet => self.kit.spreadsheet = true,
140
            Item::TeapotSpout => self.kit.teapot_spout = true,
141
            Item::EnergyDrink => self.stores.energy_drinks += 1,
142
            Item::BabyOil => self.lubes.add(Lube::BabyOil),
143
            Item::CoconutOil => self.lubes.add(Lube::CoconutOil),
144
            Item::Lotion => self.lubes.add(Lube::Lotion),
145
            Item::Vaseline => self.lubes.add(Lube::Vaseline),
146
            Item::WarmTowel | Item::Pump => {}
147
        }
148
    }
149
}