PkmnLib_rs/src/static_data/moves/secondary_effect.rs

57 lines
1.7 KiB
Rust
Raw Normal View History

2022-09-18 16:02:13 +00:00
use crate::static_data::EffectParameter;
use crate::StringKey;
2022-07-01 15:07:22 +00:00
/// A secondary effect is an effect on a move that happens after it hits.
#[derive(PartialEq, Debug)]
pub struct SecondaryEffect {
2022-07-01 15:07:22 +00:00
/// The chance in percentages that the effect triggers. -1 to make it always trigger.
chance: f32,
2022-07-01 15:07:22 +00:00
/// The name of the effect.
effect_name: StringKey,
2022-07-01 15:07:22 +00:00
/// A list of parameters for the effect.
parameters: Vec<EffectParameter>,
}
impl SecondaryEffect {
2022-07-01 15:07:22 +00:00
/// Instantiates a new Secondary Effect.
pub fn new(chance: f32, effect_name: StringKey, parameters: Vec<EffectParameter>) -> SecondaryEffect {
SecondaryEffect {
chance,
effect_name,
parameters,
}
}
2022-07-01 15:07:22 +00:00
/// The chance in percentages that the effect triggers. -1 to make it always trigger.
pub fn chance(&self) -> f32 {
self.chance
}
2022-07-01 15:07:22 +00:00
/// The name of the effect.
pub fn effect_name(&self) -> &StringKey {
&self.effect_name
}
2022-07-01 15:07:22 +00:00
/// A list of parameters for the effect.
pub fn parameters(&self) -> &Vec<EffectParameter> {
&self.parameters
}
}
#[cfg(test)]
mod tests {
use assert_approx_eq::assert_approx_eq;
2022-07-01 15:07:22 +00:00
use crate::static_data::moves::secondary_effect::SecondaryEffect;
#[test]
fn create_secondary_effect() {
let empty = SecondaryEffect::new(0.0, "".into(), vec![]);
2022-06-11 18:51:37 +00:00
assert_approx_eq!(empty.chance(), 0.0);
assert_eq!(empty.effect_name(), &"".into());
2022-06-11 18:51:37 +00:00
assert_eq!(empty.parameters().len(), 0);
let set = SecondaryEffect::new(50.0, "foo".into(), Vec::new());
2022-06-11 18:51:37 +00:00
assert_approx_eq!(set.chance(), 50.0);
assert_eq!(set.effect_name(), &"foo".into());
2022-06-11 18:51:37 +00:00
assert_eq!(set.parameters().len(), 0);
}
}