Name | Type | is_array | initial_value |
//TESH.scrollpos=-1
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.1
One map, one hashtable. Welcome to NewTable 3.1
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb)
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=-1
//TESH.alwaysfold=0
library TimerUtilsEx requires optional Table
/*************************************************
*
* TimerUtilsEx
* v2.1.0.2
* By Vexorian, Bribe & Magtheridon96
*
* Original version by Vexorian.
*
* Flavors:
* Hashtable:
* - RAM: Minimal
* - TimerData: Slow
*
* Array:
* - RAM: Maximal
* - TimerData: Fast
*
* All the functions have O(1) complexity.
* The Array version is the fastest, but the hashtable
* version is the safest. The Array version is still
* quite safe though, and I would recommend using it.
* The system is much slower in debug mode.
*
* Optional Requirement:
* - Table by Bribe
* - hiveworkshop.com/forums/showthread.php?t=188084
*
* API:
* ----
* - function NewTimer takes nothing returns timer
* - Returns a new timer from the stack.
* - function NewTimerEx takes integer i returns timer
* - Returns a new timer from the stack and attaches a value to it.
* - function ReleaseTimer takes timer t returns integer
* - Throws a timer back into the stack. Also returns timer data.
* - function SetTimerData takes timer t, integer value returns nothing
* - Attaches a value to a timer.
* - function GetTimerData takes timer t returns integer
* - Returns the attached value.
*
*************************************************/
// Configuration
globals
// Use hashtable, or fast array?
private constant boolean USE_HASH = false
// Max Number of Timers Held in Stack
private constant integer QUANTITY = 256
endglobals
globals
private timer array tT
private integer tN = 0
endglobals
private module Init
private static method onInit takes nothing returns nothing
static if not USE_HASH then
local integer i = QUANTITY
loop
set i = i - 1
set tT[i] = CreateTimer()
exitwhen i == 0
endloop
set tN = QUANTITY
elseif LIBRARY_Table then
set tb = Table.create()
endif
endmethod
endmodule
// JassHelper doesn't support static ifs for globals.
private struct Data extends array
static if not USE_HASH then
static integer array data
endif
static if LIBRARY_Table then
static Table tb = 0
else
static hashtable ht = InitHashtable()
endif
implement Init
endstruct
// Double free protection
private function ValidTimer takes integer i returns boolean
static if LIBRARY_Table then
return Data.tb.boolean[-i]
else
return LoadBoolean(Data.ht, i, 1)
endif
endfunction
private function Get takes integer id returns integer
debug if not ValidTimer(id) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to get data from invalid timer.")
debug endif
static if USE_HASH then
static if LIBRARY_Table then
return Data.tb[id]
else
return LoadInteger(Data.ht, id, 0)
endif
else
return Data.data[id - 0x100000]
endif
endfunction
private function Set takes integer id, integer data returns nothing
debug if not ValidTimer(id) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to attach data to invalid timer.")
debug endif
static if USE_HASH then
static if LIBRARY_Table then
set Data.tb[id] = data
else
call SaveInteger(Data.ht, id, 0, data)
endif
else
set Data.data[id - 0x100000] = data
endif
endfunction
function SetTimerData takes timer t, integer data returns nothing
call Set(GetHandleId(t), data)
endfunction
function GetTimerData takes timer t returns integer
return Get(GetHandleId(t))
endfunction
function NewTimerEx takes integer data returns timer
local integer id
if tN == 0 then
static if USE_HASH then
set tT[0] = CreateTimer()
else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: No Timers In The Stack! You must increase 'QUANTITY'")
return null
endif
else
set tN = tN - 1
endif
set id = GetHandleId(tT[tN])
static if LIBRARY_Table then
set Data.tb.boolean[-id] = true
else
call SaveBoolean(Data.ht, id, 1, true)
endif
call Set(id, data)
return tT[tN]
endfunction
function NewTimer takes nothing returns timer
return NewTimerEx(0)
endfunction
function ReleaseTimer takes timer t returns integer
local integer id = GetHandleId(t)
local integer data = 0
// Pause the timer just in case.
call PauseTimer(t)
// Make sure the timer is valid.
if ValidTimer(id) then
// Get the timer's data.
set data = Get(id)
// Unmark handle id as a valid timer.
static if LIBRARY_Table then
call Data.tb.boolean.remove(-id)
else
call RemoveSavedBoolean(Data.ht, id, 1)
endif
//If it's not run in USE_HASH mode, this next block is useless.
static if USE_HASH then
//At least clear hash memory while it's in the recycle stack.
static if LIBRARY_Table then
call Data.tb.remove(id)
else
call RemoveSavedInteger(Data.ht, id, 0)
endif
// If the recycle limit is reached
if tN == QUANTITY then
// then we destroy the timer.
call DestroyTimer(t)
return data
endif
endif
//Recycle the timer.
set tT[tN] = t
set tN = tN + 1
//Tried to pass a bad timer.
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to release non-active timer!")
endif
//Return Timer Data.
return data
endfunction
endlibrary
//TESH.scrollpos=-1
//TESH.alwaysfold=0
library StunSystem uses Table
//! external ObjectMerger w3a ACfb ASTN aani "" aart "" amat "" amsp "0" anam "Stun (System)" ansf "" Htb1 1 "0" aran 1 "99999" acdn 1 "0" ahdu 1 "99999" adur 1 "99999" abuf 1 "BSTN" amcs 1 "0" arac "other" atar 1 "" atp1 1 " " aub1 1 " "
//! external ObjectMerger w3h BPSE BSTN fart "ReplaceableTextures\CommandButtons\BTNStun.blp" fnsf "" fnam "Stun (System)" ftip "Stunned" fube "This unit is stunned; it cannot move nor attack temporarily."
//! external ObjectMerger w3u nalb sTUN uabi Aloc ucbs 0 udtm 0 ushr 0 umdl "none.mdl" usca 0.1 ushu "None" util " " umvh 0 umvf 0 umvs 0 umas 0 umis 0 ucol 0 urac "human" unam "Stun Dummy" utip " " utub " " usid 0 usin 0
//********************************************************************************
// Stun - Version 1.2.0.0 - By iAyanami aka Ayanami
//********************************************************************************
//
// Stun:
// - An easy to use system that stuns units
// - Able to keep track of the remaining stun duration
//
// Requirements:
// - JASS NewGen
// - Table
//
// Functions:
// - Stun.apply takes unit whichUnit, real duration, boolean stack returns nothing
// * whichUnit is the target to be stunned
// * duration is the duration of the stun
// * stack is to determine if the stun should be a stacking one or not
// * true - the stun will stack, the duration of the stun will add up with the previous duration
// * false - the stun will not stack, the unit will be stunned for the longer stun duration
//
// - Stun.getDuration takes unit whichUnit returns real
// * whichUnit is the target to check
// * returns the remaining stun duration
//
// - Stun.stop takes unit whichUnit returns nothing
// * removes stun from the target
//
// How to import:
// - Copy the whole "Stun" Trigger Folder into your map
// - Save the map. Close and re-opem the map.
// - You should have a new unit (Stun Dummy), ability (Stun (System)) and buff (Stun (System)) created
// - Read through the Configuration part of the code
//
// Credits:
// - Bribe for Table
//
//********************************************************************************
// CONFIGURABLES
//********************************************************************************
globals
// timer period. lower the value, the more accurate but might cause decrease in
// performance
private constant real PERIOD = 0.03125
// raw code of ability "Stun (System)"
private constant integer ABILID = 'ASTN'
// raw code of buff "Stun (System)"
private constant integer BUFFID = 'BSTN'
// raw code of unit "Stun Dummy"
private constant integer STUNID = 'sTUN'
endglobals
//********************************************************************************
// CODE
//********************************************************************************
// initialization
module Init
private static method onInit takes nothing returns nothing
set table = Table.create()
set caster = CreateUnit(Player(13), STUNID, 0, 0, 0)
call UnitAddAbility(caster, ABILID)
endmethod
endmodule
struct Stun extends array
private unit u
private real dur
private thistype next
private thistype prev
private static Table table
private static timer t = CreateTimer()
private static unit caster
private static integer count = 0
// remove the stun and deallocate
private method destroy takes nothing returns nothing
call UnitRemoveAbility(this.u, BUFFID)
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.dur = 0
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(t)
endif
call table.remove(GetHandleId(this.u))
endmethod
// iterating through all instances every PERIOD
private static method iterate takes nothing returns nothing
local thistype this = thistype(0)
loop
set this = this.next
exitwhen this == 0
if this.dur <= 0 or IsUnitType(this.u, UNIT_TYPE_DEAD) or GetUnitTypeId(this.u) == 0 then
call this.destroy()
else
set this.dur = this.dur - PERIOD
endif
endloop
endmethod
// immediately removes stun for the specified unit
// ex: call Stun.stop(whichTarget)
static method stop takes unit u returns nothing
local integer id = GetHandleId(u)
if table.has(id) then
call thistype(table[id]).destroy()
endif
endmethod
// gets the duration left for stun, not stunned units always return 0
// ex: local real r = Stun.getDuration(whichTarget)
static method getDuration takes unit u returns real
return thistype(table[GetHandleId(u)]).dur
endmethod
// stunning specified target and to see if the stun is a stacking one or not
// ex: call Stun.apply(whichTarget, 5.0, false)
static method apply takes unit u, real dur, boolean b returns nothing
local thistype this
local integer id = GetHandleId(u)
if table.has(id) then
set this = table[id]
else
if thistype(0).prev == 0 then
set count = count + 1
set this = count
else
set this = thistype(0).prev
set thistype(0).prev = thistype(0).prev.prev
endif
if thistype(0).next == 0 then
call TimerStart(t, PERIOD, true, function thistype.iterate)
else
set thistype(0).next.prev = this
endif
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
set table[id] = this
set this.u = u
set this.dur = 0
call IssueTargetOrder(caster, "firebolt", this.u)
endif
if b and dur > 0 then
set this.dur = this.dur + dur
else
if this.dur < dur then
set this.dur = dur
endif
endif
endmethod
implement Init
endstruct
endlibrary
//TESH.scrollpos=-1
//TESH.alwaysfold=0
scope SpikeEruption initializer init
// requires:
// - StunSystem
// http://www.hiveworkshop.com/forums/jass-resources-412/system-stun-196749/
// - TimerUtils
// http://www.wc3c.net/showthread.php?t=101322
// or
// http://www.hiveworkshop.com/forums/graveyard-418/system-timerutilsex-204500/
// HOW TO IMPORT :
// 1) Import the recquired libraries.
// 2) Download the test map.
// 3) Copy/paste this scope in your map.
// 4) Copy/paste the spell "Spike Eruption" and the destructable "Spike (Spike Eruption)".
// 5) Look the obtained spell and destructable IDs and configure the scope.
//=====================================//
// //
// CONFIGURATION BLOC //
// //
//=====================================//
globals
private constant integer RAVEN_ID = 'Amrf'
private constant integer SPELL_ID = 'A000'
private constant integer DEST_ID = 'B000'
private constant attacktype ATTACK = ATTACK_TYPE_MAGIC
private constant damagetype DAMAGE = DAMAGE_TYPE_UNIVERSAL
private constant real MIN_RADIUS = 100
private constant real SPIKE_RADIUS = 64
private constant real MAX_HEIGHT = 500 // The spike's top is at 362 height for scale 1
private constant real TIMEOUT = 0.03
private constant boolean FOLLOW_CASTER = false // true: the center of the eruption area is always updated with the position of the caster
private group TmpGroup = CreateGroup()
private real array SpellRadius // Radius of Eruption
private real array SpikesDelay // Delay between 2 spike waves
private real array StunDuration // Stun duration after reached the ground
private real array SpikeStopDuration // Duration of the spike remaining rised
private integer array SpikesWaveAmount // Amount of spikes per wave
private integer array SpikesTotalAmount // Total amount of spikes in one cast
endglobals
private function GetDamage takes unit caster, integer lvl returns real
return 0.1*GetHeroStr(caster,true)*lvl
endfunction
// Filter for units affected by the spikes
private function SpellFilter takes unit caster, unit target returns boolean
return IsUnitEnemy(target,GetOwningPlayer(caster)) and /*
*/ not IsUnitType(target,UNIT_TYPE_DEAD) and /*
*/ not IsUnitType(target,UNIT_TYPE_STRUCTURE) and /*
*/ not IsUnitType(target,UNIT_TYPE_MECHANICAL) and /*
*/ not IsUnitType(target,UNIT_TYPE_MAGIC_IMMUNE) and /*
*/ GetUnitFlyHeight(target)<MAX_HEIGHT
endfunction
private function SetupDatas takes nothing returns nothing
// Level 1
set SpellRadius[1]=400
set SpikesDelay[1]=0.3
set StunDuration[1]=3
set SpikeStopDuration[1]=2
set SpikesWaveAmount[1]=1
set SpikesTotalAmount[1]=6
// Level 2
set SpellRadius[2]=400
set SpikesDelay[2]=0.2
set StunDuration[2]=3
set SpikeStopDuration[2]=2
set SpikesWaveAmount[2]=2
set SpikesTotalAmount[2]=8
// Level 3
set SpellRadius[3]=400
set SpikesDelay[3]=0.2
set StunDuration[3]=3
set SpikeStopDuration[3]=2
set SpikesWaveAmount[3]=2
set SpikesTotalAmount[3]=10
endfunction
//=====================================//
// //
// END OF CONFIGURATION BLOC //
// //
//=====================================//
private struct SpellStructMain
unit caster
integer lvl
real x
real y
real damage
integer countleft
endstruct
private struct SpellStructSpike
unit caster
integer lvl
destructable spike
real time
unit target
endstruct
public function GetRandomRadius takes real min, real max returns real
return SquareRoot(min*min+GetRandomReal(0,max*max-min*min))
endfunction
private function SquaredDistance takes real x1, real y1, real x2, real y2 returns real
local real dx=x2-x1
local real dy=y2-y1
return dx*dx+dy*dy
endfunction
private function SpikeFallsLoop takes nothing returns nothing
local SpellStructSpike data=GetTimerData(GetExpiredTimer())
set data.time=data.time-TIMEOUT*1.18
if GetUnitTypeId(data.target)!=0 then
call SetUnitFlyHeight(data.target,RMaxBJ(GetUnitDefaultFlyHeight(data.target),MAX_HEIGHT*data.time/0.37),0)
endif
if data.time<=0 then
call RemoveDestructable(data.spike)
call ReleaseTimer(GetExpiredTimer())
call data.destroy()
endif
endfunction
private function SpikeFallsBegin takes nothing returns nothing
call SetDestructableAnimationSpeed(SpellStructSpike(GetTimerData(GetExpiredTimer())).spike,1)
call TimerStart(GetExpiredTimer(),TIMEOUT,true,function SpikeFallsLoop)
endfunction
private function SpikeRisesLoop takes nothing returns nothing
local SpellStructSpike data=GetTimerData(GetExpiredTimer())
set data.time=data.time+TIMEOUT
if GetUnitTypeId(data.target)!=0 then
call SetUnitFlyHeight(data.target,RMaxBJ(GetUnitFlyHeight(data.target),MAX_HEIGHT*data.time/0.37),0)
if data.time<=TIMEOUT then
call SetUnitX(data.target,GetWidgetX(data.spike))
call SetUnitY(data.target,GetWidgetY(data.spike))
endif
endif
if data.time>=0.37 then
call SetDestructableAnimationSpeed(data.spike,0)
call TimerStart(GetExpiredTimer(),SpikeStopDuration[data.lvl],false,function SpikeFallsBegin)
endif
endfunction
private function CreateOneSpike takes unit caster, real damage, real x, real y, integer lvl returns nothing
local SpellStructSpike data=SpellStructSpike.create()
local real range=99999
local real tmprange
local unit tmp
set data.caster=caster
set data.lvl=lvl
set data.spike=CreateDestructable(DEST_ID,x,y,GetRandomReal(0,360),2,0)
set data.time=0
set data.target=null
call GroupEnumUnitsInRange(TmpGroup,x,y,SPIKE_RADIUS+200,null)
loop
set tmp=FirstOfGroup(TmpGroup)
exitwhen tmp==null
call GroupRemoveUnit(TmpGroup,tmp)
if IsUnitInRangeXY(tmp,x,y,SPIKE_RADIUS) and SpellFilter(caster,tmp) then
set tmprange=SquaredDistance(x,y,GetUnitX(tmp),GetUnitY(tmp))
if tmprange<=range then
set data.target=tmp
set range=tmprange
endif
endif
endloop
if GetUnitTypeId(data.target)!=0 then
if UnitAddAbility(data.target,RAVEN_ID) then
call UnitRemoveAbility(data.target,RAVEN_ID)
endif
call UnitDamageTarget(caster,data.target,damage,true,false,ATTACK,DAMAGE,null)
if GetWidgetLife(data.target)>0.405 then
call Stun.apply(data.target,0.7+StunDuration[lvl]+SpikeStopDuration[lvl],false)
endif
endif
call TimerStart(NewTimerEx(data),TIMEOUT,true,function SpikeRisesLoop)
endfunction
private function SpellLoop takes nothing returns nothing
local SpellStructMain data=GetTimerData(GetExpiredTimer())
local integer i=0
local real angle
local real dist
static if FOLLOW_CASTER then
set data.x=GetUnitX(data.caster)
set data.y=GetUnitY(data.caster)
endif
loop
exitwhen i>=SpikesWaveAmount[data.lvl] or data.countleft<=0
set angle=GetRandomReal(-bj_PI,bj_PI)
set dist=GetRandomRadius(MIN_RADIUS,SpellRadius[data.lvl])
call CreateOneSpike(data.caster,data.damage,data.x+dist*Cos(angle),data.y+dist*Sin(angle),data.lvl)
set data.countleft=data.countleft-1
set i=i+1
endloop
if data.countleft<=0 then
call ReleaseTimer(GetExpiredTimer())
call data.destroy()
endif
endfunction
private function SpellCast takes nothing returns nothing
local SpellStructMain data=SpellStructMain.create()
local integer i=0
local real angle
local real dist
set data.caster=GetTriggerUnit()
set data.x=GetUnitX(data.caster)
set data.y=GetUnitY(data.caster)
set data.lvl=GetUnitAbilityLevel(data.caster,SPELL_ID)
set data.damage=GetDamage(data.caster,data.lvl)
set data.countleft=SpikesTotalAmount[data.lvl]
loop
exitwhen i>=SpikesWaveAmount[data.lvl] or data.countleft<=0
set angle=GetRandomReal(-bj_PI,bj_PI)
set dist=GetRandomRadius(MIN_RADIUS,SpellRadius[data.lvl])
call CreateOneSpike(data.caster,data.damage,data.x+dist*Cos(angle),data.y+dist*Sin(angle),data.lvl)
set data.countleft=data.countleft-1
set i=i+1
endloop
if data.countleft>0 then
call TimerStart(NewTimerEx(data),SpikesDelay[data.lvl],true,function SpellLoop)
else
call data.destroy()
endif
endfunction
private function SpellCondition takes nothing returns boolean
if GetSpellAbilityId()==SPELL_ID then
call SpellCast()
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function SpellCondition))
call SetupDatas()
set t=null
endfunction
endscope