From a59b3b8075e507d98331b55dfa207f7bb68ccd68 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 25 May 2022 13:46:41 -0400 Subject: [PATCH] Core/SmartAI: AI change on charmed Port From (https://github.com/TrinityCore/TrinityCore/commit/8a4d731d55af63210e660727dc0aea68c8ecce05) --- Source/Game/AI/SmartScripts/SmartAI.cs | 3 ++ Source/Game/AI/SmartScripts/SmartScript.cs | 59 ++++++++++++---------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Source/Game/AI/SmartScripts/SmartAI.cs b/Source/Game/AI/SmartScripts/SmartAI.cs index 3c973739b..f01ef9963 100644 --- a/Source/Game/AI/SmartScripts/SmartAI.cs +++ b/Source/Game/AI/SmartScripts/SmartAI.cs @@ -759,6 +759,9 @@ namespace Game.AI } GetScript().ProcessEventsFor(SmartEvents.Charmed, null, 0, 0, charmed); + + if (!GetScript().HasAnyEventWithFlag(SmartEventFlags.WhileCharmed)) // we can change AI if there are no events with this flag + base.OnCharmed(isNew); } public override void DoAction(int param) diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index bee9f8f5a..3594f9da6 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -67,6 +67,7 @@ namespace Game.AI uint _currentPriority; bool _eventSortingRequired; uint _nestedEventsCounter; + SmartEventFlags _allEventFlags; Dictionary _storedTargets = new(); @@ -4075,35 +4076,39 @@ namespace Game.AI { if (holder.Event.event_flags.HasAnyFlag(SmartEventFlags.DifficultyAll))//if has instance flag add only if in it { - if (obj != null && obj.GetMap().IsDungeon()) + if (!(obj != null && obj.GetMap().IsDungeon())) + continue; + + // TODO: fix it for new maps and difficulties + switch (obj.GetMap().GetDifficultyID()) { - // TODO: fix it for new maps and difficulties - switch (obj.GetMap().GetDifficultyID()) - { - case Difficulty.Normal: - case Difficulty.Raid10N: - if (holder.Event.event_flags.HasAnyFlag(SmartEventFlags.Difficulty0)) - _events.Add(holder); - break; - case Difficulty.Heroic: - case Difficulty.Raid25N: - if (holder.Event.event_flags.HasAnyFlag(SmartEventFlags.Difficulty1)) - _events.Add(holder); - break; - case Difficulty.Raid10HC: - if (holder.Event.event_flags.HasAnyFlag(SmartEventFlags.Difficulty2)) - _events.Add(holder); - break; - case Difficulty.Raid25HC: - if (holder.Event.event_flags.HasAnyFlag(SmartEventFlags.Difficulty3)) - _events.Add(holder); - break; - default: - break; - } + + + case Difficulty.Normal: + case Difficulty.Raid10N: + if (holder.Event.event_flags.HasAnyFlag(SmartEventFlags.Difficulty0)) + _events.Add(holder); + break; + case Difficulty.Heroic: + case Difficulty.Raid25N: + if (holder.Event.event_flags.HasAnyFlag(SmartEventFlags.Difficulty1)) + _events.Add(holder); + break; + case Difficulty.Raid10HC: + if (holder.Event.event_flags.HasAnyFlag(SmartEventFlags.Difficulty2)) + _events.Add(holder); + break; + case Difficulty.Raid25HC: + if (holder.Event.event_flags.HasAnyFlag(SmartEventFlags.Difficulty3)) + _events.Add(holder); + break; + default: + break; + } - continue; } + + _allEventFlags |= holder.Event.event_flags; _events.Add(holder);//NOTE: 'world(0)' events still get processed in ANY instance mode } } @@ -4353,6 +4358,8 @@ namespace Game.AI { return _trigger != null ? _atPlayer : GetBaseObject(); } + + public bool HasAnyEventWithFlag(SmartEventFlags flag) { return _allEventFlags.HasAnyFlag(flag); } public bool IsUnit(WorldObject obj) { return obj != null && (obj.IsTypeId(TypeId.Unit) || obj.IsTypeId(TypeId.Player)); } public bool IsPlayer(WorldObject obj) { return obj != null && obj.IsTypeId(TypeId.Player); }