2023-07-29 10:57:52 +00:00
|
|
|
use crate::static_data::Parameter;
|
2023-06-24 12:44:23 +00:00
|
|
|
use crate::StringKey;
|
2022-11-27 16:47:51 +00:00
|
|
|
use std::fmt::Debug;
|
2023-06-22 13:43:41 +00:00
|
|
|
use std::sync::Arc;
|
2022-11-27 16:47:51 +00:00
|
|
|
|
|
|
|
/// An ability is a passive effect in battle that is attached to a Pokemon.
|
2023-06-24 12:44:23 +00:00
|
|
|
pub trait Ability: Debug {
|
2022-11-27 16:47:51 +00:00
|
|
|
/// The name of the ability.
|
|
|
|
fn name(&self) -> &StringKey;
|
|
|
|
/// The name of the script effect of the ability.
|
|
|
|
fn effect(&self) -> &StringKey;
|
|
|
|
/// The parameters for the script effect of the ability.
|
2023-07-29 10:57:52 +00:00
|
|
|
fn parameters(&self) -> &Vec<Arc<Parameter>>;
|
2022-11-27 16:47:51 +00:00
|
|
|
}
|
2022-06-11 15:22:46 +00:00
|
|
|
|
2022-07-01 15:52:00 +00:00
|
|
|
/// An ability is a passive effect in battle that is attached to a Pokemon.
|
2022-06-11 15:22:46 +00:00
|
|
|
#[derive(Debug)]
|
2022-11-27 16:47:51 +00:00
|
|
|
pub struct AbilityImpl {
|
2022-07-01 15:52:00 +00:00
|
|
|
/// The name of the ability.
|
2022-06-11 15:22:46 +00:00
|
|
|
name: StringKey,
|
2022-07-01 15:52:00 +00:00
|
|
|
/// The name of the script effect of the ability.
|
2022-06-11 15:22:46 +00:00
|
|
|
effect: StringKey,
|
2022-07-01 15:52:00 +00:00
|
|
|
/// The parameters for the script effect of the ability.
|
2023-07-29 10:57:52 +00:00
|
|
|
parameters: Vec<Arc<Parameter>>,
|
2022-06-11 15:22:46 +00:00
|
|
|
}
|
|
|
|
|
2022-11-27 16:47:51 +00:00
|
|
|
impl AbilityImpl {
|
2022-07-01 15:52:00 +00:00
|
|
|
/// Instantiates a new ability.
|
2023-07-29 10:57:52 +00:00
|
|
|
pub fn new(name: &StringKey, effect: &StringKey, parameters: Vec<Arc<Parameter>>) -> Self {
|
2022-06-11 15:22:46 +00:00
|
|
|
Self {
|
|
|
|
name: name.clone(),
|
|
|
|
effect: effect.clone(),
|
|
|
|
parameters,
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 16:47:51 +00:00
|
|
|
}
|
2022-06-11 15:22:46 +00:00
|
|
|
|
2022-11-27 16:47:51 +00:00
|
|
|
impl Ability for AbilityImpl {
|
2022-07-01 15:52:00 +00:00
|
|
|
/// The name of the ability.
|
2022-11-27 16:47:51 +00:00
|
|
|
fn name(&self) -> &StringKey {
|
2022-06-11 15:22:46 +00:00
|
|
|
&self.name
|
|
|
|
}
|
2022-07-01 15:52:00 +00:00
|
|
|
/// The name of the script effect of the ability.
|
2022-11-27 16:47:51 +00:00
|
|
|
fn effect(&self) -> &StringKey {
|
2022-06-11 15:22:46 +00:00
|
|
|
&self.effect
|
|
|
|
}
|
2022-07-01 15:52:00 +00:00
|
|
|
/// The parameters for the script effect of the ability.
|
2023-07-29 10:57:52 +00:00
|
|
|
fn parameters(&self) -> &Vec<Arc<Parameter>> {
|
2022-06-11 15:22:46 +00:00
|
|
|
&self.parameters
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:20:16 +00:00
|
|
|
|
|
|
|
/// An ability index allows us to find an ability on a form. It combines a bool for whether the
|
|
|
|
/// ability is hidden or not, and then an index of the ability.
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
2023-07-22 10:23:33 +00:00
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
2022-08-20 10:22:12 +00:00
|
|
|
#[repr(C)]
|
2022-07-01 16:20:16 +00:00
|
|
|
pub struct AbilityIndex {
|
|
|
|
/// Whether or not the ability we're referring to is a hidden ability.
|
|
|
|
pub hidden: bool,
|
|
|
|
/// The index of the ability.
|
|
|
|
pub index: u8,
|
|
|
|
}
|
2022-11-28 20:34:28 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
2023-04-19 16:44:11 +00:00
|
|
|
#[allow(clippy::indexing_slicing)]
|
|
|
|
#[allow(clippy::unwrap_used)]
|
2022-11-28 20:34:28 +00:00
|
|
|
pub(crate) mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
mockall::mock! {
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub Ability{}
|
|
|
|
impl Ability for Ability {
|
|
|
|
fn name(&self) -> &StringKey;
|
|
|
|
fn effect(&self) -> &StringKey;
|
2023-07-29 10:57:52 +00:00
|
|
|
fn parameters(&self) -> &Vec<Arc<Parameter >>;
|
2022-11-28 20:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|