From e81d2d4f1f16954d6a0d586151de7a335d1e8128 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 21 Feb 2024 17:35:54 -0500 Subject: [PATCH] Core/Creatures: Set InteractSpellID for npc spellclick Port From (https://github.com/TrinityCore/TrinityCore/commit/6543d23a1a70768e9dce89b33ae7bf5fe6cdcc1e) --- Source/Game/Entities/Creature/Creature.cs | 15 +++++++++++ .../Entities/Object/Update/UpdateFields.cs | 26 +++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 42e599ba9..d2bab92e7 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -383,6 +383,9 @@ namespace Game.Entities if (IsTrigger()) SetUninteractible(true); + if (HasNpcFlag(NPCFlags.SpellClick)) + InitializeInteractSpellId(); + InitializeReactState(); if (Convert.ToBoolean(cInfo.FlagsExtra & CreatureFlagsExtra.NoTaunt)) @@ -1148,6 +1151,16 @@ namespace Game.Entities SummonCreature(npcEntry, GetPosition(), TempSummonType.TimedDespawn, TimeSpan.FromSeconds(1), 0, 0); } + void InitializeInteractSpellId() + { + var clickBounds = Global.ObjectMgr.GetSpellClickInfoMapBounds(GetEntry()); + // Set InteractSpellID if there is only one row in npc_spellclick_spells in db for this creature + if (clickBounds.Count == 1) + SetInteractSpellId((int)clickBounds[0].spellId); + else + SetInteractSpellId(0); + } + public bool HasFlag(CreatureStaticFlags flag) { return _staticFlags.HasFlag(flag); } public bool HasFlag(CreatureStaticFlags2 flag) { return _staticFlags.HasFlag(flag); } public bool HasFlag(CreatureStaticFlags3 flag) { return _staticFlags.HasFlag(flag); } @@ -1616,6 +1629,8 @@ namespace Game.Entities float GetSparringHealthPct() { return _sparringHealthPct; } + void SetInteractSpellId(int interactSpellId) { SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.InteractSpellID), interactSpellId); } + public void OverrideSparringHealthPct(List healthPct) { _sparringHealthPct = healthPct.SelectRandom(); diff --git a/Source/Game/Entities/Object/Update/UpdateFields.cs b/Source/Game/Entities/Object/Update/UpdateFields.cs index bcde6a75e..d0cc30d39 100644 --- a/Source/Game/Entities/Object/Update/UpdateFields.cs +++ b/Source/Game/Entities/Object/Update/UpdateFields.cs @@ -1441,7 +1441,7 @@ namespace Game.Entities data.WriteUInt32(WildBattlePetLevel); data.WriteUInt32(BattlePetCompanionExperience); data.WriteUInt32(BattlePetCompanionNameTimestamp); - data.WriteInt32(InteractSpellID); + data.WriteInt32(GetViewerDependentInteractSpellId(this, owner, receiver)); data.WriteInt32(ScaleDuration); data.WriteInt32(LooksLikeMountID); data.WriteInt32(LooksLikeCreatureID); @@ -2003,7 +2003,7 @@ namespace Game.Entities } if (changesMask[114]) { - data.WriteInt32(InteractSpellID); + data.WriteInt32(GetViewerDependentInteractSpellId(this, owner, receiver)); } if (changesMask[115]) { @@ -2388,6 +2388,28 @@ namespace Game.Entities return pvpFlags; } + int GetViewerDependentInteractSpellId(UnitData unitData, Unit unit, Player receiver) + { + int interactSpellId = unitData.InteractSpellID; + if ((unitData.NpcFlags[0] & (uint)NPCFlags.SpellClick) != 0 && interactSpellId == 0) + { + // this field is not set if there are multiple available spellclick spells + var clickBounds = Global.ObjectMgr.GetSpellClickInfoMapBounds(unit.GetEntry()); + foreach (var spellClickInfo in clickBounds) + { + if (!spellClickInfo.IsFitToRequirements(receiver, unit)) + continue; + + if (!Global.ConditionMgr.IsObjectMeetingSpellClickConditions(unit.GetEntry(), spellClickInfo.spellId, receiver, unit)) + continue; + + interactSpellId = (int)spellClickInfo.spellId; + break; + } + + } + return interactSpellId; + } } public class ChrCustomizationChoice : IComparable