Core/Auras: removed caster dependency from core
- Decoupled Unit logic: split of spell critical chance into done (caster bonuses) and taken (target bonuses), this allows to precalculate caster bonuses on aura apply and then check victim's auras on damage/healing calc - Made static a bunch of methods (they no longer have this pointer because they are now called from periodic handlers which may or may not have an active caster in world) - Simplified all AuraEffect bonuses into AuraEffect::_amount, no more duplicated code - Critical chance and whether or not caster is player owned unit (for resilience calcs) is now saved one level upper, on Aura itself (it's impossible as of 3.3.5 to have different effects with different critical chances) - Minor cleanup of SPELL_DAMAGE_CLASS_NONE and Arcane Potency (#18813) crit handling
This commit is contained in:
1 parent
d448ea4370
commit
1d3fbff332
56 files changed
+531
-437
No files matched your search
@@ -729,7 +729,7 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit* excludeCasterChannel) cons
|
||||
|| HasBreakableByDamageAuraType(SPELL_AURA_TRANSFORM, excludeAura));
|
||||
}
|
||||
|
||||
void Unit::DealDamageMods(Unit const* victim, uint32 &damage, uint32* absorb) const
|
||||
/*static*/ void Unit::DealDamageMods(Unit const* victim, uint32& damage, uint32* absorb)
|
||||
{
|
||||
if (!victim || !victim->IsAlive() || victim->HasUnitState(UNIT_STATE_IN_FLIGHT) || (victim->GetTypeId() == TYPEID_UNIT && victim->ToCreature()->IsEvadingAttacks()))
|
||||
{
|
||||
@@ -739,12 +739,12 @@ void Unit::DealDamageMods(Unit const* victim, uint32 &damage, uint32* absorb) co
|
||||
}
|
||||
}
|
||||
|
||||
uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellInfo const* spellProto, bool durabilityLoss)
|
||||
/*static*/ uint32 Unit::DealDamage(Unit* attacker, Unit* victim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellInfo const* spellProto, bool durabilityLoss)
|
||||
{
|
||||
// Sparring Checks
|
||||
if (Creature* target = victim->ToCreature())
|
||||
{
|
||||
if (IsCreature() && !IsCharmedOwnedByPlayerOrPlayer())
|
||||
if (attacker->IsCreature() && !attacker->IsCharmedOwnedByPlayerOrPlayer())
|
||||
{
|
||||
if (target->GetNoNpcDamageBelowPctHealthValue() != 0.0f)
|
||||
{
|
||||
@@ -757,23 +757,23 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
}
|
||||
|
||||
if (UnitAI* victimAI = victim->GetAI())
|
||||
victimAI->DamageTaken(this, damage);
|
||||
victimAI->DamageTaken(attacker, damage);
|
||||
|
||||
if (UnitAI* attackerAI = GetAI())
|
||||
if (UnitAI* attackerAI = attacker->GetAI())
|
||||
attackerAI->DamageDealt(victim, damage, damagetype);
|
||||
|
||||
// Hook for OnDamage Event
|
||||
sScriptMgr->OnDamage(this, victim, damage);
|
||||
sScriptMgr->OnDamage(attacker, victim, damage);
|
||||
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
// Signal to pets that their owner was attacked - except when DOT.
|
||||
if (this != victim && damagetype != DOT)
|
||||
if (attacker != victim && damagetype != DOT)
|
||||
{
|
||||
for (Unit* controlled : victim->m_Controlled)
|
||||
if (Creature* cControlled = controlled->ToCreature())
|
||||
if (CreatureAI* controlledAI = cControlled->AI())
|
||||
controlledAI->OwnerAttackedBy(this);
|
||||
controlledAI->OwnerAttackedBy(attacker);
|
||||
}
|
||||
|
||||
if (victim->ToPlayer()->GetCommandStatus(CHEAT_GOD))
|
||||
@@ -812,19 +812,19 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
uint32 share = CalculatePct(damage, (*i)->GetAmount());
|
||||
|
||||
/// @todo check packets if damage is done by victim, or by attacker of victim
|
||||
DealDamageMods(shareDamageTarget, share, nullptr);
|
||||
DealDamage(shareDamageTarget, share, nullptr, NODAMAGE, spell->GetSchoolMask(), spell, false);
|
||||
Unit::DealDamageMods(shareDamageTarget, share, nullptr);
|
||||
Unit::DealDamage(attacker, shareDamageTarget, share, nullptr, NODAMAGE, spell->GetSchoolMask(), spell, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Rage from Damage made (only from direct weapon damage)
|
||||
if (cleanDamage && damagetype == DIRECT_DAMAGE && this != victim && GetPowerType() == POWER_RAGE)
|
||||
if (attacker && cleanDamage && damagetype == DIRECT_DAMAGE && attacker != victim && attacker->GetPowerType() == POWER_RAGE)
|
||||
{
|
||||
uint32 rage = uint32((float)GetAttackTime(cleanDamage->attackType) / 1000 * 6.5f);
|
||||
uint32 rage = uint32((float)attacker->GetAttackTime(cleanDamage->attackType) / 1000 * 6.5f);
|
||||
|
||||
// Sentinel
|
||||
if (victim->GetVictim() && victim->GetVictim() != this)
|
||||
if (AuraEffect* aurEff = GetAuraEffect(SPELL_AURA_DUMMY, SPELLFAMILY_GENERIC, 1916, EFFECT_1))
|
||||
if (victim->GetVictim() && victim->GetVictim() != attacker)
|
||||
if (AuraEffect* aurEff = attacker->GetAuraEffect(SPELL_AURA_DUMMY, SPELLFAMILY_GENERIC, 1916, EFFECT_1))
|
||||
rage += CalculatePct(rage, aurEff->GetAmount());
|
||||
|
||||
switch (cleanDamage->attackType)
|
||||
@@ -833,7 +833,7 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
rage /= 2;
|
||||
[[fallthrough]];
|
||||
case BASE_ATTACK:
|
||||
RewardRage(rage, true);
|
||||
attacker->RewardRage(rage, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -849,18 +849,18 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
return 0;
|
||||
}
|
||||
|
||||
TC_LOG_DEBUG("entities.unit", "DealDamageStart");
|
||||
|
||||
uint32 health = victim->GetHealth();
|
||||
TC_LOG_DEBUG("entities.unit", "%s dealt %u damage to %s", GetGUID().ToString().c_str(), damage, victim->GetGUID().ToString().c_str());
|
||||
|
||||
// duel ends when player has 1 or less hp
|
||||
bool duel_hasEnded = false;
|
||||
bool duel_wasMounted = false;
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER && victim->ToPlayer()->duel && damage >= (health-1))
|
||||
{
|
||||
if (!attacker)
|
||||
return 0;
|
||||
|
||||
// prevent kill only if killed in duel and killed by opponent or opponent controlled creature
|
||||
if (victim->ToPlayer()->duel->opponent == GetControllingPlayer())
|
||||
if (victim->ToPlayer()->duel->opponent == attacker->GetControllingPlayer())
|
||||
damage = health - 1;
|
||||
|
||||
duel_hasEnded = true;
|
||||
@@ -871,8 +871,11 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
|
||||
if (victimRider && victimRider->duel && victimRider->duel->isMounted)
|
||||
{
|
||||
if (!attacker)
|
||||
return 0;
|
||||
|
||||
// prevent kill only if killed in duel and killed by opponent or opponent controlled creature
|
||||
if (victimRider->duel->opponent == GetControllingPlayer())
|
||||
if (victimRider->duel->opponent == attacker->GetControllingPlayer())
|
||||
damage = health - 1;
|
||||
|
||||
duel_wasMounted = true;
|
||||
@@ -880,17 +883,18 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
}
|
||||
}
|
||||
|
||||
if (GetTypeId() == TYPEID_PLAYER && this != victim)
|
||||
if (attacker && attacker != victim)
|
||||
{
|
||||
Player* killer = ToPlayer();
|
||||
if (Player* killer = attacker->ToPlayer())
|
||||
{
|
||||
// in bg, count dmg if victim is also a player
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER)
|
||||
if (Battleground* bg = killer->GetBattleground())
|
||||
bg->UpdatePlayerScore(killer, SCORE_DAMAGE_DONE, damage);
|
||||
|
||||
// in bg, count dmg if victim is also a player
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER)
|
||||
if (Battleground* bg = killer->GetBattleground())
|
||||
bg->UpdatePlayerScore(killer, SCORE_DAMAGE_DONE, damage);
|
||||
|
||||
killer->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE, health > damage ? damage : health, 0, 0, victim);
|
||||
killer->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT, damage);
|
||||
killer->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE, health > damage ? damage : health, 0, 0, victim);
|
||||
killer->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT, damage);
|
||||
}
|
||||
}
|
||||
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER)
|
||||
@@ -898,25 +902,21 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
else if (!victim->IsControlledByPlayer() || victim->IsVehicle())
|
||||
{
|
||||
if (!victim->ToCreature()->hasLootRecipient())
|
||||
victim->ToCreature()->SetLootRecipient(this);
|
||||
victim->ToCreature()->SetLootRecipient(attacker);
|
||||
|
||||
if (IsControlledByPlayer() || (ToTempSummon() && ToTempSummon()->GetSummoner() && ToTempSummon()->GetSummoner()->GetTypeId() == TYPEID_PLAYER))
|
||||
if (!attacker || attacker->IsControlledByPlayer() || (attacker->ToTempSummon() && attacker->ToTempSummon()->GetSummoner() && attacker->ToTempSummon()->GetSummoner()->GetTypeId() == TYPEID_PLAYER))
|
||||
victim->ToCreature()->LowerPlayerDamageReq(health < damage ? health : damage);
|
||||
}
|
||||
|
||||
if (health <= damage)
|
||||
{
|
||||
TC_LOG_DEBUG("entities.unit", "DealDamage: victim just died");
|
||||
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER && victim != this)
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER && victim != attacker)
|
||||
victim->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED, health);
|
||||
|
||||
Kill(victim, durabilityLoss);
|
||||
Unit::Kill(attacker, victim, durabilityLoss);
|
||||
}
|
||||
else
|
||||
{
|
||||
TC_LOG_DEBUG("entities.unit", "DealDamageAlive");
|
||||
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER)
|
||||
victim->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED, damage);
|
||||
|
||||
@@ -930,7 +930,7 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
// Part of Evade mechanics. DoT's and Thorns / Retribution Aura do not contribute to this
|
||||
if (damagetype != DOT && damage > 0 && !victim->GetOwnerGUID().IsPlayer() && (!spellProto || !spellProto->HasAura(SPELL_AURA_DAMAGE_SHIELD)))
|
||||
victim->ToCreature()->SetLastDamagedTime(GameTime::GetGameTime() + MAX_AGGRO_RESET_TIME);
|
||||
victim->GetThreatManager().AddThreat(this, float(damage), spellProto);
|
||||
victim->GetThreatManager().AddThreat(attacker, float(damage), spellProto);
|
||||
}
|
||||
else // victim is a player
|
||||
{
|
||||
@@ -943,25 +943,25 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
}
|
||||
|
||||
// Rage from damage received
|
||||
if (this != victim && victim->GetPowerType() == POWER_RAGE)
|
||||
if (attacker != victim && victim->GetPowerType() == POWER_RAGE)
|
||||
{
|
||||
uint32 rage_damage = damage + (cleanDamage ? cleanDamage->absorbed_damage : 0);
|
||||
victim->RewardRage(rage_damage, false);
|
||||
}
|
||||
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
if (attacker && attacker->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
// random durability for items (HIT DONE)
|
||||
if (roll_chance_f(sWorld->getRate(RATE_DURABILITY_LOSS_DAMAGE)))
|
||||
{
|
||||
EquipmentSlots slot = EquipmentSlots(urand(0, EQUIPMENT_SLOT_END-1));
|
||||
ToPlayer()->DurabilityPointLossForEquipSlot(slot);
|
||||
attacker->ToPlayer()->DurabilityPointLossForEquipSlot(slot);
|
||||
}
|
||||
}
|
||||
|
||||
if (damagetype != NODAMAGE)
|
||||
{
|
||||
if (victim != this
|
||||
if (victim != attacker
|
||||
&& (!spellProto || !(spellProto->HasAttribute(SPELL_ATTR7_NO_PUSHBACK_ON_DAMAGE) || spellProto->HasAttribute(SPELL_ATTR3_TREAT_AS_PERIODIC))))
|
||||
{
|
||||
if (damagetype != DOT)
|
||||
@@ -1024,8 +1024,6 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
|
||||
}
|
||||
}
|
||||
|
||||
TC_LOG_DEBUG("entities.unit", "DealDamageEnd returned %d damage", damage);
|
||||
|
||||
return damage;
|
||||
}
|
||||
|
||||
@@ -1093,8 +1091,8 @@ void Unit::CalculateSpellDamageTaken(SpellNonMeleeDamage* damageInfo, int32 dama
|
||||
// Spells with SPELL_ATTR4_FIXED_DAMAGE ignore resilience because their damage is based off another spell's damage.
|
||||
if (!spellInfo->HasAttribute(SPELL_ATTR4_FIXED_DAMAGE))
|
||||
{
|
||||
if (IsDamageReducedByArmor(damageSchoolMask, spellInfo))
|
||||
damage = CalcArmorReducedDamage(victim, damage, spellInfo, attackType);
|
||||
if (Unit::IsDamageReducedByArmor(damageSchoolMask, spellInfo))
|
||||
damage = Unit::CalcArmorReducedDamage(this, victim, damage, spellInfo, attackType);
|
||||
|
||||
bool blocked = false;
|
||||
// Per-school calc
|
||||
@@ -1159,7 +1157,8 @@ void Unit::CalculateSpellDamageTaken(SpellNonMeleeDamage* damageInfo, int32 dama
|
||||
damage -= damageInfo->blocked;
|
||||
}
|
||||
|
||||
ApplyResilience(victim, &damage);
|
||||
if (CanApplyResilience())
|
||||
Unit::ApplyResilience(victim, &damage);
|
||||
break;
|
||||
}
|
||||
// Magical Attacks
|
||||
@@ -1173,7 +1172,8 @@ void Unit::CalculateSpellDamageTaken(SpellNonMeleeDamage* damageInfo, int32 dama
|
||||
damage = Unit::SpellCriticalDamageBonus(this, spellInfo, damage);
|
||||
}
|
||||
|
||||
ApplyResilience(victim, &damage);
|
||||
if (CanApplyResilience())
|
||||
Unit::ApplyResilience(victim, &damage);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -1191,7 +1191,7 @@ void Unit::CalculateSpellDamageTaken(SpellNonMeleeDamage* damageInfo, int32 dama
|
||||
|
||||
damageInfo->damage = damage;
|
||||
DamageInfo dmgInfo(*damageInfo, SPELL_DIRECT_DAMAGE, BASE_ATTACK, PROC_HIT_NONE);
|
||||
CalcAbsorbResist(dmgInfo);
|
||||
Unit::CalcAbsorbResist(dmgInfo);
|
||||
damageInfo->absorb = dmgInfo.GetAbsorb();
|
||||
damageInfo->resist = dmgInfo.GetResist();
|
||||
|
||||
@@ -1225,7 +1225,7 @@ void Unit::DealSpellDamage(SpellNonMeleeDamage* damageInfo, bool durabilityLoss)
|
||||
|
||||
// Call default DealDamage
|
||||
CleanDamage cleanDamage(damageInfo->cleanDamage, damageInfo->absorb, BASE_ATTACK, MELEE_HIT_NORMAL);
|
||||
DealDamage(victim, damageInfo->damage, &cleanDamage, SPELL_DIRECT_DAMAGE, SpellSchoolMask(damageInfo->schoolMask), spellProto, durabilityLoss);
|
||||
Unit::DealDamage(this, victim, damageInfo->damage, &cleanDamage, SPELL_DIRECT_DAMAGE, SpellSchoolMask(damageInfo->schoolMask), spellProto, durabilityLoss);
|
||||
}
|
||||
|
||||
/// @todo for melee need create structure as in
|
||||
@@ -1286,9 +1286,9 @@ void Unit::CalculateMeleeDamage(Unit* victim, uint32 damage, CalcDamageInfo* dam
|
||||
sScriptMgr->ModifyMeleeDamage(damageInfo->target, damageInfo->attacker, damage);
|
||||
|
||||
// Calculate armor reduction
|
||||
if (IsDamageReducedByArmor((SpellSchoolMask)(damageInfo->damageSchoolMask)))
|
||||
if (Unit::IsDamageReducedByArmor((SpellSchoolMask)(damageInfo->damageSchoolMask)))
|
||||
{
|
||||
damageInfo->damage = CalcArmorReducedDamage(damageInfo->target, damage, nullptr, damageInfo->attackType);
|
||||
damageInfo->damage = Unit::CalcArmorReducedDamage(damageInfo->attacker, damageInfo->target, damage, nullptr, damageInfo->attackType);
|
||||
damageInfo->cleanDamage += damage - damageInfo->damage;
|
||||
}
|
||||
else
|
||||
@@ -1389,7 +1389,8 @@ void Unit::CalculateMeleeDamage(Unit* victim, uint32 damage, CalcDamageInfo* dam
|
||||
damageInfo->HitInfo |= HITINFO_AFFECTS_VICTIM;
|
||||
|
||||
int32 resilienceReduction = damageInfo->damage;
|
||||
ApplyResilience(victim, &resilienceReduction);
|
||||
if (CanApplyResilience())
|
||||
Unit::ApplyResilience(victim, &resilienceReduction);
|
||||
resilienceReduction = damageInfo->damage - resilienceReduction;
|
||||
damageInfo->damage -= resilienceReduction;
|
||||
damageInfo->cleanDamage += resilienceReduction;
|
||||
@@ -1400,7 +1401,7 @@ void Unit::CalculateMeleeDamage(Unit* victim, uint32 damage, CalcDamageInfo* dam
|
||||
damageInfo->procVictim |= PROC_FLAG_TAKE_ANY_DAMAGE;
|
||||
// Calculate absorb & resists
|
||||
DamageInfo dmgInfo(*damageInfo);
|
||||
CalcAbsorbResist(dmgInfo);
|
||||
Unit::CalcAbsorbResist(dmgInfo);
|
||||
damageInfo->absorb = dmgInfo.GetAbsorb();
|
||||
damageInfo->resist = dmgInfo.GetResist();
|
||||
|
||||
@@ -1458,7 +1459,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss)
|
||||
|
||||
// Call default DealDamage
|
||||
CleanDamage cleanDamage(damageInfo->cleanDamage, damageInfo->absorb, damageInfo->attackType, damageInfo->hitOutCome);
|
||||
DealDamage(victim, damageInfo->damage, &cleanDamage, DIRECT_DAMAGE, SpellSchoolMask(damageInfo->damageSchoolMask), nullptr, durabilityLoss);
|
||||
Unit::DealDamage(this, victim, damageInfo->damage, &cleanDamage, DIRECT_DAMAGE, SpellSchoolMask(damageInfo->damageSchoolMask), nullptr, durabilityLoss);
|
||||
|
||||
// If this is a creature and it attacks from behind it has a probability to daze it's victim
|
||||
if ((damageInfo->hitOutCome == MELEE_HIT_CRIT || damageInfo->hitOutCome == MELEE_HIT_CRUSHING || damageInfo->hitOutCome == MELEE_HIT_NORMAL || damageInfo->hitOutCome == MELEE_HIT_GLANCING) &&
|
||||
@@ -1522,7 +1523,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss)
|
||||
}
|
||||
|
||||
// No Unit::CalcAbsorbResist here - opcode doesn't send that data - this damage is probably not affected by that
|
||||
victim->DealDamageMods(this, damage, nullptr);
|
||||
Unit::DealDamageMods(this, damage, nullptr);
|
||||
|
||||
/// @todo Move this to a packet handler
|
||||
WorldPacket data(SMSG_SPELLDAMAGESHIELD, 8 + 8 + 4 + 4 + 4 + 4 + 4);
|
||||
@@ -1536,7 +1537,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss)
|
||||
data << uint32(0); // FIX ME: Send resisted damage, both fully resisted and partly resisted
|
||||
victim->SendMessageToSet(&data, true);
|
||||
|
||||
victim->DealDamage(this, damage, nullptr, SPELL_DIRECT_DAMAGE, spellInfo->GetSchoolMask(), spellInfo, true);
|
||||
Unit::DealDamage(victim, this, damage, nullptr, SPELL_DIRECT_DAMAGE, spellInfo->GetSchoolMask(), spellInfo, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1549,7 +1550,7 @@ void Unit::HandleEmoteCommand(uint32 anim_id)
|
||||
SendMessageToSet(&data, true);
|
||||
}
|
||||
|
||||
bool Unit::IsDamageReducedByArmor(SpellSchoolMask schoolMask, SpellInfo const* spellInfo /*= nullptr*/, int8 effIndex /*= -1*/)
|
||||
/*static*/ bool Unit::IsDamageReducedByArmor(SpellSchoolMask schoolMask, SpellInfo const* spellInfo /*= nullptr*/, int8 effIndex /*= -1*/)
|
||||
{
|
||||
// only physical spells damage gets reduced by armor
|
||||
if ((schoolMask & SPELL_SCHOOL_MASK_NORMAL) == 0)
|
||||
@@ -1593,40 +1594,43 @@ static float GetArmorReduction(float armor, uint8 attackerLevel)
|
||||
return temp * 100;
|
||||
}
|
||||
|
||||
uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo const* spellInfo, WeaponAttackType /*attackType*/) const
|
||||
/*static*/ uint32 Unit::CalcArmorReducedDamage(Unit const* attacker, Unit* victim, const uint32 damage, SpellInfo const* spellInfo, WeaponAttackType /*attackType*/, uint8 attackerLevel /*= 0*/)
|
||||
{
|
||||
float armor = float(victim->GetArmor());
|
||||
|
||||
// bypass enemy armor by SPELL_AURA_BYPASS_ARMOR_FOR_CASTER
|
||||
int32 armorBypassPct = victim->GetTotalAuraModifier(SPELL_AURA_BYPASS_ARMOR_FOR_CASTER, [&](AuraEffect const* aurEff)
|
||||
if (attacker)
|
||||
{
|
||||
return aurEff->GetCasterGUID() == GetGUID();
|
||||
});
|
||||
// bypass enemy armor by SPELL_AURA_BYPASS_ARMOR_FOR_CASTER
|
||||
int32 armorBypassPct = victim->GetTotalAuraModifier(SPELL_AURA_BYPASS_ARMOR_FOR_CASTER, [&](AuraEffect const* aurEff)
|
||||
{
|
||||
return aurEff->GetCasterGUID() == attacker->GetGUID();
|
||||
});
|
||||
|
||||
armor = CalculatePct(armor, 100 - std::min(armorBypassPct, 100));
|
||||
armor = CalculatePct(armor, 100 - std::min(armorBypassPct, 100));
|
||||
|
||||
// Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
|
||||
armor += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, SPELL_SCHOOL_MASK_NORMAL);
|
||||
// Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
|
||||
armor += attacker->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, SPELL_SCHOOL_MASK_NORMAL);
|
||||
|
||||
if (spellInfo)
|
||||
if (Player* modOwner = GetSpellModOwner())
|
||||
modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_IGNORE_ARMOR, armor);
|
||||
if (spellInfo)
|
||||
if (Player* modOwner = attacker->GetSpellModOwner())
|
||||
modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_IGNORE_ARMOR, armor);
|
||||
|
||||
for (AuraEffect const* aurEff : GetAuraEffectsByType(SPELL_AURA_MOD_IGNORE_TARGET_RESIST))
|
||||
{
|
||||
if (aurEff->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL)
|
||||
armor = std::floor(AddPct(armor, -aurEff->GetAmount()));
|
||||
for (AuraEffect const* aurEff : attacker->GetAuraEffectsByType(SPELL_AURA_MOD_IGNORE_TARGET_RESIST))
|
||||
{
|
||||
if (aurEff->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL)
|
||||
armor = std::floor(AddPct(armor, -aurEff->GetAmount()));
|
||||
}
|
||||
|
||||
if (armor < 0.0f)
|
||||
armor = 0.0f;
|
||||
}
|
||||
|
||||
if (armor < 0.0f)
|
||||
armor = 0.0f;
|
||||
|
||||
float armorReduction = 100.f - GetArmorReduction(armor, getLevel());
|
||||
float armorReduction = 100.f - GetArmorReduction(armor, attacker ? attacker->getLevel() : attackerLevel);
|
||||
|
||||
return std::max<uint32>(CalculatePct(damage, armorReduction), 1);
|
||||
}
|
||||
|
||||
uint32 Unit::CalcSpellResistedDamage(Unit* victim, uint32 damage, SpellSchoolMask schoolMask, SpellInfo const* spellInfo) const
|
||||
/*static*/ uint32 Unit::CalcSpellResistedDamage(Unit const* attacker, Unit* victim, uint32 damage, SpellSchoolMask schoolMask, SpellInfo const* spellInfo)
|
||||
{
|
||||
// Magic damage, check for resists
|
||||
if (!(schoolMask & SPELL_SCHOOL_MASK_MAGIC))
|
||||
@@ -1651,7 +1655,7 @@ uint32 Unit::CalcSpellResistedDamage(Unit* victim, uint32 damage, SpellSchoolMas
|
||||
return 0;
|
||||
}
|
||||
|
||||
float const averageResist = CalculateAverageResistReduction(schoolMask, victim, spellInfo);
|
||||
float const averageResist = Unit::CalculateAverageResistReduction(attacker, schoolMask, victim, spellInfo);
|
||||
|
||||
float discreteResistProbability[11] = { };
|
||||
if (averageResist <= 0.1f)
|
||||
@@ -1677,18 +1681,21 @@ uint32 Unit::CalcSpellResistedDamage(Unit* victim, uint32 damage, SpellSchoolMas
|
||||
float damageResisted = damage * resistance / 10.f;
|
||||
if (damageResisted > 0.0f) // if any damage was resisted
|
||||
{
|
||||
int32 ignoredResistance = GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_IGNORE_TARGET_RESIST, schoolMask);
|
||||
ignoredResistance = std::min<int32>(ignoredResistance, 100);
|
||||
ApplyPct(damageResisted, 100 - ignoredResistance);
|
||||
|
||||
// Spells with melee and magic school mask, decide whether resistance or armor absorb is higher
|
||||
if (spellInfo && spellInfo->HasAttribute(SPELL_ATTR0_CU_SCHOOLMASK_NORMAL_WITH_MAGIC))
|
||||
if (attacker)
|
||||
{
|
||||
uint32 damageAfterArmor = CalcArmorReducedDamage(victim, damage, spellInfo, BASE_ATTACK);
|
||||
float armorReduction = damage - damageAfterArmor;
|
||||
int32 ignoredResistance = attacker->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_IGNORE_TARGET_RESIST, schoolMask);
|
||||
ignoredResistance = std::min<int32>(ignoredResistance, 100);
|
||||
ApplyPct(damageResisted, 100 - ignoredResistance);
|
||||
|
||||
// pick the lower one, the weakest resistance counts
|
||||
damageResisted = std::min(damageResisted, armorReduction);
|
||||
// Spells with melee and magic school mask, decide whether resistance or armor absorb is higher
|
||||
if (spellInfo && spellInfo->HasAttribute(SPELL_ATTR0_CU_SCHOOLMASK_NORMAL_WITH_MAGIC))
|
||||
{
|
||||
uint32 damageAfterArmor = Unit::CalcArmorReducedDamage(attacker, victim, damage, spellInfo, BASE_ATTACK);
|
||||
float armorReduction = damage - damageAfterArmor;
|
||||
|
||||
// pick the lower one, the weakest resistance counts
|
||||
damageResisted = std::min(damageResisted, armorReduction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1696,20 +1703,23 @@ uint32 Unit::CalcSpellResistedDamage(Unit* victim, uint32 damage, SpellSchoolMas
|
||||
return uint32(damageResisted);
|
||||
}
|
||||
|
||||
float Unit::CalculateAverageResistReduction(SpellSchoolMask schoolMask, Unit const* victim, SpellInfo const* spellInfo) const
|
||||
/*static*/ float Unit::CalculateAverageResistReduction(Unit const* attacker, SpellSchoolMask schoolMask, Unit const* victim, SpellInfo const* spellInfo)
|
||||
{
|
||||
float victimResistance = float(victim->GetResistance(schoolMask));
|
||||
|
||||
// pets inherit 100% of masters penetration
|
||||
// excluding traps
|
||||
Player const* player = GetSpellModOwner();
|
||||
if (player && GetEntry() != WORLD_TRIGGER)
|
||||
if (attacker)
|
||||
{
|
||||
victimResistance += float(player->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask));
|
||||
victimResistance -= float(player->GetSpellPenetrationItemMod());
|
||||
// pets inherit 100% of masters penetration
|
||||
// excluding traps
|
||||
Player const* player = attacker->GetSpellModOwner();
|
||||
if (player && attacker->GetEntry() != WORLD_TRIGGER)
|
||||
{
|
||||
victimResistance += float(player->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask));
|
||||
victimResistance -= float(player->GetSpellPenetrationItemMod());
|
||||
}
|
||||
else
|
||||
victimResistance += float(attacker->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask));
|
||||
}
|
||||
else
|
||||
victimResistance += float(GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask));
|
||||
|
||||
// holy resistance exists in pve and comes from level difference, ignore template values
|
||||
if (schoolMask & SPELL_SCHOOL_MASK_HOLY)
|
||||
@@ -1722,8 +1732,8 @@ float Unit::CalculateAverageResistReduction(SpellSchoolMask schoolMask, Unit con
|
||||
victimResistance = std::max(victimResistance, 0.0f);
|
||||
|
||||
// level-based resistance does not apply to binary spells, and cannot be overcome by spell penetration
|
||||
if (!spellInfo || !spellInfo->HasAttribute(SPELL_ATTR0_CU_BINARY_SPELL))
|
||||
victimResistance += std::max((float(victim->getLevelForTarget(this)) - float(getLevelForTarget(victim))) * 5.0f, 0.0f);
|
||||
if (attacker && (!spellInfo || !spellInfo->HasAttribute(SPELL_ATTR0_CU_BINARY_SPELL)))
|
||||
victimResistance += std::max((float(victim->getLevelForTarget(attacker)) - float(attacker->getLevelForTarget(victim))) * 5.0f, 0.0f);
|
||||
|
||||
static uint32 const BOSS_LEVEL = 83;
|
||||
static float const BOSS_RESISTANCE_CONSTANT = 510.0f;
|
||||
@@ -1738,28 +1748,29 @@ float Unit::CalculateAverageResistReduction(SpellSchoolMask schoolMask, Unit con
|
||||
return victimResistance / (victimResistance + resistanceConstant);
|
||||
}
|
||||
|
||||
void Unit::CalcAbsorbResist(DamageInfo& damageInfo)
|
||||
/*static*/ void Unit::CalcAbsorbResist(DamageInfo& damageInfo)
|
||||
{
|
||||
if (!damageInfo.GetVictim() || !damageInfo.GetVictim()->IsAlive() || !damageInfo.GetDamage())
|
||||
return;
|
||||
|
||||
uint32 resistedDamage = CalcSpellResistedDamage(damageInfo.GetVictim(), damageInfo.GetDamage(), damageInfo.GetSchoolMask(), damageInfo.GetSpellInfo());
|
||||
uint32 resistedDamage = Unit::CalcSpellResistedDamage(damageInfo.GetAttacker(), damageInfo.GetVictim(), damageInfo.GetDamage(), damageInfo.GetSchoolMask(), damageInfo.GetSpellInfo());
|
||||
damageInfo.ResistDamage(resistedDamage);
|
||||
|
||||
// Ignore Absorption Auras
|
||||
float auraAbsorbMod(GetMaxPositiveAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_ABSORB_SCHOOL, damageInfo.GetSchoolMask()));
|
||||
|
||||
AuraEffectList const& abilityAbsorbAuras = GetAuraEffectsByType(SPELL_AURA_MOD_TARGET_ABILITY_ABSORB_SCHOOL);
|
||||
for (AuraEffect const* aurEff : abilityAbsorbAuras)
|
||||
float auraAbsorbMod = 0.f;
|
||||
if (Unit* attacker = damageInfo.GetAttacker())
|
||||
{
|
||||
if (!(aurEff->GetMiscValue() & damageInfo.GetSchoolMask()))
|
||||
continue;
|
||||
auraAbsorbMod = attacker->GetMaxPositiveAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_ABSORB_SCHOOL, damageInfo.GetSchoolMask());
|
||||
auraAbsorbMod = std::max(auraAbsorbMod, static_cast<float>(attacker->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_TARGET_ABILITY_ABSORB_SCHOOL, [&damageInfo](AuraEffect const* aurEff) -> bool
|
||||
{
|
||||
if (!(aurEff->GetMiscValue() & damageInfo.GetSchoolMask()))
|
||||
return false;
|
||||
|
||||
if (!aurEff->IsAffectingSpell(damageInfo.GetSpellInfo()))
|
||||
continue;
|
||||
if (!aurEff->IsAffectingSpell(damageInfo.GetSpellInfo()))
|
||||
return false;
|
||||
|
||||
if ((aurEff->GetAmount() > auraAbsorbMod))
|
||||
auraAbsorbMod = float(aurEff->GetAmount());
|
||||
return true;
|
||||
})));
|
||||
}
|
||||
|
||||
RoundToInterval(auraAbsorbMod, 0.0f, 100.0f);
|
||||
@@ -1878,7 +1889,7 @@ void Unit::CalcAbsorbResist(DamageInfo& damageInfo)
|
||||
damageInfo.ModifyDamage(absorbIgnoringDamage);
|
||||
|
||||
// split damage auras - only when not damaging self
|
||||
if (damageInfo.GetVictim() != this)
|
||||
if (damageInfo.GetVictim() != damageInfo.GetAttacker())
|
||||
{
|
||||
// We're going to call functions which can modify content of the list during iteration over it's elements
|
||||
// Let's copy the list so we can prevent iterator invalidation
|
||||
@@ -1916,27 +1927,30 @@ void Unit::CalcAbsorbResist(DamageInfo& damageInfo)
|
||||
}
|
||||
|
||||
uint32 split_absorb = 0;
|
||||
DealDamageMods(caster, splitDamage, &split_absorb);
|
||||
Unit::DealDamageMods(caster, splitDamage, &split_absorb);
|
||||
|
||||
// Sparring Checks
|
||||
if (Creature* target = damageInfo.GetVictim()->ToCreature())
|
||||
if (IsCreature() && !IsCharmedOwnedByPlayerOrPlayer())
|
||||
if (target->GetNoNpcDamageBelowPctHealthValue() != 0.0f)
|
||||
if (target->GetHealthPct() <= target->GetNoNpcDamageBelowPctHealthValue())
|
||||
damageInfo.ModifyDamage(damageInfo.GetDamage() * -1);
|
||||
if (Unit* attacker = damageInfo.GetAttacker())
|
||||
{
|
||||
// Sparring Checks
|
||||
if (Creature* target = damageInfo.GetVictim()->ToCreature())
|
||||
if (attacker->IsCreature() && !attacker->IsCharmedOwnedByPlayerOrPlayer())
|
||||
if (target->GetNoNpcDamageBelowPctHealthValue() != 0.0f)
|
||||
if (target->GetHealthPct() <= target->GetNoNpcDamageBelowPctHealthValue())
|
||||
damageInfo.ModifyDamage(damageInfo.GetDamage() * -1);
|
||||
|
||||
SendSpellNonMeleeDamageLog(caster, (*itr)->GetSpellInfo()->Id, splitDamage, damageInfo.GetSchoolMask(), split_absorb, 0, false, 0, false);
|
||||
attacker->SendSpellNonMeleeDamageLog(caster, (*itr)->GetSpellInfo()->Id, splitDamage, damageInfo.GetSchoolMask(), split_absorb, 0, false, 0, false);
|
||||
}
|
||||
|
||||
CleanDamage cleanDamage = CleanDamage(splitDamage, 0, BASE_ATTACK, MELEE_HIT_NORMAL);
|
||||
DealDamage(caster, splitDamage, &cleanDamage, DIRECT_DAMAGE, damageInfo.GetSchoolMask(), (*itr)->GetSpellInfo(), false);
|
||||
Unit::DealDamage(damageInfo.GetAttacker(), caster, splitDamage, &cleanDamage, DIRECT_DAMAGE, damageInfo.GetSchoolMask(), (*itr)->GetSpellInfo(), false);
|
||||
|
||||
// break 'Fear' and similar auras
|
||||
ProcSkillsAndAuras(caster, PROC_FLAG_NONE, PROC_FLAG_TAKE_HARMFUL_SPELL, PROC_SPELL_TYPE_DAMAGE, PROC_SPELL_PHASE_HIT, PROC_HIT_NONE, nullptr, &damageInfo, nullptr);
|
||||
Unit::ProcSkillsAndAuras(damageInfo.GetAttacker(), caster, PROC_FLAG_NONE, PROC_FLAG_TAKE_HARMFUL_SPELL, PROC_SPELL_TYPE_DAMAGE, PROC_SPELL_PHASE_HIT, PROC_HIT_NONE, nullptr, &damageInfo, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::CalcHealAbsorb(HealInfo& healInfo) const
|
||||
/*static*/ void Unit::CalcHealAbsorb(HealInfo& healInfo)
|
||||
{
|
||||
if (!healInfo.GetHeal())
|
||||
return;
|
||||
@@ -2057,7 +2071,7 @@ void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType, bool extr
|
||||
CalcDamageInfo damageInfo;
|
||||
CalculateMeleeDamage(victim, 0, &damageInfo, attType);
|
||||
// Send log damage message to client
|
||||
DealDamageMods(victim, damageInfo.damage, &damageInfo.absorb);
|
||||
Unit::DealDamageMods(victim, damageInfo.damage, &damageInfo.absorb);
|
||||
|
||||
// Sparring Checks
|
||||
if (Creature* target = victim->ToCreature())
|
||||
@@ -2071,7 +2085,7 @@ void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType, bool extr
|
||||
DealMeleeDamage(&damageInfo, true);
|
||||
|
||||
DamageInfo dmgInfo(damageInfo);
|
||||
ProcSkillsAndAuras(damageInfo.target, damageInfo.procAttacker, damageInfo.procVictim, PROC_SPELL_TYPE_NONE, PROC_SPELL_PHASE_NONE, dmgInfo.GetHitMask(), nullptr, &dmgInfo, nullptr);
|
||||
Unit::ProcSkillsAndAuras(damageInfo.attacker, damageInfo.target, damageInfo.procAttacker, damageInfo.procVictim, PROC_SPELL_TYPE_NONE, PROC_SPELL_PHASE_NONE, dmgInfo.GetHitMask(), nullptr, &dmgInfo, nullptr);
|
||||
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
TC_LOG_DEBUG("entities.unit", "AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
|
||||
@@ -2562,7 +2576,7 @@ SpellMissInfo Unit::MagicSpellHitResult(Unit* victim, SpellInfo const* spellInfo
|
||||
{
|
||||
// resistance chance for binary spells, equals to average damage reduction of non-binary spell
|
||||
if (spellInfo->HasAttribute(SPELL_ATTR0_CU_BINARY_SPELL) && (spellInfo->GetSchoolMask() & SPELL_SCHOOL_MASK_MAGIC))
|
||||
resist_chance += int32(CalculateAverageResistReduction(spellInfo->GetSchoolMask(), victim, spellInfo) * 10000.f); // 100 for spell calculations, and 100 for return value percentage
|
||||
resist_chance += int32(Unit::CalculateAverageResistReduction(this, spellInfo->GetSchoolMask(), victim, spellInfo) * 10000.f); // 100 for spell calculations, and 100 for return value percentage
|
||||
}
|
||||
|
||||
// Roll chance
|
||||
@@ -3890,7 +3904,7 @@ void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, ObjectGuid casterGUID, U
|
||||
caster->GetLimitedCastAuras(aura->GetId()).push_back(aura);
|
||||
}
|
||||
// FIXME: using aura->GetMaxDuration() maybe not blizzlike but it fixes stealing of spells like Innervate
|
||||
newAura->SetLoadedState(aura->GetMaxDuration(), int32(dur), stealCharge ? 1 : aura->GetCharges(), 1, recalculateMask, &damage[0]);
|
||||
newAura->SetLoadedState(aura->GetMaxDuration(), int32(dur), stealCharge ? 1 : aura->GetCharges(), 1, recalculateMask, aura->GetCritChance(), aura->CanApplyResilience(), &damage[0]);
|
||||
newAura->ApplyForTargets();
|
||||
}
|
||||
}
|
||||
@@ -5211,16 +5225,17 @@ void Unit::SendSpellNonMeleeDamageLog(Unit* target, uint32 SpellID, uint32 Damag
|
||||
SendSpellNonMeleeDamageLog(&log);
|
||||
}
|
||||
|
||||
void Unit::ProcSkillsAndAuras(Unit* actionTarget, uint32 typeMaskActor, uint32 typeMaskActionTarget, uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask, Spell* spell, DamageInfo* damageInfo, HealInfo* healInfo)
|
||||
/*static*/ void Unit::ProcSkillsAndAuras(Unit* actor, Unit* actionTarget, uint32 typeMaskActor, uint32 typeMaskActionTarget, uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask, Spell* spell, DamageInfo* damageInfo, HealInfo* healInfo)
|
||||
{
|
||||
WeaponAttackType attType = damageInfo ? damageInfo->GetAttackType() : BASE_ATTACK;
|
||||
if (typeMaskActor)
|
||||
ProcSkillsAndReactives(false, actionTarget, typeMaskActor, hitMask, attType);
|
||||
if (typeMaskActor && actor)
|
||||
actor->ProcSkillsAndReactives(false, actionTarget, typeMaskActor, hitMask, attType);
|
||||
|
||||
if (typeMaskActionTarget && actionTarget)
|
||||
actionTarget->ProcSkillsAndReactives(true, this, typeMaskActionTarget, hitMask, attType);
|
||||
actionTarget->ProcSkillsAndReactives(true, actor, typeMaskActionTarget, hitMask, attType);
|
||||
|
||||
TriggerAurasProcOnEvent(actionTarget, typeMaskActor, typeMaskActionTarget, spellTypeMask, spellPhaseMask, hitMask, spell, damageInfo, healInfo);
|
||||
if (actor)
|
||||
actor->TriggerAurasProcOnEvent(actionTarget, typeMaskActor, typeMaskActionTarget, spellTypeMask, spellPhaseMask, hitMask, spell, damageInfo, healInfo);
|
||||
}
|
||||
|
||||
void Unit::SendPeriodicAuraLog(SpellPeriodicAuraLogInfo* pInfo)
|
||||
@@ -6297,39 +6312,45 @@ void Unit::SetCharm(Unit* charm, bool apply)
|
||||
UpdatePetCombatState();
|
||||
}
|
||||
|
||||
void Unit::DealHeal(HealInfo& healInfo)
|
||||
/*static*/ void Unit::DealHeal(HealInfo& healInfo)
|
||||
{
|
||||
int32 gain = 0;
|
||||
Unit* healer = healInfo.GetHealer();
|
||||
Unit* victim = healInfo.GetTarget();
|
||||
uint32 addhealth = healInfo.GetHeal();
|
||||
|
||||
if (UnitAI* victimAI = victim->GetAI())
|
||||
victimAI->HealReceived(this, addhealth);
|
||||
if (healer)
|
||||
{
|
||||
if (UnitAI* victimAI = victim->GetAI())
|
||||
victimAI->HealReceived(healer, addhealth);
|
||||
|
||||
if (UnitAI* healerAI = GetAI())
|
||||
healerAI->HealDone(victim, addhealth);
|
||||
if (UnitAI* healerAI = healer->GetAI())
|
||||
healerAI->HealDone(victim, addhealth);
|
||||
}
|
||||
|
||||
if (addhealth)
|
||||
gain = victim->ModifyHealth(int32(addhealth));
|
||||
|
||||
// Hook for OnHeal Event
|
||||
sScriptMgr->OnHeal(this, victim, (uint32&)gain);
|
||||
sScriptMgr->OnHeal(healer, victim, (uint32&)gain);
|
||||
|
||||
Unit* unit = this;
|
||||
Unit* unit = healer;
|
||||
if (healer && healer->GetTypeId() == TYPEID_UNIT && healer->IsTotem())
|
||||
unit = healer->GetOwner();
|
||||
|
||||
if (GetTypeId() == TYPEID_UNIT && IsTotem())
|
||||
unit = GetOwner();
|
||||
|
||||
if (Player* player = unit->ToPlayer())
|
||||
if (unit)
|
||||
{
|
||||
if (Battleground* bg = player->GetBattleground())
|
||||
bg->UpdatePlayerScore(player, SCORE_HEALING_DONE, gain);
|
||||
if (Player* player = unit->ToPlayer())
|
||||
{
|
||||
if (Battleground* bg = player->GetBattleground())
|
||||
bg->UpdatePlayerScore(player, SCORE_HEALING_DONE, gain);
|
||||
|
||||
// use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria)
|
||||
if (gain)
|
||||
player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE, gain, 0, 0, victim);
|
||||
// use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria)
|
||||
if (gain)
|
||||
player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE, gain, 0, 0, victim);
|
||||
|
||||
player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CAST, addhealth);
|
||||
player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CAST, addhealth);
|
||||
}
|
||||
}
|
||||
|
||||
if (Player* player = victim->ToPlayer())
|
||||
@@ -6579,9 +6600,8 @@ void Unit::SendHealSpellLog(HealInfo& healInfo, bool critical /*= false*/)
|
||||
int32 Unit::HealBySpell(HealInfo& healInfo, bool critical /*= false*/)
|
||||
{
|
||||
// calculate heal absorb and reduce healing
|
||||
CalcHealAbsorb(healInfo);
|
||||
|
||||
DealHeal(healInfo);
|
||||
Unit::CalcHealAbsorb(healInfo);
|
||||
Unit::DealHeal(healInfo);
|
||||
SendHealSpellLog(healInfo, critical);
|
||||
return healInfo.GetEffectiveHeal();
|
||||
}
|
||||
@@ -9262,7 +9282,7 @@ void Unit::AtEnterCombat()
|
||||
InterruptNonMeleeSpells(false);
|
||||
|
||||
RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags::EnteringCombat);
|
||||
ProcSkillsAndAuras(nullptr, PROC_FLAG_ENTER_COMBAT, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
|
||||
ProcSkillsAndAuras(this, nullptr, PROC_FLAG_ENTER_COMBAT, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void Unit::AtExitCombat()
|
||||
@@ -11723,14 +11743,20 @@ void Unit::PlayOneShotAnimKitId(uint16 animKitId)
|
||||
SendMessageToSet(packet.Write(), true);
|
||||
}
|
||||
|
||||
void Unit::Kill(Unit* victim, bool durabilityLoss)
|
||||
/*static*/ void Unit::Kill(Unit* attacker, Unit* victim, bool durabilityLoss /*= true*/)
|
||||
{
|
||||
// Prevent killing unit twice (and giving reward from kill twice)
|
||||
if (!victim->GetHealth())
|
||||
return;
|
||||
|
||||
if (attacker && !attacker->IsInMap(victim))
|
||||
attacker = nullptr;
|
||||
|
||||
// find player: owner of controlled `this` or `this` itself maybe
|
||||
Player* player = GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
Player* player = nullptr;
|
||||
if (attacker)
|
||||
player = attacker->GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
|
||||
Creature* creature = victim->ToCreature();
|
||||
|
||||
bool isRewardAllowed = true;
|
||||
@@ -11843,23 +11869,24 @@ void Unit::Kill(Unit* victim, bool durabilityLoss)
|
||||
}
|
||||
|
||||
// Do KILL and KILLED procs. KILL proc is called only for the unit who landed the killing blow (and its owner - for pets and totems) regardless of who tapped the victim
|
||||
if (IsPet() || IsTotem())
|
||||
if (attacker && (attacker->IsPet() || attacker->IsTotem()))
|
||||
{
|
||||
// proc only once for victim
|
||||
if (Unit* owner = GetOwner())
|
||||
owner->ProcSkillsAndAuras(victim, PROC_FLAG_KILL, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
|
||||
if (Unit* owner = attacker->GetOwner())
|
||||
Unit::ProcSkillsAndAuras(owner, victim, PROC_FLAG_KILL, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
if (!victim->IsCritter())
|
||||
ProcSkillsAndAuras(victim, PROC_FLAG_KILL, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
|
||||
Unit::ProcSkillsAndAuras(attacker, victim, PROC_FLAG_KILL, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
|
||||
|
||||
// Proc auras on death - must be before aura/combat remove
|
||||
victim->ProcSkillsAndAuras(victim, PROC_FLAG_NONE, PROC_FLAG_DEATH, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
|
||||
Unit::ProcSkillsAndAuras(victim, victim, PROC_FLAG_NONE, PROC_FLAG_DEATH, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
|
||||
|
||||
// update get killing blow achievements, must be done before setDeathState to be able to require auras on target
|
||||
// and before Spirit of Redemption as it also removes auras
|
||||
if (Player* killerPlayer = GetCharmerOrOwnerPlayerOrPlayerItself())
|
||||
killerPlayer->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GET_KILLING_BLOWS, 1, 0, 0, victim);
|
||||
if (attacker)
|
||||
if (Player* killerPlayer = attacker->GetCharmerOrOwnerPlayerOrPlayerItself())
|
||||
killerPlayer->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GET_KILLING_BLOWS, 1, 0, 0, victim);
|
||||
|
||||
TC_LOG_DEBUG("entities.unit", "SET JUST_DIED");
|
||||
victim->setDeathState(JUST_DIED);
|
||||
@@ -11895,11 +11922,11 @@ void Unit::Kill(Unit* victim, bool durabilityLoss)
|
||||
// Durability loss is calculated more accurately again for each item in Player::DurabilityLoss
|
||||
plrVictim->DurabilityLossAll(baseLoss, false);
|
||||
// durability lost message
|
||||
SendDurabilityLoss(plrVictim, loss);
|
||||
plrVictim->SendDurabilityLoss(plrVictim, loss);
|
||||
}
|
||||
// Call KilledUnit for creatures
|
||||
if (IsCreature() && IsAIEnabled())
|
||||
ToCreature()->AI()->KilledUnit(victim);
|
||||
if (attacker && attacker->IsCreature() && attacker->IsAIEnabled())
|
||||
attacker->ToCreature()->AI()->KilledUnit(victim);
|
||||
|
||||
// last damage from non duel opponent or opponent controlled creature
|
||||
if (plrVictim->duel)
|
||||
@@ -11923,31 +11950,30 @@ void Unit::Kill(Unit* victim, bool durabilityLoss)
|
||||
}
|
||||
|
||||
// Call KilledUnit for creatures, this needs to be called after the lootable flag is set
|
||||
if (IsCreature() && IsAIEnabled())
|
||||
ToCreature()->AI()->KilledUnit(victim);
|
||||
if (attacker && attacker->IsCreature() && attacker->IsAIEnabled())
|
||||
attacker->ToCreature()->AI()->KilledUnit(victim);
|
||||
|
||||
// Call creature just died function
|
||||
if (CreatureAI* ai = creature->AI())
|
||||
ai->JustDied(this);
|
||||
ai->JustDied(attacker);
|
||||
|
||||
if (TempSummon* summon = creature->ToTempSummon())
|
||||
if (Unit* summoner = summon->GetSummoner())
|
||||
if (summoner->ToCreature() && summoner->IsAIEnabled())
|
||||
summoner->ToCreature()->AI()->SummonedCreatureDies(creature, this);
|
||||
summoner->ToCreature()->AI()->SummonedCreatureDies(creature, attacker);
|
||||
|
||||
// Dungeon specific stuff, only applies to players killing creatures
|
||||
if (creature->GetInstanceId())
|
||||
{
|
||||
Map* instanceMap = creature->GetMap();
|
||||
Player* creditedPlayer = GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
/// @todo do instance binding anyway if the charmer/owner is offline
|
||||
|
||||
if (instanceMap->IsDungeon() && (creditedPlayer || this == victim))
|
||||
if (instanceMap->IsDungeon() && ((attacker && attacker->GetCharmerOrOwnerPlayerOrPlayerItself()) || attacker == victim))
|
||||
{
|
||||
if (instanceMap->IsRaidOrHeroicDungeon())
|
||||
{
|
||||
if (creature->GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND)
|
||||
((InstanceMap*)instanceMap)->PermBindAllPlayers();
|
||||
instanceMap->ToInstanceMap()->PermBindAllPlayers();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -11964,7 +11990,7 @@ void Unit::Kill(Unit* victim, bool durabilityLoss)
|
||||
|
||||
// outdoor pvp things, do these after setting the death state, else the player activity notify won't work... doh...
|
||||
// handle player kill only if not suicide (spirit of redemption for example)
|
||||
if (player && this != victim)
|
||||
if (player && attacker != victim)
|
||||
{
|
||||
if (OutdoorPvP* pvp = player->GetOutdoorPvP())
|
||||
pvp->HandleKill(player, victim);
|
||||
@@ -11990,26 +12016,29 @@ void Unit::Kill(Unit* victim, bool durabilityLoss)
|
||||
}
|
||||
|
||||
// achievement stuff
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER)
|
||||
if (attacker && victim->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
if (GetTypeId() == TYPEID_UNIT)
|
||||
victim->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE, GetEntry());
|
||||
else if (GetTypeId() == TYPEID_PLAYER && victim != this)
|
||||
victim->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER, 1, ToPlayer()->GetTeam());
|
||||
if (attacker->GetTypeId() == TYPEID_UNIT)
|
||||
victim->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE, attacker->GetEntry());
|
||||
else if (attacker->GetTypeId() == TYPEID_PLAYER && victim != attacker)
|
||||
victim->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER, 1, attacker->ToPlayer()->GetTeam());
|
||||
}
|
||||
|
||||
// Hook for OnPVPKill Event
|
||||
if (Player* killerPlr = ToPlayer())
|
||||
if (attacker)
|
||||
{
|
||||
if (Player* killedPlr = victim->ToPlayer())
|
||||
sScriptMgr->OnPVPKill(killerPlr, killedPlr);
|
||||
else if (Creature* killedCre = victim->ToCreature())
|
||||
sScriptMgr->OnCreatureKill(killerPlr, killedCre);
|
||||
}
|
||||
else if (Creature* killerCre = ToCreature())
|
||||
{
|
||||
if (Player* killed = victim->ToPlayer())
|
||||
sScriptMgr->OnPlayerKilledByCreature(killerCre, killed);
|
||||
if (Player* killerPlr = attacker->ToPlayer())
|
||||
{
|
||||
if (Player* killedPlr = victim->ToPlayer())
|
||||
sScriptMgr->OnPVPKill(killerPlr, killedPlr);
|
||||
else if (Creature* killedCre = victim->ToCreature())
|
||||
sScriptMgr->OnCreatureKill(killerPlr, killedCre);
|
||||
}
|
||||
else if (Creature* killerCre = attacker->ToCreature())
|
||||
{
|
||||
if (Player* killed = victim->ToPlayer())
|
||||
sScriptMgr->OnPlayerKilledByCreature(killerCre, killed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12793,21 +12822,26 @@ void Unit::CancelSpellMissiles(uint32 spellId, bool reverseMissile /*= false*/)
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::ApplyResilience(Unit const* victim, int32* damage) const
|
||||
bool Unit::CanApplyResilience() const
|
||||
{
|
||||
return !IsVehicle() && GetOwnerGUID().IsPlayer();
|
||||
}
|
||||
|
||||
/*static*/ void Unit::ApplyResilience(Unit const* victim, int32* damage)
|
||||
{
|
||||
// player mounted on multi-passenger mount is also classified as vehicle
|
||||
if (IsVehicle() || (victim->IsVehicle() && victim->GetTypeId() != TYPEID_PLAYER))
|
||||
return;
|
||||
|
||||
// Don't consider resilience if not in PvP - player or pet
|
||||
if (!GetCharmerOrOwnerPlayerOrPlayerItself())
|
||||
if (victim->IsVehicle() && victim->GetTypeId() != TYPEID_PLAYER)
|
||||
return;
|
||||
|
||||
Unit const* target = nullptr;
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER)
|
||||
target = victim;
|
||||
else if (victim->GetTypeId() == TYPEID_UNIT && victim->GetOwner() && victim->GetOwner()->GetTypeId() == TYPEID_PLAYER)
|
||||
target = victim->GetOwner();
|
||||
else // victim->GetTypeId() == TYPEID_UNIT
|
||||
{
|
||||
if (Unit* owner = victim->GetOwner())
|
||||
if (owner->GetTypeId() == TYPEID_PLAYER)
|
||||
target = owner;
|
||||
}
|
||||
|
||||
if (!target)
|
||||
return;
|
||||
@@ -12815,6 +12849,15 @@ void Unit::ApplyResilience(Unit const* victim, int32* damage) const
|
||||
*damage -= target->GetDamageReduction(*damage);
|
||||
}
|
||||
|
||||
int32 Unit::CalculateAOEAvoidance(int32 damage, uint32 schoolMask, Unit* caster) const
|
||||
{
|
||||
damage = int32(float(damage) * GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE, schoolMask));
|
||||
if (caster->GetTypeId() == TYPEID_UNIT)
|
||||
damage = int32(float(damage) * GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CREATURE_AOE_DAMAGE_AVOIDANCE, schoolMask));
|
||||
|
||||
return damage;
|
||||
}
|
||||
|
||||
// Melee based spells can be miss, parry or dodge on this step
|
||||
// Crit or block - determined on damage calculation phase! (and can be both in some time)
|
||||
float Unit::MeleeSpellMissChance(Unit const* victim, WeaponAttackType attType, SpellInfo const* spellInfo /*= nullptr*/) const
|
||||
|
||||
Reference in new issue
Block a user