diff options
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 20 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 30 | ||||
-rw-r--r-- | src/server/game/Spells/Auras/SpellAuras.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Spells/Auras/SpellAuras.h | 2 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.cpp | 6 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.h | 25 | ||||
-rw-r--r-- | src/server/game/Spells/SpellEffects.cpp | 184 |
7 files changed, 150 insertions, 119 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 9e8f5cc9ed1..4b73c4a0dcc 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -4552,17 +4552,17 @@ Aura* Unit::GetAuraOfRankedSpell(uint32 spellId, ObjectGuid casterGUID, ObjectGu return aurApp ? aurApp->GetBase() : NULL; } -void Unit::GetDispellableAuraList(Unit* caster, uint32 dispelMask, DispelChargesList& dispelList) +void Unit::GetDispellableAuraList(Unit* caster, uint32 dispelMask, DispelChargesList& dispelList, bool isReflect /*= false*/) const { // we should not be able to dispel diseases if the target is affected by unholy blight if (dispelMask & (1 << DISPEL_DISEASE) && HasAura(50536)) dispelMask &= ~(1 << DISPEL_DISEASE); AuraMap const& auras = GetOwnedAuras(); - for (AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr) + for (auto itr = auras.begin(); itr != auras.end(); ++itr) { Aura* aura = itr->second; - AuraApplication * aurApp = aura->GetApplicationOfTarget(GetGUID()); + AuraApplication const* aurApp = aura->GetApplicationOfTarget(GetGUID()); if (!aurApp) continue; @@ -4573,17 +4573,23 @@ void Unit::GetDispellableAuraList(Unit* caster, uint32 dispelMask, DispelCharges if (aura->GetSpellInfo()->GetDispelMask() & dispelMask) { // do not remove positive auras if friendly target - // negative auras if non-friendly target - if (aurApp->IsPositive() == IsFriendlyTo(caster)) + // negative auras if non-friendly + // unless we're reflecting (dispeller eliminates one of it's benefitial buffs) + if (isReflect != (aurApp->IsPositive() == IsFriendlyTo(caster))) + continue; + + // 2.4.3 Patch Notes: "Dispel effects will no longer attempt to remove effects that have 100% dispel resistance." + int32 chance = aura->CalcDispelChance(this, !IsFriendlyTo(caster)); + if (!chance) continue; // The charges / stack amounts don't count towards the total number of auras that can be dispelled. // Ie: A dispel on a target with 5 stacks of Winters Chill and a Polymorph has 1 / (1 + 1) -> 50% chance to dispell // Polymorph instead of 1 / (5 + 1) -> 16%. - bool dispelCharges = aura->GetSpellInfo()->HasAttribute(SPELL_ATTR7_DISPEL_CHARGES); + bool const dispelCharges = aura->GetSpellInfo()->HasAttribute(SPELL_ATTR7_DISPEL_CHARGES); uint8 charges = dispelCharges ? aura->GetCharges() : aura->GetStackAmount(); if (charges > 0) - dispelList.push_back(std::make_pair(aura, charges)); + dispelList.emplace_back(aura, chance, charges); } } } diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 228929e4af6..3eab6bc50ae 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -375,7 +375,33 @@ class TransportBase; class SpellCastTargets; typedef std::list<Unit*> UnitList; -typedef std::list<std::pair<Aura*, uint8>> DispelChargesList; + +class DispelableAura +{ + public: + DispelableAura(Aura* aura, int32 dispelChance, uint8 dispelCharges) : + _aura(aura), _chance(dispelChance), _charges(dispelCharges) { } + + Aura* GetAura() const { return _aura; } + bool RollDispel() const { return roll_chance_i(_chance); } + uint8 GetDispelCharges() const { return _charges; } + + void IncrementCharges() { ++_charges; } + bool DecrementCharge() + { + if (!_charges) + return false; + + --_charges; + return _charges > 0; + } + + private: + Aura* _aura; + int32 _chance; + uint8 _charges; +}; +typedef std::vector<DispelableAura> DispelChargesList; typedef std::unordered_multimap<uint32 /*type*/, uint32 /*spellId*/> SpellImmuneContainer; @@ -1796,7 +1822,7 @@ class TC_GAME_API Unit : public WorldObject AuraApplication * GetAuraApplicationOfRankedSpell(uint32 spellId, ObjectGuid casterGUID = ObjectGuid::Empty, ObjectGuid itemCasterGUID = ObjectGuid::Empty, uint8 reqEffMask = 0, AuraApplication * except = NULL) const; Aura* GetAuraOfRankedSpell(uint32 spellId, ObjectGuid casterGUID = ObjectGuid::Empty, ObjectGuid itemCasterGUID = ObjectGuid::Empty, uint8 reqEffMask = 0) const; - void GetDispellableAuraList(Unit* caster, uint32 dispelMask, DispelChargesList& dispelList); + void GetDispellableAuraList(Unit* caster, uint32 dispelMask, DispelChargesList& dispelList, bool isReflect = false) const; bool HasAuraEffect(uint32 spellId, uint8 effIndex, ObjectGuid caster = ObjectGuid::Empty) const; uint32 GetAuraCount(uint32 spellId) const; diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index 7e605382e84..67ca679e249 100644 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -1033,7 +1033,7 @@ void Aura::UnregisterSingleTarget() SetIsSingleTarget(false); } -int32 Aura::CalcDispelChance(Unit* auraTarget, bool offensive) const +int32 Aura::CalcDispelChance(Unit const* auraTarget, bool offensive) const { // we assume that aura dispel chance is 100% on start // need formula for level difference based chance diff --git a/src/server/game/Spells/Auras/SpellAuras.h b/src/server/game/Spells/Auras/SpellAuras.h index 1533746893a..9cdf84e82cf 100644 --- a/src/server/game/Spells/Auras/SpellAuras.h +++ b/src/server/game/Spells/Auras/SpellAuras.h @@ -173,7 +173,7 @@ class TC_GAME_API Aura bool IsSingleTargetWith(Aura const* aura) const; void SetIsSingleTarget(bool val) { m_isSingleTarget = val; } void UnregisterSingleTarget(); - int32 CalcDispelChance(Unit* auraTarget, bool offensive) const; + int32 CalcDispelChance(Unit const* auraTarget, bool offensive) const; void SetLoadedState(int32 maxduration, int32 duration, int32 charges, uint8 stackamount, uint8 recalculateMask, int32 * amount); diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index a717ac97b68..aa274b3788e 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -585,6 +585,7 @@ m_caster((info->HasAttribute(SPELL_ATTR6_CAST_BY_CHARMER) && caster->GetCharmerO gameObjTarget = NULL; destTarget = NULL; damage = 0; + targetMissInfo = SPELL_MISS_NONE; effectHandleMode = SPELL_EFFECT_HANDLE_LAUNCH; m_damage = 0; m_healing = 0; @@ -614,7 +615,7 @@ m_caster((info->HasAttribute(SPELL_ATTR6_CAST_BY_CHARMER) && caster->GetCharmerO // Patch 1.2 notes: Spell Reflection no longer reflects abilities m_canReflect = m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC && !m_spellInfo->HasAttribute(SPELL_ATTR0_ABILITY) && !m_spellInfo->HasAttribute(SPELL_ATTR1_CANT_BE_REFLECTED) && !m_spellInfo->HasAttribute(SPELL_ATTR0_UNAFFECTED_BY_INVULNERABILITY) - && !m_spellInfo->IsPassive() && !m_spellInfo->IsPositive(); + && !m_spellInfo->IsPassive(); CleanupTargetList(); memset(m_effectExecuteData, 0, MAX_SPELL_EFFECTS * sizeof(ByteBuffer*)); @@ -2115,7 +2116,7 @@ void Spell::AddUnitTarget(Unit* target, uint32 effectMask, bool checkIfValid /*= // Calculate hit result if (m_originalCaster) { - targetInfo.missCondition = m_originalCaster->SpellHitResult(target, m_spellInfo, m_canReflect); + targetInfo.missCondition = m_originalCaster->SpellHitResult(target, m_spellInfo, m_canReflect && !(m_spellInfo->IsPositive() && m_caster->IsFriendlyTo(target))); if (m_skipCheck && targetInfo.missCondition != SPELL_MISS_IMMUNE) targetInfo.missCondition = SPELL_MISS_NONE; } @@ -2312,6 +2313,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target) // Need init unitTarget by default unit (can changed in code on reflect) // Or on missInfo != SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem) unitTarget = unit; + targetMissInfo = missInfo; // Reset damage/healing counter m_damage = target->damage; diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 20ec9a2d12c..e7c54dc69bb 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -216,7 +216,7 @@ enum SpellEffectHandleMode SPELL_EFFECT_HANDLE_HIT_TARGET }; -typedef std::list<std::pair<uint32, ObjectGuid>> DispelList; +typedef std::vector<std::pair<uint32, ObjectGuid>> DispelList; static const uint32 SPELL_INTERRUPT_NONPLAYER = 32747; @@ -567,6 +567,7 @@ class TC_GAME_API Spell GameObject* gameObjTarget; WorldLocation* destTarget; int32 damage; + SpellMissInfo targetMissInfo; SpellEffectHandleMode effectHandleMode; // used in effects handlers Aura* m_spellAura; @@ -592,18 +593,18 @@ class TC_GAME_API Spell // Targets store structures and data struct TargetInfo { - // a bug in gcc-4.7 needs a destructor to call move operator instead of copy operator in std::vector remove - ~TargetInfo() { } ObjectGuid targetGUID; uint64 timeDelay; - SpellMissInfo missCondition:8; - SpellMissInfo reflectResult:8; - uint8 effectMask:8; - bool processed:1; - bool alive:1; - bool crit:1; - bool scaleAura:1; int32 damage; + + SpellMissInfo missCondition; + SpellMissInfo reflectResult; + + uint8 effectMask; + bool processed; + bool alive; + bool crit; + bool scaleAura; }; std::list<TargetInfo> m_UniqueTargetInfo; uint8 m_channelTargetEffectMask; // Mask req. alive targets @@ -612,8 +613,8 @@ class TC_GAME_API Spell { ObjectGuid targetGUID; uint64 timeDelay; - uint8 effectMask:8; - bool processed:1; + uint8 effectMask; + bool processed; }; std::list<GOTargetInfo> m_UniqueGOTargetInfo; diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 0937d916868..c220e3eba01 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -2410,83 +2410,81 @@ void Spell::EffectDispel(SpellEffIndex effIndex) uint32 dispel_type = m_spellInfo->Effects[effIndex].MiscValue; uint32 dispelMask = SpellInfo::GetDispelMask(DispelType(dispel_type)); - DispelChargesList dispel_list; - unitTarget->GetDispellableAuraList(m_caster, dispelMask, dispel_list); - if (dispel_list.empty()) + DispelChargesList dispelList; + unitTarget->GetDispellableAuraList(m_caster, dispelMask, dispelList, targetMissInfo == SPELL_MISS_REFLECT); + if (dispelList.empty()) return; + size_t remaining = dispelList.size(); + // Ok if exist some buffs for dispel try dispel it uint32 failCount = 0; - DispelChargesList success_list; - WorldPacket dataFail(SMSG_DISPEL_FAILED, 8+8+4+4+damage*4); + DispelChargesList successList; + successList.reserve(damage); + + WorldPacket dataFail(SMSG_DISPEL_FAILED, 8 + 8 + 4 + 4 + damage * 4); // dispel N = damage buffs (or while exist buffs for dispel) - for (int32 count = 0; count < damage && !dispel_list.empty();) + for (int32 count = 0; count < damage && remaining > 0;) { // Random select buff for dispel - DispelChargesList::iterator itr = dispel_list.begin(); - std::advance(itr, urand(0, dispel_list.size() - 1)); + auto itr = dispelList.begin(); + std::advance(itr, urand(0, remaining - 1)); - int32 chance = itr->first->CalcDispelChance(unitTarget, !unitTarget->IsFriendlyTo(m_caster)); - // 2.4.3 Patch Notes: "Dispel effects will no longer attempt to remove effects that have 100% dispel resistance." - if (!chance) + if (itr->RollDispel()) { - dispel_list.erase(itr); - continue; + auto successItr = std::find_if(successList.begin(), successList.end(), [&itr](DispelableAura& dispelAura) -> bool + { + if (dispelAura.GetAura()->GetId() == itr->GetAura()->GetId()) + return true; + + return false; + }); + + if (successItr == successList.end()) + successList.emplace_back(itr->GetAura(), 0, 1); + else + successItr->IncrementCharges(); + + if (!itr->DecrementCharge()) + { + --remaining; + std::swap(*itr, dispelList[remaining]); + } } else { - if (roll_chance_i(chance)) + if (!failCount) { - bool alreadyListed = false; - for (DispelChargesList::iterator successItr = success_list.begin(); successItr != success_list.end(); ++successItr) - { - if (successItr->first->GetId() == itr->first->GetId()) - { - ++successItr->second; - alreadyListed = true; - } - } - if (!alreadyListed) - success_list.push_back(std::make_pair(itr->first, 1)); - --itr->second; - if (itr->second <= 0) - dispel_list.erase(itr); + // Failed to dispell + dataFail << uint64(m_caster->GetGUID()); // Caster GUID + dataFail << uint64(unitTarget->GetGUID()); // Victim GUID + dataFail << uint32(m_spellInfo->Id); // dispel spell id } - else - { - if (!failCount) - { - // Failed to dispell - dataFail << uint64(m_caster->GetGUID()); // Caster GUID - dataFail << uint64(unitTarget->GetGUID()); // Victim GUID - dataFail << uint32(m_spellInfo->Id); // dispel spell id - } - ++failCount; - dataFail << uint32(itr->first->GetId()); // Spell Id - } - ++count; + ++failCount; + dataFail << uint32(itr->GetAura()->GetId()); // Spell Id } + ++count; } if (failCount) m_caster->SendMessageToSet(&dataFail, true); - if (success_list.empty()) + if (successList.empty()) return; - WorldPacket dataSuccess(SMSG_SPELLDISPELLOG, 8+8+4+1+4+success_list.size()*5); + WorldPacket dataSuccess(SMSG_SPELLDISPELLOG, 8 + 8 + 4 + 1 + 4 + successList.size() * 5); // Send packet header dataSuccess << unitTarget->GetPackGUID(); // Victim GUID dataSuccess << m_caster->GetPackGUID(); // Caster GUID dataSuccess << uint32(m_spellInfo->Id); // dispel spell id dataSuccess << uint8(0); // not used - dataSuccess << uint32(success_list.size()); // count - for (DispelChargesList::iterator itr = success_list.begin(); itr != success_list.end(); ++itr) + dataSuccess << uint32(successList.size()); // count + for (DispelChargesList::iterator itr = successList.begin(); itr != successList.end(); ++itr) { // Send dispelled spell info - dataSuccess << uint32(itr->first->GetId()); // Spell Id - dataSuccess << uint8(0); // 0 - dispelled !=0 cleansed - unitTarget->RemoveAurasDueToSpellByDispel(itr->first->GetId(), m_spellInfo->Id, itr->first->GetCasterGUID(), m_caster, itr->second); + dataSuccess << uint32(itr->GetAura()->GetId()); // Spell Id + dataSuccess << uint8(0); // 0 - dispelled !=0 cleansed + unitTarget->RemoveAurasDueToSpellByDispel(itr->GetAura()->GetId(), m_spellInfo->Id, itr->GetAura()->GetCasterGUID(), m_caster, itr->GetDispelCharges()); } m_caster->SendMessageToSet(&dataSuccess, true); @@ -4866,14 +4864,11 @@ void Spell::EffectDispelMechanic(SpellEffIndex effIndex) continue; if (roll_chance_i(aura->CalcDispelChance(unitTarget, !unitTarget->IsFriendlyTo(m_caster)))) if ((aura->GetSpellInfo()->GetAllEffectsMechanicMask() & (1 << mechanic))) - dispel_list.push_back(std::make_pair(aura->GetId(), aura->GetCasterGUID())); + dispel_list.emplace_back(aura->GetId(), aura->GetCasterGUID()); } - while (!dispel_list.empty()) - { - unitTarget->RemoveAura(dispel_list.front().first, dispel_list.front().second, 0, AURA_REMOVE_BY_ENEMY_SPELL); - dispel_list.pop_front(); - } + for (auto itr = dispel_list.begin(); itr != dispel_list.end(); ++itr) + unitTarget->RemoveAura(itr->first, itr->second, 0, AURA_REMOVE_BY_ENEMY_SPELL); } void Spell::EffectResurrectPet(SpellEffIndex /*effIndex*/) @@ -5259,7 +5254,7 @@ void Spell::EffectStealBeneficialBuff(SpellEffIndex effIndex) if (!unitTarget || unitTarget == m_caster) // can't steal from self return; - DispelChargesList steal_list; + DispelChargesList stealList; // Create dispel mask by dispel type uint32 dispelMask = SpellInfo::GetDispelMask(DispelType(m_spellInfo->Effects[effIndex].MiscValue)); @@ -5267,7 +5262,7 @@ void Spell::EffectStealBeneficialBuff(SpellEffIndex effIndex) for (Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr) { Aura* aura = itr->second; - AuraApplication * aurApp = aura->GetApplicationOfTarget(unitTarget->GetGUID()); + AuraApplication const* aurApp = aura->GetApplicationOfTarget(unitTarget->GetGUID()); if (!aurApp) continue; @@ -5277,75 +5272,76 @@ void Spell::EffectStealBeneficialBuff(SpellEffIndex effIndex) if (!aurApp->IsPositive() || aura->IsPassive() || aura->GetSpellInfo()->HasAttribute(SPELL_ATTR4_NOT_STEALABLE)) continue; + // 2.4.3 Patch Notes: "Dispel effects will no longer attempt to remove effects that have 100% dispel resistance." + int32 chance = aura->CalcDispelChance(unitTarget, !unitTarget->IsFriendlyTo(m_caster)); + if (!chance) + continue; + // The charges / stack amounts don't count towards the total number of auras that can be dispelled. // Ie: A dispel on a target with 5 stacks of Winters Chill and a Polymorph has 1 / (1 + 1) -> 50% chance to dispell // Polymorph instead of 1 / (5 + 1) -> 16%. bool dispelCharges = aura->GetSpellInfo()->HasAttribute(SPELL_ATTR7_DISPEL_CHARGES); uint8 charges = dispelCharges ? aura->GetCharges() : aura->GetStackAmount(); if (charges > 0) - steal_list.push_back(std::make_pair(aura, charges)); + stealList.emplace_back(aura, chance, charges); } } - if (steal_list.empty()) + if (stealList.empty()) return; + size_t remaining = stealList.size(); + // Ok if exist some buffs for dispel try dispel it uint32 failCount = 0; - DispelList success_list; - WorldPacket dataFail(SMSG_DISPEL_FAILED, 8+8+4+4+damage*4); + DispelList successList; + successList.reserve(damage); + + WorldPacket dataFail(SMSG_DISPEL_FAILED, 8 + 8 + 4 + 4 + damage * 4); // dispel N = damage buffs (or while exist buffs for dispel) - for (int32 count = 0; count < damage && !steal_list.empty();) + for (int32 count = 0; count < damage && remaining > 0;) { // Random select buff for dispel - DispelChargesList::iterator itr = steal_list.begin(); - std::advance(itr, urand(0, steal_list.size() - 1)); + DispelChargesList::iterator itr = stealList.begin(); + std::advance(itr, urand(0, remaining - 1)); - int32 chance = itr->first->CalcDispelChance(unitTarget, !unitTarget->IsFriendlyTo(m_caster)); - // 2.4.3 Patch Notes: "Dispel effects will no longer attempt to remove effects that have 100% dispel resistance." - if (!chance) + if (itr->RollDispel()) { - steal_list.erase(itr); - continue; + successList.emplace_back(itr->GetAura()->GetId(), itr->GetAura()->GetCasterGUID()); + if (!itr->DecrementCharge()) + { + --remaining; + std::swap(*itr, stealList[remaining]); + } } else { - if (roll_chance_i(chance)) - { - success_list.push_back(std::make_pair(itr->first->GetId(), itr->first->GetCasterGUID())); - --itr->second; - if (itr->second <= 0) - steal_list.erase(itr); - } - else + if (!failCount) { - if (!failCount) - { - // Failed to dispell - dataFail << uint64(m_caster->GetGUID()); // Caster GUID - dataFail << uint64(unitTarget->GetGUID()); // Victim GUID - dataFail << uint32(m_spellInfo->Id); // dispel spell id - } - ++failCount; - dataFail << uint32(itr->first->GetId()); // Spell Id + // Failed to dispell + dataFail << uint64(m_caster->GetGUID()); // Caster GUID + dataFail << uint64(unitTarget->GetGUID()); // Victim GUID + dataFail << uint32(m_spellInfo->Id); // dispel spell id } - ++count; + ++failCount; + dataFail << uint32(itr->GetAura()->GetId()); // Spell Id } + ++count; } if (failCount) m_caster->SendMessageToSet(&dataFail, true); - if (success_list.empty()) + if (successList.empty()) return; - WorldPacket dataSuccess(SMSG_SPELLSTEALLOG, 8+8+4+1+4+damage*5); - dataSuccess << unitTarget->GetPackGUID(); // Victim GUID - dataSuccess << m_caster->GetPackGUID(); // Caster GUID - dataSuccess << uint32(m_spellInfo->Id); // dispel spell id - dataSuccess << uint8(0); // not used - dataSuccess << uint32(success_list.size()); // count - for (DispelList::iterator itr = success_list.begin(); itr!=success_list.end(); ++itr) + WorldPacket dataSuccess(SMSG_SPELLSTEALLOG, 8 + 8 + 4 + 1 + 4 + damage * 5); + dataSuccess << unitTarget->GetPackGUID(); // Victim GUID + dataSuccess << m_caster->GetPackGUID(); // Caster GUID + dataSuccess << uint32(m_spellInfo->Id); // dispel spell id + dataSuccess << uint8(0); // not used + dataSuccess << uint32(successList.size()); // count + for (auto itr = successList.begin(); itr != successList.end(); ++itr) { dataSuccess << uint32(itr->first); // Spell Id dataSuccess << uint8(0); // 0 - steals !=0 transfers |