Core/Spell: implement SPELL_FAILED_AURA_BOUNCED on DR spells

Port From (https://github.com/TrinityCore/TrinityCore/commit/bebc20b4de7db2fa1b80ac481902a39d92bd4dc8)
This commit is contained in:
hondacrx
2021-04-16 15:20:02 -04:00
parent 5a59f99851
commit da0b406c8a
3 changed files with 68 additions and 35 deletions
+2 -1
View File
@@ -2934,7 +2934,8 @@ namespace Game.Entities
return GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Air); return GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Air);
} }
public bool IsDungeonBoss() { return (GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.DungeonBoss)); } public bool IsDungeonBoss() { return (GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.DungeonBoss)); }
public override bool IsAffectedByDiminishingReturns() { return base.IsAffectedByDiminishingReturns() || GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.AllDiminish); }
public void SetReactState(ReactStates st) public void SetReactState(ReactStates st)
{ {
reactState = st; reactState = st;
+27 -20
View File
@@ -2711,18 +2711,17 @@ namespace Game.Entities
return null; return null;
} }
public virtual bool IsAffectedByDiminishingReturns() { return (GetCharmerOrOwnerPlayerOrPlayerItself() != null); }
public DiminishingLevels GetDiminishing(DiminishingGroup group) public DiminishingLevels GetDiminishing(DiminishingGroup group)
{ {
DiminishingReturn diminish = m_Diminishing[(int)group]; DiminishingReturn diminish = m_Diminishing[(int)group];
if (diminish.HitCount == 0) if (diminish.HitCount == 0)
return DiminishingLevels.Level1; return DiminishingLevels.Level1;
// If last spell was cast more than 18 seconds ago - reset the count. // If last spell was cast more than 18 seconds ago - reset level.
if (diminish.Stack == 0 && Time.GetMSTimeDiffToNow(diminish.HitTime) > 18 * Time.InMilliseconds) if (diminish.Stack == 0 && Time.GetMSTimeDiffToNow(diminish.HitTime) > 18 * Time.InMilliseconds)
{
diminish.HitCount = DiminishingLevels.Level1;
return DiminishingLevels.Level1; return DiminishingLevels.Level1;
}
return diminish.HitCount; return diminish.HitCount;
} }
@@ -2730,12 +2729,12 @@ namespace Game.Entities
public void IncrDiminishing(SpellInfo auraSpellInfo) public void IncrDiminishing(SpellInfo auraSpellInfo)
{ {
DiminishingGroup group = auraSpellInfo.GetDiminishingReturnsGroupForSpell(); DiminishingGroup group = auraSpellInfo.GetDiminishingReturnsGroupForSpell();
DiminishingLevels currentLevel = GetDiminishing(group);
DiminishingLevels maxLevel = auraSpellInfo.GetDiminishingReturnsMaxLevel(); DiminishingLevels maxLevel = auraSpellInfo.GetDiminishingReturnsMaxLevel();
// Checking for existing in the table
DiminishingReturn diminish = m_Diminishing[(int)group]; DiminishingReturn diminish = m_Diminishing[(int)group];
if (diminish.HitCount < maxLevel) if (currentLevel < maxLevel)
++diminish.HitCount; diminish.HitCount = currentLevel + 1;
} }
public bool ApplyDiminishingToDuration(SpellInfo auraSpellInfo, ref int duration, Unit caster, DiminishingLevels previousLevel) public bool ApplyDiminishingToDuration(SpellInfo auraSpellInfo, ref int duration, Unit caster, DiminishingLevels previousLevel)
@@ -2755,8 +2754,7 @@ namespace Game.Entities
Unit target = targetOwner ?? this; Unit target = targetOwner ?? this;
Unit source = casterOwner ?? caster; Unit source = casterOwner ?? caster;
if ((target.IsTypeId(TypeId.Player) || target.ToCreature().GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.AllDiminish)) if (target.IsAffectedByDiminishingReturns() && source.IsPlayer())
&& source.IsTypeId(TypeId.Player))
duration = limitDuration; duration = limitDuration;
} }
@@ -2789,9 +2787,9 @@ namespace Game.Entities
} }
break; break;
case DiminishingGroup.AOEKnockback: case DiminishingGroup.AOEKnockback:
if ((auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.Player && (((targetOwner ? targetOwner : this).ToPlayer()) if (auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.All ||
|| IsCreature() && ToCreature().GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.AllDiminish))) (auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.Player &&
|| auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.All) (targetOwner ? targetOwner.IsAffectedByDiminishingReturns() : IsAffectedByDiminishingReturns())))
{ {
DiminishingLevels diminish = previousLevel; DiminishingLevels diminish = previousLevel;
switch (diminish) switch (diminish)
@@ -2807,9 +2805,9 @@ namespace Game.Entities
} }
break; break;
default: default:
if ((auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.Player && (((targetOwner ? targetOwner : this).ToPlayer()) if (auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.All ||
|| IsCreature() && ToCreature().GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.AllDiminish))) (auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.Player &&
|| auraSpellInfo.GetDiminishingReturnsGroupType() == DiminishingReturnsType.All) (targetOwner ? targetOwner.IsAffectedByDiminishingReturns() : IsAffectedByDiminishingReturns())))
{ {
DiminishingLevels diminish = previousLevel; DiminishingLevels diminish = previousLevel;
switch (diminish) switch (diminish)
@@ -3195,17 +3193,26 @@ namespace Game.Entities
return false; return false;
} }
bool HasNegativeAuraWithAttribute(SpellAttr0 flag, ObjectGuid guid = default) public bool HasStrongerAuraWithDR(SpellInfo auraSpellInfo, Unit caster)
{ {
foreach (var list in GetAppliedAuras()) DiminishingGroup diminishGroup = auraSpellInfo.GetDiminishingReturnsGroupForSpell();
DiminishingLevels level = GetDiminishing(diminishGroup);
foreach (var itr in GetAppliedAuras())
{ {
Aura aura = list.Value.GetBase(); SpellInfo spellInfo = itr.Value.GetBase().GetSpellInfo();
if (!list.Value.IsPositive() && aura.GetSpellInfo().HasAttribute(flag) && (guid.IsEmpty() || aura.GetCasterGUID() == guid)) if (spellInfo.GetDiminishingReturnsGroupForSpell() != diminishGroup)
continue;
int existingDuration = itr.Value.GetBase().GetMaxDuration();
int newDuration = auraSpellInfo.GetMaxDuration();
ApplyDiminishingToDuration(auraSpellInfo, ref newDuration, caster, level);
if (newDuration > 0 && newDuration < existingDuration)
return true; return true;
} }
return false; return false;
} }
public uint GetAuraCount(uint spellId) public uint GetAuraCount(uint spellId)
{ {
uint count = 0; uint count = 0;
+39 -14
View File
@@ -2138,9 +2138,7 @@ namespace Game.Spells
diminishLevel = unit.GetDiminishing(diminishGroup); diminishLevel = unit.GetDiminishing(diminishGroup);
DiminishingReturnsType type = m_spellInfo.GetDiminishingReturnsGroupType(); DiminishingReturnsType type = m_spellInfo.GetDiminishingReturnsGroupType();
// Increase Diminishing on unit, current informations for actually casts will use values above // Increase Diminishing on unit, current informations for actually casts will use values above
if ((type == DiminishingReturnsType.Player && (unit.GetCharmerOrOwnerPlayerOrPlayerItself() if (type == DiminishingReturnsType.All || (type == DiminishingReturnsType.Player && unit.IsAffectedByDiminishingReturns()))
|| (unit.IsCreature() && unit.ToCreature().GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.AllDiminish))))
|| type == DiminishingReturnsType.All)
unit.IncrDiminishing(m_spellInfo); unit.IncrDiminishing(m_spellInfo);
} }
@@ -2716,11 +2714,9 @@ namespace Game.Spells
// skip check if done already (for instant cast spells for example) // skip check if done already (for instant cast spells for example)
if (!skipCheck) if (!skipCheck)
{ {
uint param1 = 0, param2 = 0; void cleanupSpell(SpellCastResult result, uint? param1 = null, uint? param2 = null)
SpellCastResult castResult = CheckCast(false, ref param1, ref param2);
if (castResult != SpellCastResult.SpellCastOk)
{ {
SendCastResult(castResult, param1, param2); SendCastResult(result, param1, param2);
SendInterrupted(0); SendInterrupted(0);
if (modOwner) if (modOwner)
@@ -2728,6 +2724,14 @@ namespace Game.Spells
Finish(false); Finish(false);
SetExecutedCurrently(false); SetExecutedCurrently(false);
}
uint param1 = 0, param2 = 0;
SpellCastResult castResult = CheckCast(false, ref param1, ref param2);
if (castResult != SpellCastResult.SpellCastOk)
{
cleanupSpell(castResult, param1, param2);
return; return;
} }
@@ -2744,18 +2748,39 @@ namespace Game.Spells
{ {
// Spell will be casted at completing the trade. Silently ignore at this place // Spell will be casted at completing the trade. Silently ignore at this place
my_trade.SetSpell(m_spellInfo.Id, m_CastItem); my_trade.SetSpell(m_spellInfo.Id, m_CastItem);
SendCastResult(SpellCastResult.DontReport); cleanupSpell(SpellCastResult.DontReport);
SendInterrupted(0);
modOwner.SetSpellModTakingSpell(this, false);
Finish(false);
SetExecutedCurrently(false);
return; return;
} }
} }
} }
} }
// check diminishing returns (again, only after finish cast bar, tested on retail)
Unit target = m_targets.GetUnitTarget();
if (target != null)
{
uint aura_effmask = 0;
for (byte i = 0; i < SpellConst.MaxEffects; ++i)
if (m_spellInfo.GetEffect(i) != null && m_spellInfo.GetEffect(i).IsUnitOwnedAuraEffect())
aura_effmask |= 1u << i;
if (aura_effmask != 0)
{
DiminishingGroup diminishGroup = m_spellInfo.GetDiminishingReturnsGroupForSpell();
if (diminishGroup != 0)
{
DiminishingReturnsType type = m_spellInfo.GetDiminishingReturnsGroupType();
if (type == DiminishingReturnsType.All || (type == DiminishingReturnsType.Player && target.IsAffectedByDiminishingReturns()))
{
if (target.HasStrongerAuraWithDR(m_spellInfo, m_originalCaster ?? m_caster))
{
cleanupSpell(SpellCastResult.AuraBounced);
return;
}
}
}
}
}
} }
// if the spell allows the creature to turn while casting, then adjust server-side orientation to face the target now // if the spell allows the creature to turn while casting, then adjust server-side orientation to face the target now