Improve ability interface
This commit is contained in:
parent
8e2ed3e5c2
commit
4702c5431b
1 changed files with 21 additions and 2 deletions
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue