From 69916138bdb61444c53acb059987e7b058bc175e Mon Sep 17 00:00:00 2001 From: Metalaka Date: Sun, 21 Feb 2021 17:28:47 +0100 Subject: [PATCH] Core/Unit: Fix glancing blow calculation (#26120) * Fix glancing blow calculation * Comment readability improvement Co-authored-by: Trond B. Krokli <38162891+illfated@users.noreply.github.com> * Update src/server/game/Entities/Unit/Unit.cpp Co-authored-by: Metalaka * Tabs to spaces Co-authored-by: Trond B. Krokli <38162891+illfated@users.noreply.github.com> Co-authored-by: Giacomo Pozzoni --- src/server/game/Entities/Unit/Unit.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index b2fa0d64bf1..8e69c5d03ab 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -1315,14 +1315,22 @@ void Unit::CalculateMeleeDamage(Unit* victim, CalcDamageInfo* damageInfo, Weapon { damageInfo->HitInfo |= HITINFO_GLANCING; damageInfo->TargetState = VICTIMSTATE_HIT; - int32 leveldif = int32(victim->GetLevel()) - int32(GetLevel()); + int32 leveldif = int32(victim->GetLevelForTarget(this)) - int32(GetLevel()); + if (leveldif < 0) + { + TC_LOG_DEBUG("entities.unit", "Unit::CalculateMeleeDamage: (Player) %s attacked %s. Glancing should never happen against lower level target", GetGUID().ToString().c_str(), victim->GetGUID().ToString().c_str()); + break; + } + if (leveldif == 0) + leveldif = 1; if (leveldif > 3) leveldif = 3; // against boss-level targets - 24% chance of 25% average damage reduction (damage reduction range : 20-30%) // against level 82 elites - 18% chance of 15% average damage reduction (damage reduction range : 10-20%) int32 const reductionMax = leveldif * 10; - int32 const reductionMin = reductionMax - 10; + int32 const reductionMin = std::max(1, reductionMax - 10); + float reducePercent = 1.f - irand(reductionMin, reductionMax) / 100.0f; for (uint8 i = 0; i < MAX_ITEM_PROTO_DAMAGES; ++i) @@ -2169,10 +2177,10 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst(Unit const* victim, WeaponAttackTy } // 4. GLANCING - // Max 40% chance to score a glancing blow against mobs that are higher level (can do only players and pets and not with ranged weapon) + // Max 40% chance to score a glancing blow against mobs of the same or higher level (only players and pets, not for ranged weapons). if ((GetTypeId() == TYPEID_PLAYER || IsPet()) && victim->GetTypeId() != TYPEID_PLAYER && !victim->IsPet() && - GetLevel() < victim->GetLevelForTarget(this)) + GetLevel() <= victim->GetLevelForTarget(this)) { // cap possible value (with bonuses > max skill) int32 skill = attackerWeaponSkill;