PkmnLib_rs/src/static_data/natures.rs

83 lines
2.8 KiB
Rust
Raw Normal View History

2022-06-11 18:51:37 +00:00
use crate::static_data::Statistic;
use crate::{ValueIdentifiable, ValueIdentifier};
2022-11-27 16:36:42 +00:00
use std::fmt::Debug;
use std::sync::Arc;
2022-06-06 11:54:59 +00:00
2022-11-27 16:36:42 +00:00
/// A nature is an attribute on a Pokemon that modifies the effective base stats on a Pokemon. They
/// can have an increased statistic and a decreased statistic, or be neutral.
pub trait Nature: ValueIdentifiable + Debug {
/// The stat that should receive the increased modifier.
fn increased_stat(&self) -> Statistic;
/// The stat that should receive the decreased modifier.
fn decreased_stat(&self) -> Statistic;
/// Calculates the modifier for a given stat. If it's the increased stat, returns the increased
/// modifier, if it's the decreased stat, returns the decreased modifier. Otherwise returns 1.0
fn get_stat_modifier(&self, stat: Statistic) -> f32;
}
2022-07-01 15:07:22 +00:00
/// A nature is an attribute on a Pokemon that modifies the effective base stats on a Pokemon. They
/// can have an increased statistic and a decreased statistic, or be neutral.
2022-06-06 11:54:59 +00:00
#[derive(Debug)]
2022-11-27 16:36:42 +00:00
pub struct NatureImpl {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
2022-07-01 15:07:22 +00:00
/// The stat that should receive the increased modifier.
2022-06-06 11:54:59 +00:00
increase_stat: Statistic,
2022-07-01 15:07:22 +00:00
/// The stat that should receive the decreased modifier.
2022-06-06 11:54:59 +00:00
decrease_stat: Statistic,
2022-07-01 15:07:22 +00:00
/// The amount by which the increased stat is multiplied.
2022-06-06 11:54:59 +00:00
increase_modifier: f32,
2022-07-01 15:07:22 +00:00
/// The amount by which the decreased stat is multiplied.
2022-06-06 11:54:59 +00:00
decrease_modifier: f32,
}
2022-11-27 16:36:42 +00:00
impl NatureImpl {
2022-07-01 15:07:22 +00:00
/// Instantiates a new statistic.
2022-06-06 11:54:59 +00:00
pub fn new(
increase_stat: Statistic,
decrease_stat: Statistic,
increase_modifier: f32,
decrease_modifier: f32,
) -> Arc<Self> {
Arc::new(Self {
identifier: Default::default(),
2022-06-06 11:54:59 +00:00
increase_stat,
decrease_stat,
increase_modifier,
decrease_modifier,
})
2022-06-06 11:54:59 +00:00
}
2022-11-27 16:36:42 +00:00
}
2022-06-06 11:54:59 +00:00
2022-11-27 16:36:42 +00:00
impl Nature for NatureImpl {
2022-07-01 15:07:22 +00:00
/// The stat that should receive the increased modifier.
2022-11-27 16:36:42 +00:00
fn increased_stat(&self) -> Statistic {
2022-06-06 11:54:59 +00:00
self.increase_stat
}
2022-07-01 15:07:22 +00:00
/// The stat that should receive the decreased modifier.
2022-11-27 16:36:42 +00:00
fn decreased_stat(&self) -> Statistic {
2022-06-06 11:54:59 +00:00
self.decrease_stat
}
2022-07-01 15:07:22 +00:00
/// Calculates the modifier for a given stat. If it's the increased stat, returns the increased
/// modifier, if it's the decreased stat, returns the decreased modifier. Otherwise returns 1.0
2022-11-27 16:36:42 +00:00
fn get_stat_modifier(&self, stat: Statistic) -> f32 {
2022-09-18 16:02:13 +00:00
if stat == self.increase_stat && stat != self.decrease_stat {
2022-06-06 11:54:59 +00:00
self.increase_modifier
2022-09-18 16:02:13 +00:00
} else if stat == self.decrease_stat && stat != self.increase_stat {
2022-06-06 11:54:59 +00:00
self.decrease_modifier
} else {
1.0
}
}
}
2022-11-27 16:36:42 +00:00
impl ValueIdentifiable for NatureImpl {
fn value_identifier(&self) -> ValueIdentifier {
self.identifier
}
}