2022-09-18 16:02:13 +00:00
|
|
|
use crate::static_data::EffectParameter;
|
2022-06-16 15:59:33 +00:00
|
|
|
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.
|
2022-06-06 12:43:41 +00:00
|
|
|
#[derive(PartialEq, Debug)]
|
2021-01-30 21:29:59 +00:00
|
|
|
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.
|
2021-01-30 21:29:59 +00:00
|
|
|
chance: f32,
|
2022-07-01 15:07:22 +00:00
|
|
|
/// The name of the effect.
|
2022-06-16 15:59:33 +00:00
|
|
|
effect_name: StringKey,
|
2022-07-01 15:07:22 +00:00
|
|
|
/// A list of parameters for the effect.
|
2021-01-30 21:29:59 +00:00
|
|
|
parameters: Vec<EffectParameter>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SecondaryEffect {
|
2022-07-01 15:07:22 +00:00
|
|
|
/// Instantiates a new Secondary Effect.
|
2022-06-16 15:59:33 +00:00
|
|
|
pub fn new(chance: f32, effect_name: StringKey, parameters: Vec<EffectParameter>) -> SecondaryEffect {
|
2021-01-30 21:29:59 +00:00
|
|
|
SecondaryEffect {
|
|
|
|
chance,
|
|
|
|
effect_name,
|
|
|
|
parameters,
|
|
|
|
}
|
|
|
|
}
|
2022-06-06 12:43:41 +00:00
|
|
|
|
2022-07-01 15:07:22 +00:00
|
|
|
/// The chance in percentages that the effect triggers. -1 to make it always trigger.
|
2022-06-06 12:43:41 +00:00
|
|
|
pub fn chance(&self) -> f32 {
|
|
|
|
self.chance
|
|
|
|
}
|
2022-07-01 15:07:22 +00:00
|
|
|
/// The name of the effect.
|
2022-06-16 15:59:33 +00:00
|
|
|
pub fn effect_name(&self) -> &StringKey {
|
2022-06-06 12:43:41 +00:00
|
|
|
&self.effect_name
|
|
|
|
}
|
2022-07-01 15:07:22 +00:00
|
|
|
/// A list of parameters for the effect.
|
2022-06-06 12:43:41 +00:00
|
|
|
pub fn parameters(&self) -> &Vec<EffectParameter> {
|
|
|
|
&self.parameters
|
|
|
|
}
|
2021-01-30 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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;
|
|
|
|
|
2021-01-30 21:29:59 +00:00
|
|
|
#[test]
|
|
|
|
fn create_secondary_effect() {
|
2022-06-19 10:07:54 +00:00
|
|
|
let empty = SecondaryEffect::new(0.0, "".into(), vec![]);
|
2022-06-11 18:51:37 +00:00
|
|
|
assert_approx_eq!(empty.chance(), 0.0);
|
2022-06-16 15:59:33 +00:00
|
|
|
assert_eq!(empty.effect_name(), &"".into());
|
2022-06-11 18:51:37 +00:00
|
|
|
assert_eq!(empty.parameters().len(), 0);
|
2022-06-16 15:59:33 +00:00
|
|
|
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);
|
2022-06-16 15:59:33 +00:00
|
|
|
assert_eq!(set.effect_name(), &"foo".into());
|
2022-06-11 18:51:37 +00:00
|
|
|
assert_eq!(set.parameters().len(), 0);
|
2021-01-30 21:29:59 +00:00
|
|
|
}
|
|
|
|
}
|