luminol_data/rmxp/
enemy.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, optional_id_alox, optional_id_serde, optional_path_alox,
19    optional_path_serde, Path, Table1,
20};
21
22#[derive(Default, Debug, serde::Deserialize, serde::Serialize)]
23#[derive(alox_48::Deserialize, alox_48::Serialize)]
24#[marshal(class = "RPG::Enemy")]
25pub struct Enemy {
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 battler_name: Path,
33    pub battler_hue: i32,
34    pub maxhp: i32,
35    pub maxsp: i32,
36    pub str: i32,
37    pub dex: i32,
38    pub agi: i32,
39    pub int: i32,
40    pub atk: i32,
41    pub pdef: i32,
42    pub mdef: i32,
43    pub eva: i32,
44    #[serde(with = "optional_id_serde")]
45    #[marshal(with = "optional_id_alox")]
46    pub animation1_id: Option<usize>,
47    #[serde(with = "optional_id_serde")]
48    #[marshal(with = "optional_id_alox")]
49    pub animation2_id: Option<usize>,
50    pub element_ranks: Table1,
51    pub state_ranks: Table1,
52    pub actions: Vec<Action>,
53    pub exp: i32,
54    // FIXME: make optional
55    pub gold: i32,
56    #[serde(with = "optional_id_serde")]
57    #[marshal(with = "optional_id_alox")]
58    pub item_id: Option<usize>,
59    #[serde(with = "optional_id_serde")]
60    #[marshal(with = "optional_id_alox")]
61    pub weapon_id: Option<usize>,
62    #[serde(with = "optional_id_serde")]
63    #[marshal(with = "optional_id_alox")]
64    pub armor_id: Option<usize>,
65    pub treasure_prob: i32,
66}
67
68#[derive(Debug, serde::Deserialize, serde::Serialize)]
69#[derive(alox_48::Deserialize, alox_48::Serialize)]
70#[marshal(class = "RPG::Enemy::Action")]
71pub struct Action {
72    pub kind: Kind,
73    pub basic: Basic,
74    #[serde(with = "id_serde")]
75    #[marshal(with = "id_alox")]
76    pub skill_id: usize,
77    pub condition_turn_a: i32,
78    pub condition_turn_b: i32,
79    pub condition_hp: i32,
80    pub condition_level: i32,
81    #[serde(with = "optional_id_serde")]
82    #[marshal(with = "optional_id_alox")]
83    pub condition_switch_id: Option<usize>,
84    pub rating: i32,
85}
86
87impl Default for Action {
88    fn default() -> Self {
89        Self {
90            kind: Kind::default(),
91            basic: Basic::default(),
92            skill_id: 0,
93            condition_turn_a: 0,
94            condition_turn_b: 1,
95            condition_hp: 100,
96            condition_level: 1,
97            condition_switch_id: None,
98            rating: 5,
99        }
100    }
101}
102
103#[derive(Clone, Copy, Debug, Eq, PartialEq, Default)]
104#[derive(
105    num_enum::TryFromPrimitive,
106    num_enum::IntoPrimitive,
107    strum::Display,
108    strum::EnumIter
109)]
110#[derive(serde::Deserialize, serde::Serialize)]
111#[derive(alox_48::Deserialize, alox_48::Serialize)]
112#[repr(u8)]
113#[serde(into = "u8")]
114#[serde(try_from = "u8")]
115#[marshal(into = "u8")]
116#[marshal(try_from = "u8")]
117pub enum Kind {
118    #[default]
119    Basic = 0,
120    Skill = 1,
121}
122
123#[derive(Clone, Copy, Debug, Eq, PartialEq, Default)]
124#[derive(
125    num_enum::TryFromPrimitive,
126    num_enum::IntoPrimitive,
127    strum::Display,
128    strum::EnumIter
129)]
130#[derive(serde::Deserialize, serde::Serialize)]
131#[derive(alox_48::Deserialize, alox_48::Serialize)]
132#[repr(u8)]
133#[serde(into = "u8")]
134#[serde(try_from = "u8")]
135#[marshal(into = "u8")]
136#[marshal(try_from = "u8")]
137pub enum Basic {
138    #[default]
139    Attack = 0,
140    Defend = 1,
141    Escape = 2,
142    #[strum(to_string = "Do Nothing")]
143    DoNothing = 3,
144}