refactor(Core/ScriptedAI): few improvements with threat methods (#13146)

improve threat scripts

Co-authored-by: Maelthyrr <lynethris@protonmail.ch>
This commit is contained in:
Maelthyr
2022-11-12 13:29:28 +01:00
committed by GitHub
parent 758ed35db3
commit c1c9dc6105
50 changed files with 100 additions and 73 deletions

View File

@@ -115,7 +115,7 @@ public:
case EVENT_KNOCKBACK:
DoCastVictim(SPELL_KNOCKBACK);
if (DoGetThreat(me->GetVictim()))
DoModifyThreatPercent(me->GetVictim(), -50);
DoModifyThreatByPercent(me->GetVictim(), -50);
events.ScheduleEvent(EVENT_KNOCKBACK, 15000, 30000);
break;
case EVENT_CHECK:

View File

@@ -72,7 +72,7 @@ public:
case EVENT_WINGBUFFET:
DoCastVictim(SPELL_WINGBUFFET);
if (DoGetThreat(me->GetVictim()))
DoModifyThreatPercent(me->GetVictim(), -75);
DoModifyThreatByPercent(me->GetVictim(), -75);
events.ScheduleEvent(EVENT_WINGBUFFET, 30000);
break;
case EVENT_FLAMEBUFFET:

View File

@@ -77,7 +77,7 @@ public:
case EVENT_WINGBUFFET:
DoCastVictim(SPELL_WINGBUFFET);
if (DoGetThreat(me->GetVictim()))
DoModifyThreatPercent(me->GetVictim(), -75);
DoModifyThreatByPercent(me->GetVictim(), -75);
events.ScheduleEvent(EVENT_WINGBUFFET, 30000);
break;
case EVENT_FRENZY:

View File

@@ -411,7 +411,7 @@ public:
me->SetReactState(REACT_PASSIVE);
me->InterruptNonMeleeSpells(false);
me->AttackStop();
DoResetThreat();
DoResetThreatList();
me->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NON_ATTACKABLE);
me->SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_STATE_SUBMERGED);
DoCastSelf(SPELL_RAGNA_SUBMERGE_VISUAL, true);

View File

@@ -496,7 +496,7 @@ public:
{
if (me->GetVictim())
{
DoModifyThreatPercent(me->GetVictim(), -100);
DoModifyThreatByPercent(me->GetVictim(), -100);
}
me->AddThreat(target, 1000000.0f);

View File

@@ -915,7 +915,7 @@ public:
DoCast(target, SPELL_LITTLE_RED_RIDING_HOOD, true);
TempThreat = DoGetThreat(target);
if (TempThreat)
DoModifyThreatPercent(target, -100);
DoModifyThreatByPercent(target, -100);
HoodGUID = target->GetGUID();
me->AddThreat(target, 1000000.0f);
ChaseTimer = 20000;
@@ -930,7 +930,7 @@ public:
{
HoodGUID.Clear();
if (DoGetThreat(target))
DoModifyThreatPercent(target, -100);
DoModifyThreatByPercent(target, -100);
me->AddThreat(target, TempThreat);
TempThreat = 0;
}

View File

@@ -462,7 +462,7 @@ public:
{
case EVENT_SPELL_VANISH:
me->CastSpell(me, SPELL_VANISH, false);
DoResetThreat();
DoResetThreatList();
if (Unit* unit = SelectTarget(SelectTargetMethod::Random, 0))
me->AddThreat(unit, 1000.0f);

View File

@@ -313,7 +313,7 @@ public:
case 3:
case 4:
me->NearTeleportTo(CENTER_X, CENTER_Y, CENTER_Z, me->GetOrientation());
DoResetThreat();
DoResetThreatList();
me->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, 0);
me->RemoveAurasDueToSpell(Transform[Phase].unaura);
DoCast(me, Transform[Phase].spell);

View File

@@ -232,7 +232,7 @@ public:
me->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 0, uint32(EQUIP_UNEQUIP));
me->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 1, uint32(EQUIP_UNEQUIP));
me->AttackStop();
DoResetThreat();
DoResetThreatList();
me->SetReactState(REACT_PASSIVE);
me->SetUnitFlag(UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE);
DoCastSelf(SPELL_VANISH_VISUAL);

View File

@@ -91,7 +91,7 @@ public:
}
DoCast(me, SPELL_AVATAR);
me->SetReactState(REACT_PASSIVE);
DoResetThreat();
DoResetThreatList();
events.ScheduleEvent(EVENT_START_PURSUIT, 2s);
events.ScheduleEvent(EVENT_STOP_PURSUIT, 15s);
events.ScheduleEvent(EVENT_AVATAR, 45s, 50s);

