refactor(Core): use the WeaponAttackType enum (#23457)

This commit is contained in:
Tereneckla
2025-11-01 18:26:18 +00:00
committed by GitHub
parent 97543ba50f
commit e35a5ae049
7 changed files with 24 additions and 22 deletions
+15 -14
View File
@@ -78,6 +78,7 @@
#include "TicketMgr.h" #include "TicketMgr.h"
#include "Tokenize.h" #include "Tokenize.h"
#include "Transport.h" #include "Transport.h"
#include "Unit.h"
#include "UpdateData.h" #include "UpdateData.h"
#include "Util.h" #include "Util.h"
#include "Vehicle.h" #include "Vehicle.h"
@@ -6595,13 +6596,13 @@ void Player::_ApplyItemMods(Item* item, uint8 slot, bool apply)
LOG_DEBUG("entities.player", "applying mods for item {} ", item->GetGUID().ToString()); LOG_DEBUG("entities.player", "applying mods for item {} ", item->GetGUID().ToString());
uint8 attacktype = Player::GetAttackBySlot(slot); WeaponAttackType attacktype = Player::GetAttackBySlot(slot);
if (item->HasSocket()) //only (un)equipping of items with sockets can influence metagems, so no need to waste time with normal items if (item->HasSocket()) //only (un)equipping of items with sockets can influence metagems, so no need to waste time with normal items
CorrectMetaGemEnchants(slot, apply); CorrectMetaGemEnchants(slot, apply);
if (attacktype < MAX_ATTACK) if (attacktype < MAX_ATTACK)
_ApplyWeaponDependentAuraMods(item, WeaponAttackType(attacktype), apply); _ApplyWeaponDependentAuraMods(item, attacktype, apply);
_ApplyItemBonuses(proto, slot, apply); _ApplyItemBonuses(proto, slot, apply);
@@ -6888,7 +6889,7 @@ void Player::_ApplyItemBonuses(ItemTemplate const* proto, uint8 slot, bool apply
if (proto->ArcaneRes) if (proto->ArcaneRes)
HandleStatModifier(UNIT_MOD_RESISTANCE_ARCANE, BASE_VALUE, float(proto->ArcaneRes), apply); HandleStatModifier(UNIT_MOD_RESISTANCE_ARCANE, BASE_VALUE, float(proto->ArcaneRes), apply);
uint8 attType = Player::GetAttackBySlot(slot); WeaponAttackType attType = Player::GetAttackBySlot(slot);
if (attType != MAX_ATTACK) if (attType != MAX_ATTACK)
{ {
_ApplyWeaponDamage(slot, proto, ssv, apply); _ApplyWeaponDamage(slot, proto, ssv, apply);
@@ -6935,7 +6936,7 @@ void Player::_ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, ScalingSt
ssv = ScalingStatValue ? sScalingStatValuesStore.LookupEntry(ssd_level) : nullptr; ssv = ScalingStatValue ? sScalingStatValuesStore.LookupEntry(ssd_level) : nullptr;
} }
uint8 attType = Player::GetAttackBySlot(slot); WeaponAttackType attType = Player::GetAttackBySlot(slot);
if (!IsInFeralForm() && apply && !CanUseAttackType(attType)) if (!IsInFeralForm() && apply && !CanUseAttackType(attType))
{ {
return; return;
@@ -6966,12 +6967,12 @@ void Player::_ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, ScalingSt
if (minDamage > 0.f) if (minDamage > 0.f)
{ {
SetBaseWeaponDamage(WeaponAttackType(attType), MINDAMAGE, minDamage, i); SetBaseWeaponDamage(attType, MINDAMAGE, minDamage, i);
} }
if (maxDamage > 0.f) if (maxDamage > 0.f)
{ {
SetBaseWeaponDamage(WeaponAttackType(attType), MAXDAMAGE, maxDamage, i); SetBaseWeaponDamage(attType, MAXDAMAGE, maxDamage, i);
} }
} }
} }
@@ -6980,8 +6981,8 @@ void Player::_ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, ScalingSt
{ {
for (uint8 i = 0; i < MAX_ITEM_PROTO_DAMAGES; ++i) for (uint8 i = 0; i < MAX_ITEM_PROTO_DAMAGES; ++i)
{ {
SetBaseWeaponDamage(WeaponAttackType(attType), MINDAMAGE, 0.f, i); SetBaseWeaponDamage(attType, MINDAMAGE, 0.f, i);
SetBaseWeaponDamage(WeaponAttackType(attType), MAXDAMAGE, 0.f, i); SetBaseWeaponDamage(attType, MAXDAMAGE, 0.f, i);
} }
if (attType == BASE_ATTACK) if (attType == BASE_ATTACK)
@@ -7005,8 +7006,8 @@ void Player::_ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, ScalingSt
if (IsInFeralForm()) if (IsInFeralForm())
return; return;
if (CanModifyStats() && (GetWeaponDamageRange(WeaponAttackType(attType), MAXDAMAGE) || proto->Delay)) if (CanModifyStats() && (GetWeaponDamageRange(attType, MAXDAMAGE) || proto->Delay))
UpdateDamagePhysical(WeaponAttackType(attType)); UpdateDamagePhysical(attType);
} }
void Player::CastAllObtainSpells() void Player::CastAllObtainSpells()
@@ -7599,9 +7600,9 @@ void Player::_RemoveAllItemMods()
if (!proto) if (!proto)
continue; continue;
uint32 attacktype = Player::GetAttackBySlot(i); WeaponAttackType attacktype = Player::GetAttackBySlot(i);
if (attacktype < MAX_ATTACK) if (attacktype < MAX_ATTACK)
_ApplyWeaponDependentAuraMods(m_items[i], WeaponAttackType(attacktype), false); _ApplyWeaponDependentAuraMods(m_items[i], attacktype, false);
_ApplyItemBonuses(proto, i, false); _ApplyItemBonuses(proto, i, false);
@@ -7628,9 +7629,9 @@ void Player::_ApplyAllItemMods()
if (!proto) if (!proto)
continue; continue;
uint32 attacktype = Player::GetAttackBySlot(i); WeaponAttackType attacktype = Player::GetAttackBySlot(i);
if (attacktype < MAX_ATTACK) if (attacktype < MAX_ATTACK)
_ApplyWeaponDependentAuraMods(m_items[i], WeaponAttackType(attacktype), true); _ApplyWeaponDependentAuraMods(m_items[i], attacktype, true);
_ApplyItemBonuses(proto, i, true); _ApplyItemBonuses(proto, i, true);
+1 -1
View File
@@ -1257,7 +1257,7 @@ public:
bool HasWeapon(WeaponAttackType type) const override { return GetWeaponForAttack(type, false); } bool HasWeapon(WeaponAttackType type) const override { return GetWeaponForAttack(type, false); }
bool HasWeaponForAttack(WeaponAttackType type) const override { return (Unit::HasWeaponForAttack(type) && GetWeaponForAttack(type, true)); } bool HasWeaponForAttack(WeaponAttackType type) const override { return (Unit::HasWeaponForAttack(type) && GetWeaponForAttack(type, true)); }
[[nodiscard]] Item* GetShield(bool useable = false) const; [[nodiscard]] Item* GetShield(bool useable = false) const;
static uint8 GetAttackBySlot(uint8 slot); // MAX_ATTACK if not weapon slot static WeaponAttackType GetAttackBySlot(uint8 slot); // MAX_ATTACK if not weapon slot
std::vector<Item*>& GetItemUpdateQueue() { return m_itemUpdateQueue; } std::vector<Item*>& GetItemUpdateQueue() { return m_itemUpdateQueue; }
static bool IsInventoryPos(uint16 pos) { return IsInventoryPos(pos >> 8, pos & 255); } static bool IsInventoryPos(uint16 pos) { return IsInventoryPos(pos >> 8, pos & 255); }
static bool IsInventoryPos(uint8 bag, uint8 slot); static bool IsInventoryPos(uint8 bag, uint8 slot);
@@ -51,6 +51,7 @@
#include "QuestDef.h" #include "QuestDef.h"
#include "ReputationMgr.h" #include "ReputationMgr.h"
#include "ScriptMgr.h" #include "ScriptMgr.h"
#include "ScriptObjectFwd.h"
#include "SocialMgr.h" #include "SocialMgr.h"
#include "Spell.h" #include "Spell.h"
#include "SpellAuraEffects.h" #include "SpellAuraEffects.h"
@@ -539,7 +540,7 @@ Item* Player::GetShield(bool useable) const
return item; return item;
} }
uint8 Player::GetAttackBySlot(uint8 slot) WeaponAttackType Player::GetAttackBySlot(uint8 slot)
{ {
switch (slot) switch (slot)
{ {
+2 -2
View File
@@ -8179,7 +8179,7 @@ bool Unit::HandleDummyAuraProc(Unit* victim, uint32 damage, AuraEffect* triggere
if (triggeredByAura->GetBase() && castItem->GetGUID() != triggeredByAura->GetBase()->GetCastItemGUID()) if (triggeredByAura->GetBase() && castItem->GetGUID() != triggeredByAura->GetBase()->GetCastItemGUID())
return false; return false;
WeaponAttackType attType = WeaponAttackType(player->GetAttackBySlot(castItem->GetSlot())); WeaponAttackType attType = player->GetAttackBySlot(castItem->GetSlot());
if ((attType != BASE_ATTACK && attType != OFF_ATTACK) if ((attType != BASE_ATTACK && attType != OFF_ATTACK)
|| (attType == BASE_ATTACK && procFlag & PROC_FLAG_DONE_OFFHAND_ATTACK) || (attType == BASE_ATTACK && procFlag & PROC_FLAG_DONE_OFFHAND_ATTACK)
|| (attType == OFF_ATTACK && procFlag & PROC_FLAG_DONE_MAINHAND_ATTACK)) || (attType == OFF_ATTACK && procFlag & PROC_FLAG_DONE_MAINHAND_ATTACK))
@@ -8370,7 +8370,7 @@ bool Unit::HandleDummyAuraProc(Unit* victim, uint32 damage, AuraEffect* triggere
if (!IsPlayer() || !victim || !victim->IsAlive() || !castItem || !castItem->IsEquipped()) if (!IsPlayer() || !victim || !victim->IsAlive() || !castItem || !castItem->IsEquipped())
return false; return false;
WeaponAttackType attType = WeaponAttackType(Player::GetAttackBySlot(castItem->GetSlot())); WeaponAttackType attType = Player::GetAttackBySlot(castItem->GetSlot());
if ((attType != BASE_ATTACK && attType != OFF_ATTACK) if ((attType != BASE_ATTACK && attType != OFF_ATTACK)
|| (attType == BASE_ATTACK && procFlag & PROC_FLAG_DONE_OFFHAND_ATTACK) || (attType == BASE_ATTACK && procFlag & PROC_FLAG_DONE_OFFHAND_ATTACK)
|| (attType == OFF_ATTACK && procFlag & PROC_FLAG_DONE_MAINHAND_ATTACK)) || (attType == OFF_ATTACK && procFlag & PROC_FLAG_DONE_MAINHAND_ATTACK))
+1 -1
View File
@@ -967,7 +967,7 @@ public:
inline bool HasMainhandWeaponForAttack() const { return HasWeaponForAttack(BASE_ATTACK); } inline bool HasMainhandWeaponForAttack() const { return HasWeaponForAttack(BASE_ATTACK); }
inline bool HasOffhandWeaponForAttack() const { return HasWeaponForAttack(OFF_ATTACK); } inline bool HasOffhandWeaponForAttack() const { return HasWeaponForAttack(OFF_ATTACK); }
inline bool HasRangedWeaponForAttack() const { return HasWeaponForAttack(RANGED_ATTACK); } inline bool HasRangedWeaponForAttack() const { return HasWeaponForAttack(RANGED_ATTACK); }
[[nodiscard]] bool CanUseAttackType(uint8 attacktype) const [[nodiscard]] bool CanUseAttackType(WeaponAttackType attacktype) const
{ {
switch (attacktype) switch (attacktype)
{ {
@@ -3002,12 +3002,12 @@ void AuraEffect::HandleAuraModDisarm(AuraApplication const* aurApp, uint8 mode,
{ {
if (Item* pItem = target->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, slot)) if (Item* pItem = target->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
{ {
uint8 attacktype = Player::GetAttackBySlot(slot); WeaponAttackType attacktype = Player::GetAttackBySlot(slot);
if (attacktype < MAX_ATTACK) if (attacktype < MAX_ATTACK)
{ {
target->ToPlayer()->_ApplyWeaponDamage(slot, pItem->GetTemplate(), nullptr, !apply); target->ToPlayer()->_ApplyWeaponDamage(slot, pItem->GetTemplate(), nullptr, !apply);
target->ToPlayer()->_ApplyWeaponDependentAuraMods(pItem, WeaponAttackType(attacktype), !apply); target->ToPlayer()->_ApplyWeaponDependentAuraMods(pItem, attacktype, !apply);
} }
} }
} }
+1 -1
View File
@@ -1824,7 +1824,7 @@ SpellCastResult SpellInfo::CheckTarget(Unit const* caster, WorldObject const* ta
{ {
if (Player const* player = unitTarget->ToPlayer()) if (Player const* player = unitTarget->ToPlayer())
{ {
if (player->GetWeaponForAttack(WeaponAttackType(BASE_ATTACK + i), true)) if (player->GetWeaponForAttack(WeaponAttackType(i), true))
{ {
valid = true; valid = true;
break; break;