Skip to main content

battler_data/items/
item_data.rs

1use alloc::string::String;
2
3use hashbrown::HashSet;
4use serde::{
5    Deserialize,
6    Serialize,
7};
8
9use crate::{
10    HitEffect,
11    ItemFlag,
12    ItemInput,
13    ItemTarget,
14    Type,
15};
16
17/// Data for what happens when "Fling" is used with this item.
18#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
19pub struct FlingData {
20    pub power: u32,
21    #[serde(default)]
22    pub use_item: bool,
23    pub hit_effect: Option<HitEffect>,
24}
25
26/// Data for what happens when "Natural Gift" is used with this item.
27#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28pub struct NaturalGiftData {
29    pub power: u32,
30    #[serde(rename = "type")]
31    pub typ: Type,
32}
33
34/// Data for what happens when "Judgment" is used with this item.
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
36pub struct JudgmentData {
37    #[serde(rename = "type")]
38    pub typ: Type,
39}
40
41/// Data for what happens when "Techno Blast" is used with this item.
42#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
43pub struct TechnoBlastData {
44    #[serde(rename = "type")]
45    pub typ: Type,
46}
47
48/// Data for what happens when "Multi-Attack" is used with this item.
49#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
50pub struct MultiAttackData {
51    #[serde(rename = "type")]
52    pub typ: Type,
53}
54
55/// Data for Mega Evolution.
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
57pub struct MegaEvolutionData {
58    pub from: String,
59    pub into: String,
60}
61
62/// Source of a Z-Crystal's power.
63#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
64pub enum ZCrystalSource {
65    #[serde(rename = "from")]
66    Move(String),
67    #[serde(rename = "type")]
68    Type(Type),
69}
70
71/// Data for Ultra Burst.
72#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
73pub struct UltraBurstData {
74    pub from: HashSet<String>,
75    pub into: String,
76}
77
78/// Data for Z-Crystals.
79#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
80pub struct ZCrystalData {
81    #[serde(flatten)]
82    pub source: Option<ZCrystalSource>,
83    pub into: String,
84    #[serde(default)]
85    pub users: HashSet<String>,
86}
87
88/// Data for special item effects; namely, item data associated with moves and effects.
89#[derive(Debug, Default, PartialEq, Eq, Clone, Serialize, Deserialize)]
90pub struct SpecialItemData {
91    pub mega_evolution: Option<MegaEvolutionData>,
92    pub z_crystal: Option<ZCrystalData>,
93    pub ultra_burst: Option<UltraBurstData>,
94
95    pub fling: Option<FlingData>,
96    pub natural_gift: Option<NaturalGiftData>,
97    pub judgment: Option<JudgmentData>,
98    pub techno_blast: Option<TechnoBlastData>,
99    pub multi_attack: Option<MultiAttackData>,
100}
101
102/// Data about a particular item.
103///
104/// Items can be held by a Mon in battle to produce various side effects. Items can affect stat
105/// calculations, move calculations, move choice restrictions, and much more.
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct ItemData {
108    /// Name of the item.
109    pub name: String,
110    /// Target of the item if used by a player.
111    pub target: Option<ItemTarget>,
112    /// Type of input received alongside the item.
113    pub input: Option<ItemInput>,
114    /// Data for special item effects associated with moves and effects.
115    #[serde(default)]
116    pub special_data: SpecialItemData,
117    /// The forme this item forces a Mon into.
118    pub force_forme: Option<String>,
119    /// Item flags.
120    pub flags: HashSet<ItemFlag>,
121
122    /// Dynamic battle effects.
123    #[serde(default)]
124    pub effect: serde_json::Value,
125    /// Dynamic battle effects of the condition created by this item.
126    #[serde(default)]
127    pub condition: serde_json::Value,
128}