Core/Spells: Replace MAX_SPELL_EFFECTS loop limits with correct upper bound depending on how many effects the spell has v2
Port From (https://github.com/TrinityCore/TrinityCore/commit/9ad1ab6c57dbc1167233a23b39fd3198f3317876)
This commit is contained in:
@@ -8,8 +8,10 @@ using Game.BattleGrounds;
|
|||||||
using Game.Networking.Packets;
|
using Game.Networking.Packets;
|
||||||
using Game.Spells;
|
using Game.Spells;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Game.Entities
|
namespace Game.Entities
|
||||||
@@ -3197,24 +3199,17 @@ namespace Game.Entities
|
|||||||
{
|
{
|
||||||
int[] damage = new int[SpellConst.MaxEffects];
|
int[] damage = new int[SpellConst.MaxEffects];
|
||||||
int[] baseDamage = new int[SpellConst.MaxEffects];
|
int[] baseDamage = new int[SpellConst.MaxEffects];
|
||||||
uint effMask = 0;
|
BitSet effMask = new BitSet(SpellConst.MaxEffects);
|
||||||
uint recalculateMask = 0;
|
BitSet recalculateMask = new BitSet(SpellConst.MaxEffects);
|
||||||
Unit caster = aura.GetCaster();
|
Unit caster = aura.GetCaster();
|
||||||
for (byte i = 0; i < SpellConst.MaxEffects; ++i)
|
foreach (AuraEffect aurEff in aura.GetAuraEffects())
|
||||||
{
|
{
|
||||||
if (aura.GetEffect(i) != null)
|
int i = (int)aurEff.GetEffIndex();
|
||||||
{
|
baseDamage[i] = aurEff.GetBaseAmount();
|
||||||
baseDamage[i] = aura.GetEffect(i).GetBaseAmount();
|
damage[i] = aurEff.GetAmount();
|
||||||
damage[i] = aura.GetEffect(i).GetAmount();
|
effMask[i] = true;
|
||||||
effMask |= 1u << i;
|
if (aurEff.CanBeRecalculated())
|
||||||
if (aura.GetEffect(i).CanBeRecalculated())
|
recalculateMask[i] = true;
|
||||||
recalculateMask |= 1u << i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
baseDamage[i] = 0;
|
|
||||||
damage[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool stealCharge = aura.GetSpellInfo().HasAttribute(SpellAttr7.DispelRemovesCharges);
|
bool stealCharge = aura.GetSpellInfo().HasAttribute(SpellAttr7.DispelRemovesCharges);
|
||||||
@@ -3239,7 +3234,7 @@ namespace Game.Entities
|
|||||||
if (aura.IsSingleTarget())
|
if (aura.IsSingleTarget())
|
||||||
aura.UnregisterSingleTarget();
|
aura.UnregisterSingleTarget();
|
||||||
|
|
||||||
AuraCreateInfo createInfo = new(aura.GetCastId(), aura.GetSpellInfo(), aura.GetCastDifficulty(), effMask, stealer);
|
AuraCreateInfo createInfo = new(aura.GetCastId(), aura.GetSpellInfo(), aura.GetCastDifficulty(), effMask.ToUInt(), stealer);
|
||||||
createInfo.SetCasterGUID(aura.GetCasterGUID());
|
createInfo.SetCasterGUID(aura.GetCasterGUID());
|
||||||
createInfo.SetBaseAmount(baseDamage);
|
createInfo.SetBaseAmount(baseDamage);
|
||||||
createInfo.SetStackAmount(stolenCharges);
|
createInfo.SetStackAmount(stolenCharges);
|
||||||
@@ -3256,7 +3251,7 @@ namespace Game.Entities
|
|||||||
caster.GetSingleCastAuras().Add(aura);
|
caster.GetSingleCastAuras().Add(aura);
|
||||||
}
|
}
|
||||||
// FIXME: using aura.GetMaxDuration() maybe not blizzlike but it fixes stealing of spells like Innervate
|
// FIXME: using aura.GetMaxDuration() maybe not blizzlike but it fixes stealing of spells like Innervate
|
||||||
newAura.SetLoadedState(aura.GetMaxDuration(), (int)dur, stealCharge ? stolenCharges : aura.GetCharges(), recalculateMask, damage);
|
newAura.SetLoadedState(aura.GetMaxDuration(), (int)dur, stealCharge ? stolenCharges : aura.GetCharges(), recalculateMask.ToUInt(), damage);
|
||||||
newAura.ApplyForTargets();
|
newAura.ApplyForTargets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3478,10 +3473,10 @@ namespace Game.Entities
|
|||||||
if (aurApp.HasRemoveMode())
|
if (aurApp.HasRemoveMode())
|
||||||
{
|
{
|
||||||
// remove remaining effects of an aura
|
// remove remaining effects of an aura
|
||||||
for (byte effectIndex = 0; effectIndex < SpellConst.MaxEffects; ++effectIndex)
|
foreach (AuraEffect aurEff in aurApp.GetBase().GetAuraEffects())
|
||||||
{
|
{
|
||||||
if (aurApp.HasEffect(effectIndex))
|
if (aurApp.HasEffect(aurEff.GetEffIndex()))
|
||||||
aurApp._HandleEffect(effectIndex, false);
|
aurApp._HandleEffect(aurEff.GetEffIndex(), false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3903,11 +3898,9 @@ namespace Game.Entities
|
|||||||
aura._UnapplyForTarget(this, caster, aurApp);
|
aura._UnapplyForTarget(this, caster, aurApp);
|
||||||
|
|
||||||
// remove effects of the spell - needs to be done after removing aura from lists
|
// remove effects of the spell - needs to be done after removing aura from lists
|
||||||
for (byte c = 0; c < SpellConst.MaxEffects; ++c)
|
foreach (AuraEffect aurEff in aura.GetAuraEffects())
|
||||||
{
|
if (aurApp.HasEffect(aurEff.GetEffIndex()))
|
||||||
if (aurApp.HasEffect(c))
|
aurApp._HandleEffect(aurEff.GetEffIndex(), false);
|
||||||
aurApp._HandleEffect(c, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// all effect mustn't be applied
|
// all effect mustn't be applied
|
||||||
Cypher.Assert(aurApp.GetEffectMask() == 0);
|
Cypher.Assert(aurApp.GetEffectMask() == 0);
|
||||||
@@ -4152,10 +4145,14 @@ namespace Game.Entities
|
|||||||
aura.HandleAuraSpecificMods(aurApp, caster, true, false);
|
aura.HandleAuraSpecificMods(aurApp, caster, true, false);
|
||||||
|
|
||||||
// apply effects of the aura
|
// apply effects of the aura
|
||||||
for (byte i = 0; i < SpellConst.MaxEffects; i++)
|
foreach (AuraEffect aurEff in aura.GetAuraEffects())
|
||||||
{
|
{
|
||||||
if (Convert.ToBoolean(effMask & 1 << i) && !(aurApp.HasRemoveMode()))
|
if ((effMask & 1 << (int)aurEff.GetEffIndex()) != 0)
|
||||||
aurApp._HandleEffect(i, true);
|
{
|
||||||
|
aurApp._HandleEffect(aurEff.GetEffIndex(), true);
|
||||||
|
if (aurApp.GetRemoveMode() != 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = ToPlayer();
|
Player player = ToPlayer();
|
||||||
@@ -4336,7 +4333,10 @@ namespace Game.Entities
|
|||||||
if (diff == 0)
|
if (diff == 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < SpellConst.MaxEffects; ++i)
|
for (int i = 0; i < SpellConst.MaxEffects; ++i)
|
||||||
diff += (long)((auraEffectMask & (1 << i)) >> i) - (long)((existingAurEff.GetBase().GetEffectMask() & (1 << i)) >> i);
|
{
|
||||||
|
// treat the aura with more effects as stronger
|
||||||
|
diff = BitOperations.PopCount(auraEffectMask) - BitOperations.PopCount(existingAurEff.GetBase().GetEffectMask());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diff > 0)
|
if (diff > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user