aboutsummaryrefslogtreecommitdiff
path: root/src/server/game
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2018-03-07 03:32:32 -0300
committerariel- <ariel-@users.noreply.github.com>2018-03-07 03:34:45 -0300
commit6e0b9a7916d158981cebe6107710141458d656cc (patch)
tree2a44ad4e6049a7ed60b04ffbb8dd7f86d30d44a3 /src/server/game
parent68dde9f8c5467c5983078b190e58105f99dad75c (diff)
Core/Creatures: port power type updates from master branch
Core/Misc: Added helper function Unit::SetFullPower Cherry-picked from 8199eef81cad464bb43f3613ed884a2c8fc3973d Core/Creatures: Updated power type handling (#20981) Cherry-picked from 16a7a414abcc93c4514905b871f53c1049261c12
Diffstat (limited to 'src/server/game')
-rw-r--r--src/server/game/AI/CoreAI/UnitAI.cpp2
-rw-r--r--src/server/game/AI/PlayerAI/PlayerAI.cpp2
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp18
-rw-r--r--src/server/game/Entities/Creature/TemporarySummon.h21
-rw-r--r--src/server/game/Entities/Pet/Pet.cpp19
-rw-r--r--src/server/game/Entities/Player/Player.cpp84
-rw-r--r--src/server/game/Entities/Unit/StatSystem.cpp12
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp92
-rw-r--r--src/server/game/Entities/Unit/Unit.h6
-rwxr-xr-xsrc/server/game/Entities/Vehicle/Vehicle.cpp8
-rw-r--r--src/server/game/Handlers/GroupHandler.cpp16
-rw-r--r--src/server/game/Spells/Auras/SpellAuraEffects.cpp23
-rw-r--r--src/server/game/Spells/Auras/SpellAuras.cpp2
-rw-r--r--src/server/game/Spells/Spell.cpp4
-rw-r--r--src/server/game/Spells/SpellEffects.cpp12
15 files changed, 167 insertions, 154 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp
index c36db401f59..0d8700fb091 100644
--- a/src/server/game/AI/CoreAI/UnitAI.cpp
+++ b/src/server/game/AI/CoreAI/UnitAI.cpp
@@ -372,7 +372,7 @@ bool PowerUsersSelector::operator()(Unit const* target) const
if (!_me || !target)
return false;
- if (target->getPowerType() != _power)
+ if (target->GetPowerType() != _power)
return false;
if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER)
diff --git a/src/server/game/AI/PlayerAI/PlayerAI.cpp b/src/server/game/AI/PlayerAI/PlayerAI.cpp
index 69a5bc45f1f..677d39ca322 100644
--- a/src/server/game/AI/PlayerAI/PlayerAI.cpp
+++ b/src/server/game/AI/PlayerAI/PlayerAI.cpp
@@ -919,7 +919,7 @@ PlayerAI::TargetedSpell SimpleCharmedPlayerAI::SelectAppropriateCastForSpec()
VerifyAndPushSpellCast(spells, SPELL_FREEZING_ARROW, TARGET_VICTIM, 2);
VerifyAndPushSpellCast(spells, SPELL_RAPID_FIRE, TARGET_NONE, 10);
VerifyAndPushSpellCast(spells, SPELL_KILL_SHOT, TARGET_VICTIM, 10);
- if (me->GetVictim() && me->GetVictim()->getPowerType() == POWER_MANA && !me->GetVictim()->GetAuraApplicationOfRankedSpell(SPELL_VIPER_STING, me->GetGUID()))
+ if (me->GetVictim() && me->GetVictim()->GetPowerType() == POWER_MANA && !me->GetVictim()->GetAuraApplicationOfRankedSpell(SPELL_VIPER_STING, me->GetGUID()))
VerifyAndPushSpellCast(spells, SPELL_VIPER_STING, TARGET_VICTIM, 5);
switch (GetSpec())
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 5aae0f6db05..3a061c816bc 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -825,7 +825,7 @@ void Creature::Update(uint32 diff)
if (!IsInEvadeMode() && (!bInCombat || IsPolymorphed() || CanNotReachTarget())) // regenerate health if not in combat or if polymorphed
RegenerateHealth();
- if (getPowerType() == POWER_ENERGY)
+ if (GetPowerType() == POWER_ENERGY)
Regenerate(POWER_ENERGY);
else
Regenerate(POWER_MANA);
@@ -1439,18 +1439,22 @@ void Creature::UpdateLevelDependantStats()
// mana
uint32 mana = stats->GenerateMana(cInfo);
-
SetCreateMana(mana);
- SetMaxPower(POWER_MANA, mana); // MAX Mana
- SetPower(POWER_MANA, mana);
- /// @todo set UNIT_FIELD_POWER*, for some creature class case (energy, etc)
+ switch (getClass())
+ {
+ case UNIT_CLASS_PALADIN:
+ case UNIT_CLASS_MAGE:
+ SetMaxPower(POWER_MANA, mana);
+ SetFullPower(POWER_MANA);
+ break;
+ default: // We don't set max power here, 0 makes power bar hidden
+ break;
+ }
SetStatFlatModifier(UNIT_MOD_HEALTH, BASE_VALUE, (float)health);
- SetStatFlatModifier(UNIT_MOD_MANA, BASE_VALUE, (float)mana);
// damage
-
float basedamage = stats->GenerateBaseDamage(cInfo);
float weaponBaseMinDamage = basedamage;
diff --git a/src/server/game/Entities/Creature/TemporarySummon.h b/src/server/game/Entities/Creature/TemporarySummon.h
index ed09b3304cc..3fa20dbeabc 100644
--- a/src/server/game/Entities/Creature/TemporarySummon.h
+++ b/src/server/game/Entities/Creature/TemporarySummon.h
@@ -21,6 +21,16 @@
#include "Creature.h"
+enum PetEntry : uint32
+{
+ // Death Knight pets
+ PET_GHOUL = 26125,
+ PET_RISEN_ALLY = 30230,
+
+ // Shaman pet
+ PET_SPIRIT_WOLF = 29264
+};
+
struct SummonPropertiesEntry;
class TC_GAME_API TempSummon : public Creature
@@ -59,10 +69,15 @@ class TC_GAME_API Minion : public TempSummon
Unit* GetOwner() const { return m_owner; }
float GetFollowAngle() const override { return m_followAngle; }
void SetFollowAngle(float angle) { m_followAngle = angle; }
- bool IsPetGhoul() const { return GetEntry() == 26125; } // Ghoul may be guardian or pet
- bool IsSpiritWolf() const { return GetEntry() == 29264; } // Spirit wolf from feral spirits
+
+ // Death Knight pets
+ bool IsPetGhoul() const { return GetEntry() == PET_GHOUL; } // Ghoul may be guardian or pet
+ bool IsRisenAlly() const { return GetEntry() == PET_RISEN_ALLY; }
+
+ // Shaman pet
+ bool IsSpiritWolf() const { return GetEntry() == PET_SPIRIT_WOLF; } // Spirit wolf from feral spirits
+
bool IsGuardianPet() const;
- bool IsRisenAlly() const { return GetEntry() == 30230; }
protected:
Unit* const m_owner;
float m_followAngle;
diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp
index df32c680c09..cf6f1094dce 100644
--- a/src/server/game/Entities/Pet/Pet.cpp
+++ b/src/server/game/Entities/Pet/Pet.cpp
@@ -222,7 +222,6 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool c
case HUNTER_PET:
SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_CLASS, CLASS_WARRIOR);
SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_GENDER, GENDER_NONE);
- SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_POWER_TYPE, POWER_FOCUS);
SetSheath(SHEATH_STATE_MELEE);
SetByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PET_FLAGS, fields[9].GetBool() ? UNIT_CAN_BE_ABANDONED : UNIT_CAN_BE_RENAMED | UNIT_CAN_BE_ABANDONED);
@@ -592,7 +591,7 @@ void Pet::Update(uint32 diff)
m_focusRegenTimer -= diff;
else
{
- switch (getPowerType())
+ switch (GetPowerType())
{
case POWER_FOCUS:
Regenerate(POWER_FOCUS);
@@ -773,7 +772,6 @@ bool Pet::CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phas
SetMaxPower(POWER_HAPPINESS, GetCreatePowers(POWER_HAPPINESS));
SetPower(POWER_HAPPINESS, 166500);
- setPowerType(POWER_FOCUS);
SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32(sObjectMgr->GetXPForLevel(getLevel()+1)*PET_XP_FACTOR));
@@ -783,7 +781,6 @@ bool Pet::CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phas
{
SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_CLASS, CLASS_WARRIOR);
SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_GENDER, GENDER_NONE);
- SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_POWER_TYPE, POWER_FOCUS);
SetSheath(SHEATH_STATE_MELEE);
SetByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PET_FLAGS, UNIT_CAN_BE_RENAMED | UNIT_CAN_BE_ABANDONED);
}
@@ -854,13 +851,12 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
for (uint8 i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
SetStatFlatModifier(UnitMods(UNIT_MOD_RESISTANCE_START + i), BASE_VALUE, float(cinfo->resistance[i]));
- //health, mana, armor and resistance
+ // Health, Mana or Power, Armor
PetLevelInfo const* pInfo = sObjectMgr->GetPetLevelInfo(creature_ID, petlevel);
if (pInfo) // exist in DB
{
SetCreateHealth(pInfo->health);
- if (petType != HUNTER_PET) //hunter pet use focus
- SetCreateMana(pInfo->mana);
+ SetCreateMana(pInfo->mana);
if (pInfo->armor > 0)
SetStatFlatModifier(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor));
@@ -882,6 +878,15 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
SetCreateStat(STAT_SPIRIT, 27);
}
+ // Power
+ if (petType == HUNTER_PET) // Hunter pets have focus
+ SetPowerType(POWER_FOCUS);
+ else if (IsPetGhoul() || IsRisenAlly()) // DK pets have energy
+ SetPowerType(POWER_ENERGY);
+ else
+ SetPowerType(POWER_MANA);
+
+ // Damage
SetBonusDamage(0);
switch (petType)
{
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index c632c8b7cea..6f5ec8a8f09 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -586,19 +586,7 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
// apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()
UpdateMaxHealth(); // Update max Health (for add bonus from stamina)
SetFullHealth();
- if (getPowerType() == POWER_MANA)
- {
- UpdateMaxPower(POWER_MANA); // Update max Mana (for add bonus from intellect)
- SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
- }
-
- if (getPowerType() == POWER_RUNIC_POWER)
- {
- SetPower(POWER_RUNE, 8);
- SetMaxPower(POWER_RUNE, 8);
- SetPower(POWER_RUNIC_POWER, 0);
- SetMaxPower(POWER_RUNIC_POWER, 1000);
- }
+ SetFullPower(POWER_MANA);
// original spells
LearnDefaultSkills();
@@ -2195,17 +2183,17 @@ void Player::RegenerateHealth()
void Player::ResetAllPowers()
{
- SetHealth(GetMaxHealth());
- switch (getPowerType())
+ SetFullHealth();
+ switch (GetPowerType())
{
case POWER_MANA:
- SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
+ SetFullPower(POWER_MANA);
break;
case POWER_RAGE:
SetPower(POWER_RAGE, 0);
break;
case POWER_ENERGY:
- SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY));
+ SetFullPower(POWER_ENERGY);
break;
case POWER_RUNIC_POWER:
SetPower(POWER_RUNIC_POWER, 0);
@@ -2630,12 +2618,7 @@ void Player::GiveLevel(uint8 level)
// set current level health and mana/energy to maximum after applying all mods.
SetFullHealth();
- SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
- SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY));
- if (GetPower(POWER_RAGE) > GetMaxPower(POWER_RAGE))
- SetPower(POWER_RAGE, GetMaxPower(POWER_RAGE));
- SetPower(POWER_FOCUS, 0);
- SetPower(POWER_HAPPINESS, 0);
+ SetFullPower(POWER_MANA);
// update level to hunter/summon pet
if (Pet* pet = GetPet())
@@ -2852,11 +2835,11 @@ void Player::InitStatsForLevel(bool reapplyMods)
// set current level health and mana/energy to maximum after applying all mods.
SetFullHealth();
- SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
- SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY));
+ SetFullPower(POWER_MANA);
+ SetFullPower(POWER_ENERGY);
if (GetPower(POWER_RAGE) > GetMaxPower(POWER_RAGE))
- SetPower(POWER_RAGE, GetMaxPower(POWER_RAGE));
- SetPower(POWER_FOCUS, 0);
+ SetFullPower(POWER_RAGE);
+ SetFullPower(POWER_FOCUS);
SetPower(POWER_HAPPINESS, 0);
SetPower(POWER_RUNIC_POWER, 0);
@@ -17534,6 +17517,7 @@ bool Player::LoadFromDB(ObjectGuid guid, SQLQueryHolder *holder)
m_activeSpec = 0;
}
+ UpdateDisplayPower();
_LoadTalents(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_TALENTS));
_LoadSpells(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_SPELLS));
@@ -17599,11 +17583,11 @@ bool Player::LoadFromDB(ObjectGuid guid, SQLQueryHolder *holder)
// restore remembered power/health values (but not more max values)
uint32 savedHealth = fields[55].GetUInt32();
- SetHealth(savedHealth > GetMaxHealth() ? GetMaxHealth() : savedHealth);
+ SetHealth(savedHealth);
for (uint8 i = 0; i < MAX_POWERS; ++i)
{
uint32 savedPower = fields[56 + i].GetUInt32();
- SetPower(Powers(i), savedPower > GetMaxPower(Powers(i)) ? GetMaxPower(Powers(i)) : savedPower);
+ SetPower(static_cast<Powers>(i), savedPower);
}
TC_LOG_DEBUG("entities.player.loading", "Player::LoadFromDB: The value of player '%s' after load item and aura is: ", m_name.c_str());
@@ -21340,30 +21324,7 @@ void Player::InitDataForForm(bool reapplyMods)
else
SetRegularAttackTime();
- switch (form)
- {
- case FORM_GHOUL:
- case FORM_CAT:
- {
- if (getPowerType() != POWER_ENERGY)
- setPowerType(POWER_ENERGY);
- break;
- }
- case FORM_BEAR:
- case FORM_DIREBEAR:
- {
- if (getPowerType() != POWER_RAGE)
- setPowerType(POWER_RAGE);
- break;
- }
- default: // 0, for example
- {
- ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(getClass());
- if (cEntry && cEntry->powerType < MAX_POWERS && uint32(getPowerType()) != cEntry->powerType)
- setPowerType(Powers(cEntry->powerType));
- break;
- }
- }
+ UpdateDisplayPower();
// update auras at form change, ignore this at mods reapply (.reset stats/etc) when form not change.
if (!reapplyMods)
@@ -23732,19 +23693,11 @@ void Player::ResurrectUsingRequestDataImpl()
ResurrectPlayer(0.0f, false);
- if (GetMaxHealth() > resurrectHealth)
- SetHealth(resurrectHealth);
- else
- SetFullHealth();
-
- if (GetMaxPower(POWER_MANA) > resurrectMana)
- SetPower(POWER_MANA, resurrectMana);
- else
- SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
+ SetHealth(resurrectHealth);
+ SetPower(POWER_MANA, resurrectMana);
SetPower(POWER_RAGE, 0);
-
- SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY));
+ SetFullPower(POWER_ENERGY);
SpawnCorpseBones();
}
@@ -25914,7 +25867,7 @@ void Player::ActivateSpec(uint8 spec)
}));
}
- Powers pw = getPowerType();
+ Powers pw = GetPowerType();
if (pw != POWER_MANA)
SetPower(POWER_MANA, 0); // Mana must be 0 even if it isn't the active power type.
@@ -26442,7 +26395,6 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy
pet->SetCreatorGUID(GetGUID());
pet->SetFaction(GetFaction());
- pet->setPowerType(POWER_MANA);
pet->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
pet->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
pet->InitStatsForLevel(getLevel());
diff --git a/src/server/game/Entities/Unit/StatSystem.cpp b/src/server/game/Entities/Unit/StatSystem.cpp
index 46f1c50c11e..eba057a6c67 100644
--- a/src/server/game/Entities/Unit/StatSystem.cpp
+++ b/src/server/game/Entities/Unit/StatSystem.cpp
@@ -326,7 +326,7 @@ void Player::UpdateMaxPower(Powers power)
value += GetFlatModifierValue(unitMod, TOTAL_VALUE) + bonusPower;
value *= GetPctModifierValue(unitMod, TOTAL_PCT);
- SetMaxPower(power, uint32(value));
+ SetMaxPower(power, uint32(std::lroundf(value)));
}
void Player::ApplyFeralAPBonus(int32 amount, bool apply)
@@ -1029,8 +1029,12 @@ void Creature::UpdateMaxPower(Powers power)
{
UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + power);
- float value = GetTotalAuraModValue(unitMod);
- SetMaxPower(power, uint32(value));
+ float value = GetFlatModifierValue(unitMod, BASE_VALUE) + GetCreatePowers(power);
+ value *= GetPctModifierValue(unitMod, BASE_PCT);
+ value += GetFlatModifierValue(unitMod, TOTAL_VALUE);
+ value *= GetPctModifierValue(unitMod, TOTAL_PCT);
+
+ SetMaxPower(power, uint32(std::lroundf(value)));
}
void Creature::UpdateAttackPowerAndDamage(bool ranged)
@@ -1237,6 +1241,8 @@ bool Guardian::UpdateStats(Stats stat)
bool Guardian::UpdateAllStats()
{
+ UpdateMaxHealth();
+
for (uint8 i = STAT_STRENGTH; i < MAX_STATS; ++i)
UpdateStats(Stats(i));
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index ce611130ddc..e811a87e227 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -729,7 +729,7 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit* excludeCasterChannel) cons
}
// Rage from Damage made (only from direct weapon damage)
- if (attacker && cleanDamage && damagetype == DIRECT_DAMAGE && attacker != victim && attacker->getPowerType() == POWER_RAGE)
+ if (attacker && cleanDamage && damagetype == DIRECT_DAMAGE && attacker != victim && attacker->GetPowerType() == POWER_RAGE)
{
uint32 weaponSpeedHitFactor;
@@ -755,7 +755,7 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit* excludeCasterChannel) cons
if (!damage)
{
// Rage from absorbed damage
- if (cleanDamage && cleanDamage->absorbed_damage && victim->getPowerType() == POWER_RAGE)
+ if (cleanDamage && cleanDamage->absorbed_damage && victim->GetPowerType() == POWER_RAGE)
victim->RewardRage(cleanDamage->absorbed_damage, 0, false);
return 0;
@@ -857,7 +857,7 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit* excludeCasterChannel) cons
}
// Rage from damage received
- if (attacker != victim && victim->getPowerType() == POWER_RAGE)
+ if (attacker != victim && victim->GetPowerType() == POWER_RAGE)
{
rage_damage = damage + (cleanDamage ? cleanDamage->absorbed_damage : 0);
victim->RewardRage(rage_damage, 0, false);
@@ -5541,9 +5541,9 @@ void Unit::SendAttackStateUpdate(uint32 HitInfo, Unit* target, uint8 /*SwingType
SendAttackStateUpdate(&dmgInfo);
}
-void Unit::setPowerType(Powers new_powertype)
+void Unit::SetPowerType(Powers new_powertype)
{
- if (getPowerType() == new_powertype)
+ if (GetPowerType() == new_powertype)
return;
SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_POWER_TYPE, new_powertype);
@@ -5563,32 +5563,73 @@ void Unit::setPowerType(Powers new_powertype)
}
}
- float powerMultiplier = 1.0f;
- if (!IsPet())
- if (Creature* creature = ToCreature())
- powerMultiplier = creature->GetCreatureTemplate()->ModMana;
+ // Update max power
+ UpdateMaxPower(new_powertype);
+ // Update current power
switch (new_powertype)
{
- default:
- case POWER_MANA:
+ case POWER_MANA: // Keep the same (druid form switching...)
+ case POWER_ENERGY:
break;
- case POWER_RAGE:
- SetMaxPower(POWER_RAGE, uint32(std::ceil(GetCreatePowers(POWER_RAGE) * powerMultiplier)));
+ case POWER_RAGE: // Reset to zero
SetPower(POWER_RAGE, 0);
break;
- case POWER_FOCUS:
- SetMaxPower(POWER_FOCUS, uint32(std::ceil(GetCreatePowers(POWER_FOCUS) * powerMultiplier)));
- SetPower(POWER_FOCUS, uint32(std::ceil(GetCreatePowers(POWER_FOCUS) * powerMultiplier)));
+ case POWER_FOCUS: // Make it full
+ SetFullPower(new_powertype);
break;
- case POWER_ENERGY:
- SetMaxPower(POWER_ENERGY, uint32(std::ceil(GetCreatePowers(POWER_ENERGY) * powerMultiplier)));
+ default:
+ break;
+ }
+}
+
+void Unit::UpdateDisplayPower()
+{
+ Powers displayPower = POWER_MANA;
+ switch (GetShapeshiftForm())
+ {
+ case FORM_GHOUL:
+ case FORM_CAT:
+ displayPower = POWER_ENERGY;
+ break;
+ case FORM_BEAR:
+ case FORM_DIREBEAR:
+ displayPower = POWER_RAGE;
break;
- case POWER_HAPPINESS:
- SetMaxPower(POWER_HAPPINESS, uint32(std::ceil(GetCreatePowers(POWER_HAPPINESS) * powerMultiplier)));
- SetPower(POWER_HAPPINESS, uint32(std::ceil(GetCreatePowers(POWER_HAPPINESS) * powerMultiplier)));
+ case FORM_TRAVEL:
+ case FORM_GHOSTWOLF:
+ displayPower = POWER_MANA;
+ break;
+ default:
+ {
+ if (GetTypeId() == TYPEID_PLAYER)
+ {
+ ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(getClass());
+ if (cEntry && cEntry->powerType < MAX_POWERS)
+ displayPower = Powers(cEntry->powerType);
+ }
+ else if (GetTypeId() == TYPEID_UNIT)
+ {
+ if (Vehicle* vehicle = GetVehicleKit())
+ {
+ if (PowerDisplayEntry const* powerDisplay = sPowerDisplayStore.LookupEntry(vehicle->GetVehicleInfo()->m_powerDisplayId))
+ displayPower = Powers(powerDisplay->PowerType);
+ else if (getClass() == CLASS_ROGUE)
+ displayPower = POWER_ENERGY;
+ }
+ else if (Pet* pet = ToPet())
+ {
+ if (pet->getPetType() == HUNTER_PET) // Hunter pets have focus
+ displayPower = POWER_FOCUS;
+ else if (pet->IsPetGhoul() || pet->IsRisenAlly()) // DK pets have energy
+ displayPower = POWER_ENERGY;
+ }
+ }
break;
+ }
}
+
+ SetPowerType(displayPower);
}
FactionTemplateEntry const* Unit::GetFactionTemplateEntry() const
@@ -6303,14 +6344,9 @@ void Unit::SetMinion(Minion *minion, bool apply)
for (uint8 i = 0; i < MAX_MOVE_TYPE; ++i)
minion->SetSpeedRate(UnitMoveType(i), m_speed_rate[i]);
- // Ghoul pets have energy instead of mana (is anywhere better place for this code?)
- if (minion->IsPetGhoul() || minion->IsRisenAlly())
- minion->setPowerType(POWER_ENERGY);
-
// Send infinity cooldown - client does that automatically but after relog cooldown needs to be set again
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(minion->GetUInt32Value(UNIT_CREATED_BY_SPELL));
-
- if (spellInfo && (spellInfo->IsCooldownStartedOnEvent()))
+ if (spellInfo && spellInfo->IsCooldownStartedOnEvent())
GetSpellHistory()->StartCooldown(spellInfo, 0, nullptr, true);
}
else
@@ -9366,7 +9402,7 @@ void Unit::setDeathState(DeathState s)
// without this when removing IncreaseMaxHealth aura player may stuck with 1 hp
// do not why since in IncreaseMaxHealth currenthealth is checked
SetHealth(0);
- SetPower(getPowerType(), 0);
+ SetPower(GetPowerType(), 0);
SetUInt32Value(UNIT_NPC_EMOTESTATE, 0);
// players in instance don't have ZoneScript, but they have InstanceScript
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index f133013161f..d464861f2ea 100644
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -878,12 +878,14 @@ class TC_GAME_API Unit : public WorldObject
int32 ModifyHealth(int32 val);
int32 GetHealthGain(int32 dVal);
- Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_POWER_TYPE)); }
- void setPowerType(Powers power);
+ Powers GetPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_POWER_TYPE)); }
+ void SetPowerType(Powers power);
+ void UpdateDisplayPower();
uint32 GetPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1 +power); }
uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1+power); }
void SetPower(Powers power, uint32 val);
void SetMaxPower(Powers power, uint32 val);
+ inline void SetFullPower(Powers power) { SetPower(power, GetMaxPower(power)); }
// returns the change in power
int32 ModifyPower(Powers power, int32 val);
diff --git a/src/server/game/Entities/Vehicle/Vehicle.cpp b/src/server/game/Entities/Vehicle/Vehicle.cpp
index b4fce815cc6..898a7a6e043 100755
--- a/src/server/game/Entities/Vehicle/Vehicle.cpp
+++ b/src/server/game/Entities/Vehicle/Vehicle.cpp
@@ -75,14 +75,6 @@ Vehicle::~Vehicle()
void Vehicle::Install()
{
- if (_me->GetTypeId() == TYPEID_UNIT)
- {
- if (PowerDisplayEntry const* powerDisplay = sPowerDisplayStore.LookupEntry(_vehicleInfo->m_powerDisplayId))
- _me->setPowerType(Powers(powerDisplay->PowerType));
- else if (_me->getClass() == CLASS_ROGUE)
- _me->setPowerType(POWER_ENERGY);
- }
-
_status = STATUS_INSTALLED;
if (GetBase()->GetTypeId() == TYPEID_UNIT)
sScriptMgr->OnInstall(this);
diff --git a/src/server/game/Handlers/GroupHandler.cpp b/src/server/game/Handlers/GroupHandler.cpp
index bc2e552b47c..b52386f2778 100644
--- a/src/server/game/Handlers/GroupHandler.cpp
+++ b/src/server/game/Handlers/GroupHandler.cpp
@@ -781,7 +781,7 @@ void WorldSession::BuildPartyMemberStatsChangedPacket(Player* player, WorldPacke
if (mask & GROUP_UPDATE_FLAG_MAX_HP)
*data << uint32(player->GetMaxHealth());
- Powers powerType = player->getPowerType();
+ Powers powerType = player->GetPowerType();
if (mask & GROUP_UPDATE_FLAG_POWER_TYPE)
*data << uint8(powerType);
@@ -862,7 +862,7 @@ void WorldSession::BuildPartyMemberStatsChangedPacket(Player* player, WorldPacke
if (mask & GROUP_UPDATE_FLAG_PET_POWER_TYPE)
{
if (pet)
- *data << uint8(pet->getPowerType());
+ *data << uint8(pet->GetPowerType());
else
*data << uint8(0);
}
@@ -870,7 +870,7 @@ void WorldSession::BuildPartyMemberStatsChangedPacket(Player* player, WorldPacke
if (mask & GROUP_UPDATE_FLAG_PET_CUR_POWER)
{
if (pet)
- *data << uint16(pet->GetPower(pet->getPowerType()));
+ *data << uint16(pet->GetPower(pet->GetPowerType()));
else
*data << uint16(0);
}
@@ -878,7 +878,7 @@ void WorldSession::BuildPartyMemberStatsChangedPacket(Player* player, WorldPacke
if (mask & GROUP_UPDATE_FLAG_PET_MAX_POWER)
{
if (pet)
- *data << uint16(pet->GetMaxPower(pet->getPowerType()));
+ *data << uint16(pet->GetMaxPower(pet->GetPowerType()));
else
*data << uint16(0);
}
@@ -932,7 +932,7 @@ void WorldSession::HandleRequestPartyMemberStatsOpcode(WorldPacket &recvData)
}
Pet* pet = player->GetPet();
- Powers powerType = player->getPowerType();
+ Powers powerType = player->GetPowerType();
WorldPacket data(SMSG_PARTY_MEMBER_STATS_FULL, 4+2+2+2+1+2*6+8+1+8);
data << uint8(0); // only for SMSG_PARTY_MEMBER_STATS_FULL, probably arena/bg related
@@ -1016,13 +1016,13 @@ void WorldSession::HandleRequestPartyMemberStatsOpcode(WorldPacket &recvData)
data << uint32(pet->GetMaxHealth());
if (updateFlags & GROUP_UPDATE_FLAG_PET_POWER_TYPE)
- data << (uint8)pet->getPowerType();
+ data << (uint8)pet->GetPowerType();
if (updateFlags & GROUP_UPDATE_FLAG_PET_CUR_POWER)
- data << uint16(pet->GetPower(pet->getPowerType()));
+ data << uint16(pet->GetPower(pet->GetPowerType()));
if (updateFlags & GROUP_UPDATE_FLAG_PET_MAX_POWER)
- data << uint16(pet->GetMaxPower(pet->getPowerType()));
+ data << uint16(pet->GetMaxPower(pet->GetPowerType()));
uint64 petAuraMask = 0;
maskPos = data.wpos();
diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
index 5f7cfe21584..2eb09d0907d 100644
--- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp
+++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
@@ -1703,8 +1703,8 @@ void AuraEffect::HandleAuraModShapeshift(AuraApplication const* aurApp, uint8 mo
{
uint32 oldPower = target->GetPower(PowerType);
// reset power to default values only at power change
- if (target->getPowerType() != PowerType)
- target->setPowerType(PowerType);
+ if (target->GetPowerType() != PowerType)
+ target->SetPowerType(PowerType);
switch (form)
{
@@ -1713,7 +1713,7 @@ void AuraEffect::HandleAuraModShapeshift(AuraApplication const* aurApp, uint8 mo
case FORM_DIREBEAR:
{
// get furor proc chance
- uint32 FurorChance = 0;
+ int32 FurorChance = 0;
if (AuraEffect const* dummy = target->GetDummyAuraEffect(SPELLFAMILY_DRUID, 238, 0))
FurorChance = std::max(dummy->GetAmount(), 0);
@@ -1722,19 +1722,19 @@ void AuraEffect::HandleAuraModShapeshift(AuraApplication const* aurApp, uint8 mo
case FORM_CAT:
{
CastSpellExtraArgs args(this);
- args.AddSpellMod(SPELLVALUE_BASE_POINT0, std::min(oldPower, FurorChance));
+ args.AddSpellMod(SPELLVALUE_BASE_POINT0, std::min<int32>(oldPower, FurorChance));
target->SetPower(POWER_ENERGY, 0);
target->CastSpell(target, 17099, args);
break;
}
case FORM_BEAR:
case FORM_DIREBEAR:
- if (urand(0, 99) < FurorChance)
+ if (roll_chance_i(FurorChance))
target->CastSpell(target, 17057, true);
break;
default:
{
- uint32 newEnergy = std::min(target->GetPower(POWER_ENERGY), FurorChance);
+ uint32 newEnergy = std::min<int32>(target->GetPower(POWER_ENERGY), FurorChance);
target->SetPower(POWER_ENERGY, newEnergy);
break;
}
@@ -1771,7 +1771,6 @@ void AuraEffect::HandleAuraModShapeshift(AuraApplication const* aurApp, uint8 mo
target->SetShapeshiftForm(FORM_NONE);
if (target->getClass() == CLASS_DRUID)
{
- target->setPowerType(POWER_MANA);
// Remove movement impairing effects also when shifting out
target->RemoveAurasByShapeShift();
}
@@ -1833,6 +1832,8 @@ void AuraEffect::HandleAuraModShapeshift(AuraApplication const* aurApp, uint8 mo
if (target->GetTypeId() == TYPEID_PLAYER)
target->ToPlayer()->InitDataForForm();
+ else
+ target->UpdateDisplayPower();
if (target->getClass() == CLASS_DRUID)
{
@@ -5437,7 +5438,7 @@ void AuraEffect::HandlePeriodicManaLeechAuraTick(Unit* target, Unit* caster) con
{
Powers powerType = Powers(GetMiscValue());
- if (!caster || !caster->IsAlive() || !target->IsAlive() || target->getPowerType() != powerType)
+ if (!caster || !caster->IsAlive() || !target->IsAlive() || target->GetPowerType() != powerType)
return;
if (target->HasUnitState(UNIT_STATE_ISOLATED) || target->IsImmunedToDamage(GetSpellInfo()))
@@ -5509,7 +5510,7 @@ void AuraEffect::HandleObsModPowerAuraTick(Unit* target, Unit* caster) const
{
Powers powerType;
if (GetMiscValue() == POWER_ALL)
- powerType = target->getPowerType();
+ powerType = target->GetPowerType();
else
powerType = Powers(GetMiscValue());
@@ -5544,7 +5545,7 @@ void AuraEffect::HandlePeriodicEnergizeAuraTick(Unit* target, Unit* caster) cons
{
Powers powerType = Powers(GetMiscValue());
- if (target->GetTypeId() == TYPEID_PLAYER && target->getPowerType() != powerType && !m_spellInfo->HasAttribute(SPELL_ATTR7_CAN_RESTORE_SECONDARY_POWER))
+ if (target->GetTypeId() == TYPEID_PLAYER && target->GetPowerType() != powerType && !m_spellInfo->HasAttribute(SPELL_ATTR7_CAN_RESTORE_SECONDARY_POWER))
return;
if (!target->IsAlive() || !target->GetMaxPower(powerType))
@@ -5579,7 +5580,7 @@ void AuraEffect::HandlePeriodicPowerBurnAuraTick(Unit* target, Unit* caster) con
{
Powers powerType = Powers(GetMiscValue());
- if (!caster || !target->IsAlive() || target->getPowerType() != powerType)
+ if (!caster || !target->IsAlive() || target->GetPowerType() != powerType)
return;
if (target->HasUnitState(UNIT_STATE_ISOLATED) || target->IsImmunedToDamage(GetSpellInfo()))
diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp
index b727ded8565..4dc92fd9ac7 100644
--- a/src/server/game/Spells/Auras/SpellAuras.cpp
+++ b/src/server/game/Spells/Auras/SpellAuras.cpp
@@ -1589,7 +1589,7 @@ void Aura::HandleAuraSpecificMods(AuraApplication const* aurApp, Unit* caster, b
break;
int32 triggeredSpellId = 0;
- switch (target->getPowerType())
+ switch (target->GetPowerType())
{
case POWER_MANA:
{
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index b74453ba138..918887fb131 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -5326,7 +5326,7 @@ SpellCastResult Spell::CheckCast(bool strict, uint32* param1 /*= nullptr*/, uint
// Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
if (m_caster->GetTypeId() == TYPEID_PLAYER)
if (Unit* target = m_targets.GetUnitTarget())
- if (target != m_caster && target->getPowerType() != Powers(m_spellInfo->Effects[i].MiscValue))
+ if (target != m_caster && target->GetPowerType() != Powers(m_spellInfo->Effects[i].MiscValue))
return SPELL_FAILED_BAD_TARGETS;
break;
}
@@ -5753,7 +5753,7 @@ SpellCastResult Spell::CheckCast(bool strict, uint32* param1 /*= nullptr*/, uint
if (m_caster->GetTypeId() != TYPEID_PLAYER || m_CastItem)
break;
- if (m_targets.GetUnitTarget()->getPowerType() != POWER_MANA)
+ if (m_targets.GetUnitTarget()->GetPowerType() != POWER_MANA)
return SPELL_FAILED_BAD_TARGETS;
break;
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp
index 9ea2928c423..286e6b8c1fe 100644
--- a/src/server/game/Spells/SpellEffects.cpp
+++ b/src/server/game/Spells/SpellEffects.cpp
@@ -1193,7 +1193,7 @@ void Spell::EffectPowerDrain(SpellEffIndex effIndex)
Powers powerType = Powers(m_spellInfo->Effects[effIndex].MiscValue);
- if (!unitTarget || !unitTarget->IsAlive() || unitTarget->getPowerType() != powerType || damage < 0)
+ if (!unitTarget || !unitTarget->IsAlive() || unitTarget->GetPowerType() != powerType || damage < 0)
return;
// add spell damage bonus
@@ -1272,7 +1272,7 @@ void Spell::EffectPowerBurn(SpellEffIndex effIndex)
Powers powerType = Powers(m_spellInfo->Effects[effIndex].MiscValue);
- if (!unitTarget || !unitTarget->IsAlive() || unitTarget->getPowerType() != powerType || damage < 0)
+ if (!unitTarget || !unitTarget->IsAlive() || unitTarget->GetPowerType() != powerType || damage < 0)
return;
// burn x% of target's mana, up to maximum of 2x% of caster's mana (Mana Burn)
@@ -1714,7 +1714,7 @@ void Spell::EffectEnergize(SpellEffIndex effIndex)
Powers power = Powers(m_spellInfo->Effects[effIndex].MiscValue);
- if (unitTarget->GetTypeId() == TYPEID_PLAYER && unitTarget->getPowerType() != power && m_spellInfo->SpellFamilyName != SPELLFAMILY_POTION
+ if (unitTarget->GetTypeId() == TYPEID_PLAYER && unitTarget->GetPowerType() != power && m_spellInfo->SpellFamilyName != SPELLFAMILY_POTION
&& !m_spellInfo->HasAttribute(SPELL_ATTR7_CAN_RESTORE_SECONDARY_POWER))
return;
@@ -1784,7 +1784,7 @@ void Spell::EffectEnergizePct(SpellEffIndex effIndex)
Powers power = Powers(m_spellInfo->Effects[effIndex].MiscValue);
- if (unitTarget->GetTypeId() == TYPEID_PLAYER && unitTarget->getPowerType() != power && !m_spellInfo->HasAttribute(SPELL_ATTR7_CAN_RESTORE_SECONDARY_POWER))
+ if (unitTarget->GetTypeId() == TYPEID_PLAYER && unitTarget->GetPowerType() != power && !m_spellInfo->HasAttribute(SPELL_ATTR7_CAN_RESTORE_SECONDARY_POWER))
return;
uint32 maxPower = unitTarget->GetMaxPower(power);
@@ -2952,8 +2952,8 @@ void Spell::EffectSummonPet(SpellEffIndex effIndex)
if (OldSummon->getPetType() == SUMMON_PET)
{
OldSummon->SetHealth(OldSummon->GetMaxHealth());
- OldSummon->SetPower(OldSummon->getPowerType(),
- OldSummon->GetMaxPower(OldSummon->getPowerType()));
+ OldSummon->SetPower(OldSummon->GetPowerType(),
+ OldSummon->GetMaxPower(OldSummon->GetPowerType()));
}
if (owner->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled())