Improve ability interface

This commit is contained in:
hodasemi 2024-08-27 15:24:10 +02:00
parent 8e2ed3e5c2
commit 4702c5431b

View file

@ -29,7 +29,7 @@ pub trait Ability: Send + Sync + Clone + Default {
fn mana_cost(&self) -> u32;
fn mana_cost_per_level(&self) -> u32;
fn damage_type(&self) -> DamageType;
fn damage(&self, level: u32, addons: &AbilityAddonCollection, statistics: &Statistics) -> u32;
fn base_damage(&self, level: u32) -> u32;
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@ -240,6 +240,25 @@ impl<A: Ability> AbilityBook<A> {
self.ability.mana_cost() + self.ability.mana_cost_per_level() * (self.level - 1)
}
pub fn damage(&self, statistics: &Statistics) -> u32 {
// calculate damage of base ability
let ability_base_damage = self.ability.base_damage(self.level);
// get bonus damage from statistics
let stats_damage = match self.ability.damage_type() {
DamageType::Air => statistics.air_damage.raw(),
DamageType::Fire => statistics.fire_damage.raw(),
DamageType::Water => statistics.water_damage.raw(),
DamageType::Physical => statistics.physical_damage.raw(),
};
// damage from addons multiplied with level
let addon_damage = self.addons.damage() * self.level;
// sum up
ability_base_damage + stats_damage + addon_damage
}
pub fn into_persistent(&self) -> String {
let mut base = format!("{}|{}|{}", self.ability().name(), self.rarity(), self.level);
@ -308,7 +327,7 @@ impl<A: Ability> AbilityBook<A> {
let cooldown: Arc<Label> = gui.element("cooldown")?;
mana_costs.set_text(self.mana_cost())?;
damage.set_text(self.ability.damage(self.level(), self.addons(), statistics))?;
damage.set_text(self.damage(statistics))?;
damage.set_text_color(self.ability.damage_type().into())?;
cooldown.set_text(format!(
"{:.1} s",