feat(Core/AI): CU_SAI - Custom Event Options (#2881)

This commit is contained in:
P-Kito
2020-04-17 00:40:06 +02:00
committed by GitHub
parent 8aa80eef18
commit 6a410efa36
3 changed files with 90 additions and 5 deletions

View File

@@ -4300,6 +4300,34 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
ProcessTimedAction(e, e.event.counter.cooldownMin, e.event.counter.cooldownMax);
break;
case SMART_EVENT_NEAR_PLAYERS:
{
float range = (float)e.event.nearPlayer.radius;
ObjectList* units = GetWorldObjectsInDist(range);
if (!units->empty())
{
units->remove_if([](WorldObject* unit) { return unit->GetTypeId() != TYPEID_PLAYER; });
if (units->size() >= e.event.nearPlayer.minCount)
ProcessAction(e, unit);
}
RecalcTimer(e, e.event.nearPlayer.checkTimer, e.event.nearPlayer.checkTimer);
break;
}
case SMART_EVENT_NEAR_PLAYERS_NEGATION:
{
float range = (float)e.event.nearPlayerNegation.radius;
ObjectList* units = GetWorldObjectsInDist(range);
if (!units->empty())
{
units->remove_if([](WorldObject* unit) { return unit->GetTypeId() != TYPEID_PLAYER; });
if (units->size() < e.event.nearPlayerNegation.minCount)
ProcessAction(e, unit);
}
RecalcTimer(e, e.event.nearPlayerNegation.checkTimer, e.event.nearPlayerNegation.checkTimer);
break;
}
default:
sLog->outErrorDb("SmartScript::ProcessEvent: Unhandled Event type %u", e.GetEventType());
break;
@@ -4310,7 +4338,11 @@ void SmartScript::InitTimer(SmartScriptHolder& e)
{
switch (e.GetEventType())
{
//set only events which have initial timers
//set only events which have initial timers
case SMART_EVENT_NEAR_PLAYERS:
case SMART_EVENT_NEAR_PLAYERS_NEGATION:
RecalcTimer(e, e.event.nearPlayer.firstTimer, e.event.nearPlayer.firstTimer);
break;
case SMART_EVENT_UPDATE:
case SMART_EVENT_UPDATE_IC:
case SMART_EVENT_UPDATE_OOC:
@@ -4369,6 +4401,8 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff)
e.active = true;//activate events with cooldown
switch (e.GetEventType())//process ONLY timed events
{
case SMART_EVENT_NEAR_PLAYERS:
case SMART_EVENT_NEAR_PLAYERS_NEGATION:
case SMART_EVENT_UPDATE:
case SMART_EVENT_UPDATE_OOC:
case SMART_EVENT_UPDATE_IC: