After using the spell for a few times, the game's frame rate dropped.
Then I went to the task manager and found out that the processor is serving 50% of this power to warcraft. (Its a duo core CPU)
I checked for leaks and it doesn't seemed to have any...
Or maybe I have missed out some of them
Here is the code
Edit: Updated with destroying groups, but still lags
Edit2: Updated another time with a few leaks removed, but still lags even after the spell is cast.
Edit3: Something amusing, when I removed most of the functions in the trigger (except the init and condition) the processing power rose and never comes down! I am 100% sure its with this code as the problem didn't occur when I cast different spells with the same unit.
The new code
Then I went to the task manager and found out that the processor is serving 50% of this power to warcraft. (Its a duo core CPU)
I checked for leaks and it doesn't seemed to have any...
Or maybe I have missed out some of them
Here is the code
JASS:
scope PiercingThunder initializer init
scope PiercingThunder initializer init
globals
private constant integer AbiId=039;A004039;
private constant integer Range=100
endglobals
private struct dat
unit u
integer level
real x
real y
real ox
real oy
real oz
group g = CreateGroup()
real angle
lightning bolt
static method create takes unit cu,location loc returns dat
local dat this=.allocate()
set .u=cu
set .level=GetUnitAbilityLevel(cu,AbiId)
set .x=GetLocationX(loc)
set .y=GetLocationY(loc)
set .oz=GetLocationZ(loc)
set .ox=GetUnitX(.u)
set .oy=GetUnitY(.u)
set .oz=GetUnitZ(.u)
set .angle=bj_RADTODEG*Atan2(.y - GetUnitY(.u), .x - GetUnitX(.u))
set .bolt=AddLightningEx("FORK",true,.ox,.oy,.oz,GetUnitX(.u),GetUnitY(.u),GetUnitZ(.u))
return this
endmethod
static method setLightning takes dat this returns nothing
call MoveLightningEx(.bolt,true,.ox,.oy,.oz,GetUnitX(.u),GetUnitY(.u),GetUnitZ(.u))
endmethod
method onDestroy takes nothing returns nothing
call GroupClear(.g)
call DestroyLightning(.bolt)
endmethod
endstruct
private function damage takes integer i returns real
if i==1 then
return 100.
endif
if i==2 then
return 150.
endif
if i==3 then
return 225.
endif
return 300.
endfunction
private function Check takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)!=true and GetWidgetLife(GetFilterUnit())> .405
endfunction
private function tick takes nothing returns boolean
local dat d=KT_GetData()
local unit tempu
local real rx=GetUnitX(d.u)
local real ry=GetUnitY(d.u)
local real x = rx-d.x
local real y = ry-d.y
local real dis=SquareRoot(x*x+y*y)
local group tempg=CreateGroup()
local rect re = Rect( rx-Range, ry-Range,rx+Range, ry+Range )
call d.setLightning(d)
//Check unit distance
if dis<50 then
call SetUnitPosition(d.u,d.x,d.y)
call SetUnitPathing(d.u,true)
call GroupClear(tempg)
call RemoveRect(re)
call d.destroy()
return true
else
call SetUnitPosition(d.u,rx+50*Cos(d.angle*bj_DEGTORAD),ry+50*Sin(d.angle*bj_DEGTORAD))
endif
//Get unit in range
call GroupEnumUnitsInRect(tempg,re,Condition(function Check))
//Damage loop
loop
set tempu=FirstOfGroup(tempg)
exitwhen tempu==null
if IsUnitInGroup(tempu,d.g) == false and IsUnitEnemy(tempu,GetOwningPlayer(d.u)) then
call UnitDamageTarget(d.u,tempu,damage(d.level),true,false,ATTACK_TYPE_HERO,DAMAGE_TYPE_NORMAL,null)
endif
call GroupRemoveUnit(tempg,tempu)
call GroupAddUnit(d.g,tempu)
endloop
call GroupClear(tempg)
call RemoveRect(re)
return false
endfunction
private function a takes nothing returns nothing
local dat d=dat.create(GetTriggerUnit(),GetSpellTargetLoc())
call KT_Add(function tick,d,0.0125)
call SetUnitPathing(d.u,false)
endfunction
private function c takes nothing returns boolean
if GetSpellAbilityId()==AbiId then
call a()
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
local integer index=0
loop
call TriggerRegisterPlayerUnitEvent( t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition(t,Condition(function c))
endfunction
endscope
Edit: Updated with destroying groups, but still lags
Edit2: Updated another time with a few leaks removed, but still lags even after the spell is cast.
Edit3: Something amusing, when I removed most of the functions in the trigger (except the init and condition) the processing power rose and never comes down! I am 100% sure its with this code as the problem didn't occur when I cast different spells with the same unit.
The new code
JASS:
scope PiercingThunder initializer init
globals
private constant integer AbiId=039;A004039;
private constant integer Range=100
endglobals
private function a takes nothing returns nothing
local location spellTar=GetSpellTargetLoc()
//local dat d=dat.create(GetTriggerUnit(),spellTar)
call RemoveLocation(spellTar)
//call KT_Add(function tick,d,0.0125)
//call SetUnitPathing(d.u,false)
endfunction
private function c takes nothing returns boolean
if GetSpellAbilityId()==AbiId then
call a()
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
local integer index=0
loop
call TriggerRegisterPlayerUnitEvent( t, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition(t,Condition(function c))
endfunction
endscope