refactor(Core/Unit): PC&NPC Immunity (#11986)

* initial

* refactor(Core/Unit): PC & NPC Immunities

Cherry-pick TC: 74af880217

Co-authored-by: Treeston <treeston.nmoc@gmail.com>

* fix builds error

Cherry-pick TC: 74af880217

Co-authored-by: Treeston <treeston.nmoc@gmail.com>

* Fix nef combat, and replace SetFlag by SetUnitFlag

* fix combat with jedoga

Co-authored-by: Treeston <treeston.nmoc@gmail.com>
This commit is contained in:
Maelthyr
2022-06-18 14:16:45 +02:00
committed by GitHub
parent 4bc99f8070
commit d928d8d96a
88 changed files with 450 additions and 328 deletions

View File

@@ -212,7 +212,7 @@ public:
me->SetDynamicFlag(UNIT_DYNFLAG_DEAD);
me->SetUnitFlag2(UNIT_FLAG2_FEIGN_DEATH);
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->SetImmuneToAll(true);
me->SetReactState(REACT_PASSIVE);
}
}
@@ -367,7 +367,8 @@ public:
{
case ACTION_STAND_UP:
summons.DespawnEntry(WORLD_TRIGGER);
me->RemoveUnitFlag(UNIT_FLAG_PREVENT_EMOTES_FROM_CHAT_TEXT | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->RemoveUnitFlag(UNIT_FLAG_PREVENT_EMOTES_FROM_CHAT_TEXT | UNIT_FLAG_NOT_SELECTABLE);
me->SetImmuneToAll(false);
me->RemoveDynamicFlag(UNIT_DYNFLAG_DEAD);
me->RemoveUnitFlag2(UNIT_FLAG2_FEIGN_DEATH);
me->SetReactState(REACT_AGGRESSIVE);
@@ -471,7 +472,7 @@ public:
me->SetDynamicFlag(UNIT_DYNFLAG_DEAD);
me->SetUnitFlag2(UNIT_FLAG2_FEIGN_DEATH);
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->SetImmuneToAll(true);
me->SetReactState(REACT_PASSIVE);
}
}
@@ -636,7 +637,8 @@ public:
{
case ACTION_STAND_UP:
summons.DespawnEntry(WORLD_TRIGGER);
me->RemoveUnitFlag(UNIT_FLAG_PREVENT_EMOTES_FROM_CHAT_TEXT | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->RemoveUnitFlag(UNIT_FLAG_PREVENT_EMOTES_FROM_CHAT_TEXT | UNIT_FLAG_NOT_SELECTABLE);
me->SetImmuneToAll(false);
me->RemoveDynamicFlag(UNIT_DYNFLAG_DEAD);
me->RemoveUnitFlag2(UNIT_FLAG2_FEIGN_DEATH);
me->SetReactState(REACT_AGGRESSIVE);
@@ -755,7 +757,7 @@ public:
me->SetDynamicFlag(UNIT_DYNFLAG_DEAD);
me->SetUnitFlag2(UNIT_FLAG2_FEIGN_DEATH);
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->SetImmuneToAll(true);
me->SetReactState(REACT_PASSIVE);
}
}
@@ -929,7 +931,8 @@ public:
{
case ACTION_STAND_UP:
summons.DespawnEntry(WORLD_TRIGGER);
me->RemoveUnitFlag(UNIT_FLAG_PREVENT_EMOTES_FROM_CHAT_TEXT | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->RemoveUnitFlag(UNIT_FLAG_PREVENT_EMOTES_FROM_CHAT_TEXT | UNIT_FLAG_NOT_SELECTABLE);
me->SetImmuneToAll(false);
me->RemoveDynamicFlag(UNIT_DYNFLAG_DEAD);
me->RemoveUnitFlag2(UNIT_FLAG2_FEIGN_DEATH);
me->SetReactState(REACT_AGGRESSIVE);

View File

@@ -251,7 +251,7 @@ public:
void Reset() override
{
_Reset();
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_NOT_SELECTABLE);
me->SetImmuneToAll(true);
me->SetReactState(REACT_DEFENSIVE);
events.Reset();
_introDone = false;
@@ -323,7 +323,7 @@ public:
void AttackStart(Unit* victim) override
{
if (!_introDone || me->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_PC))
if (!_introDone || me->IsImmuneToPC())
return;
ScriptedAI::AttackStart(victim);
@@ -707,7 +707,7 @@ public:
if (Creature* deathbringer = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_DEATHBRINGER_SAURFANG)))
{
deathbringer->AI()->DoAction(ACTION_INTRO_DONE);
deathbringer->RemoveUnitFlag(UNIT_FLAG_IMMUNE_TO_PC);
deathbringer->SetImmuneToPC(false);
if (Player* target = deathbringer->SelectNearestPlayer(100.0f))
deathbringer->AI()->AttackStart(target);
}
@@ -945,7 +945,7 @@ public:
if (Creature* deathbringer = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_DEATHBRINGER_SAURFANG)))
{
deathbringer->AI()->DoAction(ACTION_INTRO_DONE);
deathbringer->RemoveUnitFlag(UNIT_FLAG_IMMUNE_TO_PC);
deathbringer->SetImmuneToPC(false);
if (Player* target = deathbringer->SelectNearestPlayer(100.0f))
deathbringer->AI()->AttackStart(target);
}

