struct rangedattack extends projectile
static trigger rangedtrigger = CreateTrigger()
private real damage
private real collisionHeight
static location tempLoc = Location(0,0)
private integer element
method isValidTargetUnit takes unit u returns boolean
local boolean inRange = false
call MoveLocation(tempLoc, GetUnitX(u), GetUnitY(u))
if (absoluteReal(GetLocationZ(thistype.tempLoc)+GetUnitFlyHeight(u) - z) < .collisionHeight) then
set inRange = true
endif
return (u != source) and GetWidgetLife(u) >= .405 and inRange
endmethod
method onUnitCollision takes unit u returns nothing
if not (destroyed) then
call Damage.Unit(.source, u, .damage, .element)
call destroy()
endif
endmethod
method isValidTargetDest takes destructable d returns boolean
call DisplayTextToPlayer(Player(0), 0.0, 0.0, "Hit") //for debugging
return true
endmethod
method onDestCollision takes destructable d returns nothing
if (not (destroyed)) then
if not IsDestructableInvulnerable(d) then
call SetDestructableLife(d, GetDestructableLife(d) - .damage)
endif
call destroy()
endif
endmethod
static method create takes unit source, unit target, real damage, vector startVector, vector endVector, /*
*/ real speed, real arc, string modelpath, integer element returns thistype
local real a = Atan2(endVector.y-startVector.y, endVector.x-startVector.x)
local thistype d = .allocate(CreateUnit(GetOwningPlayer(source), 'dumy', startVector.x, startVector.y, a*bj_RADTODEG))
// Ranged data setup:
set d.damage = damage
call d.setModel(modelpath)
// Projectile setup:
set d.source = source
set d.collision = 32
set d.collisionHeight = 128
set d.element = element
set d.activeUnitCollision = true
set d.activeDestCollision = true
set d.toRemove = false
set d.toKill = true
set d.toDestroy = true
set d.activePitch = true
set d.activeRotation = true
set d.activeTargetFollow = false
set d.targetZOffset = 60
set d.target = target
call d.launch(startVector, endVector, speed, arc)
return d
endmethod
endstruct