use hashbrown::HashSet; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use crate::StringKey; /// An item category defines which bag slot items are stored in. #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[repr(u8)] pub enum ItemCategory { /// This is where most items should go. MiscItem, /// Pokeballs are used for capturing Pokemons. Pokeball, /// Medicine is used for healing HP, PP, and status effects Medicine, /// Berry is used for all berries. Berry, /// TMHM is used for Technical and Hidden Machines. TMHM, /// Form Changer is used for items that change forms, such as mega stones. FormChanger, /// Key Items are single stored items, generally used for story progression. KeyItem, /// Mail is used for mail items. Mail, } /// A battle item category defines how the item is categorized when in battle. #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[repr(u8)] pub enum BattleItemCategory { /// This item can't be used in battle. None, /// This item is used for healing Pokemon. Healing, /// This item is used for healing Pokemon from a status. StatusHealing, /// This item is used for capturing Pokemon. Pokeball, /// This item does not belong in above categories, but is still a battle item. MiscBattleItem, } /// An item is an object which the player can pick up, keep in their Bag, and use in some manner #[derive(Debug)] #[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))] pub struct Item { /// The name of the item. name: StringKey, /// Which bag slot items are stored in. category: ItemCategory, /// How the item is categorized when in battle. battle_category: BattleItemCategory, /// The buying value of the item. price: i32, /// A set of arbitrary flags that can be set on the item. flags: HashSet, } impl Item { /// Instantiates an item. pub fn new( name: &StringKey, category: ItemCategory, battle_category: BattleItemCategory, price: i32, flags: HashSet, ) -> Item { Item { name: name.clone(), category, battle_category, price, flags, } } /// The name of the item. pub fn name(&self) -> &StringKey { &self.name } /// Which bag slot items are stored in. pub fn category(&self) -> ItemCategory { self.category } /// How the item is categorized when in battle. pub fn battle_category(&self) -> BattleItemCategory { self.battle_category } /// The buying value of the item. pub fn price(&self) -> i32 { self.price } /// A set of arbitrary flags that can be set on the item. pub fn flags(&self) -> &HashSet { &self.flags } /// Checks whether the item has a specific flag. pub fn has_flag(&self, key: &StringKey) -> bool { self.flags.contains(key) } }