Unknown damage bonus?

Status
Not open for further replies.
Level 13
Joined
Mar 29, 2012
Messages
542
I've been trying to get the exact weapon damage value of a hero against a unit or structure.
There are 2 functions that I used:

Function to get the hero weapon damage, which returned 20.
JASS:
function hAI_GetUnitWeaponDamage takes unit u, integer weaponId returns integer
    local integer dice = BlzGetUnitDiceNumber(u, weaponId)
    local integer min = BlzGetUnitBaseDamage(u, weaponId) + dice
    local integer max = min + (dice * BlzGetUnitDiceSides(u, weaponId))
 
    return min + ((max - min) / 2)
endfunction

And function to get the target's armor damage reduction, which returned 0.5.
JASS:
function hAI_GetUnitArmorDamageFactor takes unit u, attacktype aType returns real
    local boolean dmgEventEnabled = IsTriggerEnabled(udg_hAI_DE_DamageEventTrigger)
    local real originalArmor = BlzGetUnitArmor(u)
    local real originalMaxLife = BlzGetUnitMaxHP(u)
    local real originalMaxMana = BlzGetUnitMaxMana(u)
    local real originalLife = GetWidgetLife(u)
    local real originalMana = GetUnitState(u, UNIT_STATE_MANA)
    local real testLife
 
    call BlzSetUnitArmor(u, 0)
    call BlzSetUnitMaxHP(u, 10000)
    call SetWidgetLife(u, 10000.)
    call BlzSetUnitMaxMana(u, 10000)
    call SetUnitState(u, UNIT_STATE_MAX_MANA, 10000.)
    call DisableTrigger(udg_hAI_DE_DamageEventTrigger)
    call UnitDamageTarget(u, u, 100., false, false, aType, DAMAGE_TYPE_UNKNOWN, null)
    set testLife = GetWidgetLife(u)
 
    if dmgEventEnabled then
        call EnableTrigger(udg_hAI_DE_DamageEventTrigger)
    endif
    call BlzSetUnitArmor(u, originalArmor)
    call BlzSetUnitMaxHP(u, R2I(originalMaxLife))
    call SetWidgetLife(u, originalLife)
    call BlzSetUnitMaxMana(u, R2I(originalMaxMana))
    call SetUnitState(u, UNIT_STATE_MANA, originalMana)
 
    return (10000. - testLife) / 100.
endfunction

But the in-game result when the hero damaged the target, the damage value is 7.692. The right value should be 10. [weapon damage value (20) * armor damage reduction (0.5)]
Anyone know what might cause this?
 
It looks like "hAI_GetUnitArmorDamageFactor" only accounts for the reduction added by armor type. It sets the armor value of the unit to 0 before doing the test, if you pay close attention.

What seems to be missing is the additional % reduction from the armor value.
 
It looks like "hAI_GetUnitArmorDamageFactor" only accounts for the reduction added by armor type. It sets the armor value of the unit to 0 before doing the test, if you pay close attention.

What seems to be missing is the additional % reduction from the armor value.
Hmmm.. that might be the missing part.
I forgot if I did take a look on the armor value.

I'll test it ASAP.
* On mobile phone

Edit:
I've tested it. You're right, the missing damage reduction is from armor value, thank you.
But now I need to get the formula for that. Please help me on this post.

The problem here is solved.
 
Last edited:
Status
Not open for further replies.
Back
Top