Core/Creature: Fix health regeneration. Creatures immediately reset to full health upon reaching home, rather than slowly regaining it over multiple seconds, which allows players to re-engage them at less than max health. (#17756)

This commit is contained in:
Treeston
2016-08-08 11:22:11 +02:00
committed by Shauren
parent 358af1ccc2
commit fdd78d2077
3 changed files with 37 additions and 23 deletions

View File

@@ -1383,26 +1383,7 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool ad
} }
} }
uint32 curhealth; SetSpawnHealth();
if (!m_regenHealth)
{
curhealth = data->curhealth;
if (curhealth)
{
curhealth = uint32(curhealth*_GetHealthMod(GetCreatureTemplate()->rank));
if (curhealth < 1)
curhealth = 1;
}
SetPower(POWER_MANA, data->curmana);
}
else
{
curhealth = GetMaxHealth();
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
}
SetHealth(m_deathState == ALIVE ? curhealth : 0);
// checked at creature_template loading // checked at creature_template loading
m_defaultMovementType = MovementGeneratorType(data->movementType); m_defaultMovementType = MovementGeneratorType(data->movementType);
@@ -1443,6 +1424,35 @@ void Creature::LoadEquipment(int8 id, bool force /*= true*/)
SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + i, einfo->ItemEntry[i]); SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + i, einfo->ItemEntry[i]);
} }
void Creature::SetSpawnHealth()
{
uint32 curhealth;
if (!m_regenHealth)
{
if (m_creatureData)
{
curhealth = m_creatureData->curhealth;
if (curhealth)
{
curhealth = uint32(curhealth*_GetHealthMod(GetCreatureTemplate()->rank));
if (curhealth < 1)
curhealth = 1;
}
SetPower(POWER_MANA, m_creatureData->curmana);
}
else
curhealth = GetHealth();
}
else
{
curhealth = GetMaxHealth();
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
}
SetHealth(m_deathState == ALIVE ? curhealth : 0);
}
bool Creature::hasQuest(uint32 quest_id) const bool Creature::hasQuest(uint32 quest_id) const
{ {
QuestRelationBounds qr = sObjectMgr->GetCreatureQuestRelationBounds(GetEntry()); QuestRelationBounds qr = sObjectMgr->GetCreatureQuestRelationBounds(GetEntry());
@@ -1654,9 +1664,11 @@ void Creature::setDeathState(DeathState s)
} }
else if (s == JUST_RESPAWNED) else if (s == JUST_RESPAWNED)
{ {
//if (IsPet()) if (IsPet())
// setActive(true); SetFullHealth();
SetFullHealth(); else
SetSpawnHealth();
SetLootRecipient(nullptr); SetLootRecipient(nullptr);
ResetPlayerDamageReq(); ResetPlayerDamageReq();

View File

@@ -442,6 +442,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
bool LoadCreaturesAddon(); bool LoadCreaturesAddon();
void SelectLevel(); void SelectLevel();
void LoadEquipment(int8 id = 1, bool force = false); void LoadEquipment(int8 id = 1, bool force = false);
void SetSpawnHealth();
ObjectGuid::LowType GetSpawnId() const { return m_spawnId; } ObjectGuid::LowType GetSpawnId() const { return m_spawnId; }

View File

@@ -34,6 +34,7 @@ void HomeMovementGenerator<Creature>::DoFinalize(Creature* owner)
owner->ClearUnitState(UNIT_STATE_EVADE); owner->ClearUnitState(UNIT_STATE_EVADE);
owner->SetWalk(true); owner->SetWalk(true);
owner->LoadCreaturesAddon(); owner->LoadCreaturesAddon();
owner->SetSpawnHealth();
owner->AI()->JustReachedHome(); owner->AI()->JustReachedHome();
} }
} }