function CalcHit takes unit A, unit D, boolean r returns real
local integer Alvl = GetUnitAbilityLevelSwapped('A000', A)
local integer Dlvl = GetUnitAbilityLevelSwapped('A000', D)
local integer Amor = GetUnitAbilityLevelSwapped('A001', A)
local integer Dmor = GetUnitAbilityLevelSwapped('A001', D)
local integer Aexp = GetUnitAbilityLevelSwapped('A002', A)
local integer Dexp = GetUnitAbilityLevelSwapped('A002', D)
local integer Awep = GetUnitAbilityLevelSwapped('A003', A)
local integer Apop = R2I(GetUnitStateSwap(UNIT_STATE_LIFE, A))
local integer Arol = (((GetRandomInt(1, 10) + Alvl)*5) + Aexp) + Amor
local integer Drol = (((GetRandomInt(1, 10) + Dlvl)*5) + Dexp) + Dmor
local integer dmg = 0
local integer Amin = 0
local integer Amax = 0
local integer Dmin = 0
local integer Dmax = 0
local texttag ae = CreateTextTag()
local texttag de = CreateTextTag()
if r then
set dmg = ((GetRandomInt((Apop / 6), (Apop / 4))-(Apop / 8)) + Awep) + (Amor - Dmor)
set Amin = (25-(Alvl*2)) - Amor
set Amax = (105-Alvl) - Amor
set Dmin = (35+(Dlvl*2)) + Dmor
set Dmax = (105-Dlvl) - Dmor
else
set dmg = (GetRandomInt((Apop / 6), (Apop / 4)) + Awep) + (Amor - Dmor)
set Amin = (20-(Alvl*2)) - Amor
set Amax = (100-Alvl) - Amor
set Dmin = (30+(Dlvl*2)) + Dmor
set Dmax = (100-Dlvl) - Dmor
endif
if (Alvl > 0)then
if (Arol <= Amin) 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 >= Amax) 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 <= Dmin) then
set dmg = dmg / 2
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 >= Dmax) 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 I2R(dmg)
endfunction