feat(Core/SmartAI): Implement AoE variants of VICTIM_CASTING and RANGE events (#16720)

* init

* areaRange

* Update SmartScript.cpp

* error checks

* update SAI for area range

* areaCasting

* more

* Update rev_1689199652093827600.sql

* typo

* dont interrupt totems

* Update SmartScriptMgr.cpp

* target type needs to be 7

* Update rev_1689199652093827600.sql
This commit is contained in:
Gultask
2023-07-30 05:17:48 -03:00
committed by GitHub
parent c590b6ce81
commit 52aa18f8bd
4 changed files with 523 additions and 22 deletions

View File

@@ -2875,6 +2875,18 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
break;
}
case SMART_ACTION_PLAY_SPELL_VISUAL:
{
for (WorldObject* target : targets)
{
if (IsUnit(target))
{
if (e.action.spellVisual.visualId)
target->ToUnit()->SendPlaySpellVisual(e.action.spellVisual.visualId);
}
}
break;
}
default:
LOG_ERROR("sql.sql", "SmartScript::ProcessAction: Entry {} SourceType {}, Event {}, Unhandled Action type {}", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
break;
@@ -3679,7 +3691,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
ProcessTimedAction(e, e.event.rangeRepeat.repeatMin, e.event.rangeRepeat.repeatMax, me->GetVictim());
}
else
RecalcTimer(e, 500, 500); // make it predictable
RecalcTimer(e, 1200, 1200); // make it predictable
break;
}
@@ -4240,7 +4252,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
playerCount++;
}
if (playerCount <= e.event.nearPlayerNegation.maxCount)
if (playerCount < e.event.nearPlayerNegation.maxCount)
ProcessAction(e, unit);
}
RecalcTimer(e, e.event.nearPlayerNegation.repeatMin, e.event.nearPlayerNegation.repeatMax);
@@ -4277,6 +4289,37 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
RecalcTimer(e, e.event.nearUnit.timer, e.event.nearUnit.timer);
break;
}
case SMART_EVENT_NEAR_UNIT_NEGATION:
{
uint32 unitCount = 0;
ObjectVector targets;
GetWorldObjectsInDist(targets, static_cast<float>(e.event.nearUnitNegation.range));
if (!targets.empty())
{
if (e.event.nearUnitNegation.type)
{
for (WorldObject* target : targets)
{
if (IsGameObject(target) && target->GetEntry() == e.event.nearUnitNegation.entry)
unitCount++;
}
}
else
{
for (WorldObject* target : targets)
{
if (IsCreature(target) && target->GetEntry() == e.event.nearUnitNegation.entry)
unitCount++;
}
}
if (unitCount < e.event.nearUnitNegation.count)
ProcessAction(e, unit);
}
RecalcTimer(e, e.event.nearUnitNegation.timer, e.event.nearUnitNegation.timer);
break;
}
case SMART_EVENT_AREA_CASTING:
{
if (!me || !me->IsEngaged())
@@ -4288,25 +4331,45 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
{
if (Unit* target = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()))
{
if (!target || target->IsPet() || target->IsTotem() || !target->IsNonMeleeSpellCast(false, false, true))
continue;
if (e.event.areaCasting.range && !me->IsWithinDistInMap(target, range))
continue;
if (!target || !target->IsNonMeleeSpellCast(false, false, true))
ProcessAction(e, target);
RecalcTimer(e, e.event.areaCasting.repeatMin, e.event.areaCasting.repeatMax);
return;
}
// If no targets are found and it's off cooldown, check again in 1200ms
RecalcTimer(e, 1200, 1200);
break;
}
break;
}
case SMART_EVENT_AREA_RANGE:
{
if (!me || !me->IsEngaged())
return;
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 (!(me->IsInRange(target, 0.f, (float)e.event.areaRange.range)))
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);
RecalcTimer(e, e.event.areaRange.repeatMin, e.event.areaRange.repeatMax);
return;
}
}
// If no targets are found and it's off cooldown, check again
RecalcTimer(e, e.event.areaCasting.checkTimer, e.event.areaCasting.checkTimer);
RecalcTimer(e, 1200, 1200);
break;
}
default:
@@ -4325,7 +4388,10 @@ void SmartScript::InitTimer(SmartScriptHolder& e)
if (e.event.rangeRepeat.onlyFireOnRepeat == 1)
e.event.rangeRepeat.onlyFireOnRepeat = 2;
// make it predictable
RecalcTimer(e, 500, 500);
RecalcTimer(e, 1200, 1200);
break;
case SMART_EVENT_AREA_RANGE:
RecalcTimer(e, e.event.areaRange.min, e.event.areaRange.max);
break;
case SMART_EVENT_NEAR_PLAYERS:
case SMART_EVENT_NEAR_PLAYERS_NEGATION:
@@ -4346,10 +4412,11 @@ void SmartScript::InitTimer(SmartScriptHolder& e)
RecalcTimer(e, e.event.distance.repeat, e.event.distance.repeat);
break;
case SMART_EVENT_NEAR_UNIT:
case SMART_EVENT_NEAR_UNIT_NEGATION:
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);
RecalcTimer(e, e.event.areaCasting.min, e.event.areaCasting.max);
break;
default:
e.active = true;
@@ -4405,6 +4472,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_NEAR_UNIT_NEGATION:
case SMART_EVENT_UPDATE:
case SMART_EVENT_UPDATE_OOC:
case SMART_EVENT_UPDATE_IC:
@@ -4413,6 +4481,7 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff)
case SMART_EVENT_MANA_PCT:
case SMART_EVENT_TARGET_MANA_PCT:
case SMART_EVENT_RANGE:
case SMART_EVENT_AREA_RANGE:
case SMART_EVENT_VICTIM_CASTING:
case SMART_EVENT_AREA_CASTING:
case SMART_EVENT_FRIENDLY_HEALTH:

