Core/Creatures: Set InteractSpellID for npc spellclick

Port From (https://github.com/TrinityCore/TrinityCore/commit/6543d23a1a70768e9dce89b33ae7bf5fe6cdcc1e)
This commit is contained in:
hondacrx
2024-02-21 17:35:54 -05:00
parent 0f4130704a
commit e81d2d4f1f
2 changed files with 39 additions and 2 deletions
@@ -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<ChrCustomizationChoice>