function CalcHit takes unit A, unit D, real dmg returns real
local integer Alvl = GetUnitAbilityLevelSwapped('A000', A)
local integer Dlvl = GetUnitAbilityLevelSwapped('A000', D)
local integer Arol = ((GetRandomInt(1, 10) + Alvl)*5)
local integer Drol = ((GetRandomInt(1, 10) + Dlvl)*5)
local texttag ae = CreateTextTag()
local texttag de = CreateTextTag()
if (Alvl > 0)then
if (Arol <= (30-(Alvl*2))) then
set dmg = 0
call SetTextTagText(ae,"Miss!", 0.024)
call SetTextTagPos(ae, GetUnitX(A), GetUnitY(A), 0.00)
call SetTextTagColor(ae, 255, 0, 0, 255)
call SetTextTagVelocity(ae, 0, 0.04)
call SetTextTagVisibility(ae, true)
call SetTextTagFadepoint(ae, 2)
call SetTextTagLifespan(ae, 5)
call SetTextTagPermanent(ae, false)
endif
if (Arol >= (100-Alvl)) then
set dmg = dmg*2
call SetTextTagText(ae,"Crit!", 0.024)
call SetTextTagPos(ae, GetUnitX(A), GetUnitY(A), 0.00)
call SetTextTagColor(ae, 255, 0, 0, 255)
call SetTextTagVelocity(ae, 0, 0.04)
call SetTextTagVisibility(ae, true)
call SetTextTagFadepoint(ae, 2)
call SetTextTagLifespan(ae, 5)
call SetTextTagPermanent(ae, false)
endif
endif
if (Dlvl > 0) then
if (Drol <= (30+(Dlvl*2))) then
set dmg = dmg*0.5
call SetTextTagText(de,"Block!", 0.024)
call SetTextTagPos(de, GetUnitX(D), GetUnitY(D), 0.00)
call SetTextTagColor(de, 0, 0, 255, 255)
call SetTextTagVelocity(de, 0, 0.04)
call SetTextTagVisibility(de, true)
call SetTextTagFadepoint(de, 2)
call SetTextTagLifespan(de, 5)
call SetTextTagPermanent(de, false)
endif
if (Drol >= (100-Dlvl)) then
set dmg = 0
call SetTextTagText(de,"Dodge!", 0.024)
call SetTextTagPos(de, GetUnitX(D), GetUnitY(D), 0.00)
call SetTextTagColor(de, 0, 0, 255, 255)
call SetTextTagVelocity(de, 0, 0.04)
call SetTextTagVisibility(de, true)
call SetTextTagFadepoint(de, 2)
call SetTextTagLifespan(de, 5)
call SetTextTagPermanent(de, false)
endif
endif
set ae = null
set de = null
set A = null
set D = null
return dmg
endfunction