Skip to content

Commit

Permalink
Core/Creatures: updated power type handling (The-Legion-Preservation-…
Browse files Browse the repository at this point in the history
…Project#174)

* Core/Misc: rename to GetPowerType and SetPowerType

* Core/Misc: add helper function Unit::SetFullPower

* Core/Entities: creature powers
  • Loading branch information
jasongdove authored Nov 22, 2024
1 parent 2f88ca0 commit 84b6b46
Show file tree
Hide file tree
Showing 75 changed files with 282 additions and 242 deletions.
8 changes: 4 additions & 4 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3313,9 +3313,9 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
}
case SMART_EVENT_MANA_PCT:
{
if (!me || (!me->isInCombat() && !(e.event.event_flags & SMART_EVENT_FLAG_ALLOW_EVENT_IN_COMBAT)) || !me->GetMaxPower(me->getPowerType()))
if (!me || (!me->isInCombat() && !(e.event.event_flags & SMART_EVENT_FLAG_ALLOW_EVENT_IN_COMBAT)) || !me->GetMaxPower(me->GetPowerType()))
return;
auto perc = uint32(100.0f * me->GetPower(me->getPowerType()) / me->GetMaxPower(me->getPowerType()));
auto perc = uint32(me->GetPowerPct(me->GetPowerType()));
if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
return;
RecalcTimer(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax);
Expand All @@ -3324,9 +3324,9 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
}
case SMART_EVENT_TARGET_MANA_PCT:
{
if (!me || (!me->isInCombat() && !(e.event.event_flags & SMART_EVENT_FLAG_ALLOW_EVENT_IN_COMBAT)) || !me->getVictim() || !me->getVictim()->GetMaxPower(me->getPowerType()))
if (!me || (!me->isInCombat() && !(e.event.event_flags & SMART_EVENT_FLAG_ALLOW_EVENT_IN_COMBAT)) || !me->getVictim() || !me->getVictim()->GetMaxPower(me->GetPowerType()))
return;
auto perc = uint32(100.0f * me->getVictim()->GetPower(me->getPowerType()) / me->getVictim()->GetMaxPower(me->getPowerType()));
auto perc = uint32(me->getVictim()->GetPowerPct(me->getVictim()->GetPowerType()));
if (perc > e.event.minMaxRepeat.max || perc < e.event.minMaxRepeat.min)
return;
RecalcTimer(e, e.event.minMaxRepeat.repeatMin, e.event.minMaxRepeat.repeatMax);
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/DataStores/DB2Stores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3318,9 +3318,9 @@ bool ChrClassesXPowerTypesEntryComparator::Compare(ChrClassesXPowerTypesEntry co
return left->PowerType < right->PowerType;
}

uint32 DB2Manager::GetPowerIndexByClass(uint32 powerType, uint32 classId) const
uint32 DB2Manager::GetPowerIndexByClass(Powers power, uint32 classId) const
{
return _powersByClass[classId][powerType];
return _powersByClass[classId][power];
}

AreaTableEntry const* DB2Manager::FindAreaEntry(uint32 area)
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/DataStores/DB2Stores.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class DB2Manager
ChrSpecializationEntry const* GetChrSpecializationByIndex(uint8 classID, uint32 ID);
ChrSpecializationEntry const* GetDefaultChrSpecializationForClass(uint32 class_) const;
PetFamilySpellsSet const* GetPetFamilySpells(uint32 family);
uint32 GetPowerIndexByClass(uint32 powerType, uint32 classId) const;
uint32 GetPowerIndexByClass(Powers power, uint32 classId) const;
AreaTableEntry const* FindAreaEntry(uint32 area);
uint32 GetParentZoneOrSelf(uint32 zone);
static char const* GetPetName(uint32 petfamily, LocaleConstant localeConstant);
Expand Down
32 changes: 11 additions & 21 deletions src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ void Creature::Update(uint32 diff)
if(HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_REGENERATE_POWER))
{
m_regenTimerCount += diff;
Regenerate(getPowerType(), diff);
Regenerate(GetPowerType(), diff);

if (m_regenTimerCount >= GetRegenerateInterval())
m_regenTimerCount -= m_sendInterval;
Expand Down Expand Up @@ -1870,25 +1870,15 @@ void Creature::SelectLevel(const CreatureTemplate* cInfo)

switch (getClass())
{
case CLASS_WARRIOR:
setPowerType(POWER_RAGE);
//SetMaxPower(POWER_RAGE, GetCreatePowers(POWER_RAGE));
//SetPower(POWER_RAGE, GetCreatePowers(POWER_RAGE));
break;
case CLASS_ROGUE:
setPowerType(POWER_ENERGY);
SetMaxPower(POWER_ENERGY, GetCreatePowers(POWER_ENERGY));
SetPower(POWER_ENERGY, GetCreatePowers(POWER_ENERGY));
break;
default:
setPowerType(POWER_MANA);
case CLASS_PALADIN:
case CLASS_MAGE:
SetMaxPower(POWER_MANA, mana);
SetPower(POWER_MANA, mana);
SetFullPower(POWER_MANA);
default: // We don't set max power here, 0 makes power bar hidden
break;
}

SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, static_cast<float>(health));
SetModifierValue(UNIT_MOD_MANA, BASE_VALUE, static_cast<float>(mana));

