Scripts/SmartAI: SMART_TARGET_INVOKER cleanup step 1. The core will now log errors on start-up if SMART_TARGET_INVOKER abuse is found, but will continue to load the scripts as deprecated for now.

Port From (https://github.com/TrinityCore/TrinityCore/commit/06b5b8d8b7ac3da65013ccc0f03599ee9dee2163)
This commit is contained in:
hondacrx
2021-06-23 22:41:44 -04:00
parent de6b8b0240
commit fc49a98dab
5 changed files with 72 additions and 6 deletions
+1 -1
View File
@@ -397,7 +397,7 @@ namespace Framework.Constants
public enum SmartTargets
{
None = 0, // None, Defaulting To Invoket
None = 0, // None
Self = 1, // Self Cast
Victim = 2, // Our Current Target (Ie: Highest Aggro)
HostileSecondAggro = 3, // Second highest aggro, maxdist, playerOnly, powerType + 1
+1 -1
View File
@@ -888,7 +888,7 @@ namespace Game.AI
SetDespawnTime(5000);
StartDespawn();
GetScript().ProcessEventsFor(SmartEvents.FollowCompleted);
GetScript().ProcessEventsFor(SmartEvents.FollowCompleted, player);
}
public void SetScript9(SmartScriptHolder e, uint entry, Unit invoker)
+67 -3
View File
@@ -373,6 +373,63 @@ namespace Game.AI
Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} SmartAI waypoint paths (total {total} waypoints) in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
}
static bool EventHasInvoker(SmartEvents smartEvent)
{
switch (smartEvent)
{ // white list of events that actually have an invoker passed to them
case SmartEvents.Aggro:
case SmartEvents.Death:
case SmartEvents.Kill:
case SmartEvents.SummonedUnit:
case SmartEvents.SpellHit:
case SmartEvents.SpellHitTarget:
case SmartEvents.Damaged:
case SmartEvents.ReceiveHeal:
case SmartEvents.ReceiveEmote:
case SmartEvents.JustSummoned:
case SmartEvents.DamagedTarget:
case SmartEvents.SummonDespawned:
case SmartEvents.PassengerBoarded:
case SmartEvents.PassengerRemoved:
case SmartEvents.GossipHello:
case SmartEvents.GossipSelect:
case SmartEvents.AcceptedQuest:
case SmartEvents.RewardQuest:
case SmartEvents.FollowCompleted:
case SmartEvents.OnSpellclick:
case SmartEvents.GoLootStateChanged:
case SmartEvents.AreatriggerOntrigger:
case SmartEvents.IcLos:
case SmartEvents.OocLos:
case SmartEvents.DistanceCreature:
case SmartEvents.FriendlyHealth:
case SmartEvents.FriendlyHealthPCT:
case SmartEvents.FriendlyIsCc:
case SmartEvents.FriendlyMissingBuff:
case SmartEvents.ActionDone:
case SmartEvents.TargetHealthPct:
case SmartEvents.TargetManaPct:
case SmartEvents.Range:
case SmartEvents.VictimCasting:
case SmartEvents.TargetBuffed:
case SmartEvents.IsBehindTarget:
case SmartEvents.InstancePlayerEnter:
case SmartEvents.TransportAddcreature:
case SmartEvents.QuestAccepted:
case SmartEvents.QuestObjCompletion:
case SmartEvents.QuestCompletion:
case SmartEvents.QuestFail:
case SmartEvents.QuestRewarded:
case SmartEvents.SceneStart:
case SmartEvents.SceneTrigger:
case SmartEvents.SceneCancel:
case SmartEvents.SceneComplete:
return true;
default:
return false;
}
}
static bool IsTargetValid(SmartScriptHolder e)
{
if (Math.Abs(e.Target.o) > 2 * MathFunctions.PI)
@@ -426,6 +483,16 @@ namespace Game.AI
}
break;
}
case SmartTargets.ActionInvoker:
case SmartTargets.ActionInvokerVehicle:
case SmartTargets.InvokerParty:
if (e.GetScriptType() != SmartScriptType.TimedActionlist && e.GetEventType() != SmartEvents.Link && !EventHasInvoker(e.Event.type))
{
Log.outError(LogFilter.Sql, "SmartAIMgr: Entry {e.entryOrGuid} SourceType {e.GetScriptType()} Event {e.GetEventType()} Action {}e.GetActionType() has invoker target, but action does not provide any invoker!");
// allow this to load for now
// return false;
break;
}
case SmartTargets.PlayerRange:
case SmartTargets.Self:
case SmartTargets.Victim:
@@ -433,11 +500,8 @@ namespace Game.AI
case SmartTargets.HostileLastAggro:
case SmartTargets.HostileRandom:
case SmartTargets.HostileRandomNotTop:
case SmartTargets.ActionInvoker:
case SmartTargets.InvokerParty:
case SmartTargets.Position:
case SmartTargets.None:
case SmartTargets.ActionInvokerVehicle:
case SmartTargets.OwnerOrSummoner:
case SmartTargets.ThreatList:
case SmartTargets.ClosestGameobject:
+1 -1
View File
@@ -3102,7 +3102,7 @@ namespace Game.AI
uint count = _me.GetVictim().GetAuraCount(e.Event.aura.spell);
if (count < e.Event.aura.count)
return;
ProcessTimedAction(e, e.Event.aura.repeatMin, e.Event.aura.repeatMax);
ProcessTimedAction(e, e.Event.aura.repeatMin, e.Event.aura.repeatMax, _me.GetVictim());
break;
}
case SmartEvents.Charmed:
@@ -0,0 +1,2 @@
-- SMART_ACTION_FLEE_FOR_ASSIST (25) does not need a target
UPDATE `smart_scripts` SET `target_type`=0 WHERE `action_type`=25;