Initial commit, implements most of the static_data side.
This commit is contained in:
65
src/static_data/statistic_set.rs
Normal file
65
src/static_data/statistic_set.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use super::statistics::Statistic;
|
||||
use derive_getters::Getters;
|
||||
use num_traits::PrimInt;
|
||||
|
||||
#[derive(Default, Eq, PartialEq, Debug, Getters)]
|
||||
pub struct StatisticSet<T>
|
||||
where
|
||||
T: PrimInt,
|
||||
{
|
||||
hp: T,
|
||||
attack: T,
|
||||
defense: T,
|
||||
special_attack: T,
|
||||
special_defense: T,
|
||||
speed: T,
|
||||
}
|
||||
|
||||
impl<T> StatisticSet<T>
|
||||
where
|
||||
T: PrimInt,
|
||||
{
|
||||
pub fn get_stat(&self, stat: Statistic) -> T {
|
||||
match stat {
|
||||
Statistic::HP => self.hp,
|
||||
Statistic::Attack => self.attack,
|
||||
Statistic::Defense => self.defense,
|
||||
Statistic::SpecialAttack => self.special_attack,
|
||||
Statistic::SpecialDefense => self.special_defense,
|
||||
Statistic::Speed => self.speed,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_stat(&mut self, stat: Statistic, value: T) {
|
||||
match stat {
|
||||
Statistic::HP => self.hp = value,
|
||||
Statistic::Attack => self.attack = value,
|
||||
Statistic::Defense => self.defense = value,
|
||||
Statistic::SpecialAttack => self.special_attack = value,
|
||||
Statistic::SpecialDefense => self.special_defense = value,
|
||||
Statistic::Speed => self.speed = value,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn increase_stat(&mut self, stat: Statistic, value: T) {
|
||||
match stat {
|
||||
Statistic::HP => self.hp = self.hp + value,
|
||||
Statistic::Attack => self.attack = self.attack + value,
|
||||
Statistic::Defense => self.defense = self.defense + value,
|
||||
Statistic::SpecialAttack => self.special_attack = self.special_attack + value,
|
||||
Statistic::SpecialDefense => self.special_defense = self.special_defense + value,
|
||||
Statistic::Speed => self.speed = self.speed + value,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decrease_stat(&mut self, stat: Statistic, value: T) {
|
||||
match stat {
|
||||
Statistic::HP => self.hp = self.hp - value,
|
||||
Statistic::Attack => self.attack = self.attack - value,
|
||||
Statistic::Defense => self.defense = self.defense - value,
|
||||
Statistic::SpecialAttack => self.special_attack = self.special_attack - value,
|
||||
Statistic::SpecialDefense => self.special_defense = self.special_defense - value,
|
||||
Statistic::Speed => self.speed = self.speed - value,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user