Core/Creatures: Set InteractSpellID for npc spellclick
Port From (https://github.com/TrinityCore/TrinityCore/commit/6543d23a1a70768e9dce89b33ae7bf5fe6cdcc1e)
This commit is contained in:
@@ -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<float> healthPct)
|
||||
{
|
||||
_sparringHealthPct = healthPct.SelectRandom();
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user