View File

@@ -164,7 +164,7 @@ struct boss_jeklik : public BossAI
if (events.IsInPhase(PHASE_ONE) && !HealthAbovePct(50))
{
me->RemoveAurasDueToSpell(SPELL_BAT_FORM);
DoResetThreat();
DoResetThreatList();
events.SetPhase(PHASE_TWO);
events.CancelEventGroup(PHASE_ONE);

View File

@@ -163,7 +163,7 @@ public:
me->SetReactState(REACT_PASSIVE);
me->SetStandState(UNIT_STAND_STATE_SLEEP);
me->AttackStop();
DoResetThreat();
DoResetThreatList();
WasDead = true;
CheckPhaseTransition();
Talk(EMOTE_THEKAL_DIES);
@@ -245,7 +245,7 @@ public:
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0))
{
DoCast(target, SPELL_CHARGE);
DoResetThreat();
DoResetThreatList();
AttackStart(target);
}
context.Repeat(15s, 22s);
@@ -407,7 +407,7 @@ public:
if (DoGetThreat(me->GetVictim()))
{
DoModifyThreatPercent(me->GetVictim(), -100);
DoModifyThreatByPercent(me->GetVictim(), -100);
}
context.Repeat(17s, 27s);

View File

@@ -252,7 +252,7 @@ public:
// shapeshift at 50% health
DoCast(me, SPELL_VENOXIS_TRANSFORM);
Talk(SAY_VENOXIS_TRANSFORM);
DoResetThreat();
DoResetThreatList();
// phase two events (snakeform)
events.ScheduleEvent(EVENT_VENOM_SPIT, 5000, 0, PHASE_TWO);

View File

@@ -354,7 +354,7 @@ public:
me->AttackStop();
me->SetReactState(REACT_PASSIVE);
me->StopMoving();
DoResetThreat();
DoResetThreatList();
me->GetMotionMaster()->MovePoint(10, OnyxiaMoveData[0].x, OnyxiaMoveData[0].y, OnyxiaMoveData[0].z);
break;
}
@@ -404,7 +404,7 @@ public:
Talk(SAY_PHASE_3_TRANS);
me->SendMeleeAttackStop(me->GetVictim());
me->GetMotionMaster()->MoveLand(13, OnyxiaMoveData[0].x + 1.0f, OnyxiaMoveData[0].y, OnyxiaMoveData[0].z, 12.0f);
DoResetThreat();
DoResetThreatList();
break;
}
case EVENT_SPELL_FIREBALL_FIRST:

View File

@@ -221,7 +221,7 @@ struct boss_ayamiss : public BossAI
me->SetCanFly(false);
me->SetDisableGravity(false);
me->GetMotionMaster()->MovePath(me->GetEntry() * 10, false);
DoResetThreat();
DoResetThreatList();
_scheduler.CancelGroup(PHASE_AIR);
}

View File

@@ -120,7 +120,7 @@ struct boss_buru : public BossAI
events.ScheduleEvent(EVENT_GATHERING_SPEED, 2s);
if (Unit* victim = SelectTarget(SelectTargetMethod::Random, 0, 0.f, true))
{
DoResetThreat();
DoResetThreatList();
AttackStart(victim);
me->AddThreat(victim, 1000000.f);
Talk(EMOTE_TARGET, victim);
@@ -143,7 +143,7 @@ struct boss_buru : public BossAI
events.Reset();
_phase = PHASE_TRANSFORM;
instance->SetData(DATA_BURU_PHASE, _phase);
DoResetThreat();
DoResetThreatList();
events.ScheduleEvent(EVENT_CREEPING_PLAGUE, 2s);
DoCastSelf(SPELL_BURU_TRANSFORM);
}

View File

