mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 10:05:32 +01:00
Core/SmartAI: AI change on charmed (#26065)
* Fix AI refresh on charmed
* Remove unnecessary refresh
* Check SMART_EVENT_FLAG_WHILE_CHARMED flag
(cherry picked from commit f6e52f6b3d)
This commit is contained in:
@@ -671,7 +671,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
|
||||
@@ -705,6 +705,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)
|
||||
|
||||
@@ -62,6 +62,7 @@ SmartScript::SmartScript()
|
||||
mCurrentPriority = 0;
|
||||
mEventSortingRequired = false;
|
||||
mNestedEventsCounter = 0;
|
||||
mAllEventFlags = 0;
|
||||
}
|
||||
|
||||
SmartScript::~SmartScript()
|
||||
@@ -4133,35 +4134,35 @@ 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 (!(obj && 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_10_N:
|
||||
if (scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_0)
|
||||
mEvents.emplace_back(std::move(scriptholder));
|
||||
break;
|
||||
case DIFFICULTY_HEROIC:
|
||||
case DIFFICULTY_25_N:
|
||||
if (scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_1)
|
||||
mEvents.emplace_back(std::move(scriptholder));
|
||||
break;
|
||||
case DIFFICULTY_10_HC:
|
||||
if (scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_2)
|
||||
mEvents.emplace_back(std::move(scriptholder));
|
||||
break;
|
||||
case DIFFICULTY_25_HC:
|
||||
if (scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_3)
|
||||
mEvents.emplace_back(std::move(scriptholder));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case DIFFICULTY_NORMAL:
|
||||
case DIFFICULTY_10_N:
|
||||
if (!(scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_0))
|
||||
continue;
|
||||
break;
|
||||
case DIFFICULTY_HEROIC:
|
||||
case DIFFICULTY_25_N:
|
||||
if (!(scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_1))
|
||||
continue;
|
||||
break;
|
||||
case DIFFICULTY_10_HC:
|
||||
if (!(scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_2))
|
||||
continue;
|
||||
break;
|
||||
case DIFFICULTY_25_HC:
|
||||
if (!(scriptholder.event.event_flags & SMART_EVENT_FLAG_DIFFICULTY_3))
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
mAllEventFlags |= scriptholder.event.event_flags;
|
||||
mEvents.push_back(scriptholder);//NOTE: 'world(0)' events still get processed in ANY instance mode
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ class TC_GAME_API SmartScript
|
||||
WorldObject* GetBaseObject() const;
|
||||
WorldObject* GetBaseObjectOrUnit(Unit* unit);
|
||||
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);
|
||||
@@ -138,6 +139,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;
|
||||
|
||||
Reference in New Issue
Block a user