scope CruelEvasion initializer Init
//Cruel Evasion by The_Witcher
//
// requires my Stun System
//
// the unit has a chance to evade an attack, blink behind the attacker, hit him critical and stun him.
//
// The SETUP part
globals
// The rawcode of your ability
private constant integer AbiID = 'A000'
// The effect created at the target loc
private constant string BlinkTargetSFX = "Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl"
// The effect created at the caster loc
private constant string BlinkCasterSFX = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
// If ranged is false only attacks from nearer then 200 will fire the effect
private boolean ranged = true
endglobals
private function GetEvasionPercentage takes integer level returns real
return 0.2 * level //20% on level 1, 40% on level 2, 60% on level 3,...
endfunction
private function GetDamage takes integer level returns real
return 100 + 50 * I2R(level) //150 on level 1, 200 level 2, 250 level 3,...
endfunction
private function GetStunTime takes integer level returns real
return 1 + 1 * I2R(level) //2sec on level 1, 3sec level 2, 4sec level 3,...
endfunction
// END OF SETUP PART
private function DistanceBetweenUnits takes unit a, unit b returns real
local real dx = GetUnitX(b) - GetUnitX(a)
local real dy = GetUnitY(b) - GetUnitY(a)
return SquareRoot(dx * dx + dy * dy)
endfunction
private function check takes nothing returns boolean
local unit a = GetTriggerUnit()
local unit b = GetAttacker()
local integer lvl = GetUnitAbilityLevel(a,AbiID)
local real time = GetStunTime(lvl)
local real p = GetEvasionPercentage(lvl)
local real dmg = GetDamage(lvl)
local real x = GetUnitX(b) + 100 * Cos((GetUnitFacing(b)-180) *bj_DEGTORAD)
local real y = GetUnitY(b) + 100 * Sin((GetUnitFacing(b)-180) *bj_DEGTORAD)
local real rp = GetRandomReal(0,1)
local boolean bool = DistanceBetweenUnits(a,b) < 200
if ranged then
set bool = true
endif
if lvl > 0 and rp > (1-p) and bool then
call DestroyEffect(AddSpecialEffect(BlinkCasterSFX,GetUnitX(a),GetUnitY(a)))
call DestroyEffect(AddSpecialEffect(BlinkTargetSFX,x,y))
call SetUnitPosition(a,x,y)
call SetUnitFacing(a,GetUnitFacing(b))
call StunUnit(b,time)
call UnitDamageTarget(a,b,dmg,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
call SetUnitAnimation(a,"attack")
endif
set a = null
set b = null
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition(t,Condition(function check))
endfunction
endscope