View File

@@ -1431,7 +1431,7 @@ public:
return;
me->setActive(true);
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC);
me->SetImmuneToPC(true);
float moveTime = me->GetExactDist(&SpinestalkerFlyPos) / (me->GetSpeed(MOVE_RUN) * 0.001f);
me->m_Events.AddEvent(new FrostwyrmLandEvent(*me, SpinestalkerLandPos), me->m_Events.CalculateTime(uint64(moveTime) + 250));
me->SetDefaultMovementType(IDLE_MOTION_TYPE);
@@ -1450,7 +1450,7 @@ public:
me->SetDisableGravity(false);
me->SetHomePosition(SpinestalkerLandPos);
me->SetFacingTo(SpinestalkerLandPos.GetOrientation());
me->RemoveUnitFlag(UNIT_FLAG_IMMUNE_TO_PC);
me->SetImmuneToPC(false);
}
void UpdateAI(uint32 diff) override
@@ -1562,7 +1562,7 @@ public:
return;
me->setActive(true);
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC);
me->SetImmuneToPC(true);
float moveTime = me->GetExactDist(&RimefangFlyPos) / (me->GetSpeed(MOVE_RUN) * 0.001f);
me->m_Events.AddEvent(new FrostwyrmLandEvent(*me, RimefangLandPos), me->m_Events.CalculateTime(uint64(moveTime) + 250));
me->SetDefaultMovementType(IDLE_MOTION_TYPE);
@@ -1583,7 +1583,7 @@ public:
me->SetDisableGravity(false);
me->SetHomePosition(RimefangLandPos);
me->SetFacingTo(RimefangLandPos.GetOrientation());
me->RemoveUnitFlag(UNIT_FLAG_IMMUNE_TO_PC);
me->SetImmuneToPC(false);
}
else if (point == POINT_LAND_GROUND)
{

View File

@@ -631,7 +631,7 @@ public:
boss_the_lich_kingAI(Creature* creature) : BossAI(creature, DATA_THE_LICH_KING)
{
me->AddAura(SPELL_EMOTE_SIT_NO_SHEATH, me);
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC);
me->SetImmuneToPC(true);
me->SetReactState(REACT_PASSIVE);
}
@@ -658,7 +658,7 @@ public:
_Reset();
DoAction(ACTION_RESTORE_LIGHT);
SetEquipmentSlots(true);
if (me->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_PC))
if (me->IsImmuneToPC())
me->SetStandState(UNIT_STAND_STATE_SIT);
}
@@ -704,7 +704,7 @@ public:
Cell::VisitGridObjects(me, worker, 333.0f);
me->AddAura(SPELL_EMOTE_SIT_NO_SHEATH, me);
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC);
me->SetImmuneToPC(true);
me->SetReactState(REACT_PASSIVE);
me->SetStandState(UNIT_STAND_STATE_SIT);
}
@@ -1207,7 +1207,7 @@ public:
spawner->CastSpell(spawner, SPELL_SUMMON_SPIRIT_BOMB_1, true); // summons bombs randomly
spawner->CastSpell(spawner, SPELL_SUMMON_SPIRIT_BOMB_2, true); // summons bombs on players
spawner->m_Events.AddEvent(new TriggerWickedSpirit(spawner), spawner->m_Events.CalculateTime(3000));
terenas->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC); // to avoid being healed by player trinket procs. terenas' health doesn't matter on heroic
terenas->SetImmuneToAll(true); // to avoid being healed by player trinket procs. terenas' health doesn't matter on heroic
}
}
break;
@@ -1454,7 +1454,7 @@ public:
if (Creature* theLichKing = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_THE_LICH_KING)))
{
theLichKing->SetWalk(false);
theLichKing->RemoveUnitFlag(UNIT_FLAG_IMMUNE_TO_PC);
theLichKing->SetImmuneToPC(false);
theLichKing->SetReactState(REACT_AGGRESSIVE);
theLichKing->SetInCombatWithZone();
if (!theLichKing->IsInCombat())
@@ -1587,7 +1587,7 @@ public:
terenas->CastSpell((Unit*)nullptr, SPELL_MASS_RESURRECTION, false);
if (Creature* lichKing = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_THE_LICH_KING)))
{
lichKing->RemoveUnitFlag(UNIT_FLAG_IMMUNE_TO_NPC);
lichKing->SetImmuneToNPC(false);
me->SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_ONESHOT_NONE);
me->RemoveAllAuras();
SetEquipmentSlots(true);
@@ -3708,7 +3708,8 @@ public:
if (!target)
return;
target->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1 | UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
target->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1);
target->SetImmuneToAll(false);
target->ForceValuesUpdateAtIndex(UNIT_FIELD_FLAGS);
VileSpiritActivateEvent(target).Execute(0, 0);
}