@@ -166,7 +166,7 @@ public:
me->SetSpeed(MOVE_RUN, 15.f/7.f); // From sniffs
DoCastSelf(SPELL_FULL_HEAL, true);
if (me->GetThreatMgr().GetThreatListSize())
DoResetThreat();
DoResetThreatList();
if (Creature* dying = instance->GetCreature(_creatureDying))
{
dying->AI()->DoAction(ACTION_EXPLODE);
@@ -419,7 +419,7 @@ struct boss_yauj : public boss_bug_trio
.Schedule(12s, [this](TaskContext context)
{
DoCastAOE(SPELL_FEAR);
DoResetThreat();
DoResetThreatList();
context.Repeat(20600ms);
})
.Schedule(11s, 14500ms, [this](TaskContext context)

View File

@@ -352,7 +352,7 @@ struct npc_dirt_mound : ScriptedAI
void ChaseNewTarget()
{
DoResetThreat();
DoResetThreatList();
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 200.f, true))
{
me->AddThreat(target, 1000000.f);

View File

@@ -178,7 +178,7 @@ struct boss_skeram : public BossAI
break;
case EVENT_BLINK:
DoCast(me, BlinkSpells[urand(0, 2)]);
DoResetThreat();
DoResetThreatList();
events.ScheduleEvent(EVENT_BLINK, 10s, 30s);
break;
case EVENT_EARTH_SHOCK:
@@ -196,7 +196,7 @@ struct boss_skeram : public BossAI
DoTeleport(image);
}
}
DoResetThreat();
DoResetThreatList();
events.RescheduleEvent(EVENT_BLINK, 10s, 30s);
break;
case EVENT_INIT_IMAGE:

View File

@@ -158,7 +158,7 @@ struct boss_twinemperorsAI : public BossAI
if (action == ACTION_AFTER_TELEPORT)
{
DoResetThreat();
DoResetThreatList();
me->SetReactState(REACT_PASSIVE);
DoCastSelf(SPELL_TWIN_TELEPORT_VISUAL, true);
_scheduler.DelayAll(2300ms);

View File

@@ -195,7 +195,7 @@ struct boss_viscidus : public BossAI
me->SetAuraStack(SPELL_VISCIDUS_SHRINKS, me, 20);
me->LowerPlayerDamageReq(me->GetMaxHealth());
me->SetHealth(me->GetMaxHealth() * 0.01f); // set 1% health
DoResetThreat();
DoResetThreatList();
me->NearTeleportTo(roomCenter.GetPositionX(),
roomCenter.GetPositionY(),
roomCenter.GetPositionZ(),

View File

@@ -429,7 +429,7 @@ public:
{
case SPELL_CLAW_N:
case SPELL_CLAW_H:
DoResetThreat();
DoResetThreatList();
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 30.0f))
{
me->AddThreat(target, 100.0f);

View File

@@ -927,7 +927,7 @@ public:
Player* player = itr->GetSource();
if( player && me->IsInRange(player, 8.0f, 25.0f, false) )
{
DoResetThreat();
DoResetThreatList();
me->AddThreat(player, 5.0f);
me->CastSpell(player, SPELL_INTERCEPT, false);
break;

View File

@@ -767,7 +767,7 @@ public:
me->RemoveAllAuras();
}
DoZoneInCombat();
DoResetThreat();
DoResetThreatList();
if( Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 250.0f, true) )
{
if (!next)

View File

@@ -336,7 +336,7 @@ public:
case EVENT_SPELL_FEL_STEAK:
if( Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 44.0f, true) )
{
DoResetThreat();
DoResetThreatList();
me->AddThreat(target, 50000.0f);
me->CastSpell(target, SPELL_FEL_STEAK_MORPH, true);
me->CastSpell(target, SPELL_FEL_STEAK, true);

View File

@@ -593,7 +593,7 @@ struct boss_jormungarAI : public ScriptedAI
}
me->UpdatePosition(Locs[LOC_CENTER].GetPositionX() + cos(angle)*dist, Locs[LOC_CENTER].GetPositionY() + std::sin(angle)*dist, me->GetPositionZ(), me->GetOrientation(), true);
me->StopMovingOnCurrentPos();
DoResetThreat();
DoResetThreatList();
events.RescheduleEvent(EVENT_EMERGE, 6000);
}

View File

@@ -971,7 +971,7 @@ public:
case EVENT_SHADOW_STEP:
if (Unit* target = SelectTargetFromPlayerList(100.0f, 0, true))
{
DoResetThreat();
DoResetThreatList();
me->AddThreat(target, 5000.0f);
AttackStart(target);
me->CastSpell(target, SPELL_SHADOW_STEP, false);

View File

@@ -305,7 +305,7 @@ public:
Unit* unit = ObjectAccessor::GetUnit((*me), (*itr)->getUnitGuid());
if (unit && DoGetThreat(unit))
DoModifyThreatPercent(unit, -100);
DoModifyThreatByPercent(unit, -100);
}
Talk(SAY_PHASE_2);

View File

