Skip to content

Commit

Permalink
[9427] Add helper functions for Unit::Get/SetHealthPercent
Browse files Browse the repository at this point in the history
Signed-off-by: NoFantasy <nofantasy@nf.no>
  • Loading branch information
NoFantasy committed Feb 21, 2010
1 parent 28dfc8c commit cd2bb44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/game/Unit.cpp
Expand Up @@ -11649,6 +11649,12 @@ void Unit::SetMaxHealth(uint32 val)
SetHealth(val);
}

void Unit::SetHealthPercent(float percent)
{
uint32 newHealth = GetMaxHealth() * percent/100.0f;
SetHealth(newHealth);
}

void Unit::SetPower(Powers power, uint32 val)
{
if(GetPower(power) == val)
Expand Down
2 changes: 2 additions & 0 deletions src/game/Unit.h
Expand Up @@ -1160,8 +1160,10 @@ class MANGOS_DLL_SPEC Unit : public WorldObject

uint32 GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH); }
uint32 GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH); }
float GetHealthPercent() const { return (GetHealth()*100.0f) / GetMaxHealth(); }
void SetHealth( uint32 val);
void SetMaxHealth(uint32 val);
void SetHealthPercent(float percent);
int32 ModifyHealth(int32 val);

Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, 3)); }
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9426"
#define REVISION_NR "9427"
#endif // __REVISION_NR_H__

0 comments on commit cd2bb44

Please sign in to comment.