View File

@@ -743,7 +743,8 @@ public:
return;
me->setActive(true);
me->SetUnitFlag(UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_IMMUNE_TO_NPC | UNIT_FLAG_IMMUNE_TO_PC);
me->SetUnitFlag(UNIT_FLAG_NON_ATTACKABLE);
me->SetImmuneToAll(true);
// Load Grid with Sister Svalna
me->GetMap()->LoadGrid(4356.71f, 2484.33f);
if (Creature* svalna = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_SISTER_SVALNA)))
@@ -930,7 +931,8 @@ public:
Talk(SAY_CROK_INTRO_3);
break;
case EVENT_START_PATHING:
me->RemoveUnitFlag(UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_IMMUNE_TO_NPC | UNIT_FLAG_IMMUNE_TO_PC);
me->RemoveUnitFlag(UNIT_FLAG_NON_ATTACKABLE);
me->SetImmuneToAll(false);
Start(true, true);
break;
case EVENT_SCOURGE_STRIKE:
@@ -998,7 +1000,7 @@ public:
void Reset() override
{
_Reset();
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->SetImmuneToAll(true);
me->SetReactState(REACT_PASSIVE);
me->SetCanFly(true);
me->SetDisableGravity(true);
@@ -1007,7 +1009,7 @@ public:
void AttackStart(Unit* victim) override
{
if (me->HasReactState(REACT_PASSIVE) || me->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC))
if (me->HasReactState(REACT_PASSIVE) || me->IsImmuneToAll())
return;
BossAI::AttackStart(victim);
}
@@ -1037,10 +1039,10 @@ public:
void EnterCombat(Unit* /*attacker*/) override
{
if (me->HasReactState(REACT_PASSIVE) || me->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC))
if (me->HasReactState(REACT_PASSIVE) || me->IsImmuneToAll())
{
me->CombatStop(false);
me->SetUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->SetImmuneToAll(true);
me->SetReactState(REACT_PASSIVE);
return;
}
@@ -1121,7 +1123,7 @@ public:
if (type != EFFECT_MOTION_TYPE || id != POINT_LAND)
return;
me->RemoveUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC);
me->SetImmuneToAll(false);
me->SetCanFly(false);
me->SetDisableGravity(false);
me->SetReactState(REACT_AGGRESSIVE);
@@ -1915,7 +1917,8 @@ public:
if (Creature* target = GetTarget()->ToCreature())
{
target->SetReactState(REACT_PASSIVE);
target->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_IMMUNE_TO_PC);
target->SetUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
target->SetImmuneToPC(true);
target->SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_STATE_CUSTOM_SPELL_02);
}
}
@@ -1925,7 +1928,8 @@ public:
if (Creature* target = GetTarget()->ToCreature())
{
target->SetReactState(REACT_AGGRESSIVE);
target->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_IMMUNE_TO_PC);
target->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
target->SetImmuneToPC(false);
target->SetUInt32Value(UNIT_NPC_EMOTESTATE, 0);
}
}