- 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.
And function to get the target's armor damage reduction, which returned 0.5.
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?
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?