//damage
float maxDmgMod = 1.5f;
Expand Down Expand Up @@ -2280,12 +2270,12 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType guid, Map* map, bool addTo
switch (getClass())
{
case CLASS_WARRIOR:
setPowerType(POWER_RAGE);
SetPowerType(POWER_RAGE);
//SetMaxPower(POWER_RAGE, GetCreatePowers(POWER_RAGE));
//SetPower(POWER_RAGE, GetCreatePowers(POWER_RAGE));
break;
case CLASS_ROGUE:
setPowerType(POWER_ENERGY);
SetPowerType(POWER_ENERGY);
SetMaxPower(POWER_ENERGY, GetCreatePowers(POWER_ENERGY));
SetPower(POWER_ENERGY, GetCreatePowers(POWER_ENERGY));
break;
Expand All @@ -2300,17 +2290,17 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType guid, Map* map, bool addTo
switch (getClass())
{
case CLASS_WARRIOR:
setPowerType(POWER_RAGE);
SetPowerType(POWER_RAGE);
//SetMaxPower(POWER_RAGE, GetCreatePowers(POWER_RAGE));
//SetPower(POWER_RAGE, GetCreatePowers(POWER_RAGE));
break;
case CLASS_ROGUE:
setPowerType(POWER_ENERGY);
SetPowerType(POWER_ENERGY);
SetMaxPower(POWER_ENERGY, GetCreatePowers(POWER_ENERGY));
SetPower(POWER_ENERGY, GetCreatePowers(POWER_ENERGY));
break;
default:
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
SetFullPower(POWER_MANA);
break;
}
}
Expand Down Expand Up @@ -2382,7 +2372,7 @@ void Creature::SetSpawnHealth()
}

SetHealth((m_deathState == ALIVE || m_deathState == JUST_RESPAWNED) ? curhealth : 0);
SetInitialPowerValue(getPowerType());
SetInitialPowerValue(GetPowerType());
}

bool Creature::hasQuest(uint32 quest_id) const
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Entities/Creature/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ class Creature : public Unit, public GridObject<Creature>, public MapObject
void UpdateArmor() override;
void UpdateMaxHealth() override;
void UpdateMaxPower(Powers power) override;
uint32 GetPowerIndex(Powers power) const override;
void UpdateAttackPowerAndDamage(bool ranged = false) override;
void UpdateDamagePhysical(WeaponAttackType attType) override;
int8 GetOriginalEquipmentId() const { return m_originalEquipmentId; }
Expand Down
15 changes: 2 additions & 13 deletions src/server/game/Entities/Creature/TemporarySummon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ bool TempSummon::InitBaseStat(uint32 creatureId, bool& damageSet)
SetHealth(GetCreateHealth());
}

if (getPowerType() != pStats->energy_type)
setPowerType(Powers(pStats->energy_type));
if (GetPowerType() != pStats->energy_type)
SetPowerType(Powers(pStats->energy_type));

if (pStats->energy_type)
{
Expand Down Expand Up @@ -573,17 +573,6 @@ bool Minion::IsGuardianPet() const
return isPet() || (m_Properties && m_Properties->Control == SUMMON_CATEGORY_PET);
}

bool Minion::IsWarlockPet() const
{
if (isPet())
{
if (m_owner && m_owner->getClass() == CLASS_WARLOCK)
return true;
}

return false;
}

