diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 5 | ||||
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.cpp | 15 | ||||
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.h | 2 |
3 files changed, 13 insertions, 9 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 682fb7e6638..e005396c3cf 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -669,7 +669,7 @@ void SmartAI::PassengerBoarded(Unit* who, int8 seatId, bool apply) GetScript()->ProcessEventsFor(apply ? SMART_EVENT_PASSENGER_BOARDED : SMART_EVENT_PASSENGER_REMOVED, who, uint32(seatId), 0, apply); } -void SmartAI::OnCharmed(bool /*isNew*/) +void SmartAI::OnCharmed(bool isNew) { bool const charmed = me->IsCharmed(); if (charmed) // do this before we change charmed state, as charmed state might prevent these things from processing @@ -703,6 +703,9 @@ void SmartAI::OnCharmed(bool /*isNew*/) } GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, nullptr, 0, 0, charmed); + + if (!GetScript()->HasAnyEventWithFlag(SMART_EVENT_FLAG_WHILE_CHARMED)) // we can change AI if there are no events with this flag + UnitAI::OnCharmed(isNew); } void SmartAI::DoAction(int32 param) diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 8c876614735..92028be94dd 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -60,6 +60,7 @@ SmartScript::SmartScript() mCurrentPriority = 0; mEventSortingRequired = false; mNestedEventsCounter = 0; + mAllEventFlags = 0; } SmartScript::~SmartScript() @@ -3836,15 +3837,13 @@ void SmartScript::FillScript(SmartAIEventList e, WorldObject* obj, AreaTriggerEn if (scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_ALL)//if has instance flag add only if in it { - if (obj && obj->GetMap()->IsDungeon()) - { - if ((1 << (obj->GetMap()->GetSpawnMode()+1)) & scriptholder.event.event_flags) - { - mEvents.push_back(scriptholder); - } - } - continue; + if (!(obj && obj->GetMap()->IsDungeon())) + continue; + + if (!(1 << (obj->GetMap()->GetSpawnMode() + 1) & scriptholder.event.event_flags)) + continue; } + mAllEventFlags |= scriptholder.event.event_flags; mEvents.push_back(scriptholder);//NOTE: 'world(0)' events still get processed in ANY instance mode } } diff --git a/src/server/game/AI/SmartScripts/SmartScript.h b/src/server/game/AI/SmartScripts/SmartScript.h index a2237ff2562..c3099f57e8c 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.h +++ b/src/server/game/AI/SmartScripts/SmartScript.h @@ -56,6 +56,7 @@ class TC_GAME_API SmartScript uint32 GetPathId() const { return mPathId; } WorldObject* GetBaseObject() const; WorldObject* GetBaseObjectOrPlayerTrigger() const; + bool HasAnyEventWithFlag(uint32 flag) const { return mAllEventFlags & flag; } static bool IsUnit(WorldObject* obj); static bool IsPlayer(WorldObject* obj); static bool IsCreature(WorldObject* obj); @@ -130,6 +131,7 @@ class TC_GAME_API SmartScript uint32 mCurrentPriority; bool mEventSortingRequired; uint32 mNestedEventsCounter; + uint32 mAllEventFlags; // Max number of nested ProcessEventsFor() calls to avoid infinite loops static constexpr uint32 MAX_NESTED_EVENTS = 10; |