Further massive amounts of work

This commit is contained in:
2022-06-06 13:54:59 +02:00
parent df662ce6b5
commit ce33ec0649
33 changed files with 848 additions and 80 deletions

View File

@@ -19,6 +19,24 @@ impl<T> StatisticSet<T>
where
T: PrimInt,
{
pub fn new(
hp: T,
attack: T,
defense: T,
special_attack: T,
special_defense: T,
speed: T,
) -> Self {
Self {
hp,
attack,
defense,
special_attack,
special_defense,
speed,
}
}
pub const fn get_stat(&self, stat: Statistic) -> T {
match stat {
Statistic::HP => self.hp,
@@ -63,3 +81,91 @@ where
}
}
}
#[derive(Default, Eq, PartialEq, Copy, Clone, Debug, Getters)]
pub struct ClampedStatisticSet<T, const MIN: i64, const MAX: i64>
where
T: PrimInt,
{
hp: T,
attack: T,
defense: T,
special_attack: T,
special_defense: T,
speed: T,
}
impl<T, const MIN: i64, const MAX: i64> ClampedStatisticSet<T, MIN, MAX>
where
T: PrimInt,
{
pub const 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, mut value: T) {
if value < T::from(MIN).unwrap() {
value = T::from(MIN).unwrap();
} else if value > T::from(MAX).unwrap() {
value = T::from(MAX).unwrap();
}
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,
}
}
fn change_stat(mut new_value: T, original_value: &mut T) -> bool {
if new_value < T::from(MIN).unwrap() {
new_value = T::from(MIN).unwrap();
} else if new_value > T::from(MAX).unwrap() {
new_value = T::from(MAX).unwrap();
}
if *original_value == new_value {
return false;
}
*original_value = new_value;
true
}
pub fn increase_stat(&mut self, stat: Statistic, value: T) -> bool {
match stat {
Statistic::HP => Self::change_stat(self.hp + value, &mut self.hp),
Statistic::Attack => Self::change_stat(self.attack + value, &mut self.attack),
Statistic::Defense => Self::change_stat(self.defense + value, &mut self.defense),
Statistic::SpecialAttack => {
Self::change_stat(self.special_attack + value, &mut self.special_attack)
}
Statistic::SpecialDefense => {
Self::change_stat(self.special_defense + value, &mut self.special_defense)
}
Statistic::Speed => Self::change_stat(self.speed + value, &mut self.speed),
}
}
pub fn decrease_stat(&mut self, stat: Statistic, value: T) -> bool {
match stat {
Statistic::HP => Self::change_stat(self.hp - value, &mut self.hp),
Statistic::Attack => Self::change_stat(self.attack - value, &mut self.attack),
Statistic::Defense => Self::change_stat(self.defense - value, &mut self.defense),
Statistic::SpecialAttack => {
Self::change_stat(self.special_attack - value, &mut self.special_attack)
}
Statistic::SpecialDefense => {
Self::change_stat(self.special_defense - value, &mut self.special_defense)
}
Statistic::Speed => Self::change_stat(self.speed - value, &mut self.speed),
}
}
}