Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework Battle::Unit::CalculateSpellDamage() method to use fheroes2::getSpellDamage() and fheroes2::getMonsterData() functions #8839

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 28 additions & 80 deletions src/fheroes2/battle/battle_troop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,68 +1377,32 @@ uint32_t Battle::Unit::CalculateSpellDamage( const Spell & spell, uint32_t spell
{
assert( spell.isDamage() );

// TODO: use fheroes2::getSpellDamage function to remove code duplication.
uint32_t dmg = spell.Damage() * spellPoints;

switch ( GetID() ) {
case Monster::IRON_GOLEM:
case Monster::STEEL_GOLEM:
switch ( spell.GetID() ) {
// 50% damage
case Spell::COLDRAY:
case Spell::COLDRING:
case Spell::FIREBALL:
case Spell::FIREBLAST:
case Spell::LIGHTNINGBOLT:
case Spell::CHAINLIGHTNING:
case Spell::ELEMENTALSTORM:
case Spell::ARMAGEDDON:
dmg /= 2;
break;
default:
break;
}
break;

case Monster::WATER_ELEMENT:
switch ( spell.GetID() ) {
// 200% damage
case Spell::FIREBALL:
case Spell::FIREBLAST:
dmg *= 2;
break;
default:
break;
}
break;

case Monster::AIR_ELEMENT:
switch ( spell.GetID() ) {
// 200% damage
case Spell::ELEMENTALSTORM:
case Spell::LIGHTNINGBOLT:
case Spell::CHAINLIGHTNING:
dmg *= 2;
break;
default:
break;
uint32_t dmg = fheroes2::getSpellDamage( spell, spellPoints, applyingHero );
for ( const fheroes2::MonsterAbility & targetAbility : fheroes2::getMonsterData( GetID() ).battleStats.abilities ) {
if ( targetAbility.type == fheroes2::MonsterAbilityType::ELEMENTAL_SPELL_DAMAGE_REDUCTION ) {
switch ( spell.GetID() ) {
// Reduced elemental spell damage
case Spell::COLDRAY:
case Spell::COLDRING:
case Spell::FIREBALL:
case Spell::FIREBLAST:
case Spell::LIGHTNINGBOLT:
case Spell::CHAINLIGHTNING:
case Spell::ELEMENTALSTORM:
case Spell::ARMAGEDDON:
dmg -= dmg * targetAbility.percentage / 100;
break;
default:
break;
}
}
break;

case Monster::FIRE_ELEMENT:
switch ( spell.GetID() ) {
// 200% damage
case Spell::COLDRAY:
case Spell::COLDRING:
dmg *= 2;
break;
default:
break;
}
for ( const fheroes2::MonsterWeakness & targetWeakness : fheroes2::getMonsterData( GetID() ).battleStats.weaknesses ) {
if ( targetWeakness.type == fheroes2::MonsterWeaknessType::EXTRA_DAMAGE_FROM_CERTAIN_SPELL ) {
if ( spell.GetID() == (int)targetWeakness.value ) {
dmg += dmg * targetWeakness.percentage / 100;
}
}
break;

default:
break;
}

// check artifact
Expand All @@ -1449,20 +1413,15 @@ uint32_t Battle::Unit::CalculateSpellDamage( const Spell & spell, uint32_t spell
switch ( spell.GetID() ) {
case Spell::COLDRAY:
case Spell::COLDRING: {
std::vector<int32_t> extraDamagePercent
= applyingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactBonusType::COLD_SPELL_EXTRA_EFFECTIVENESS_PERCENT );
for ( const int32_t value : extraDamagePercent ) {
dmg = dmg * ( 100 + value ) / 100;
}

if ( useDefendingHeroArts ) {
const std::vector<int32_t> damageReductionPercent
= defendingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactBonusType::COLD_SPELL_DAMAGE_REDUCTION_PERCENT );
for ( const int32_t value : damageReductionPercent ) {
dmg = dmg * ( 100 - value ) / 100;
}

extraDamagePercent = defendingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactCurseType::COLD_SPELL_EXTRA_DAMAGE_PERCENT );
const std::vector<int32_t> extraDamagePercent
= defendingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactCurseType::COLD_SPELL_EXTRA_DAMAGE_PERCENT );
for ( const int32_t value : extraDamagePercent ) {
dmg = dmg * ( 100 + value ) / 100;
}
Expand All @@ -1472,20 +1431,15 @@ uint32_t Battle::Unit::CalculateSpellDamage( const Spell & spell, uint32_t spell
}
case Spell::FIREBALL:
case Spell::FIREBLAST: {
std::vector<int32_t> extraDamagePercent
= applyingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactBonusType::FIRE_SPELL_EXTRA_EFFECTIVENESS_PERCENT );
for ( const int32_t value : extraDamagePercent ) {
dmg = dmg * ( 100 + value ) / 100;
}

if ( useDefendingHeroArts ) {
const std::vector<int32_t> damageReductionPercent
= defendingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactBonusType::FIRE_SPELL_DAMAGE_REDUCTION_PERCENT );
for ( const int32_t value : damageReductionPercent ) {
dmg = dmg * ( 100 - value ) / 100;
}

extraDamagePercent = defendingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactCurseType::FIRE_SPELL_EXTRA_DAMAGE_PERCENT );
const std::vector<int32_t> extraDamagePercent
= defendingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactCurseType::FIRE_SPELL_EXTRA_DAMAGE_PERCENT );
for ( const int32_t value : extraDamagePercent ) {
dmg = dmg * ( 100 + value ) / 100;
}
Expand All @@ -1495,12 +1449,6 @@ uint32_t Battle::Unit::CalculateSpellDamage( const Spell & spell, uint32_t spell
}
case Spell::LIGHTNINGBOLT:
case Spell::CHAINLIGHTNING: {
const std::vector<int32_t> extraDamagePercent
= applyingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactBonusType::LIGHTNING_SPELL_EXTRA_EFFECTIVENESS_PERCENT );
for ( const int32_t value : extraDamagePercent ) {
dmg = dmg * ( 100 + value ) / 100;
}

if ( useDefendingHeroArts ) {
const std::vector<int32_t> damageReductionPercent
= defendingHero->GetBagArtifacts().getTotalArtifactMultipliedPercent( fheroes2::ArtifactBonusType::LIGHTNING_SPELL_DAMAGE_REDUCTION_PERCENT );
Expand Down
Loading