@@ -383,7 +383,7 @@ public:
me->CastSpell(me, SPELL_WEAK_RADIATING_OOZE, true);
events.Reset();
events.ScheduleEvent(EVENT_STICKY_OOZE, 5000);
DoResetThreat();
DoResetThreatList();
me->SetInCombatWithZone();
if (TempSummon* ts = me->ToTempSummon())
if (Unit* summoner = ts->GetSummonerUnit())
@@ -468,7 +468,7 @@ public:
me->CastSpell(me, SPELL_GREEN_ABOMINATION_HITTIN__YA_PROC, true);
events.Reset();
events.ScheduleEvent(EVENT_STICKY_OOZE, 5000);
DoResetThreat();
DoResetThreatList();
me->SetInCombatWithZone();
if (Player* p = me->SelectNearestPlayer(100.0f))
AttackStart(p);

View File

@@ -1777,7 +1777,7 @@ public:
c->NearTeleportTo(myPos.GetPositionX(), myPos.GetPositionY(), myPos.GetPositionZ(), myPos.GetOrientation());
const ThreatContainer::StorageType me_tl = me->GetThreatMgr().GetThreatList();
const ThreatContainer::StorageType target_tl = c->GetThreatMgr().GetThreatList();
DoResetThreat();
DoResetThreatList();
for (ThreatContainer::StorageType::const_iterator iter = target_tl.begin(); iter != target_tl.end(); ++iter)
me->GetThreatMgr().AddThreat((*iter)->getTarget(), (*iter)->GetThreat());

View File

@@ -254,7 +254,7 @@ public:
StartBalconyPhase();
break;
case EVENT_BLINK:
DoResetThreat();
DoResetThreatList();
me->CastSpell(me, RAID_MODE(SPELL_CRIPPLE_10, SPELL_CRIPPLE_25), false);
me->CastSpell(me, SPELL_BLINK, true);
Talk(EMOTE_BLINK);

View File

@@ -835,7 +835,7 @@ public:
_flyTargetGUID.Clear();
me->RemoveAura(SPELL_LIGHTNING_TENDRILS);
me->RemoveAura(61883);
DoResetThreat();
DoResetThreatList();
break;
case EVENT_ENRAGE:
Talk(SAY_BRUNDIR_BERSERK);

View File

@@ -412,7 +412,7 @@ public:
if (_feralRushTimer >= 6000)
{
DoResetThreat();
DoResetThreatList();
if (!UpdateVictim())
return;

View File

@@ -1184,7 +1184,7 @@ public:
break;
case EVENT_DETONATING_LASHER_FLAME_LASH:
me->CastSpell(me->GetVictim(), SPELL_FLAME_LASH, false);
DoResetThreat();
DoResetThreatList();
if (Unit* target = SelectTargetFromPlayerList(80))
AttackStart(target);
else

View File

@@ -1033,7 +1033,7 @@ public:
break;
case 4:
me->SetReactState(REACT_AGGRESSIVE);
DoResetThreat();
DoResetThreatList();
Phase = 4;
me->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
if (Unit* target = SelectTargetFromPlayerList(75.0f))
@@ -1613,7 +1613,7 @@ public:
break;
case 4:
me->SetReactState(REACT_AGGRESSIVE);
DoResetThreat();
DoResetThreatList();
Phase = 4;
me->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
if (Unit* target = SelectTargetFromPlayerList(75.0f))

View File

@@ -518,7 +518,7 @@ public:
Talk(EMOTE_PERMA_GROUND);
me->SetControlled(false, UNIT_STATE_ROOT);
me->DisableRotate(false);
DoResetThreat();
DoResetThreatList();
Unit* target = SelectTarget(SelectTargetMethod::MaxDistance, 0, 0.0, true);
if (!target)
target = me->SelectNearestPlayer(200.0f);

View File

@@ -552,7 +552,7 @@ public:
summons.DoAction(ACTION_SIF_JOIN_FIGHT, pred);
}
DoResetThreat();
DoResetThreatList();
if (Player* player = GetArenaPlayer())
me->AddThreat(player, 1000.0f);
}

View File

@@ -1511,7 +1511,7 @@ public:
{
if (who && damagetype == DIRECT_DAMAGE)
{
DoResetThreat();
DoResetThreatList();
me->AddThreat(who, 100000);
AttackStart(who);
me->InterruptNonMeleeSpells(false);
@@ -1539,7 +1539,7 @@ public:
return;
me->CastSpell(me, SPELL_DIMINISH_POWER, false);
DoResetThreat();
DoResetThreatList();
}
};
};

View File

