feat(Core/Scripting): Implement SetInvincibility() to prevent creatur… (#20508)
This commit is contained in:
@@ -194,6 +194,7 @@ ScriptedAI::ScriptedAI(Creature* creature) : CreatureAI(creature),
|
|||||||
{
|
{
|
||||||
_isHeroic = me->GetMap()->IsHeroic();
|
_isHeroic = me->GetMap()->IsHeroic();
|
||||||
_difficulty = Difficulty(me->GetMap()->GetSpawnMode());
|
_difficulty = Difficulty(me->GetMap()->GetSpawnMode());
|
||||||
|
_invincible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptedAI::AttackStartNoMove(Unit* who)
|
void ScriptedAI::AttackStartNoMove(Unit* who)
|
||||||
@@ -222,6 +223,12 @@ void ScriptedAI::UpdateAI(uint32 /*diff*/)
|
|||||||
DoMeleeAttackIfReady();
|
DoMeleeAttackIfReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptedAI::DamageTaken(Unit* /*attacker*/, uint32& damage, DamageEffectType /*damagetype*/, SpellSchoolMask /*damageSchoolMask*/)
|
||||||
|
{
|
||||||
|
if (IsInvincible() && damage >= me->GetHealth())
|
||||||
|
damage = me->GetHealth() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptedAI::DoStartMovement(Unit* victim, float distance, float angle)
|
void ScriptedAI::DoStartMovement(Unit* victim, float distance, float angle)
|
||||||
{
|
{
|
||||||
if (victim)
|
if (victim)
|
||||||
@@ -732,8 +739,10 @@ void BossAI::UpdateAI(uint32 diff)
|
|||||||
DoMeleeAttackIfReady();
|
DoMeleeAttackIfReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BossAI::DamageTaken(Unit* /*attacker*/, uint32& damage, DamageEffectType /*damagetype*/, SpellSchoolMask /*damageSchoolMask*/)
|
void BossAI::DamageTaken(Unit* attacker, uint32& damage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask)
|
||||||
{
|
{
|
||||||
|
ScriptedAI::DamageTaken(attacker, damage, damagetype, damageSchoolMask);
|
||||||
|
|
||||||
if (_nextHealthCheck._valid)
|
if (_nextHealthCheck._valid)
|
||||||
if (me->HealthBelowPctDamaged(_nextHealthCheck._healthPct, damage))
|
if (me->HealthBelowPctDamaged(_nextHealthCheck._healthPct, damage))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ struct ScriptedAI : public CreatureAI
|
|||||||
void AttackStartNoMove(Unit* target);
|
void AttackStartNoMove(Unit* target);
|
||||||
|
|
||||||
// Called at any Damage from any attacker (before damage apply)
|
// Called at any Damage from any attacker (before damage apply)
|
||||||
void DamageTaken(Unit* /*attacker*/, uint32& /*damage*/, DamageEffectType /*damagetype*/, SpellSchoolMask /*damageSchoolMask*/) override {}
|
void DamageTaken(Unit* /*attacker*/, uint32& /*damage*/, DamageEffectType /*damagetype*/, SpellSchoolMask /*damageSchoolMask*/) override;
|
||||||
|
|
||||||
//Called at World update tick
|
//Called at World update tick
|
||||||
void UpdateAI(uint32 diff) override;
|
void UpdateAI(uint32 diff) override;
|
||||||
@@ -438,9 +438,14 @@ struct ScriptedAI : public CreatureAI
|
|||||||
|
|
||||||
Player* SelectTargetFromPlayerList(float maxdist, uint32 excludeAura = 0, bool mustBeInLOS = false) const;
|
Player* SelectTargetFromPlayerList(float maxdist, uint32 excludeAura = 0, bool mustBeInLOS = false) const;
|
||||||
|
|
||||||
|
// Allows dropping to 1 HP but prevents creature from dying.
|
||||||
|
void SetInvincibility(bool apply) { _invincible = apply; };
|
||||||
|
[[nodiscard]] bool IsInvincible() const { return _invincible; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Difficulty _difficulty;
|
Difficulty _difficulty;
|
||||||
bool _isHeroic;
|
bool _isHeroic;
|
||||||
|
bool _invincible;
|
||||||
std::unordered_set<uint32> _uniqueTimedEvents;
|
std::unordered_set<uint32> _uniqueTimedEvents;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -62,13 +62,20 @@ public:
|
|||||||
|
|
||||||
void Reset() override
|
void Reset() override
|
||||||
{
|
{
|
||||||
_summonedRend = false;
|
|
||||||
if (instance->GetBossState(DATA_GYTH) == IN_PROGRESS)
|
if (instance->GetBossState(DATA_GYTH) == IN_PROGRESS)
|
||||||
{
|
{
|
||||||
instance->SetBossState(DATA_GYTH, NOT_STARTED);
|
instance->SetBossState(DATA_GYTH, NOT_STARTED);
|
||||||
summons.DespawnAll();
|
summons.DespawnAll();
|
||||||
me->DespawnOrUnsummon();
|
me->DespawnOrUnsummon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetInvincibility(true); // Don't let boss die before summoning Rend.
|
||||||
|
|
||||||
|
ScheduleHealthCheckEvent(25, [&] {
|
||||||
|
DoCastAOE(SPELL_SUMMON_REND, true);
|
||||||
|
me->RemoveAura(SPELL_REND_MOUNTS);
|
||||||
|
SetInvincibility(false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void JustEngagedWith(Unit* /*who*/) override
|
void JustEngagedWith(Unit* /*who*/) override
|
||||||
@@ -104,21 +111,6 @@ public:
|
|||||||
instance->SetBossState(DATA_GYTH, DONE);
|
instance->SetBossState(DATA_GYTH, DONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DamageTaken(Unit* /*attacker*/, uint32& damage, DamageEffectType /*type*/, SpellSchoolMask /*school*/) override
|
|
||||||
{
|
|
||||||
if (!_summonedRend && me->HealthBelowPctDamaged(25, damage))
|
|
||||||
{
|
|
||||||
if (damage >= me->GetHealth())
|
|
||||||
{
|
|
||||||
// Let creature fall to 1 HP but prevent it from dying before boss is summoned.
|
|
||||||
damage = me->GetHealth() - 1;
|
|
||||||
}
|
|
||||||
DoCast(me, SPELL_SUMMON_REND, true);
|
|
||||||
me->RemoveAura(SPELL_REND_MOUNTS);
|
|
||||||
_summonedRend = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateAI(uint32 diff) override
|
void UpdateAI(uint32 diff) override
|
||||||
{
|
{
|
||||||
if (!UpdateVictim())
|
if (!UpdateVictim())
|
||||||
@@ -173,9 +165,6 @@ public:
|
|||||||
}
|
}
|
||||||
DoMeleeAttackIfReady();
|
DoMeleeAttackIfReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
bool _summonedRend;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CreatureAI* GetAI(Creature* creature) const override
|
CreatureAI* GetAI(Creature* creature) const override
|
||||||
|
|||||||
Reference in New Issue
Block a user