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