From cd249ac67ab3e7876590a368f33c8a241e763a81 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 13 Mar 2023 02:36:50 -0400 Subject: [PATCH] Core/Spells: Updated silence flags for 9.0 and rename unit flag to its new meaning Port From (https://github.com/TrinityCore/TrinityCore/commit/3400c5a52c8ea35e56d57326f904dc0127c33048) --- Source/Framework/Constants/CreatureConst.cs | 4 ++-- Source/Game/AI/ScriptedAI/ScriptedAI.cs | 2 +- Source/Game/Entities/Player/Player.cs | 2 +- Source/Game/Entities/Unit/Unit.Spells.cs | 6 ++++++ Source/Game/Spells/Auras/AuraEffect.cs | 13 ++++++++----- Source/Game/Spells/Spell.cs | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Source/Framework/Constants/CreatureConst.cs b/Source/Framework/Constants/CreatureConst.cs index 87a23959b..f6b14a109 100644 --- a/Source/Framework/Constants/CreatureConst.cs +++ b/Source/Framework/Constants/CreatureConst.cs @@ -48,7 +48,7 @@ namespace Framework.Constants Looting = 0x400, PetInCombat = 0x800, PvpEnabling = 0x1000, - Silenced = 0x2000, + ForceNameplate = 0x2000, CantSwim = 0x4000, CanSwim = 0x8000, // shows swim animation in water NonAttackable2 = 0x10000, @@ -71,7 +71,7 @@ namespace Framework.Constants Disallowed = (ServerControlled | NonAttackable | RemoveClientControl | PlayerControlled | Rename | Preparation | /* UNIT_FLAG_UNK_6 | */ NotAttackable1 | Looting | PetInCombat | PvpEnabling | - Silenced | NonAttackable2 | Pacified | Stunned | + NonAttackable2 | Pacified | Stunned | InCombat | OnTaxi | Disarmed | Confused | Fleeing | Possessed | Skinnable | Mount | Unk28 | PreventEmotesFromChatText | Sheathe | Immune), diff --git a/Source/Game/AI/ScriptedAI/ScriptedAI.cs b/Source/Game/AI/ScriptedAI/ScriptedAI.cs index 341377d30..7d745422f 100644 --- a/Source/Game/AI/ScriptedAI/ScriptedAI.cs +++ b/Source/Game/AI/ScriptedAI/ScriptedAI.cs @@ -258,7 +258,7 @@ namespace Game.AI return null; //Silenced so we can't cast - if (me.HasUnitFlag(UnitFlags.Silenced)) + if (me.IsSilenced(school != 0 ? school : SpellSchoolMask.Magic)) return null; //Using the extended script system we first create a list of viable spells diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index bcbddb525..e36abfd16 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -5569,7 +5569,7 @@ namespace Game.Entities // cleanup unit flags (will be re-applied if need at aura load). RemoveUnitFlag(UnitFlags.NonAttackable | UnitFlags.RemoveClientControl | UnitFlags.NotAttackable1 | UnitFlags.ImmuneToPc | UnitFlags.ImmuneToNpc | UnitFlags.Looting | - UnitFlags.PetInCombat | UnitFlags.Silenced | UnitFlags.Pacified | + UnitFlags.PetInCombat | UnitFlags.Pacified | UnitFlags.Stunned | UnitFlags.InCombat | UnitFlags.Disarmed | UnitFlags.Confused | UnitFlags.Fleeing | UnitFlags.Uninteractible | UnitFlags.Skinnable | UnitFlags.Mount | UnitFlags.OnTaxi); diff --git a/Source/Game/Entities/Unit/Unit.Spells.cs b/Source/Game/Entities/Unit/Unit.Spells.cs index 3c219c6c7..dfd41cbdf 100644 --- a/Source/Game/Entities/Unit/Unit.Spells.cs +++ b/Source/Game/Entities/Unit/Unit.Spells.cs @@ -923,6 +923,12 @@ namespace Game.Entities return base.GetCastSpellXSpellVisualId(spellInfo); } + public bool IsSilenced(SpellSchoolMask schoolMask) { return (m_unitData.SilencedSchoolMask & (uint)schoolMask) != 0; } + + public void SetSilencedSchoolMask(SpellSchoolMask schoolMask) { SetUpdateFieldFlagValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.SilencedSchoolMask), (uint)schoolMask); } + + public void ReplaceAllSilencedSchoolMask(SpellSchoolMask schoolMask) { SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.SilencedSchoolMask), (uint)schoolMask); } + public SpellHistory GetSpellHistory() { return _spellHistory; } public static ProcFlagsHit CreateProcHitMask(SpellNonMeleeDamage damageInfo, SpellMissInfo missCondition) diff --git a/Source/Game/Spells/Auras/AuraEffect.cs b/Source/Game/Spells/Auras/AuraEffect.cs index ab22959fb..70d31f009 100644 --- a/Source/Game/Spells/Auras/AuraEffect.cs +++ b/Source/Game/Spells/Auras/AuraEffect.cs @@ -1832,7 +1832,7 @@ namespace Game.Spells if (apply) { - target.SetUnitFlag(UnitFlags.Silenced); + target.SetSilencedSchoolMask((SpellSchoolMask)GetMiscValue()); // call functions which may have additional effects after changing state of unit // Stop cast only spells vs PreventionType & SPELL_PREVENTION_TYPE_SILENCE @@ -1847,11 +1847,14 @@ namespace Game.Spells } else { - // do not remove unit flag if there are more than this auraEffect of that kind on unit on unit - if (target.HasAuraType(AuraType.ModSilence) || target.HasAuraType(AuraType.ModPacifySilence)) - return; + int silencedSchoolMask = 0; + foreach (AuraEffect auraEffect in target.GetAuraEffectsByType(AuraType.ModSilence)) + silencedSchoolMask |= auraEffect.GetMiscValue(); - target.RemoveUnitFlag(UnitFlags.Silenced); + foreach (AuraEffect auraEffect in target.GetAuraEffectsByType(AuraType.ModPacifySilence)) + silencedSchoolMask |= auraEffect.GetMiscValue(); + + target.ReplaceAllSilencedSchoolMask((SpellSchoolMask)silencedSchoolMask); } } diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 18ddff304..af9819e10 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -5909,7 +5909,7 @@ namespace Game.Spells else if ((m_spellInfo.Mechanic & Mechanics.ImmuneShield) != 0 && m_caster.IsUnit() && m_caster.ToUnit().HasAuraWithMechanic(1 << (int)Mechanics.Banish)) result = SpellCastResult.Stunned; } - else if (unitflag.HasAnyFlag(UnitFlags.Silenced) && m_spellInfo.PreventionType.HasAnyFlag(SpellPreventionType.Silence) && !CheckSpellCancelsSilence(ref param1)) + else if (unitCaster.IsSilenced(m_spellSchoolMask) && (m_spellInfo.PreventionType & SpellPreventionType.Silence) != 0 && !CheckSpellCancelsSilence(ref param1)) result = SpellCastResult.Silenced; else if (unitflag.HasAnyFlag(UnitFlags.Pacified) && m_spellInfo.PreventionType.HasAnyFlag(SpellPreventionType.Pacify) && !CheckSpellCancelsPacify(ref param1)) result = SpellCastResult.Pacified;