Core/Entities: killed Creature::SetInCombatWithZone and replaced with AI version

Closes #12108 (again)

(cherry picked from commit 7c9722a4ae08b5f283f6a085a411e37604a7da9f)
This commit is contained in:
ariel-
2021-06-16 21:03:06 +02:00
committed by Shauren
parent 29bfa32fc3
commit c77925da4a
33 changed files with 60 additions and 95 deletions
@@ -1005,7 +1005,9 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
if (IsCreature(target))
{
target->ToCreature()->SetInCombatWithZone();
Creature* creature = target->ToCreature();
if (creature->IsAIEnabled)
creature->AI()->DoZoneInCombat();
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction: SMART_ACTION_SET_IN_COMBAT_WITH_ZONE: Creature %s, target: %s", me->GetGUID().ToString().c_str(), target->GetGUID().ToString().c_str());
}
}
@@ -2756,40 +2756,6 @@ void Creature::SendZoneUnderAttackMessage(Player* attacker)
sWorld->SendGlobalMessage(packet.Write(), nullptr, (enemy_team == ALLIANCE ? HORDE : ALLIANCE));
}
void Creature::SetInCombatWithZone()
{
if (!CanHaveThreatList())
{
TC_LOG_ERROR("entities.unit", "Creature entry %u call SetInCombatWithZone but creature cannot have threat list.", GetEntry());
return;
}
Map* map = GetMap();
if (!map->IsDungeon())
{
TC_LOG_ERROR("entities.unit", "Creature entry %u call SetInCombatWithZone for map (id: %u) that isn't an instance.", GetEntry(), map->GetId());
return;
}
Map::PlayerList const& PlList = map->GetPlayers();
if (PlList.isEmpty())
return;
for (Map::PlayerList::const_iterator i = PlList.begin(); i != PlList.end(); ++i)
{
if (Player* player = i->GetSource())
{
if (player->IsGameMaster())
continue;
if (player->IsAlive())
EngageWithTarget(player);
}
}
}
bool Creature::HasSpell(uint32 spellID) const
{
for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
@@ -275,8 +275,6 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
void SendZoneUnderAttackMessage(Player* attacker);
void SetInCombatWithZone();
bool hasQuest(uint32 quest_id) const override;
bool hasInvolvedQuest(uint32 quest_id) const override;
@@ -169,7 +169,7 @@ struct boss_coren_direbrew : public BossAI
events.SetPhase(PHASE_ONE);
me->SetImmuneToPC(false);
me->SetFaction(FACTION_GOBLIN_DARK_IRON_BAR_PATRON);
me->SetInCombatWithZone();
DoZoneInCombat();
EntryCheckPredicate pred(NPC_ANTAGONIST);
summons.DoAction(ACTION_ANTAGONIST_HOSTILE, pred);
@@ -217,7 +217,7 @@ struct boss_coren_direbrew : public BossAI
void SummonSister(uint32 entry)
{
if (Creature* sister = me->SummonCreature(entry, me->GetPosition(), TEMPSUMMON_DEAD_DESPAWN))
sister->SetInCombatWithZone();
DoZoneInCombat(sister);
}
void UpdateAI(uint32 diff) override
@@ -343,7 +343,7 @@ struct npc_direbrew_minion : public ScriptedAI
void Reset() override
{
me->SetFaction(FACTION_GOBLIN_DARK_IRON_BAR_PATRON);
me->SetInCombatWithZone();
DoZoneInCombat();
}
void IsSummonedBy(Unit* /*summoner*/) override
@@ -373,7 +373,7 @@ struct npc_direbrew_antagonist : public ScriptedAI
case ACTION_ANTAGONIST_HOSTILE:
me->SetImmuneToPC(false);
me->SetFaction(FACTION_GOBLIN_DARK_IRON_BAR_PATRON);
me->SetInCombatWithZone();
DoZoneInCombat();
break;
default:
break;
@@ -380,7 +380,7 @@ public:
for (std::list<Creature*>::iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr)
{
if (Creature* creature = *itr)
creature->SetInCombatWithZone(); // AI()->AttackStart(me->GetVictim());
DoZoneInCombat(creature); // AI()->AttackStart(me->GetVictim());
}
_events.ScheduleEvent(EVENT_STRIKE, urand(8000, 16000));
@@ -455,7 +455,7 @@ public:
if (id == 1)
{
me->SetInCombatWithZone();
DoZoneInCombat();
if (me->GetVictim())
AttackStart(me->GetVictim());
}
@@ -574,7 +574,7 @@ public:
if ((*itr) && !(*itr)->IsAlive())
{
(*itr)->Respawn();
(*itr)->SetInCombatWithZone();
DoZoneInCombat((*itr));
(*itr)->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
(*itr)->SetReactState(REACT_AGGRESSIVE);
(*itr)->SetStandState(UNIT_STAND_STATE_STAND);
@@ -244,9 +244,9 @@ public:
switch (eventId)
{
case EVENT_RAZOR_SPAWN:
for (uint8 i = urand(2, 5); i > 0 ; --i)
if (Creature* summon = instance->SummonCreature(Entry[urand(0, 4)], SummonPosition[urand(0, 7)]))
summon->SetInCombatWithZone();
for (uint8 i = urand(2, 5); i > 0; --i)
if (Creature* summon = instance->SummonCreature(Entry[urand(0, 4)], SummonPosition[urand(0, 7)]))
summon->AI()->DoZoneInCombat();
_events.ScheduleEvent(EVENT_RAZOR_SPAWN, urand(12, 17) * IN_MILLISECONDS);
break;
case EVENT_RAZOR_PHASE_TWO:
@@ -299,7 +299,7 @@ public:
break;
case EVENT_INTRO_LANDING:
me->SetImmuneToPC(false);
me->SetInCombatWithZone();
DoZoneInCombat();
break;
case EVENT_LAND:
Talk(YELL_LAND_PHASE);
@@ -217,7 +217,7 @@ class boss_apothecary_hummel : public CreatureScript
case EVENT_START_FIGHT:
{
me->SetImmuneToAll(false);
me->SetInCombatWithZone();
DoZoneInCombat();
events.ScheduleEvent(EVENT_CALL_BAXTER, Seconds(6));
events.ScheduleEvent(EVENT_CALL_FRYE, Seconds(14));
events.ScheduleEvent(EVENT_PERFUME_SPRAY, Milliseconds(3640));
@@ -298,7 +298,7 @@ struct npc_apothecary_genericAI : public ScriptedAI
else if (action == ACTION_START_FIGHT)
{
me->SetImmuneToAll(false);
me->SetInCombatWithZone();
DoZoneInCombat();
}
}
@@ -173,7 +173,7 @@ public:
void JustSummoned(Creature* summoned) override
{
summoned->SetInCombatWithZone();
DoZoneInCombat(summoned);
if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0))
summoned->AI()->AttackStart(target);
@@ -89,7 +89,7 @@ public:
Position goPos = go->GetPosition();
if (Creature* temp = go->SummonCreature(NPC_WHELP, goPos, TEMPSUMMON_CORPSE_DESPAWN))
{
temp->SetInCombatWithZone();
temp->AI()->DoZoneInCombat();
++manyWhelpsCounter;
}
break;
@@ -216,7 +216,7 @@ struct dummy_dragonAI : public ScriptedAI
if (pointId == POINT_ID_LAND)
{
me->GetMotionMaster()->Clear();
me->SetInCombatWithZone();
DoZoneInCombat();
if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 0, true))
{
AddThreat(target, 1.0f);
@@ -820,7 +820,7 @@ public:
void JustSummoned(Creature* who) override
{
who->SetInCombatWithZone();
DoZoneInCombat(who);
}
void UpdateAI(uint32 diff) override
@@ -987,7 +987,7 @@ public:
void Reset() override
{
me->RemoveAllAuras();
me->SetInCombatWithZone();
DoZoneInCombat();
events.ScheduleEvent(EVENT_FADE_ARMOR, 1000);
}
@@ -214,7 +214,7 @@ class npc_onyx_flamecaller : public CreatureScript
if (type != SPLINE_CHAIN_MOTION_TYPE && pointId != POINT_GENERAL_ROOM)
return;
me->SetInCombatWithZone();
DoZoneInCombat();
}
void MoveToGeneral()
@@ -1280,7 +1280,7 @@ class npc_living_inferno : public CreatureScript
void IsSummonedBy(Unit* /*summoner*/) override
{
me->SetInCombatWithZone();
DoZoneInCombat();
me->CastSpell(me, SPELL_BLAZING_AURA, true);
// SMSG_SPELL_GO for the living ember stuff isn't even sent to the client - Blizzard on drugs.
@@ -465,7 +465,7 @@ class npc_swarm_scarab : public CreatureScript
me->SetCorpseDelay(0);
Initialize();
DoCast(me, SPELL_ACID_MANDIBLE);
me->SetInCombatWithZone();
DoZoneInCombat();
if (me->IsInCombat())
if (Creature* anubarak = _instance->GetCreature(DATA_ANUBARAK))
anubarak->AI()->JustSummoned(me);
@@ -545,7 +545,7 @@ class npc_nerubian_burrower : public CreatureScript
DoCast(me, SPELL_EXPOSE_WEAKNESS);
DoCast(me, SPELL_SPIDER_FRENZY);
DoCast(me, SPELL_AWAKENED);
me->SetInCombatWithZone();
DoZoneInCombat();
if (me->IsInCombat())
if (Creature* anubarak = _instance->GetCreature(DATA_ANUBARAK))
anubarak->AI()->JustSummoned(me);
@@ -708,7 +708,7 @@ class npc_anubarak_spike : public CreatureScript
{
Initialize();
// make sure the spike has everyone on threat list
me->SetInCombatWithZone();
DoZoneInCombat();
}
bool CanAIAttack(Unit const* victim) const override
@@ -821,7 +821,7 @@ class npc_anubarak_spike : public CreatureScript
me->SetSpeedRate(MOVE_RUN, 0.5f);
// make sure the Spine will really follow the one he should
me->GetThreatManager().ResetAllThreat();
me->SetInCombatWithZone();
DoZoneInCombat();
AddThreat(who, 1000000.0f);
me->GetMotionMaster()->Clear(true);
me->GetMotionMaster()->MoveChase(who);
@@ -358,7 +358,7 @@ struct boss_gormok : public boss_northrend_beastsAI
// Npc that should keep raid in combat while boss change
if (Creature* combatStalker = me->SummonCreature(NPC_BEASTS_COMBAT_STALKER, CombatStalkerPosition))
{
combatStalker->SetInCombatWithZone();
DoZoneInCombat(combatStalker);
combatStalker->SetCombatPulseDelay(5);
}
DoZoneInCombat();
@@ -256,11 +256,11 @@ struct boss_twin_baseAI : public BossAI
void JustEngagedWith(Unit* /*who*/) override
{
me->SetInCombatWithZone();
DoZoneInCombat();
if (Creature* pSister = GetSister())
{
me->AddAura(MyEmphatySpellId, pSister);
pSister->SetInCombatWithZone();
DoZoneInCombat(pSister);
}
instance->SetBossState(DATA_TWIN_VALKIRIES, IN_PROGRESS);
@@ -152,7 +152,7 @@ class boss_drakkari_colossus : public CreatureScript
me->SetReactState(REACT_AGGRESSIVE);
me->RemoveAura(SPELL_FREEZE_ANIM);
me->SetInCombatWithZone();
DoZoneInCombat();
break;
}
@@ -222,10 +222,10 @@ class boss_drakkari_colossus : public CreatureScript
void JustSummoned(Creature* summon) override
{
summon->SetInCombatWithZone();
DoZoneInCombat(summon);
if (phase == COLOSSUS_PHASE_SECOND_ELEMENTAL_SUMMON)
summon->SetHealth(summon->GetMaxHealth() / 2);
if (phase == COLOSSUS_PHASE_SECOND_ELEMENTAL_SUMMON)
summon->SetHealth(summon->GetMaxHealth() / 2);
}
private:
@@ -424,7 +424,7 @@ public:
colossus->AI()->DoAction(ACTION_UNFREEZE_COLOSSUS);
if (!colossus->AI()->GetData(DATA_INTRO_DONE))
colossus->AI()->SetData(DATA_INTRO_DONE, true);
colossus->SetInCombatWithZone();
DoZoneInCombat(colossus);
me->DespawnOrUnsummon();
}
}
@@ -740,7 +740,7 @@ class npc_putricide_oozeAI : public ScriptedAI
if (_instance->GetBossState(DATA_PROFESSOR_PUTRICIDE) != IN_PROGRESS)
me->DespawnOrUnsummon();
me->SetInCombatWithZone();
DoZoneInCombat();
DoCastAOE(_auraSpellId, true);
}
@@ -466,7 +466,7 @@ public:
me->GetMotionMaster()->MoveLand(POINT_LAND_P_ONE, pos);
me->SetImmuneToAll(false);
me->SetReactState(REACT_AGGRESSIVE);
me->SetInCombatWithZone();
DoZoneInCombat();
events.ScheduleEvent(EVENT_LAND_START_ENCOUNTER, 7*IN_MILLISECONDS, 1, PHASE_NOT_STARTED);
}
break;
@@ -1184,7 +1184,7 @@ public:
if (unit->GetTypeId() == TYPEID_UNIT)
{
unit->CastSpell(unit, SPELL_TELEPORT_VISUAL_ONLY);
unit->ToCreature()->SetInCombatWithZone();
DoZoneInCombat(unit->ToCreature());
}
else if (unit->GetTypeId() == TYPEID_PLAYER)
me->SetDisableGravity(true);
@@ -131,7 +131,7 @@ class boss_kologarn : public CreatureScript
if (Vehicle* vehicle = me->GetVehicleKit())
for (uint8 i = 0; i < 2; ++i)
if (Unit* arm = vehicle->GetPassenger(i))
arm->ToCreature()->SetInCombatWithZone();
DoZoneInCombat(arm->ToCreature());
_JustEngagedWith();
}
@@ -204,7 +204,7 @@ class boss_kologarn : public CreatureScript
else
{
events.CancelEvent(EVENT_STONE_SHOUT);
who->ToCreature()->SetInCombatWithZone();
DoZoneInCombat(who->ToCreature());
}
}
@@ -1285,7 +1285,7 @@ struct npc_darkrune_watcher : public ScriptedAI
{
case EVENT_START_COMBAT:
me->SetReactState(REACT_AGGRESSIVE);
me->SetInCombatWithZone();
DoZoneInCombat();
break;
case EVENT_LIGHTNING_BOLT:
DoCastVictim(LIGHTNING_BOLT);
@@ -1356,7 +1356,7 @@ struct npc_darkrune_guardian : public ScriptedAI
{
case EVENT_START_COMBAT:
me->SetReactState(REACT_AGGRESSIVE);
me->SetInCombatWithZone();
DoZoneInCombat();
break;
case EVENT_STORMSTRIKE:
DoCastVictim(SPELL_STORMSTRIKE);
@@ -1415,7 +1415,7 @@ struct npc_darkrune_sentinel : public ScriptedAI
{
case EVENT_START_COMBAT:
me->SetReactState(REACT_AGGRESSIVE);
me->SetInCombatWithZone();
DoZoneInCombat();
break;
case EVENT_HEROIC_STRIKE:
DoCastVictim(SPELL_HEROIC_STRIKE);
@@ -459,11 +459,10 @@ class boss_voice_of_yogg_saron : public CreatureScript
}
void MoveInLineOfSight(Unit* who) override
{
// TODO: MoveInLineOfSight doesn't work for such a big distance
if (who->GetTypeId() == TYPEID_PLAYER && me->GetDistance2d(who) < 99.0f && !me->IsInCombat())
me->SetInCombatWithZone();
DoZoneInCombat();
}
void EnterEvadeMode(EvadeReason why) override
@@ -623,7 +622,7 @@ class boss_voice_of_yogg_saron : public CreatureScript
events.SetPhase(PHASE_TWO);
me->SummonCreature(NPC_YOGG_SARON, YoggSaronSpawnPos);
if (Creature* brain = instance->GetCreature(DATA_BRAIN_OF_YOGG_SARON))
brain->SetInCombatWithZone();
DoZoneInCombat(brain);
events.ScheduleEvent(EVENT_SUMMON_CORRUPTOR_TENTACLE, 1, EVENT_GROUP_SUMMON_TENTACLES, PHASE_TWO);
events.ScheduleEvent(EVENT_SUMMON_CONSTRICTOR_TENTACLE, 1, EVENT_GROUP_SUMMON_TENTACLES, PHASE_TWO);
events.ScheduleEvent(EVENT_SUMMON_CRUSHER_TENTACLE, 1, EVENT_GROUP_SUMMON_TENTACLES, PHASE_TWO);
@@ -117,7 +117,7 @@ public:
{
_owner->SetReactState(REACT_AGGRESSIVE);
_owner->SetTempSummonType(TEMPSUMMON_CORPSE_DESPAWN);
_owner->SetInCombatWithZone();
_owner->AI()->DoZoneInCombat();
return true;
}
@@ -160,7 +160,7 @@ struct npc_frozen_orb : public ScriptedAI
if (toravon->IsInCombat())
{
toravon->AI()->JustSummoned(me);
me->SetInCombatWithZone();
DoZoneInCombat();
}
else
me->DespawnOrUnsummon();
@@ -1379,7 +1379,7 @@ struct npc_parasitic_shadowfiend : public ScriptedAI
_scheduler.Schedule(Seconds(2), [this](TaskContext /*context*/)
{
me->SetReactState(REACT_AGGRESSIVE);
me->SetInCombatWithZone();
DoZoneInCombat();
});
}
@@ -1394,7 +1394,7 @@ struct npc_parasitic_shadowfiend : public ScriptedAI
_scheduler.Schedule(Seconds(2), [this](TaskContext /*context*/)
{
me->SetReactState(REACT_AGGRESSIVE);
me->SetInCombatWithZone();
DoZoneInCombat();
});
}
@@ -1497,7 +1497,7 @@ struct npc_flame_of_azzinoth : public ScriptedAI
{
case EVENT_ENGAGE:
me->SetReactState(REACT_AGGRESSIVE);
me->SetInCombatWithZone();
DoZoneInCombat();
_events.ScheduleEvent(EVENT_FLAME_CHARGE, Seconds(5));
break;
case EVENT_FLAME_CHARGE:
@@ -634,7 +634,7 @@ struct npc_enslaved_soul : public ScriptedAI
_scheduler.Schedule(Seconds(3), [this](TaskContext /*context*/)
{
me->SetReactState(REACT_AGGRESSIVE);
me->SetInCombatWithZone();
DoZoneInCombat();
});
}
@@ -233,7 +233,7 @@ struct npc_doom_blossom : public NullCreatureAI
DoCast(SPELL_SUMMON_BLOSSOM_MOVE_TARGET);
_scheduler.CancelAll();
me->SetInCombatWithZone();
DoZoneInCombat();
_scheduler.Schedule(Seconds(12), [this](TaskContext shadowBolt)
{
if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0))
@@ -391,7 +391,7 @@ public:
if (summon->GetEntry() == NPC_AHUNE)
return;
summon->SetInCombatWithZone();
DoZoneInCombat(summon);
_summons.Summon(summon);
}
@@ -470,7 +470,7 @@ public:
if (TempSummon* ahune = me->SummonCreature(NPC_AHUNE, SummonPositions[0], TEMPSUMMON_DEAD_DESPAWN))
{
ahune->SummonCreature(NPC_FROZEN_CORE, SummonPositions[1], TEMPSUMMON_CORPSE_DESPAWN);
ahune->SetInCombatWithZone();
DoZoneInCombat(ahune);
DoCast(ahune, SPELL_RESURFACE);
}
break;
@@ -671,7 +671,7 @@ public:
if (Creature* ahuneBunny = ObjectAccessor::GetCreature(*me, instance->GetGuidData(DATA_AHUNE_BUNNY)))
{
ahuneBunny->AI()->DoAction(ACTION_START_EVENT);
ahuneBunny->SetInCombatWithZone();
ahuneBunny->AI()->DoZoneInCombat();
}
if (Creature* luma = ObjectAccessor::GetCreature(*me, instance->GetGuidData(DATA_LUMA_SKYMOTHER)))
luma->CastSpell(player, SPELL_SUMMONING_RHYME_AURA, true);
@@ -103,7 +103,7 @@ class boss_broggok : public CreatureScript
switch (action)
{
case ACTION_PREPARE_BROGGOK:
me->SetInCombatWithZone();
DoZoneInCombat();
break;
case ACTION_ACTIVATE_BROGGOK:
me->SetReactState(REACT_AGGRESSIVE);
@@ -294,7 +294,7 @@ class instance_blood_furnace : public InstanceMapScript
{
prisoner->RemoveUnitFlag(UNIT_FLAG_NON_ATTACKABLE);
prisoner->SetImmuneToAll(false);
prisoner->SetInCombatWithZone();
prisoner->AI()->DoZoneInCombat();
}
}
@@ -250,7 +250,7 @@ class boss_magtheridon : public CreatureScript
case EVENT_RELEASED:
me->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
me->SetImmuneToPC(false);
me->SetInCombatWithZone();
DoZoneInCombat();
instance->SetData(DATA_MANTICRON_CUBE, ACTION_ENABLE);
events.ScheduleEvent(EVENT_CLEAVE, Seconds(10));
events.ScheduleEvent(EVENT_BLAST_NOVA, Seconds(60));
@@ -354,7 +354,7 @@ class npc_hellfire_channeler : public CreatureScript
if (Creature* magtheridon = _instance->GetCreature(DATA_MAGTHERIDON))
magtheridon->AI()->JustSummoned(summon);
summon->SetInCombatWithZone();
DoZoneInCombat(summon);
}
void EnterEvadeMode(EvadeReason /*why*/) override
@@ -123,7 +123,7 @@ class instance_magtheridons_lair : public InstanceMapScript
for (ObjectGuid warderGuid : warderGUIDS)
if (Creature* warder = instance->GetCreature(warderGuid))
if (warder->IsAlive())
warder->SetInCombatWithZone();
warder->AI()->DoZoneInCombat();
break;
default:
break;