mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-18 11:25:42 +00:00
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();
|
||||
_difficulty = Difficulty(me->GetMap()->GetSpawnMode());
|
||||
_invincible = false;
|
||||
}
|
||||
|
||||
void ScriptedAI::AttackStartNoMove(Unit* who)
|
||||
@@ -222,6 +223,12 @@ void ScriptedAI::UpdateAI(uint32 /*diff*/)
|
||||
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)
|
||||
{
|
||||
if (victim)
|
||||
@@ -732,8 +739,10 @@ void BossAI::UpdateAI(uint32 diff)
|
||||
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 (me->HealthBelowPctDamaged(_nextHealthCheck._healthPct, damage))
|
||||
{
|
||||
|
||||
@@ -198,7 +198,7 @@ struct ScriptedAI : public CreatureAI
|
||||
void AttackStartNoMove(Unit* target);
|
||||
|
||||
// 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
|
||||
void UpdateAI(uint32 diff) override;
|
||||
@@ -438,9 +438,14 @@ struct ScriptedAI : public CreatureAI
|
||||
|
||||
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:
|
||||
Difficulty _difficulty;
|
||||
bool _isHeroic;
|
||||
bool _invincible;
|
||||
std::unordered_set<uint32> _uniqueTimedEvents;
|
||||
};
|
||||
|
||||
|
||||
@@ -62,13 +62,20 @@ public:
|
||||
|
||||
void Reset() override
|
||||
{
|
||||
_summonedRend = false;
|
||||
if (instance->GetBossState(DATA_GYTH) == IN_PROGRESS)
|
||||
{
|
||||
instance->SetBossState(DATA_GYTH, NOT_STARTED);
|
||||
summons.DespawnAll();
|
||||
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
|
||||
@@ -104,21 +111,6 @@ public:
|
||||
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
|
||||
{
|
||||
if (!UpdateVictim())
|
||||
@@ -173,9 +165,6 @@ public:
|
||||
}
|
||||
DoMeleeAttackIfReady();
|
||||
}
|
||||
|
||||
private:
|
||||
bool _summonedRend;
|
||||
};
|
||||
|
||||
CreatureAI* GetAI(Creature* creature) const override
|
||||
|
||||
Reference in New Issue
Block a user