- Joined
- Mar 25, 2016
- Messages
- 1,327
JASS:
scope Dummy initializer Init
globals
private constant integer DUMMY_ID = 'h000'
private constant player PLAYER = Player(0)
private constant integer ABILITY_ID = 'A000'
endglobals
globals
private unit tauren
private Shockwave array waves
private integer waveCount
private hashtable hash
endglobals
struct Shockwave
real direction
real speed
unit dummy
real maxDist
real dist
integer playerNumber
unit owner
public method Setup takes integer playerNumber, unit owner, integer unitId, real x, real y, real direction returns nothing
set this.dummy = CreateUnit(Player( PLAYER_NEUTRAL_PASSIVE ), unitId, x, y, direction)
set this.direction = direction
set this.playerNumber = playerNumber
set this.owner = owner
set this.dist = 0
endmethod
public method SetMovement takes real maxDist, real direction, real speed returns nothing
set this.maxDist = maxDist
set this.direction = direction
set this.speed = speed
endmethod
public method Move takes nothing returns nothing
local real x = GetUnitX(this.dummy)
local real y = GetUnitY(this.dummy)
local group g
local unit u
call SetUnitFacing(this.dummy, this.direction)
set x = x + Cos(this.direction * bj_DEGTORAD)*speed
set y = y + Sin(this.direction *bj_DEGTORAD)*speed
call SetUnitX(this.dummy, x)
call SetUnitY(this.dummy, y)
set this.dist = this.dist + this.speed
set g = CreateGroup()
call GroupEnumUnitsInRange(g, x, y, 100, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
if(IsPlayerEnemy(GetOwningPlayer(u), Player(this. playerNumber)) and GetWidgetLife(u)>0.405) then
call UnitDamageTarget(this.owner, u, 100*0.03, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
endif
endloop
call DestroyGroup(g)
set g = null
set u = null
endmethod
method destroy takes nothing returns nothing
// null your variables
call RemoveUnit(this.dummy)
set this.dummy = null
call this.deallocate()
endmethod
endstruct
private function Periodic takes nothing returns nothing
local integer h = 1
local Shockwave wave
local timer t = GetExpiredTimer()
set h = GetHandleId(t)
set wave = LoadInteger(hash, h, 0)
call wave.Move()
if(wave.dist >= wave. maxDist) then
call wave.destroy()
call FlushChildHashtable(hash, h)
call PauseTimer(t)
call DestroyTimer(t)
endif
set t = null
endfunction
private function EscButton takes nothing returns nothing
local real x = GetUnitX(tauren)
local real y = GetUnitY(tauren)
local real degrees = GetUnitFacing(tauren)
local integer i = 0
local timer t
local Shockwave wave
loop
exitwhen i>=8
set wave = Shockwave.create()
call wave.Setup(GetPlayerId(PLAYER),tauren , DUMMY_ID, x, y, degrees+45*i)
call wave.SetMovement(1000, degrees+45*i, 25)
set t = CreateTimer()
call TimerStart(t,0.03,true, function Periodic)
call SaveInteger(hash, GetHandleId(t), 0, wave)
set i = i + 1
endloop
set t = null
endfunction
private function Init takes nothing returns nothing
local real x = GetRectCenterX( bj_mapInitialPlayableArea )
local real y = GetRectCenterY( bj_mapInitialPlayableArea )
local trigger trg = CreateTrigger()
local timer t
set tauren = CreateUnit(PLAYER, 'Otch', x, y, 0)
call TriggerRegisterPlayerEvent(trg, PLAYER, EVENT_PLAYER_END_CINEMATIC)
call TriggerAddAction(trg, function EscButton)
set t = CreateTimer()
set hash = InitHashtable()
set t = null
set waveCount = 0
set trg = null
endfunction
endscope
Feedback would be appreciated. This is my first time using structs.