Core/Creatures: Implement StringId for Creatures, a custom identifier to make finding specific creatures in script easier

Port From (https://github.com/TrinityCore/TrinityCore/commit/61c51b76c00d932a9180bc6781a244dc18375ef7)
This commit is contained in:
hondacrx
2023-01-05 16:44:30 -05:00
parent 23c3084f00
commit 0c782c60c2
11 changed files with 110 additions and 22 deletions
@@ -27,6 +27,9 @@ namespace Game.Entities
CreatureTemplate m_creatureInfo;
CreatureData m_creatureData;
string[] m_stringIds = new string[3];
string m_scriptStringId;
SpellFocusInfo _spellFocusInfo;
long _lastDamagedTime; // Part of Evade mechanics
+25
View File
@@ -433,6 +433,8 @@ namespace Game.Entities
//We must update last scriptId or it looks like we reloaded a script, breaking some things such as gossip temporarily
LastUsedScriptID = GetScriptId();
m_stringIds[0] = cInfo.StringId;
return true;
}
@@ -2759,6 +2761,27 @@ namespace Game.Entities
return Global.ObjectMgr.GetCreatureTemplate(GetEntry()) != null ? Global.ObjectMgr.GetCreatureTemplate(GetEntry()).ScriptID : 0;
}
public bool HasStringId(string id)
{
return m_stringIds.Contains(id);
}
void SetScriptStringId(string id)
{
if (!id.IsEmpty())
{
m_scriptStringId = id;
m_stringIds[2] = m_scriptStringId;
}
else
{
m_scriptStringId = null;
m_stringIds[2] = null;
}
}
public string[] GetStringIds() { return m_stringIds; }
public VendorItemData GetVendorItems()
{
return Global.ObjectMgr.GetNpcVendorItemList(GetEntry());
@@ -3293,6 +3316,8 @@ namespace Game.Entities
// checked at creature_template loading
DefaultMovementType = (MovementGeneratorType)data.movementType;
m_stringIds[1] = data.StringId;
if (addToMap && !GetMap().AddToMap(this))
return false;
return true;
@@ -92,6 +92,7 @@ namespace Game.Entities
public uint SpellSchoolImmuneMask;
public CreatureFlagsExtra FlagsExtra;
public uint ScriptID;
public string StringId;
public QueryCreatureResponse QueryData;
+20 -4
View File
@@ -1666,8 +1666,9 @@ namespace Game.Entities
public Creature FindNearestCreatureWithOptions(float range, FindCreatureOptions options)
{
var checker = new NearestCreatureEntryWithLiveStateAndAuraInObjectRangeCheck(this, range, options);
var searcher = new CreatureLastSearcher(this, checker);
NearestCheckCustomizer checkCustomizer = new(this, range);
CreatureWithOptionsInObjectRangeCheck<NearestCheckCustomizer> checker = new(this, checkCustomizer, options);
CreatureLastSearcher searcher = new(this, checker);
if (options.IgnorePhases)
searcher.i_phaseShift = PhasingHandler.GetAlwaysVisiblePhaseShift();
@@ -2571,7 +2572,6 @@ namespace Game.Entities
SendMessageToSet(cancelSpellVisualKit, true);
}
// function based on function Unit::CanAttack from 13850 client
public bool IsValidAttackTarget(WorldObject target, SpellInfo bySpell = null)
{
@@ -2883,7 +2883,7 @@ namespace Game.Entities
{
return spellInfo.GetSpellXSpellVisualId(this);
}
public List<GameObject> GetGameObjectListWithEntryInGrid(uint entry = 0, float maxSearchRange = 250.0f)
{
List<GameObject> gameobjectList = new();
@@ -2904,6 +2904,20 @@ namespace Game.Entities
return creatureList;
}
public List<Creature> GetCreatureListWithOptionsInGrid(float maxSearchRange, FindCreatureOptions options)
{
List<Creature> creatureList = new();
NoopCheckCustomizer checkCustomizer = new();
CreatureWithOptionsInObjectRangeCheck<NoopCheckCustomizer> check = new(this, checkCustomizer, options);
CreatureListSearcher searcher = new(this, creatureList, check);
if (options.IgnorePhases)
searcher.i_phaseShift = PhasingHandler.GetAlwaysVisiblePhaseShift();
Cell.VisitGridObjects(this, searcher, maxSearchRange);
return creatureList;
}
public List<Unit> GetPlayerListInGrid(float maxSearchRange, bool alive = true)
{
List<Unit> playerList = new();
@@ -4050,6 +4064,7 @@ namespace Game.Entities
public struct FindCreatureOptions
{
public FindCreatureOptions SetCreatureId(uint creatureId) { CreatureId = creatureId; return this; }
public FindCreatureOptions SetStringId(string stringId) { StringId = stringId; return this; }
public FindCreatureOptions SetIsAlive(bool isAlive) { IsAlive = isAlive; return this; }
public FindCreatureOptions SetIsInCombat(bool isInCombat) { IsInCombat = isInCombat; return this; }
@@ -4067,6 +4082,7 @@ namespace Game.Entities
public FindCreatureOptions SetPrivateObjectOwner(ObjectGuid privateObjectOwnerGuid) { PrivateObjectOwnerGuid = privateObjectOwnerGuid; return this; }
public uint? CreatureId;
public string StringId;
public bool? IsAlive;
public bool? IsInCombat;