View File

@@ -275,6 +275,10 @@ void SmartAIMgr::LoadSmartAIFromDB()
if (temp.event.rangeRepeat.onlyFireOnRepeat > 1)
temp.event.rangeRepeat.onlyFireOnRepeat = 1;
break;
case SMART_EVENT_AREA_RANGE:
if (temp.event.areaRange.repeatMin == 0 && temp.event.areaRange.repeatMax == 0)
temp.event.event_flags |= SMART_EVENT_FLAG_NOT_REPEATABLE;
break;
case SMART_EVENT_VICTIM_CASTING:
case SMART_EVENT_IS_BEHIND_TARGET:
if (temp.event.minMaxRepeat.min == 0 && temp.event.minMaxRepeat.max == 0)
@@ -349,6 +353,7 @@ void SmartAIMgr::LoadSmartAIFromDB()
case SMART_EVENT_TARGET_HEALTH_PCT:
case SMART_EVENT_TARGET_MANA_PCT:
case SMART_EVENT_RANGE:
case SMART_EVENT_AREA_RANGE:
case SMART_EVENT_VICTIM_CASTING:
case SMART_EVENT_AREA_CASTING:
case SMART_EVENT_TARGET_BUFFED:
@@ -579,7 +584,9 @@ bool SmartAIMgr::CheckUnusedEventParams(SmartScriptHolder const& e)
case SMART_EVENT_NEAR_PLAYERS: return sizeof(SmartEvent::nearPlayer);
case SMART_EVENT_NEAR_PLAYERS_NEGATION: return sizeof(SmartEvent::nearPlayerNegation);
case SMART_EVENT_NEAR_UNIT: return sizeof(SmartEvent::nearUnit);
case SMART_EVENT_NEAR_UNIT_NEGATION: return sizeof(SmartEvent::nearUnitNegation);
case SMART_EVENT_AREA_CASTING: return sizeof(SmartEvent::areaCasting);
case SMART_EVENT_AREA_RANGE: return sizeof(SmartEvent::areaRange);
default:
LOG_WARN("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} is using an event {} with no unused params specified in SmartAIMgr::CheckUnusedEventParams(), please report this.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetEventType());
@@ -773,6 +780,7 @@ bool SmartAIMgr::CheckUnusedActionParams(SmartScriptHolder const& e)
case SMART_ACTION_DISABLE: return sizeof(SmartAction::disable);
case SMART_ACTION_SET_SCALE: return sizeof(SmartAction::setScale);
case SMART_ACTION_SUMMON_RADIAL: return sizeof(SmartAction::radialSummon);
case SMART_ACTION_PLAY_SPELL_VISUAL: return sizeof(SmartAction::spellVisual);
default:
LOG_WARN("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} is using an action with no unused params specified in SmartAIMgr::CheckUnusedActionParams(), please report this.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
@@ -962,6 +970,14 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
if (!IsMinMaxValid(e, e.event.rangeRepeat.repeatMin, e.event.rangeRepeat.repeatMax))
return false;
break;
case SMART_EVENT_AREA_RANGE:
if (!IsMinMaxValid(e, e.event.areaRange.min, e.event.areaRange.max))
return false;
if (!IsMinMaxValid(e, e.event.areaRange.repeatMin, e.event.areaRange.repeatMax))
return false;
break;
case SMART_EVENT_SPELLHIT:
case SMART_EVENT_SPELLHIT_TARGET:
if (e.event.spellHit.spell)
@@ -1052,11 +1068,8 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
return false;
break;
case SMART_EVENT_AREA_CASTING:
if (e.event.areaCasting.spellId > 0 && !sSpellMgr->GetSpellInfo(e.event.areaCasting.spellId))
{
LOG_ERROR("scripts.ai.sai", "SmartAIMgr: Entry {} SourceType {} Event {} Action {} uses non-existent Spell entry {}, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.event.spellHit.spell);
if (!IsMinMaxValid(e, e.event.areaCasting.min, e.event.areaCasting.max))
return false;
}
if (!IsMinMaxValid(e, e.event.areaCasting.repeatMin, e.event.areaCasting.repeatMax))
return false;
@@ -1297,6 +1310,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
case SMART_EVENT_GO_STATE_CHANGED:
case SMART_EVENT_GO_EVENT_INFORM:
case SMART_EVENT_NEAR_UNIT:
case SMART_EVENT_NEAR_UNIT_NEGATION:
case SMART_EVENT_TIMED_EVENT_TRIGGERED:
case SMART_EVENT_INSTANCE_PLAYER_ENTER:
case SMART_EVENT_TRANSPORT_RELOCATE:
@@ -1949,6 +1963,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
case SMART_ACTION_DISABLE:
case SMART_ACTION_SET_SCALE:
case SMART_ACTION_SUMMON_RADIAL:
case SMART_ACTION_PLAY_SPELL_VISUAL:
break;
default:
LOG_ERROR("sql.sql", "SmartAIMgr: Not handled action_type({}), event_type({}), Entry {} SourceType {} Event {}, skipped.", e.GetActionType(), e.GetEventType(), e.entryOrGuid, e.GetScriptType(), e.event_id);

View File

@@ -209,9 +209,11 @@ enum SMART_EVENT
SMART_EVENT_NEAR_PLAYERS = 101, // min, radius, first timer, repeatMin, repeatMax
SMART_EVENT_NEAR_PLAYERS_NEGATION = 102, // max, radius, first timer, repeatMin, repeatMax
SMART_EVENT_NEAR_UNIT = 103, // type (0: creature 1: gob), entry, count, range, timer
SMART_EVENT_AREA_CASTING = 104, // spellId (0: any), range (0: any), repeatMin, repeatMax, checkTimer
SMART_EVENT_NEAR_UNIT_NEGATION = 104, // type (0: creature 1: gob), entry, count, range, timer
SMART_EVENT_AREA_CASTING = 105, // min, max, repeatMin, repeatMax, range
SMART_EVENT_AREA_RANGE = 106, // min, max, repeatMin, repeatMax, range
SMART_EVENT_AC_END = 105
SMART_EVENT_AC_END = 107
};
struct SmartEvent
@@ -508,13 +510,31 @@ struct SmartEvent
struct
{
uint32 spellId;
uint32 type;
uint32 entry;
uint32 count;
uint32 range;
uint32 timer;
} nearUnitNegation;
struct
{
uint32 min;
uint32 max;
uint32 repeatMin;
uint32 repeatMax;
uint32 checkTimer;
uint32 range;
} areaCasting;
struct
{
uint32 min;
uint32 max;
uint32 repeatMin;
uint32 repeatMax;
uint32 range;
} areaRange;
struct
{
uint32 param1;
@@ -718,8 +738,9 @@ enum SMART_ACTION
SMART_ACTION_DISABLE = 226, // state
SMART_ACTION_SET_SCALE = 227, // scale
SMART_ACTION_SUMMON_RADIAL = 228, // summonEntry, summonDuration, repetitions, startAngle, stepAngle, dist
SMART_ACTION_PLAY_SPELL_VISUAL = 229, // visualId, visualIdImpact
SMART_ACTION_AC_END = 229, // placeholder
SMART_ACTION_AC_END = 230, // placeholder
};
enum class SmartActionSummonCreatureFlags
@@ -1416,6 +1437,11 @@ struct SmartAction
uint32 stepAngle;
uint32 dist;
} radialSummon;
struct
{
uint32 visualId;
} spellVisual;
//! Note for any new future actions
//! All parameters must have type uint32
@@ -1820,7 +1846,9 @@ const uint32 SmartAIEventMask[SMART_EVENT_AC_END][2] =
{SMART_EVENT_NEAR_PLAYERS, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
{SMART_EVENT_NEAR_PLAYERS_NEGATION, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
{SMART_EVENT_NEAR_UNIT, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
{SMART_EVENT_AREA_CASTING, SMART_SCRIPT_TYPE_MASK_CREATURE }
{SMART_EVENT_NEAR_UNIT_NEGATION, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
{SMART_EVENT_AREA_CASTING, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_AREA_RANGE, SMART_SCRIPT_TYPE_MASK_CREATURE }
};
enum SmartEventFlags