luminol_data/rmxp/
item.rs

1// Copyright (C) 2024 Melody Madeline Lyons
2//
3// This file is part of Luminol.
4//
5// Luminol is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Luminol is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Luminol.  If not, see <http://www.gnu.org/licenses/>.
17pub use crate::{
18    id_alox, id_serde, id_vec_alox, id_vec_serde, optional_id_alox, optional_id_serde,
19    optional_path_alox, optional_path_serde, rpg::AudioFile, Path,
20};
21
22#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
23#[derive(alox_48::Deserialize, alox_48::Serialize)]
24#[marshal(class = "RPG::Item")]
25pub struct Item {
26    #[serde(with = "id_serde")]
27    #[marshal(with = "id_alox")]
28    pub id: usize,
29    pub name: String,
30    #[serde(with = "optional_path_serde")]
31    #[marshal(with = "optional_path_alox")]
32    pub icon_name: Option<camino::Utf8PathBuf>,
33    pub description: String,
34    pub scope: crate::rpg::Scope,
35    pub occasion: crate::rpg::Occasion,
36    #[serde(with = "optional_id_serde")]
37    #[marshal(with = "optional_id_alox")]
38    pub animation1_id: Option<usize>,
39    #[serde(with = "optional_id_serde")]
40    #[marshal(with = "optional_id_alox")]
41    pub animation2_id: Option<usize>,
42    pub menu_se: AudioFile,
43    #[serde(with = "optional_id_serde")]
44    #[marshal(with = "optional_id_alox")]
45    pub common_event_id: Option<usize>,
46    pub price: i32,
47    pub consumable: bool,
48    pub parameter_type: ParameterType,
49    pub parameter_points: i32,
50    pub recover_hp_rate: i32,
51    pub recover_hp: i32,
52    // These fields are missing in rmxp data *sometimes*.
53    // Why? Who knows!
54    #[marshal(default)]
55    #[serde(default)]
56    pub recover_sp_rate: i32,
57    #[marshal(default)]
58    #[serde(default)]
59    pub recover_sp: i32,
60    pub hit: i32,
61    pub pdef_f: i32,
62    pub mdef_f: i32,
63    pub variance: i32,
64    #[serde(with = "id_vec_serde")]
65    #[marshal(with = "id_vec_alox")]
66    pub element_set: Vec<usize>,
67    #[serde(with = "id_vec_serde")]
68    #[marshal(with = "id_vec_alox")]
69    pub plus_state_set: Vec<usize>,
70    #[serde(with = "id_vec_serde")]
71    #[marshal(with = "id_vec_alox")]
72    pub minus_state_set: Vec<usize>,
73}
74
75#[derive(Clone, Copy, Debug, Eq, PartialEq, Default)]
76#[derive(
77    num_enum::TryFromPrimitive,
78    num_enum::IntoPrimitive,
79    strum::Display,
80    strum::EnumIter
81)]
82#[derive(serde::Deserialize, serde::Serialize)]
83#[derive(alox_48::Deserialize, alox_48::Serialize)]
84#[repr(u8)]
85#[serde(into = "u8")]
86#[serde(try_from = "u8")]
87#[marshal(into = "u8")]
88#[marshal(try_from = "u8")]
89pub enum ParameterType {
90    #[default]
91    None = 0,
92    #[strum(to_string = "Max HP")]
93    MaxHP = 1,
94    #[strum(to_string = "Max SP")]
95    MaxSP = 2,
96    #[strum(to_string = "STR")]
97    Str = 3,
98    #[strum(to_string = "DEX")]
99    Dex = 4,
100    #[strum(to_string = "AGI")]
101    Agi = 5,
102    #[strum(to_string = "INT")]
103    Int = 6,
104}
105
106impl ParameterType {
107    pub fn is_none(&self) -> bool {
108        matches!(self, Self::None)
109    }
110}