TriggerHappy
...
- Reaction score
- 341
Warp
TriggerHappy187
TriggerHappy187
Spell Info:
Coding: vJASS
Requirements: TimerUtils
Description: Warps the unit to a point, damaging all the units that comes it the casters way.
Screenshot: (link)
Requirements: TimerUtils
Description: Warps the unit to a point, damaging all the units that comes it the casters way.
Screenshot: (link)
Spell Code:
JASS:
library Warp initializer InitTrig requires TimerUtils
globals
private constant integer SPELL_ID = 039;A000039; // The raw ID of the spell
private constant real TIMEOUT = 0.03 // How fast the timer runs
private constant real FX_TIMEOUT = 0.05 // How fast the effects are created
private constant real SPEED = 30 // How fast the caster is "Warped"
private constant real DAMAGE_RADIUS = 300 // How close the units need to be to get damaged
private constant real TARGET_RADIUS = 90 // How close to the destination the caster has to be for it to stop, just a safety global
private constant string TRAIL_EFFECT = "Abilities\\Spells\\Human\\Invisibility\\InvisibilityTarget.mdl" // the warp effect
private constant attacktype ATTACK = ATTACK_TYPE_MAGIC // the damage attack type
private constant damagetype DAMAGE = DAMAGE_TYPE_UNIVERSAL // the damage damage type
endglobals
private constant function GetDamage takes integer level returns real
return 5.*level
endfunction
private struct data
unit caster
real x
real y
real sin
real cos
real last
static group g = CreateGroup()
static data temp
static real MapMaxX
static real MapMinX
static real MapMaxY
static real MapMinY
private static method True takes nothing returns boolean
return true
endmethod
private static method mapbounds takes real x, real y returns boolean
return x < data.MapMaxX or x > data.MapMinX or y < data.MapMaxY or y > data.MapMinY
endmethod
private static method fx takes nothing returns nothing
local data d = GetTimerData(GetExpiredTimer())
local real x1 = GetUnitX(d.caster)
local real y1 = GetUnitY(d.caster)
local real x = x1 + d.cos
local real y = y1 + d.sin
call GroupEnumUnitsInRange(data.g, d.x, d.y, TARGET_RADIUS, Filter(function data.True))
if not IsUnitInGroup(d.caster, data.g) then
call DestroyEffect(AddSpecialEffect(TRAIL_EFFECT, x, y))
return
else
call ReleaseTimer(GetExpiredTimer())
endif
endmethod
private static method callback takes nothing returns nothing
local data d = GetTimerData(GetExpiredTimer())
local real x1 = GetUnitX(d.caster)
local real y1 = GetUnitY(d.caster)
local real x = x1 + d.cos
local real y = y1 + d.sin
local real dmg = GetDamage(GetUnitAbilityLevel(d.caster, SPELL_ID))
local integer i = 0
local unit u
local real dis
if data.mapbounds(x,y) then
call SetUnitX(d.caster, x)
call SetUnitY(d.caster, y)
endif
set dis = SquareRoot((d.x - x1) * (d.x - x1) + (d.y - y1) * (d.y - y1))
if dis <= TARGET_RADIUS or dis > (d.last+TARGET_RADIUS) then
call ReleaseTimer(GetExpiredTimer())
call d.destroy()
return
endif
set d.last = dis
call GroupEnumUnitsInRange(data.g, x1, y1, DAMAGE_RADIUS, Filter(function data.True))
loop
set u = FirstOfGroup(data.g)
exitwhen u == null
call UnitDamageTarget(d.caster, u, dmg, true, false, ATTACK, DAMAGE, null)
call GroupRemoveUnit(data.g, u)
endloop
endmethod
static method create takes unit u, real x, real y returns data
local data d = data.allocate()
local real angle
local timer t = NewTimer()
local timer a = NewTimer()
local real x1 = GetUnitX(u)
local real y1 = GetUnitY(u)
call SetTimerData(t, d)
call SetTimerData(a, d)
set d.x = x
set d.y = y
set d.caster = u
call SetUnitX(d.caster, x1)
call SetUnitY(d.caster, y1)
call IssueImmediateOrder(d.caster, "stop")
set x = x - x1
set y = y - y1
set d.last = SquareRoot(x*x+y*y)
set angle = Atan2(y,x)
set d.cos = SPEED * Cos(angle)
set d.sin = SPEED * Sin(angle)
call TimerStart(t, TIMEOUT, true, function data.callback)
call TimerStart(a, FX_TIMEOUT, true, function data.fx)
return d
endmethod
endstruct
private function Actions takes nothing returns boolean
local location l = GetSpellTargetLoc()
if GetSpellAbilityId() == SPELL_ID then
call data.create(GetTriggerUnit(), GetLocationX(l), GetLocationY(l))
endif
call RemoveLocation(l)
set l = null
return false
endfunction
//===========================================================================
private function InitTrig takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(t, Condition(function Actions))
set data.MapMaxX = GetRectMaxX(bj_mapInitialPlayableArea)-64.00
set data.MapMaxY = GetRectMaxY(bj_mapInitialPlayableArea)-64.00
set data.MapMinY = GetRectMinX(bj_mapInitialPlayableArea)+64.00
set data.MapMinX = GetRectMinY(bj_mapInitialPlayableArea)+64.0
endfunction
endlibrary