Core/Units: ported power type updates from master branch

This commit is contained in:
Ovahlord committed 2020-04-22 03:13:02 +02:00
1 parent e67167e8cf
commit b653f2f819
40 files changed
+259 -278

No files matched your search

+64 -44
View File
@@ -862,7 +862,7 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
}
// Rage from Damage made (only from direct weapon damage)
if (cleanDamage && damagetype == DIRECT_DAMAGE && this != victim && getPowerType() == POWER_RAGE)
if (cleanDamage && damagetype == DIRECT_DAMAGE && this != victim && GetPowerType() == POWER_RAGE)
{
uint32 rage = uint32(GetAttackTime(cleanDamage->attackType) / 1000 * 6.5f);
@@ -887,7 +887,7 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
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, false);
return 0;
@@ -985,7 +985,7 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
}
// Rage from damage received
if (this != victim && victim->getPowerType() == POWER_RAGE)
if (this != victim && victim->GetPowerType() == POWER_RAGE)
{
uint32 rage_damage = damage + (cleanDamage ? cleanDamage->absorbed_damage : 0);
victim->RewardRage(rage_damage, false);
@@ -5385,9 +5385,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);
@@ -5407,30 +5407,74 @@ 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:
displayPower = POWER_RAGE;
break;
case FORM_TRAVEL:
case FORM_GHOSTWOLF:
displayPower = POWER_MANA;
break;
default:
{
if (GetTypeId() == TYPEID_PLAYER)
{
ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(getClass());
if (cEntry && cEntry->DisplayPower < MAX_POWERS)
displayPower = Powers(cEntry->DisplayPower);
}
else if (GetTypeId() == TYPEID_UNIT)
{
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;
}
}
break;
}
}
SetPowerType(displayPower);
}
FactionTemplateEntry const* Unit::GetFactionTemplateEntry() const
{
FactionTemplateEntry const* entry = sFactionTemplateStore.LookupEntry(GetFaction());
@@ -6117,14 +6161,10 @@ void Unit::SetMinion(Minion* minion, bool apply)
// PvP, FFAPvP
minion->SetByteValue(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PVP_FLAG, GetByteValue(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PVP_FLAG));
// Ghoul pets have energy instead of mana (is anywhere better place for this code?)
if (minion->IsPetGhoul())
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
@@ -9171,7 +9211,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
@@ -10192,26 +10232,6 @@ void Unit::SetMaxPower(Powers power, int32 val)
SetPower(power, val);
}
uint32 Unit::GetPowerIndex(uint32 powerType) const
{
/// This is here because hunter pets are of the warrior class.
/// With the current implementation, the core only gives them
/// POWER_RAGE, so we enforce the class to hunter so that they
/// effectively get focus power.
/// Also, Death Knight ghouls are of Mage class.
/// this is necessary so they get energy
uint32 classId = getClass();
if (Pet const* pet = ToPet())
{
if (pet->IsHunterPet())
classId = CLASS_HUNTER;
else if (pet->IsPetGhoul())
classId = CLASS_ROGUE;
}
return sDBCManager.GetPowerIndexByClass(powerType, classId);
}
int32 Unit::GetCreatePowers(Powers power) const
{
switch (power)