Guardian::Guardian(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) : Minion(properties, owner, isWorldObject)
{
m_owner = owner;
Expand Down
40 changes: 37 additions & 3 deletions src/server/game/Entities/Creature/TemporarySummon.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@

#include "Creature.h"

enum PetEntry
{
// Warlock pets
PET_IMP = 416,
PET_FEL_HUNTER = 691,
PET_VOID_WALKER = 1860,
PET_SUCCUBUS = 1863,
PET_DOOMGUARD = 18540,
PET_FELGUARD = 30146,

// Death Knight pets
PET_GHOUL = 26125,
PET_GARGOYLE = 27829,
PET_ABOMINATION = 106848,

// Shaman pet
PET_SPIRIT_WOLF = 29264
};

enum SummonActionType
{
SUMMON_ACTION_TYPE_DEFAULT = 0,
Expand Down Expand Up @@ -94,9 +113,24 @@ class Minion : public TempSummon
void RemoveFromWorld() override;

Unit* GetOwner() { return m_owner; }
bool IsPetGhoul() const {return GetEntry() == 26125;} // Ghoul may be guardian or pet
bool IsPetGargoyle() const { return GetEntry() == 27829; }
bool IsWarlockPet() const;

// Warlock pets
bool IsPetImp() const { return GetEntry() == PET_IMP; }
bool IsPetFelHunter() const { return GetEntry() == PET_FEL_HUNTER; }
bool IsPetVoidwalker() const { return GetEntry() == PET_VOID_WALKER; }
bool IsPetSuccubus() const { return GetEntry() == PET_SUCCUBUS; }
bool IsPetDoomguard() const { return GetEntry() == PET_DOOMGUARD; }
bool IsPetFelguard() const { return GetEntry() == PET_FELGUARD; }

// Death Knight pets
bool IsPetGhoul() const {return GetEntry() == PET_GHOUL;} // Ghoul may be guardian or pet
bool IsPetGargoyle() const { return GetEntry() == PET_GARGOYLE; }
bool IsPetAbomination() const { return GetEntry() == PET_ABOMINATION; } // Sludge Belcher dk talent

// Shaman pet
bool IsSpiritWolf() const { return GetEntry() == PET_SPIRIT_WOLF; } // Spirit wolf from feral spirits

bool IsWarlockPet() const { return IsPetImp() || IsPetFelHunter() || IsPetVoidwalker() || IsPetSuccubus() || IsPetDoomguard() || IsPetFelguard(); }
bool IsGuardianPet() const;
};

Expand Down
20 changes: 15 additions & 5 deletions src/server/game/Entities/Pet/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool c
SetCanModifyStats(true);

if (getPetType() == SUMMON_PET && !current)
SetPower(getPowerType(), GetMaxPower(getPowerType()));
SetFullPower(GetPowerType());
else
{
uint32 savedhealth = petInfo->Health;
Expand All @@ -350,7 +350,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool c
else
{
SetHealth(savedhealth);
SetPower(getPowerType(), savedmana > uint32(GetMaxPower(getPowerType())) ? GetMaxPower(getPowerType()) : savedmana);
SetPower(GetPowerType(), savedmana > uint32(GetMaxPower(GetPowerType())) ? GetMaxPower(GetPowerType()) : savedmana);
}
}

Expand Down Expand Up @@ -922,7 +922,6 @@ bool Pet::CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phas
if (!Create(guid, map, phaseMask, cinfo->Entry, pet_number))
return false;

setPowerType(POWER_FOCUS);
SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
SetUInt32Value(UNIT_FIELD_PET_EXPERIENCE, 0);
SetUInt32Value(UNIT_FIELD_PET_NEXT_LEVEL_EXPERIENCE, 2147483647);
Expand Down Expand Up @@ -981,12 +980,12 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)

CreatureBaseStats const* stats = sObjectMgr->GetCreatureBaseStats(petlevel, cinfo->unit_class);

//health, mana, armor and resistance
// Health, Mana or Power, Armor
if(!InitBaseStat(creature_ID, damageSet))
{
SetCreateHealth(stats->BaseHealth[cinfo->HealthScalingExpansion]);
SetCreateMana(stats->GenerateMana(cinfo));
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
SetFullPower(POWER_MANA);
}

if(owner && (owner->getClass() == CLASS_HUNTER || owner->getClass() == CLASS_WARLOCK))
Expand All @@ -1004,6 +1003,17 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
SetCreateStat(STAT_INTELLECT, 14 + (petlevel * 4.45));
}

// Power
if (petType == HUNTER_PET) // Hunter pets have focus
SetPowerType(POWER_FOCUS);
else if (IsPetGhoul() || IsPetGargoyle() || IsPetAbomination()) // DK pets have energy
SetPowerType(POWER_ENERGY);
else if (IsWarlockPet()) // Warlock pets have energy (since 5.x)
SetPowerType(POWER_ENERGY);
else
SetPowerType(POWER_MANA);

// Damage
SetBonusDamage(0);
UpdateAllStats();

Expand Down
Loading

0 comments on commit 84b6b46

Please sign in to comment.