fix(Core/Creature): Fix bosses with hard reset flag not respawning an… (#14862)

This commit is contained in:
Skjalf
2023-02-04 15:35:53 -03:00
committed by GitHub
parent c08a5ba3fa
commit 8aa331b432
3 changed files with 23 additions and 1 deletions
@@ -554,6 +554,19 @@ BossAI::BossAI(Creature* creature, uint32 bossId) : ScriptedAI(creature),
SetBoundary(instance->GetBossBoundary(bossId)); SetBoundary(instance->GetBossBoundary(bossId));
} }
bool BossAI::CanRespawn()
{
if (instance)
{
if (instance->GetBossState(_bossId) == DONE)
{
return false;
}
}
return true;
}
void BossAI::_Reset() void BossAI::_Reset()
{ {
if (!me->IsAlive()) if (!me->IsAlive())
@@ -438,6 +438,8 @@ public:
InstanceScript* const instance; InstanceScript* const instance;
bool CanRespawn() override;
void JustSummoned(Creature* summon) override; void JustSummoned(Creature* summon) override;
void SummonedCreatureDespawn(Creature* summon) override; void SummonedCreatureDespawn(Creature* summon) override;
void SummonedCreatureDespawnAll() override; void SummonedCreatureDespawnAll() override;
@@ -648,15 +648,22 @@ void Creature::Update(uint32 diff)
ObjectGuid dbtableHighGuid = ObjectGuid::Create<HighGuid::Unit>(m_creatureData ? m_creatureData->id1 : GetEntry(), m_spawnId); ObjectGuid dbtableHighGuid = ObjectGuid::Create<HighGuid::Unit>(m_creatureData ? m_creatureData->id1 : GetEntry(), m_spawnId);
time_t linkedRespawntime = GetMap()->GetLinkedRespawnTime(dbtableHighGuid); time_t linkedRespawntime = GetMap()->GetLinkedRespawnTime(dbtableHighGuid);
if (!linkedRespawntime) // Can respawn
CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(GetEntry());
if (!linkedRespawntime || (cInfo && cInfo->HasFlagsExtra(CREATURE_FLAG_EXTRA_HARD_RESET))) // Can respawn
Respawn(); Respawn();
else // the master is dead else // the master is dead
{ {
ObjectGuid targetGuid = sObjectMgr->GetLinkedRespawnGuid(dbtableHighGuid); ObjectGuid targetGuid = sObjectMgr->GetLinkedRespawnGuid(dbtableHighGuid);
if (targetGuid == dbtableHighGuid) // if linking self, never respawn (check delayed to next day) if (targetGuid == dbtableHighGuid) // if linking self, never respawn (check delayed to next day)
{
SetRespawnTime(DAY); SetRespawnTime(DAY);
}
else else
{
m_respawnTime = (now > linkedRespawntime ? now : linkedRespawntime) + urand(5, MINUTE); // else copy time from master and add a little m_respawnTime = (now > linkedRespawntime ? now : linkedRespawntime) + urand(5, MINUTE); // else copy time from master and add a little
}
SaveRespawnTime(); // also save to DB immediately SaveRespawnTime(); // also save to DB immediately
} }
} }