Core/Units: make health regeneration functions for players and creatures virtual

This commit is contained in:
Ovahlord committed 2020-04-27 14:39:07 +02:00
1 parent e7ba484fcf
commit 5cf7de6aa7
6 files changed
+27 -19

No files matched your search

+7 -14
View File
@@ -212,7 +212,6 @@ m_formation(nullptr), m_triggerJustAppeared(true), m_respawnCompatibilityMode(fa
DisableReputationGain = false;
_healthRegenerationTimer = UNIT_HEALTH_REGENERATION_INTERVAL;
m_SightDistance = sWorld->getFloatConfig(CONFIG_SIGHT_MONSTER);
m_CombatDistance = 0;//MELEE_RANGE;
@@ -773,19 +772,6 @@ void Creature::Update(uint32 diff)
if (!IsAlive())
break;
_healthRegenerationTimer -= diff;
if (_healthRegenerationTimer <= 0)
{
bool isInCombat = IsInCombat() && (!GetVictim() || // if IsInCombat() is true and this has no victim
!EnsureVictim()->GetCharmerOrOwnerPlayerOrPlayerItself() || // or the victim/owner/charmer is not a player
!EnsureVictim()->GetCharmerOrOwnerPlayerOrPlayerItself()->IsGameMaster()); // or the victim/owner/charmer is not a GameMaster
if (!IsInEvadeMode() && (!isInCombat || IsPolymorphed() || CanNotReachTarget())) // regenerate health if not in combat or if polymorphed
RegenerateHealth();
_healthRegenerationTimer += UNIT_HEALTH_REGENERATION_INTERVAL;
}
if (HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_REGENERATE_POWER))
Regenerate(GetPowerType(), diff);
@@ -815,6 +801,13 @@ void Creature::RegenerateHealth()
if (!isRegeneratingHealth())
return;
bool isInCombat = IsInCombat() && (!GetVictim() || // if IsInCombat() is true and this has no victim
!EnsureVictim()->GetCharmerOrOwnerPlayerOrPlayerItself() || // or the victim/owner/charmer is not a player
!EnsureVictim()->GetCharmerOrOwnerPlayerOrPlayerItself()->IsGameMaster()); // or the victim/owner/charmer is not a GameMaster
if (IsInEvadeMode() || (isInCombat && !IsPolymorphed() && !CanNotReachTarget())) // regenerate health if not in combat or if polymorphed
return;
uint32 curValue = GetHealth();
uint32 maxValue = GetMaxHealth();
+1 -2
View File
@@ -320,7 +320,6 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
static float _GetDamageMod(int32 Rank);
int32 _healthRegenerationTimer;
float m_SightDistance;
float m_CombatDistance;
@@ -371,7 +370,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
uint32 m_combatPulseDelay; // (secs) how often the creature puts the entire zone in combat (only works in dungeons)
ReactStates m_reactState; // for AI, not charmInfo
void RegenerateHealth();
void RegenerateHealth() override;
MovementGeneratorType m_defaultMovementType;
ObjectGuid::LowType m_spawnId; ///< For new or temporary creatures is 0 for saved it is lowguid
uint8 m_equipmentId;
@@ -1883,6 +1883,10 @@ void Player::RegenerateAll(uint32 diff)
void Player::RegenerateHealth()
{
// Do not regenerate health when in combat, when not polymorphed or when any regeneration aura allows it
if (IsInCombat() && !IsPolymorphed() && !m_baseHealthRegen && !HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT) && !HasAuraType(SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT))
return;
uint32 curValue = GetHealth();
uint32 maxValue = GetMaxHealth();
+1 -1
View File
@@ -1515,7 +1515,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void SendTalentWipeConfirm(ObjectGuid guid) const;
void ResetPetTalents();
void RegenerateAll(uint32 diff);
void RegenerateHealth();
void RegenerateHealth() override;
void SetRegenerationTimer(uint32 time) { _regenerationTimer = time;}
void setWeaponChangeTimer(uint32 time) { m_weaponChangeTimer = time;}
+10 -1
View File
@@ -416,7 +416,8 @@ Unit::Unit(bool isWorldObject) :
for (uint8 i = 0; i < MAX_POWERS_PER_CLASS; ++i)
_powerFraction[i] = 0;
_regenerationTimer = 0;
_regenerationTimer = GetRegenerationInterval();
_healthRegenerationTimer = UNIT_HEALTH_REGENERATION_INTERVAL;
_oldFactionId = 0;
_isWalkingBeforeCharm = false;
@@ -554,6 +555,14 @@ void Unit::Update(uint32 p_time)
_regenerationTimer -= (GetRegenerationInterval() - p_time);
else
_regenerationTimer += p_time;
// Update Health Regeneration
_healthRegenerationTimer -= p_time;
if (_healthRegenerationTimer <= 0)
{
RegenerateHealth();
_healthRegenerationTimer += UNIT_HEALTH_REGENERATION_INTERVAL;
}
}
bool Unit::haveOffhandWeapon() const
+4 -1
View File
@@ -1057,7 +1057,7 @@ class TC_GAME_API Unit : public WorldObject
void ClearUnitState(uint32 f) { m_state &= ~f; }
bool CanFreeMove() const;
virtual void UpdatePowerRegeneration(Powers powerType) { }
virtual void UpdatePowerRegeneration(Powers /*powerType*/) { }
uint32 HasUnitTypeMask(uint32 mask) const { return mask & m_unitTypeMask; }
void AddUnitTypeMask(uint32 mask) { m_unitTypeMask |= mask; }
@@ -1124,6 +1124,8 @@ class TC_GAME_API Unit : public WorldObject
int32 ModifyPowerPct(Powers power, float pct, bool apply = true);
float GetPowerRegen(Powers powerType, bool isInCombat) const;
virtual void RegenerateHealth() { }
uint32 GetAttackTime(WeaponAttackType att) const;
void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME+att, val*m_modAttackSpeedPct[att]); }
void ApplyAttackTimePercentMod(WeaponAttackType att, float val, bool apply);
@@ -2006,6 +2008,7 @@ class TC_GAME_API Unit : public WorldObject
uint32 _powerBarId;
float _powerFraction[MAX_POWERS_PER_CLASS];
int32 _regenerationTimer;
int32 _healthRegenerationTimer;
bool IsAlwaysVisibleFor(WorldObject const* seer) const override;
bool IsAlwaysDetectableFor(WorldObject const* seer) const override;