@@ -198,7 +198,7 @@ public:
case EVENT_SHARVALD_CHARGE:
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, (IsHeroic() ? 100.0f : 30.0f), true))
{
ScriptedAI::DoResetThreat();
DoResetThreatList();
me->AddThreat(target, 10000.0f);
me->CastSpell(target, SPELL_CHARGE, false);
}

View File

@@ -123,7 +123,7 @@ public:
break;
case EVENT_SPELL_ARCANE_VACUUM:
me->CastSpell((Unit*)nullptr, SPELL_ARCANE_VACUUM, false);
DoResetThreat();
DoResetThreatList();
me->SetControlled(true, UNIT_STATE_ROOT);
me->setAttackTimer(BASE_ATTACK, 3000);
events.RepeatEvent(30000);

View File

@@ -124,7 +124,7 @@ public:
me->CastSpell(target, SPELL_INCITE_CHAOS_B, true);
}
DoResetThreat();
DoResetThreatList();
InciteChaos = true;
events.DelayEvents(15000);
events.RepeatEvent(40000);

View File

@@ -247,7 +247,7 @@ public:
if (me->IsWithinMeleeRange(me->GetVictim()))
{
me->SetReactState(REACT_AGGRESSIVE);
DoResetThreat();
DoResetThreatList();
me->GetVictim()->InterruptNonMeleeSpells(false);
me->AddThreat(me->GetVictim(), 1000000.0f);
me->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE);

View File

@@ -80,7 +80,7 @@ public:
{
events.CancelEventGroup(EVENT_GROUP_ABILITIES);
events.ScheduleEvent(EVENT_SWITCH_PHASE, 60000);
DoResetThreat();
DoResetThreatList();
if (!run)
{
@@ -167,7 +167,7 @@ public:
case EVENT_SWITCH_TARGET:
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 100, true))
{
DoResetThreat();
DoResetThreatList();
me->AddThreat(target, 5000000.0f);
Talk(EMOTE_NEW_TARGET);
}

View File

@@ -553,7 +553,7 @@ public:
me->CastSpell(me, SPELL_VANISH_OUT, false);
break;
case EVENT_SPELL_ENRAGE:
DoResetThreat();
DoResetThreatList();
if (Creature* council = ObjectAccessor::GetCreature(*me, instance->GetGuidData(NPC_ILLIDARI_COUNCIL)))
council->GetAI()->DoAction(ACTION_ENRAGE);
break;

View File

@@ -120,7 +120,7 @@ public:
void SetForm(bool corrupt, bool initial)
{
events.CancelEventGroup(GROUP_ABILITIES);
DoResetThreat();
DoResetThreatList();
if (corrupt)
{

View File

@@ -203,7 +203,7 @@ public:
{
if (me->GetDisplayId() != me->GetNativeDisplayId())
{
DoResetThreat();
DoResetThreatList();
me->LoadEquipment();
me->RemoveAurasDueToSpell(SPELL_METAMORPHOSIS);
events.ScheduleEvent(EVENT_SPELL_WHIRLWIND, 10000);
@@ -223,7 +223,7 @@ public:
events.ScheduleEvent(EVENT_HEALTH_CHECK, 1000);
break;
case EVENT_SWITCH_TO_DEMON:
DoResetThreat();
DoResetThreatList();
Talk(SAY_SWITCH_TO_DEMON);
me->LoadEquipment(0, true);
me->GetMotionMaster()->MoveChase(me->GetVictim(), 25.0f);
@@ -234,7 +234,7 @@ public:
events.ScheduleEvent(EVENT_SWITCH_TO_ELF, 60000);
break;
case EVENT_SWITCH_TO_ELF:
DoResetThreat();
DoResetThreatList();
me->LoadEquipment();
me->GetMotionMaster()->MoveChase(me->GetVictim(), 0.0f);
me->RemoveAurasDueToSpell(SPELL_METAMORPHOSIS);

View File

@@ -201,7 +201,7 @@ public:
head->AI()->Talk(threatYell - 1);
events.ScheduleEvent(threatYell, 3000);
DoResetThreat();
DoResetThreatList();
me->AddThreat(target, 10.0f);
}
events.ScheduleEvent(EVENT_RESET_THREAT, 30000);

View File

@@ -480,7 +480,7 @@ public:
events2.CancelEvent(EVENT_PREFIGHT_PHASE71);
Talk(SAY_PHASE4_INTRO2);
phase = PHASE_FINAL;
DoResetThreat();
DoResetThreatList();
me->RemoveUnitFlag(UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_DISABLE_MOVE);
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0))
AttackStart(target);