aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2016-08-08 11:22:11 +0200
committerjoschiwald <joschiwald.trinity@gmail.com>2017-02-11 22:58:58 +0100
commit62e7d7042cece5561f6ff7b9011c5553c6cd4741 (patch)
tree727e8c1b71868d6e0e956dd377e06baffb13250b /src
parente57efc201ae5e62c122e0fa308134219318495a3 (diff)
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)
(cherry picked from commit fdd78d20772701b3e0fd7caf0da2cd5a2e6b6354) Entities/Creature: Fix spawn health, fdd78d2 follow-up. Fixes and closes #17757. (cherry picked from commit 5b6eb29b74bbc9e62f12c449b1896a075bdd25a2) Entity/Creature: Fix spawn health, for real this time. Closes #17757. Also for real this time. (cherry picked from commit ac35f93c2d6d5436054be474da06c9483e311c36)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp61
-rw-r--r--src/server/game/Entities/Creature/Creature.h1
-rw-r--r--src/server/game/Movement/MovementGenerators/HomeMovementGenerator.cpp1
3 files changed, 38 insertions, 25 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 6334b4ea339..b1225d1be5d 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -1384,6 +1384,7 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool ad
}
m_spawnId = spawnId;
+ m_creatureData = data;
if (!Create(map->GenerateLowGuid<HighGuid::Creature>(), map, data->phaseMask, data->id, data->posX, data->posY, data->posZ, data->orientation, data))
return false;
@@ -1407,32 +1408,11 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool ad
}
}
- uint32 curhealth;
-
- 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);
+ SetSpawnHealth();
// checked at creature_template loading
m_defaultMovementType = MovementGeneratorType(data->movementType);
- m_creatureData = data;
-
loot.SetGUID(ObjectGuid::Create<HighGuid::LootObject>(data->mapid, data->id, GetMap()->GenerateLowGuid<HighGuid::LootObject>()));
if (addToMap && !GetMap()->AddToMap(this))
@@ -1469,6 +1449,35 @@ void Creature::LoadEquipment(int8 id, bool force /*= true*/)
SetVirtualItem(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 || m_deathState == JUST_RESPAWNED) ? curhealth : 0);
+}
+
bool Creature::hasQuest(uint32 quest_id) const
{
QuestRelationBounds qr = sObjectMgr->GetCreatureQuestRelationBounds(GetEntry());
@@ -1680,9 +1689,11 @@ void Creature::setDeathState(DeathState s)
}
else if (s == JUST_RESPAWNED)
{
- //if (IsPet())
- // setActive(true);
- SetFullHealth();
+ if (IsPet())
+ SetFullHealth();
+ else
+ SetSpawnHealth();
+
SetLootRecipient(nullptr);
ResetPlayerDamageReq();
diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h
index 1b394aa897d..57d5c3447f5 100644
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -712,6 +712,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
bool LoadCreaturesAddon();
void SelectLevel();
void LoadEquipment(int8 id = 1, bool force = false);
+ void SetSpawnHealth();
ObjectGuid::LowType GetSpawnId() const { return m_spawnId; }
diff --git a/src/server/game/Movement/MovementGenerators/HomeMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/HomeMovementGenerator.cpp
index 5503c27d360..002e247dc14 100644
--- a/src/server/game/Movement/MovementGenerators/HomeMovementGenerator.cpp
+++ b/src/server/game/Movement/MovementGenerators/HomeMovementGenerator.cpp
@@ -34,6 +34,7 @@ void HomeMovementGenerator<Creature>::DoFinalize(Creature* owner)
owner->ClearUnitState(UNIT_STATE_EVADE);
owner->SetWalk(true);
owner->LoadCreaturesAddon();
+ owner->SetSpawnHealth();
owner->AI()->JustReachedHome();
}
}