Core/Entities: cleanup of weapon damage

- ScalingStatDistribution/Value (ie heirlooms): apply bonuses in all cases, some calls used nullptr (like after disarm) and item wasn't regaining them
- AP multiplier wasn't correctly reflected after unequipping a weapon
- Correctly set base damages at unequip
This commit is contained in:
ariel- authored and Ovahlord committed 2022-09-12 09:15:18 +02:00
1 parent 460c317399
commit 082121cb38
3 files changed
+68 -41

No files matched your search

+55 -32
View File
@@ -7397,22 +7397,36 @@ void Player::_ApplyItemMods(Item* item, uint8 slot, bool apply, bool updateItemA
TC_LOG_DEBUG("entities.player.items", "Player::_ApplyItemMods: completed");
}
ScalingStatDistributionEntry const* Player::GetScalingStatDistributionFor(ItemTemplate const& itemTemplate) const
{
if (!itemTemplate.GetScalingStatDistribution())
return nullptr;
return sScalingStatDistributionStore.LookupEntry(itemTemplate.GetScalingStatDistribution());
}
ScalingStatValuesEntry const* Player::GetScalingStatValuesFor(ItemTemplate const& itemTemplate) const
{
if (!itemTemplate.GetStatScalingFactor())
return nullptr;
ScalingStatDistributionEntry const* ssd = GetScalingStatDistributionFor(itemTemplate);
if (!ssd)
return nullptr;
// req. check at equip, but allow use for extended range if range limit max level, set proper level
uint32 const ssd_level = std::min(uint32(getLevel()), ssd->Maxlevel);
return sScalingStatValuesStore.LookupEntry(ssd_level);
}
void Player::_ApplyItemBonuses(ItemTemplate const* proto, uint8 slot, bool apply, bool only_level_scale /*= false*/)
{
if (slot >= INVENTORY_SLOT_BAG_END || !proto)
return;
ScalingStatDistributionEntry const* ssd = proto->GetScalingStatDistribution() ? sScalingStatDistributionStore.LookupEntry(proto->GetScalingStatDistribution()) : nullptr;
if (only_level_scale && !ssd)
return;
// req. check at equip, but allow use for extended range if range limit max level, set proper level
uint32 ssd_level = getLevel();
if (ssd && ssd_level > ssd->Maxlevel)
ssd_level = ssd->Maxlevel;
ScalingStatValuesEntry const* ssv = ssd ? sScalingStatValuesStore.LookupEntry(ssd_level) : nullptr;
if (only_level_scale && !ssv)
ScalingStatDistributionEntry const* ssd = GetScalingStatDistributionFor(*proto);
ScalingStatValuesEntry const* ssv = GetScalingStatValuesFor(*proto);
if (only_level_scale && (!ssd || !ssv))
return;
for (uint8 i = 0; i < MAX_ITEM_PROTO_STATS; ++i)
@@ -7628,15 +7642,16 @@ void Player::_ApplyItemBonuses(ItemTemplate const* proto, uint8 slot, bool apply
WeaponAttackType attType = Player::GetAttackBySlot(slot);
if (attType != MAX_ATTACK && CanUseAttackType(attType))
_ApplyWeaponDamage(slot, proto, ssv, apply);
_ApplyWeaponDamage(slot, proto, apply);
}
void Player::_ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, ScalingStatValuesEntry const* ssv, bool apply)
void Player::_ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, bool apply)
{
WeaponAttackType attType = Player::GetAttackBySlot(slot);
if (attType == MAX_ATTACK)
return;
ScalingStatValuesEntry const* ssv = GetScalingStatValuesFor(*proto);
float damage = 0.0f;
float minDamage, maxDamage, dps;
@@ -7656,29 +7671,37 @@ void Player::_ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, ScalingSt
}
}
if (minDamage > 0)
if (apply)
{
damage = apply ? minDamage : BASE_MINDAMAGE;
SetBaseWeaponDamage(attType, MINDAMAGE, damage);
if (minDamage > 0.f)
SetBaseWeaponDamage(attType, MINDAMAGE, minDamage);
if (maxDamage > 0.f)
SetBaseWeaponDamage(attType, MAXDAMAGE, maxDamage);
}
if (maxDamage > 0)
if (!apply)
{
damage = apply ? maxDamage : BASE_MAXDAMAGE;
SetBaseWeaponDamage(attType, MAXDAMAGE, damage);
if (attType == BASE_ATTACK)
{
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, BASE_MINDAMAGE);
SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, BASE_MAXDAMAGE);
}
else
{
SetBaseWeaponDamage(attType, MINDAMAGE, 0.f);
SetBaseWeaponDamage(attType, MAXDAMAGE, 0.f);
}
}
if (proto->GetDelay() && !IsInFeralForm())
{
if (slot == EQUIPMENT_SLOT_RANGED)
SetAttackTime(RANGED_ATTACK, apply ? proto->GetDelay() : BASE_ATTACK_TIME);
else if (slot == EQUIPMENT_SLOT_MAINHAND)
SetAttackTime(BASE_ATTACK, apply ? proto->GetDelay() : BASE_ATTACK_TIME);
else if (slot == EQUIPMENT_SLOT_OFFHAND)
SetAttackTime(OFF_ATTACK, apply ? proto->GetDelay() : BASE_ATTACK_TIME);
}
SetAttackTime(attType, apply ? proto->GetDelay() : BASE_ATTACK_TIME);
if (CanModifyStats() && (damage || proto->GetDelay()))
// No need to modify any physical damage for ferals as it is calculated from stats only
if (IsInFeralForm())
return;
if (CanModifyStats() && (GetWeaponDamageRange(attType, MAXDAMAGE) || proto->GetDelay()))
UpdateDamagePhysical(attType);
}
@@ -11905,19 +11928,19 @@ void Player::RemoveItem(uint8 bag, uint8 slot, bool update)
{
if (slot < INVENTORY_SLOT_BAG_END)
{
ItemTemplate const* pProto = pItem->GetTemplate();
// item set bonuses applied only at equip and removed at unequip, and still active for broken items
if (pProto && pProto->GetItemSet())
ItemTemplate const* pProto = ASSERT_NOTNULL(pItem->GetTemplate());
if (pProto->GetItemSet())
RemoveItemsSetItem(this, pProto);
// remove here before _ApplyItemMods (for example to register correct damages of unequipped weapon)
m_items[slot] = nullptr;
_ApplyItemMods(pItem, slot, false, update);
if (slot == EQUIPMENT_SLOT_MAINHAND || slot == EQUIPMENT_SLOT_OFFHAND)
UpdateExpertise(OFF_ATTACK);
}
m_items[slot] = nullptr;
SetGuidValue(PLAYER_FIELD_INV_SLOT_HEAD + (slot * 2), ObjectGuid::Empty);
if (slot < EQUIPMENT_SLOT_END)
+4 -1
View File
@@ -49,6 +49,7 @@ struct ItemSetEffect;
struct ItemTemplate;
struct Loot;
struct Mail;
struct ScalingStatDistributionEntry;
struct ScalingStatValuesEntry;
struct TrainerSpell;
struct VendorItem;
@@ -2030,8 +2031,10 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void _RemoveAllItemMods();
void _ApplyAllItemMods();
void _ApplyAllLevelScaleItemMods(bool apply);
ScalingStatDistributionEntry const* GetScalingStatDistributionFor(ItemTemplate const& itemTemplate) const;
ScalingStatValuesEntry const* GetScalingStatValuesFor(ItemTemplate const& itemTemplate) const;
void _ApplyItemBonuses(ItemTemplate const* proto, uint8 slot, bool apply, bool only_level_scale = false);
void _ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, ScalingStatValuesEntry const* ssv, bool apply);
void _ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, bool apply);
bool EnchantmentFitsRequirements(uint32 enchantmentcondition, int8 slot) const;
void ToggleMetaGemsActive(uint8 exceptslot, bool apply);
void CorrectMetaGemEnchants(uint8 slot, bool apply);
@@ -1983,7 +1983,7 @@ void AuraEffect::HandleAuraModShapeshift(AuraApplication const* aurApp, uint8 mo
if (!target->CanUseAttackType(BASE_ATTACK))
{
if (Item* pItem = target->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND))
target->ToPlayer()->_ApplyWeaponDamage(EQUIPMENT_SLOT_MAINHAND, pItem->GetTemplate(), nullptr, apply);
target->ToPlayer()->_ApplyWeaponDamage(EQUIPMENT_SLOT_MAINHAND, pItem->GetTemplate(), apply);
}
}
@@ -2371,7 +2371,10 @@ void AuraEffect::HandleAuraModDisarm(AuraApplication const* aurApp, uint8 mode,
Unit* target = aurApp->GetTarget();
//Prevent handling aura twice
AuraType type = GetAuraType();
if (apply ? target->GetAuraEffectsByType(type).size() > 1 : target->HasAuraType(type))
return;
// Prevent handling aura twice
if (apply ? target->GetAuraEffectsByType(type).size() > 1 : target->HasAuraType(type))
@@ -2403,8 +2406,10 @@ void AuraEffect::HandleAuraModDisarm(AuraApplication const* aurApp, uint8 mode,
return;
}
// if disarm aura is to be removed, remove the flag first to reapply damage/aura mods
if (!apply)
// set/remove flag before weapon bonuses so it's properly reflected in CanUseAttackType
if (apply)
target->SetFlag(field, flag);
else
target->RemoveFlag(field, flag);
// Handle damage modification, shapeshifted druids are not affected
@@ -2418,17 +2423,13 @@ void AuraEffect::HandleAuraModDisarm(AuraApplication const* aurApp, uint8 mode,
player->ApplyItemDependentAuras(item, !apply);
if (attackType != MAX_ATTACK)
{
player->_ApplyWeaponDamage(slot, item->GetTemplate(), nullptr, !apply);
player->_ApplyWeaponDamage(slot, item->GetTemplate(), !apply);
if (!apply) // apply case already handled on item dependent aura removal (if any)
player->UpdateWeaponDependentAuras(attackType);
}
}
}
// if disarm effects should be applied, wait to set flag until damage mods are unapplied
if (apply)
target->SetFlag(field, flag);
if (target->GetTypeId() == TYPEID_UNIT && target->ToCreature()->GetCurrentEquipmentId())
target->UpdateDamagePhysical(attType);
}