Skip to content

Commit

Permalink
[c12858] Initialize power type and power type values for creatures
Browse files Browse the repository at this point in the history
This will assign the correct power type based on UnitClass and will also provide proper values for the scaled powers

(based on commit [12656] - 186069f)

Signed-off-by: Xfurry <xfurry@scriptdev2.com>
  • Loading branch information
xfurry committed Aug 12, 2014
1 parent a4457bd commit d51b3fb
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 15 deletions.
55 changes: 49 additions & 6 deletions src/game/Creature.cpp
Expand Up @@ -294,6 +294,24 @@ bool Creature::InitEntry(uint32 Entry, CreatureData const* data /*=NULL*/, GameE

SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);

// set PowerType based on unit class
switch (cinfo->UnitClass)
{
case CLASS_WARRIOR:
SetByteValue(UNIT_FIELD_BYTES_0, 3, POWER_RAGE);
break;
case CLASS_PALADIN:
case CLASS_MAGE:
SetByteValue(UNIT_FIELD_BYTES_0, 3, POWER_MANA);
break;
case CLASS_ROGUE:
SetByteValue(UNIT_FIELD_BYTES_0, 3, POWER_ENERGY);
break;
default:
sLog.outErrorDb("Creature (Entry: %u) has unhandled unit class. Power type will not be set!", Entry);
break;
}

// Load creature equipment
if (eventData && eventData->equipment_id)
{
Expand Down Expand Up @@ -1205,6 +1223,7 @@ void Creature::SelectLevel(const CreatureInfo* cinfo, float percentHealth, float
// Set values
//////////////////////////////////////////////////////////////////////////

// health
SetCreateHealth(health);
SetMaxHealth(health);

Expand All @@ -1213,14 +1232,38 @@ void Creature::SelectLevel(const CreatureInfo* cinfo, float percentHealth, float
else
SetHealthPercent(percentHealth);

SetCreateMana(mana);
SetMaxPower(POWER_MANA, mana); // MAX Mana
SetPower(POWER_MANA, mana);
SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, float(health));

// all power types
for (int i = POWER_MANA; i <= POWER_RUNIC_POWER; ++i)
{
uint32 maxValue;

// TODO: set UNIT_FIELD_POWER*, for some creature class case (energy, etc)
switch (i)
{
case POWER_MANA: maxValue = mana; break;
case POWER_RAGE: maxValue = 0; break;
case POWER_FOCUS: maxValue = POWER_FOCUS_DEFAULT; break;
case POWER_ENERGY: maxValue = POWER_ENERGY_DEFAULT * cinfo->PowerMultiplier; break;
case POWER_RUNE: maxValue = 0; break;
case POWER_RUNIC_POWER: maxValue = 0; break;
}

SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, float(health));
SetModifierValue(UNIT_MOD_MANA, BASE_VALUE, float(mana));
uint32 value = maxValue;

// For non regenerating powers set 0
if ((i == POWER_ENERGY || i == POWER_MANA) && !IsRegeneratingPower())
value = 0;

// Mana requires an extra field to be set
if (i == POWER_MANA)
SetCreateMana(value);

// Do not use the wrappers for setting power, to avoid side-effects
SetStatInt32Value(UNIT_FIELD_MAXPOWER1 + i , maxValue);
SetStatInt32Value(UNIT_FIELD_POWER1 +i, value);
SetModifierValue(UnitMods(UNIT_MOD_POWER_START + i), BASE_VALUE, float(value));
}

// damage
float damagemod = _GetDamageMod(rank);
Expand Down
16 changes: 8 additions & 8 deletions src/game/Unit.cpp
Expand Up @@ -10236,14 +10236,14 @@ uint32 Unit::GetCreatePowers(Powers power) const
{
case POWER_HEALTH: return 0; // is it really should be here?
case POWER_MANA: return GetCreateMana();
case POWER_RAGE: return 1000;
case POWER_RAGE: return POWER_RAGE_DEFAULT;
case POWER_FOCUS:
if(GetTypeId() == TYPEID_PLAYER && ((Player const*)this)->getClass() == CLASS_HUNTER)
return 100;
return (GetTypeId() == TYPEID_PLAYER || !((Creature const*)this)->IsPet() || ((Pet const*)this)->getPetType() != HUNTER_PET ? 0 : 100);
case POWER_ENERGY: return 100;
case POWER_RUNE: return GetTypeId() == TYPEID_PLAYER && ((Player const*)this)->getClass() == CLASS_DEATH_KNIGHT ? 8 : 0;
case POWER_RUNIC_POWER: return GetTypeId() == TYPEID_PLAYER && ((Player const*)this)->getClass() == CLASS_DEATH_KNIGHT ? 1000 : 0;
return POWER_FOCUS_DEFAULT;
return (GetTypeId() == TYPEID_PLAYER || !((Creature const*)this)->IsPet() || ((Pet const*)this)->getPetType() != HUNTER_PET ? 0 : POWER_FOCUS_DEFAULT);
case POWER_ENERGY: return POWER_ENERGY_DEFAULT;
case POWER_RUNE: return GetTypeId() == TYPEID_PLAYER && ((Player const*)this)->getClass() == CLASS_DEATH_KNIGHT ? POWER_RUNE_DEFAULT : 0;
case POWER_RUNIC_POWER: return GetTypeId() == TYPEID_PLAYER && ((Player const*)this)->getClass() == CLASS_DEATH_KNIGHT ? POWER_RUNIC_POWER_DEFAULT : 0;
case POWER_SOUL_SHARDS: return 0;
case POWER_ECLIPSE: return 0; // TODO: fix me
case POWER_HOLY_POWER: return 0;
Expand All @@ -10257,9 +10257,9 @@ uint32 Unit::GetCreateMaxPowers(Powers power) const
switch (power)
{
case POWER_HOLY_POWER:
return GetTypeId() == TYPEID_PLAYER && ((Player const*)this)->getClass() == CLASS_PALADIN ? 3 : 0;
return GetTypeId() == TYPEID_PLAYER && ((Player const*)this)->getClass() == CLASS_PALADIN ? POWER_HOLY_POWER_DEFAULT : 0;
case POWER_SOUL_SHARDS:
return GetTypeId() == TYPEID_PLAYER && ((Player const*)this)->getClass() == CLASS_WARLOCK ? 3 : 0;
return GetTypeId() == TYPEID_PLAYER && ((Player const*)this)->getClass() == CLASS_WARLOCK ? POWER_SOUL_SHARDS_DEFAULT : 0;
default:
return GetCreatePowers(power);
}
Expand Down
12 changes: 12 additions & 0 deletions src/game/Unit.h
Expand Up @@ -1165,6 +1165,18 @@ enum IgnoreUnitState
#define REGEN_TIME_PRECISE 500 // Used in Spell::CheckPower for precise regeneration in spell cast time
#define REGEN_TIME_HOLY_POWER 10000 // This determines how often holy power regen is processed

// Power type values defines
enum PowerDefaults
{
POWER_RAGE_DEFAULT = 1000,
POWER_FOCUS_DEFAULT = 100,
POWER_ENERGY_DEFAULT = 100,
POWER_RUNE_DEFAULT = 8,
POWER_RUNIC_POWER_DEFAULT = 1000,
POWER_HOLY_POWER_DEFAULT = 3,
POWER_SOUL_SHARDS_DEFAULT = 3,
};

struct SpellProcEventEntry; // used only privately

#define MAX_OBJECT_SLOT 5
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 "12857"
#define REVISION_NR "12858"
#endif // __REVISION_NR_H__

0 comments on commit d51b3fb

Please sign in to comment.