71 lines
2.2 KiB
Rust
Executable File
71 lines
2.2 KiB
Rust
Executable File
use crate::StringKey;
|
|
|
|
/// A parameter for an effect. This is basically a simple way to dynamically store multiple different
|
|
/// primitives on data.
|
|
#[derive(PartialEq, Debug)]
|
|
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
|
pub enum EffectParameter {
|
|
/// A boolean value.
|
|
Bool(bool),
|
|
/// An integer value. Stored as a 64 bit int to deal with potentially large numbers.
|
|
Int(i64),
|
|
/// A float value. Stored as a 32 bit float.
|
|
Float(f32),
|
|
/// A string value.
|
|
String(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<EffectParameter>,
|
|
}
|
|
|
|
impl SecondaryEffect {
|
|
/// Instantiates a new Secondary Effect.
|
|
pub fn new(chance: f32, effect_name: StringKey, parameters: Vec<EffectParameter>) -> 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<EffectParameter> {
|
|
&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);
|
|
}
|
|
}
|