mirror of
https://gitcode.com/GitHub_Trending/az/azerothcore-wotlk.git
synced 2026-10-10 07:06:38 +08:00
refactor(Core/Unit): extract rage weapon-speed term with test (#27004)
This commit is contained in:
@@ -1110,15 +1110,13 @@ uint32 Unit::DealDamage(Unit* attacker, Unit* victim, uint32 damage, CleanDamage
|
||||
case BASE_ATTACK:
|
||||
case OFF_ATTACK:
|
||||
{
|
||||
weaponSpeedHitFactor = uint32(attacker->GetAttackTime(cleanDamage->attackType) / 1000.0f * (cleanDamage->attackType == BASE_ATTACK ? 3.5f : 1.75f));
|
||||
weaponSpeedHitFactor = attacker->GetRageWeaponSpeedHitFactor(cleanDamage->attackType);
|
||||
if (cleanDamage->hitOutCome == MELEE_HIT_CRIT)
|
||||
weaponSpeedHitFactor *= 2;
|
||||
|
||||
attacker->RewardRage(rage_damage, weaponSpeedHitFactor, true);
|
||||
break;
|
||||
}
|
||||
case RANGED_ATTACK:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -2081,7 +2079,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss)
|
||||
case BASE_ATTACK:
|
||||
case OFF_ATTACK:
|
||||
{
|
||||
uint32 weaponSpeedHitFactor = uint32(GetAttackTime(damageInfo->attackType) / 1000.0f * (damageInfo->attackType == BASE_ATTACK ? 3.5f : 1.75f));
|
||||
uint32 weaponSpeedHitFactor = GetRageWeaponSpeedHitFactor(damageInfo->attackType);
|
||||
RewardRage(damageInfo->cleanDamage, weaponSpeedHitFactor, true);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -918,6 +918,11 @@ public:
|
||||
return (uint32)f_BaseAttackTime;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline uint32 GetRageWeaponSpeedHitFactor(WeaponAttackType att) const
|
||||
{
|
||||
return uint32(GetAttackTime(att) / 1000.0f * (att == BASE_ATTACK ? 3.5f : 1.75f));
|
||||
}
|
||||
|
||||
void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(static_cast<uint16>(UNIT_FIELD_BASEATTACKTIME) + att, val * m_modAttackSpeedPct[att]); }
|
||||
void ApplyAttackTimePercentMod(WeaponAttackType att, float val, bool apply);
|
||||
void ApplyCastTimePercentMod(float val, bool apply);
|
||||
|
||||
@@ -275,7 +275,7 @@ pAuraEffectHandler AuraEffectHandler[TOTAL_AURAS] =
|
||||
&AuraEffect::HandleAuraModIncreaseFlightSpeed, //210 SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACKING
|
||||
&AuraEffect::HandleAuraModIncreaseFlightSpeed, //211 SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
|
||||
&AuraEffect::HandleAuraModRangedAttackPowerOfStatPercent, //212 SPELL_AURA_MOD_RANGED_ATTACK_POWER_OF_STAT_PERCENT
|
||||
&AuraEffect::HandleNoImmediateEffect, //213 SPELL_AURA_MOD_RAGE_FROM_DAMAGE_DEALT implemented in Player::RewardRage
|
||||
&AuraEffect::HandleNoImmediateEffect, //213 SPELL_AURA_MOD_RAGE_FROM_DAMAGE_DEALT implemented in Unit::RewardRage
|
||||
&AuraEffect::HandleNULL, //214 Tamed Pet Passive
|
||||
&AuraEffect::HandleArenaPreparation, //215 SPELL_AURA_ARENA_PREPARATION
|
||||
&AuraEffect::HandleModCastingSpeed, //216 SPELL_AURA_HASTE_SPELLS
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "IntegrationTestFixture.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// Haste must shorten the swing interval but never the per-swing rage reward.
|
||||
TEST_F(IntegrationTestFixture, HasteChangesIntervalNotRage)
|
||||
{
|
||||
TestPlayer* player = CreateTestPlayer(1, "RageTest", SEC_PLAYER);
|
||||
player->SetUInt32Value(UNIT_FIELD_LEVEL, 80);
|
||||
player->SetMaxPower(POWER_RAGE, 10000);
|
||||
player->SetAttackTime(BASE_ATTACK, 2000);
|
||||
|
||||
uint32 const before = player->GetPower(POWER_RAGE);
|
||||
player->RewardRage(1000, player->GetRageWeaponSpeedHitFactor(BASE_ATTACK), true);
|
||||
uint32 const rageNoHaste = player->GetPower(POWER_RAGE) - before;
|
||||
EXPECT_GT(rageNoHaste, 0u); // rage was granted
|
||||
|
||||
player->ApplyAttackTimePercentMod(BASE_ATTACK, 50.0f, true); // 50% haste
|
||||
|
||||
EXPECT_EQ(player->GetRageWeaponSpeedHitFactor(BASE_ATTACK), 7u); // 2000/1000 * 3.5
|
||||
|
||||
uint32 const beforeHasted = player->GetPower(POWER_RAGE);
|
||||
player->RewardRage(1000, player->GetRageWeaponSpeedHitFactor(BASE_ATTACK), true);
|
||||
uint32 const rageHasted = player->GetPower(POWER_RAGE) - beforeHasted;
|
||||
|
||||
EXPECT_EQ(rageHasted, rageNoHaste); // per-swing rage unaffected by haste
|
||||
|
||||
player->resetAttackTimer(BASE_ATTACK);
|
||||
EXPECT_EQ(player->getAttackTimer(BASE_ATTACK), 1333); // 2000 / 1.5 (50% haste)
|
||||
}
|
||||
Reference in New Issue
Block a user