mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-01 10:03:47 +00:00
feat(Core/Unit): New helper HasActivePowerType and script hook OnPlayerHasActivePowerType (#18293)
* Create HasActivePower for script intercept * Replace relevant player-related getPowerType() comparators with HasActivePowerType * Change OnPlayerHasActivePowerType to regular bool instead of optional --------- Co-authored-by: NathanHandley <nathanhandley@protonmail.com>
This commit is contained in:
@@ -587,13 +587,13 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
|
||||
InitPrimaryProfessions(); // to max set before any spell added
|
||||
|
||||
// apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()
|
||||
if (getPowerType() == POWER_MANA)
|
||||
if (HasActivePowerType(POWER_MANA))
|
||||
{
|
||||
UpdateMaxPower(POWER_MANA); // Update max Mana (for add bonus from intellect)
|
||||
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
|
||||
}
|
||||
|
||||
if (getPowerType() == POWER_RUNIC_POWER)
|
||||
if (HasActivePowerType(POWER_RUNIC_POWER))
|
||||
{
|
||||
SetPower(POWER_RUNE, 8);
|
||||
SetMaxPower(POWER_RUNE, 8);
|
||||
@@ -2019,22 +2019,21 @@ void Player::RegenerateHealth()
|
||||
void Player::ResetAllPowers()
|
||||
{
|
||||
SetHealth(GetMaxHealth());
|
||||
switch (getPowerType())
|
||||
if (HasActivePowerType(POWER_MANA))
|
||||
{
|
||||
case POWER_MANA:
|
||||
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
|
||||
break;
|
||||
case POWER_RAGE:
|
||||
SetPower(POWER_RAGE, 0);
|
||||
break;
|
||||
case POWER_ENERGY:
|
||||
SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY));
|
||||
break;
|
||||
case POWER_RUNIC_POWER:
|
||||
SetPower(POWER_RUNIC_POWER, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
|
||||
}
|
||||
if (HasActivePowerType(POWER_RAGE))
|
||||
{
|
||||
SetPower(POWER_RAGE, 0);
|
||||
}
|
||||
if (HasActivePowerType(POWER_ENERGY))
|
||||
{
|
||||
SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY));
|
||||
}
|
||||
if (HasActivePowerType(POWER_RUNIC_POWER))
|
||||
{
|
||||
SetPower(POWER_RUNIC_POWER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2714,6 +2713,14 @@ void Player::InitStatsForLevel(bool reapplyMods)
|
||||
pet->SynchronizeLevelWithOwner();
|
||||
}
|
||||
|
||||
bool Player::HasActivePowerType(Powers power)
|
||||
{
|
||||
if (sScriptMgr->OnPlayerHasActivePowerType(this, power))
|
||||
return true;
|
||||
else
|
||||
return (getPowerType() == power);
|
||||
}
|
||||
|
||||
void Player::SendInitialSpells()
|
||||
{
|
||||
uint32 curTime = GameTime::GetGameTimeMS().count();
|
||||
|
||||
@@ -1170,6 +1170,8 @@ public:
|
||||
|
||||
void InitStatsForLevel(bool reapplyMods = false);
|
||||
|
||||
[[nodiscard]] bool HasActivePowerType(Powers power) override;
|
||||
|
||||
// .cheat command related
|
||||
[[nodiscard]] bool GetCommandStatus(uint32 command) const { return _activeCheats & command; }
|
||||
void SetCommandStatusOn(uint32 command) { _activeCheats |= command; }
|
||||
|
||||
@@ -929,7 +929,7 @@ uint32 Unit::DealDamage(Unit* attacker, Unit* victim, uint32 damage, CleanDamage
|
||||
}
|
||||
|
||||
// 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->HasActivePowerType(POWER_RAGE))
|
||||
{
|
||||
uint32 weaponSpeedHitFactor;
|
||||
|
||||
@@ -957,10 +957,10 @@ uint32 Unit::DealDamage(Unit* attacker, Unit* victim, uint32 damage, CleanDamage
|
||||
// Rage from absorbed damage
|
||||
if (cleanDamage && cleanDamage->absorbed_damage)
|
||||
{
|
||||
if (victim->getPowerType() == POWER_RAGE)
|
||||
if (victim->HasActivePowerType(POWER_RAGE))
|
||||
victim->RewardRage(cleanDamage->absorbed_damage, 0, false);
|
||||
|
||||
if (attacker && attacker->getPowerType() == POWER_RAGE )
|
||||
if (attacker && attacker->HasActivePowerType(POWER_RAGE))
|
||||
attacker->RewardRage(cleanDamage->absorbed_damage, 0, true);
|
||||
}
|
||||
|
||||
@@ -1083,7 +1083,7 @@ uint32 Unit::DealDamage(Unit* attacker, Unit* victim, uint32 damage, CleanDamage
|
||||
}
|
||||
|
||||
// Rage from damage received
|
||||
if (attacker != victim && victim->getPowerType() == POWER_RAGE)
|
||||
if (attacker != victim && victim->HasActivePowerType(POWER_RAGE))
|
||||
{
|
||||
uint32 rageDamage = damage + (cleanDamage ? cleanDamage->absorbed_damage : 0);
|
||||
victim->RewardRage(rageDamage, 0, false);
|
||||
@@ -6996,7 +6996,7 @@ bool Unit::HandleDummyAuraProc(Unit* victim, uint32 damage, AuraEffect* triggere
|
||||
// Magic Absorption
|
||||
if (dummySpell->SpellIconID == 459) // only this spell has SpellIconID == 459 and dummy aura
|
||||
{
|
||||
if (getPowerType() != POWER_MANA)
|
||||
if (!HasActivePowerType(POWER_MANA))
|
||||
return false;
|
||||
|
||||
// mana reward
|
||||
@@ -7775,7 +7775,7 @@ bool Unit::HandleDummyAuraProc(Unit* victim, uint32 damage, AuraEffect* triggere
|
||||
// Judgement of Wisdom
|
||||
case 20186:
|
||||
{
|
||||
if (!victim || !victim->IsAlive() || victim->getPowerType() != POWER_MANA || victim->HasSpellCooldown(20268))
|
||||
if (!victim || !victim->IsAlive() || !victim->HasActivePowerType(POWER_MANA) || victim->HasSpellCooldown(20268))
|
||||
return false;
|
||||
|
||||
// 2% of base mana
|
||||
|
||||
@@ -1472,6 +1472,7 @@ public:
|
||||
|
||||
[[nodiscard]] Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, 3)); }
|
||||
void setPowerType(Powers power);
|
||||
[[nodiscard]] virtual bool HasActivePowerType(Powers power) { return getPowerType() == power; }
|
||||
[[nodiscard]] uint32 GetPower(Powers power) const { return GetUInt32Value(static_cast<uint16>(UNIT_FIELD_POWER1) + power); }
|
||||
[[nodiscard]] uint32 GetMaxPower(Powers power) const { return GetUInt32Value(static_cast<uint16>(UNIT_FIELD_MAXPOWER1) + power); }
|
||||
void SetPower(Powers power, uint32 val, bool withPowerUpdate = true, bool fromRegenerate = false);
|
||||
|
||||
Reference in New Issue
Block a user