PkmnLib_rs/src/static_data/moves/move_data.rs

117 lines
2.5 KiB
Rust
Raw Normal View History

2022-06-11 18:51:37 +00:00
use crate::static_data::SecondaryEffect;
use crate::StringKey;
use hashbrown::HashSet;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum MoveCategory {
Physical = 0,
Special = 1,
Status = 2,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum MoveTarget {
Adjacent = 0,
AdjacentAlly,
AdjacentAllySelf,
AdjacentOpponent,
All,
AllAdjacent,
AllAdjacentOpponent,
AllAlly,
AllOpponent,
Any,
RandomOpponent,
#[cfg_attr(feature = "serde", serde(rename = "Self"))]
SelfUse,
}
#[derive(PartialEq, Debug)]
pub struct MoveData {
name: StringKey,
move_type: u8,
category: MoveCategory,
base_power: u8,
accuracy: u8,
base_usages: u8,
target: MoveTarget,
priority: i8,
secondary_effect: SecondaryEffect,
flags: HashSet<StringKey>,
}
impl MoveData {
pub fn new(
name: &StringKey,
move_type: u8,
category: MoveCategory,
base_power: u8,
accuracy: u8,
base_usages: u8,
target: MoveTarget,
priority: i8,
secondary_effect: SecondaryEffect,
flags: HashSet<StringKey>,
) -> MoveData {
MoveData {
name: name.clone(),
move_type,
category,
base_power,
accuracy,
base_usages,
target,
priority,
secondary_effect,
flags,
}
}
pub fn name(&self) -> &StringKey {
&self.name
}
pub fn move_type(&self) -> u8 {
self.move_type
}
pub fn category(&self) -> MoveCategory {
self.category
}
pub fn base_power(&self) -> u8 {
self.base_power
}
pub fn accuracy(&self) -> u8 {
self.accuracy
}
pub fn base_usages(&self) -> u8 {
self.base_usages
}
pub fn target(&self) -> MoveTarget {
self.target
}
pub fn priority(&self) -> i8 {
self.priority
}
pub fn secondary_effect(&self) -> &SecondaryEffect {
&self.secondary_effect
}
pub fn has_secondary_effect(&self) -> bool {
self.secondary_effect.effect_name() != &StringKey::empty()
}
pub fn has_flag(&self, key: &StringKey) -> bool {
self.flags.contains(key)
}
}