Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Core/Units: Power handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren authored and Ovahlord committed Dec 18, 2023
1 parent 620c39b commit b5ec59a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 84 deletions.
11 changes: 6 additions & 5 deletions src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,23 +1443,24 @@ void Creature::UpdateLevelDependantStats()
SetHealth(health);
ResetPlayerDamageReq();

SetStatFlatModifier(UNIT_MOD_HEALTH, BASE_VALUE, (float)health);

// mana
uint32 mana = stats->GenerateMana(cInfo);
SetCreateMana(mana);
Powers powerType = CalculateDisplayPowerType();
SetCreateMana(stats->BaseMana);
SetStatPctModifier(UnitMods(UNIT_MOD_POWER_START + AsUnderlyingType(powerType)), BASE_PCT, cInfo->ModMana * cInfo->ModManaExtra);
SetPowerType(powerType);

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);

// damage
float basedamage = stats->GenerateBaseDamage(cInfo);

Expand Down
9 changes: 0 additions & 9 deletions src/server/game/Entities/Creature/CreatureData.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,6 @@ struct TC_GAME_API CreatureBaseStats
return uint32(ceil(BaseHealth[info->expansion] * info->ModHealth * info->ModHealthExtra));
}

uint32 GenerateMana(CreatureTemplate const* info) const
{
// Mana can be 0.
if (!BaseMana)
return 0;

return uint32(ceil(BaseMana * info->ModMana * info->ModManaExtra));
}

uint32 GenerateArmor(CreatureTemplate const* info) const
{
return uint32(ceil(BaseArmor * info->ModArmor));
Expand Down
17 changes: 6 additions & 11 deletions src/server/game/Entities/Pet/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,13 +757,17 @@ 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]));

Powers powerType = CalculateDisplayPowerType();

// Health, mana, armor and resistance
PetLevelInfo const* pInfo = sObjectMgr->GetPetLevelInfo(creature_ID, petlevel);
if (pInfo) // exist in DB
{
SetCreateHealth(pInfo->health);
SetCreateMana(pInfo->mana);

SetStatPctModifier(UnitMods(UNIT_MOD_POWER_START + AsUnderlyingType(powerType)), BASE_PCT, 1.0f);

if (pInfo->armor > 0)
SetStatFlatModifier(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor));

Expand All @@ -778,10 +782,9 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
float healthmod = _GetHealthMod(cinfo->rank);
uint32 basehp = stats->GenerateHealth(cinfo);
uint32 health = uint32(basehp * healthmod);
uint32 mana = stats->GenerateMana(cinfo);

SetCreateHealth(health);
SetCreateMana(mana);
SetCreateMana(stats->BaseMana);
SetCreateStat(STAT_STRENGTH, 22);
SetCreateStat(STAT_AGILITY, 22);
SetCreateStat(STAT_STAMINA, 25);
Expand All @@ -793,15 +796,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
}

// Power
if (petType == HUNTER_PET) // Hunter pets have focus
SetPowerType(POWER_FOCUS);
else if (IsPetGhoul() || IsRisenAlly()) // DK pets have energy
{
SetPowerType(POWER_ENERGY);
SetFullPower(POWER_ENERGY);
}
else
SetPowerType(POWER_MANA);
SetPowerType(powerType);

// Damage
SetBonusDamage(0);
Expand Down
41 changes: 37 additions & 4 deletions src/server/game/Entities/Unit/StatSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@ void Unit::UpdateDamagePhysical(WeaponAttackType attType)
}
}

int32 Unit::GetCreatePowerValue(Powers power) const
{
switch (power)
{
case POWER_MANA:
return GetCreateMana();
case POWER_RAGE:
if (IsPlayer()) // only players are allowed to use rage
return 1000;
break;
case POWER_FOCUS:
return 100;
case POWER_ENERGY:
return 100;
case POWER_RUNIC_POWER:
return 1000;
case POWER_RUNE:
return 0;
case POWER_SOUL_SHARDS:
return 3;
case POWER_ECLIPSE:
return 100;
case POWER_HOLY_POWER:
return 3;
case POWER_HEALTH:
return 0;
default:
break;
}

return 0;
}

