66 lines
2.0 KiB
Rust
Executable File
66 lines
2.0 KiB
Rust
Executable File
use crate::static_data::EffectParameter;
|
|
use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
|
|
|
|
/// A secondary effect is an effect on a move that happens after it hits.
|
|
#[derive(PartialEq, Debug)]
|
|
pub struct SecondaryEffect {
|
|
/// A unique identifier so we know what value this is.
|
|
identifier: ValueIdentifier,
|
|
/// 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<EffectParameter>,
|
|
}
|
|
|
|
impl SecondaryEffect {
|
|
/// Instantiates a new Secondary Effect.
|
|
pub fn new(chance: f32, effect_name: StringKey, parameters: Vec<EffectParameter>) -> SecondaryEffect {
|
|
SecondaryEffect {
|
|
identifier: Default::default(),
|
|
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<EffectParameter> {
|
|
&self.parameters
|
|
}
|
|
}
|
|
|
|
impl ValueIdentifiable for SecondaryEffect {
|
|
fn value_identifier(&self) -> ValueIdentifier {
|
|
self.identifier
|
|
}
|
|
}
|
|
|
|
#[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);
|
|
}
|
|
}
|