firecore_battle/
moves.rs

1use serde::{Deserialize, Serialize};
2
3use pokedex::{
4    ailment::LiveAilment,
5    item::ItemId,
6    moves::{MoveId, PP},
7    pokemon::{Experience, Level},
8};
9
10use crate::pokemon::{
11    stat::{BattleStatType, Stage},
12    Indexed, PokemonIdentifier,
13};
14
15pub mod damage;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
18pub enum MoveCancel {
19    Flinch,
20    Sleep,
21    Paralysis,
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
25pub enum BattleMove<ID> {
26    /// Move (by its index), and its optional target.
27    Move(usize, Option<PokemonIdentifier<ID>>),
28    UseItem(Indexed<ID, ItemId>),
29    Switch(usize),
30}
31
32#[derive(Debug, Clone, Deserialize, Serialize)]
33pub enum ClientMove<ID> {
34    /// Id of move, PP lost from using the move, client move actions
35    Move(MoveId, PP, Vec<Indexed<ID, ClientMoveAction>>),
36    UseItem(Indexed<ID, ItemId>),
37    Switch(usize),
38}
39
40#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
41pub enum ClientMoveAction {
42    /// This contains the percent HP the pokemon was left at, how effective the attack was, and if it was a critical hit.
43    /// A Pokemon faints when it's hp is set to 0.0
44    SetHP(damage::ClientDamage<f32>),
45    AddStat(BattleStatType, Stage),
46    Ailment(Option<LiveAilment>),
47
48    Cancel(MoveCancel),
49    Miss,
50
51    SetExp(Experience, Level),
52
53    Error,
54}
55
56pub type Critical = bool;
57/// 0 through 100
58pub type Percent = u8;
59
60impl<ID: core::fmt::Display> core::fmt::Display for BattleMove<ID> {
61    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
62        match self {
63            BattleMove::Move(index, ..) => write!(f, "Move #{}", index),
64            BattleMove::UseItem(Indexed(.., id)) => write!(f, "Item {}", id.as_str()),
65            BattleMove::Switch(index) => write!(f, "Switch to {}", index),
66        }
67    }
68}