/*#######################################
######## ########
######## PLAYERS STAT SYSTEM ########
Expand Down Expand Up @@ -323,9 +356,9 @@ void Player::UpdateMaxPower(Powers power)

UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + AsUnderlyingType(power));

float bonusPower = (power == POWER_MANA && GetCreatePowers(power) > 0) ? GetManaBonusFromIntellect() : 0;
float bonusPower = (power == POWER_MANA && GetCreatePowerValue(power) > 0) ? GetManaBonusFromIntellect() : 0;

float value = GetFlatModifierValue(unitMod, BASE_VALUE) + GetCreatePowers(power);
float value = GetFlatModifierValue(unitMod, BASE_VALUE) + GetCreatePowerValue(power);
value *= GetPctModifierValue(unitMod, BASE_PCT);
value += GetFlatModifierValue(unitMod, TOTAL_VALUE) + bonusPower;
value *= GetPctModifierValue(unitMod, TOTAL_PCT);
Expand Down Expand Up @@ -942,7 +975,7 @@ void Creature::UpdateMaxPower(Powers power)

UnitMods unitMod = UnitMods(UNIT_MOD_POWER_START + AsUnderlyingType(power));

float value = GetFlatModifierValue(unitMod, BASE_VALUE) + GetCreatePowers(power);
float value = GetFlatModifierValue(unitMod, BASE_VALUE) + GetCreatePowerValue(power);
value *= GetPctModifierValue(unitMod, BASE_PCT);
value += GetFlatModifierValue(unitMod, TOTAL_VALUE);
value *= GetPctModifierValue(unitMod, TOTAL_PCT);
Expand Down Expand Up @@ -1174,7 +1207,7 @@ void Guardian::UpdateMaxPower(Powers power)
float addValue = (power == POWER_MANA) ? GetStat(STAT_INTELLECT) - GetCreateStat(STAT_INTELLECT) : 0.0f;
float multiplicator = 15.0f;

float value = GetFlatModifierValue(unitMod, BASE_VALUE) + GetCreatePowers(power);
float value = GetFlatModifierValue(unitMod, BASE_VALUE) + GetCreatePowerValue(power);
value *= GetPctModifierValue(unitMod, BASE_PCT);
value += GetFlatModifierValue(unitMod, TOTAL_VALUE) + addValue * multiplicator;
value *= GetPctModifierValue(unitMod, TOTAL_PCT);
Expand Down
75 changes: 21 additions & 54 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5229,7 +5229,7 @@ void Unit::SetPowerType(Powers new_powertype)
}
}

void Unit::UpdateDisplayPower()
Powers Unit::CalculateDisplayPowerType() const
{
Powers displayPower = POWER_MANA;
switch (GetShapeshiftForm())
Expand All @@ -5247,34 +5247,34 @@ void Unit::UpdateDisplayPower()
break;
default:
{
if (GetTypeId() == TYPEID_PLAYER)
ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(getClass());
if (cEntry && cEntry->DisplayPower < MAX_POWERS)
displayPower = Powers(cEntry->DisplayPower);

if (Vehicle* vehicle = GetVehicleKit())
{
ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(getClass());
if (cEntry && cEntry->DisplayPower < MAX_POWERS)
displayPower = Powers(cEntry->DisplayPower);
if (PowerDisplayEntry const* powerDisplay = sPowerDisplayStore.LookupEntry(vehicle->GetVehicleInfo()->PowerDisplayID[0])) // To-do: 4.x has 3 power display id fields.
displayPower = Powers(powerDisplay->ActualType);
else if (getClass() == CLASS_ROGUE)
displayPower = POWER_ENERGY;
}
else if (GetTypeId() == TYPEID_UNIT)
else if (Pet const* pet = ToPet())
{
if (Vehicle* vehicle = GetVehicleKit())
{
if (PowerDisplayEntry const* powerDisplay = sPowerDisplayStore.LookupEntry(vehicle->GetVehicleInfo()->PowerDisplayID[0])) // To-do: 4.x has 3 power display id fields.
displayPower = Powers(powerDisplay->ActualType);
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;
}
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);
return displayPower;
}

void Unit::UpdateDisplayPower()
{
SetPowerType(CalculateDisplayPowerType());
}

void Unit::SetSheath(SheathState sheathed)
Expand Down Expand Up @@ -9369,39 +9369,6 @@ void Unit::SetMaxPower(Powers power, int32 val)
SetPower(power, val);
}

int32 Unit::GetCreatePowers(Powers power) const
{
switch (power)
{
case POWER_MANA:
return GetCreateMana();
case POWER_RAGE:
return 1000;
case POWER_FOCUS:
if (GetTypeId() == TYPEID_PLAYER && 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_RUNIC_POWER:
return 1000;
case POWER_RUNE:
return 0;
case POWER_SOUL_SHARDS:
return 3;
case POWER_ECLIPSE:
return 100;
case POWER_HOLY_POWER:
return 3;
case POWER_HEALTH:
return 0;
default:
break;
}

return 0;
}

void Unit::Regenerate(Powers powerType, uint32 diff)
{
uint32 maxValue = GetMaxPower(powerType);
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ class TC_GAME_API Unit : public WorldObject

Powers GetPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_POWER_TYPE)); }
void SetPowerType(Powers power);
Powers CalculateDisplayPowerType() const;
void UpdateDisplayPower();
int32 GetPower(Powers power) const;
int32 GetMinPower(Powers power) const { return power == POWER_ECLIPSE ? -100 : 0; }
Expand Down Expand Up @@ -1402,7 +1403,7 @@ class TC_GAME_API Unit : public WorldObject
uint32 GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH); }
void SetCreateMana(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_MANA, val); }
uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); }
int32 GetCreatePowers(Powers power) const;
int32 GetCreatePowerValue(Powers power) const;
float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0 + AsUnderlyingType(stat)); }
float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0 + AsUnderlyingType(stat)); }
float GetCreateStat(Stats stat) const { return m_createStats[stat]; }
Expand Down

0 comments on commit b5ec59a

Please sign in to comment.