feat(Core/SmartAI): Add more smart events (#16642)

* init

* :)

* Update rev_1687966694240866600.sql

* >:)

change name from unit -> target
fix typo

Co-Authored-By: Angelo Venturini <nefertum.dev@protonmail.com>

* Update data/sql/updates/pending_db_world/rev_1687966694240866600.sql

Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com>

* more_events

* Update SmartScriptMgr.cpp

---------

Co-authored-by: Angelo Venturini <nefertum.dev@protonmail.com>
Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com>
This commit is contained in:
Gultask
2023-07-02 03:57:56 -03:00
committed by GitHub
parent d0fa5f04ef
commit 54f8386d99
4 changed files with 148 additions and 23 deletions

View File

@@ -4208,34 +4208,105 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
break;
case SMART_EVENT_NEAR_PLAYERS:
{
ObjectVector units;
GetWorldObjectsInDist(units, static_cast<float>(e.event.nearPlayer.radius));
uint32 playerCount = 0;
ObjectVector targets;
GetWorldObjectsInDist(targets, static_cast<float>(e.event.nearPlayer.radius));
if (!units.empty())
if (!targets.empty())
{
if (!unit || unit->GetTypeId() != TYPEID_PLAYER)
return;
for (WorldObject* target : targets)
{
if (IsPlayer(target))
playerCount++;
if (units.size() >= e.event.nearPlayer.minCount)
ProcessAction(e, unit);
if (playerCount >= e.event.nearPlayer.minCount)
ProcessAction(e, target->ToUnit());
}
}
RecalcTimer(e, e.event.nearPlayer.checkTimer, e.event.nearPlayer.checkTimer);
RecalcTimer(e, e.event.nearPlayer.repeatMin, e.event.nearPlayer.repeatMax);
break;
}
case SMART_EVENT_NEAR_PLAYERS_NEGATION:
{
ObjectVector units;
GetWorldObjectsInDist(units, static_cast<float>(e.event.nearPlayerNegation.radius));
uint32 playerCount = 0;
ObjectVector targets;
GetWorldObjectsInDist(targets, static_cast<float>(e.event.nearPlayerNegation.radius));
if (!units.empty())
if (!targets.empty())
{
if (!unit || unit->GetTypeId() != TYPEID_PLAYER)
return;
for (WorldObject* target : targets)
{
if (IsPlayer(target))
playerCount++;
}
if (units.size() < e.event.nearPlayerNegation.minCount)
if (playerCount <= e.event.nearPlayerNegation.maxCount)
ProcessAction(e, unit);
}
RecalcTimer(e, e.event.nearPlayerNegation.checkTimer, e.event.nearPlayerNegation.checkTimer);
RecalcTimer(e, e.event.nearPlayerNegation.repeatMin, e.event.nearPlayerNegation.repeatMax);
break;
}
case SMART_EVENT_NEAR_UNIT:
{
uint32 unitCount = 0;
ObjectVector targets;
GetWorldObjectsInDist(targets, static_cast<float>(e.event.nearUnit.range));
if (!targets.empty())
{
if (e.event.nearUnit.type)
{
for (WorldObject* target : targets)
{
if (IsGameObject(target) && target->GetEntry() == e.event.nearUnit.entry)
unitCount++;
}
}
else
{
for (WorldObject* target : targets)
{
if (IsCreature(target) && target->GetEntry() == e.event.nearUnit.entry)
unitCount++;
}
}
if (unitCount >= e.event.nearUnit.count)
ProcessAction(e, unit);
}
RecalcTimer(e, e.event.nearUnit.timer, e.event.nearUnit.timer);
break;
}
case SMART_EVENT_AREA_CASTING:
{
if (!me || !me->IsEngaged())
return;
float range = static_cast<float>(e.event.areaCasting.range);
ThreatContainer::StorageType threatList = me->GetThreatMgr().GetThreatList();
for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
{
if (Unit* target = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()))
{
if (e.event.areaCasting.range && !me->IsWithinDistInMap(target, range))
continue;
if (!target || !target->IsNonMeleeSpellCast(false, false, true))
continue;
if (e.event.areaCasting.spellId > 0)
if (Spell* currSpell = target->GetCurrentSpell(CURRENT_GENERIC_SPELL))
if (currSpell->m_spellInfo->Id != e.event.areaCasting.spellId)
continue;
ProcessAction(e, target);
RecalcTimer(e, e.event.areaCasting.repeatMin, e.event.areaCasting.repeatMin);
return;
}
}
// If no targets are found and it's off cooldown, check again
RecalcTimer(e, e.event.areaCasting.checkTimer, e.event.areaCasting.checkTimer);
break;
}
default:
@@ -4274,6 +4345,12 @@ void SmartScript::InitTimer(SmartScriptHolder& e)
case SMART_EVENT_DISTANCE_GAMEOBJECT:
RecalcTimer(e, e.event.distance.repeat, e.event.distance.repeat);
break;
case SMART_EVENT_NEAR_UNIT:
RecalcTimer(e, e.event.nearUnit.timer, e.event.nearUnit.timer);
break;
case SMART_EVENT_AREA_CASTING:
RecalcTimer(e, e.event.areaCasting.repeatMin, e.event.areaCasting.repeatMax);
break;
default:
e.active = true;
break;
@@ -4327,6 +4404,7 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff)
{
case SMART_EVENT_NEAR_PLAYERS:
case SMART_EVENT_NEAR_PLAYERS_NEGATION:
case SMART_EVENT_NEAR_UNIT:
case SMART_EVENT_UPDATE:
case SMART_EVENT_UPDATE_OOC:
case SMART_EVENT_UPDATE_IC:
@@ -4336,6 +4414,7 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff)
case SMART_EVENT_TARGET_MANA_PCT:
case SMART_EVENT_RANGE:
case SMART_EVENT_VICTIM_CASTING:
case SMART_EVENT_AREA_CASTING:
case SMART_EVENT_FRIENDLY_HEALTH:
case SMART_EVENT_FRIENDLY_IS_CC:
case SMART_EVENT_FRIENDLY_MISSING_BUFF: