Array
(
    [scriptVersion] => 7
    [oeValues] => Array
        (
            [RngBuff1] => 250
            [MissileHoming] => 1
            [Upgrade] => Array
                (
                )

            [targs1] => Array
                (
                )

            [goldcost] => 3500
            [dice1] => 1
            [Missilespeed] => 1500
            [file] => buildings\other\ArcaneObservatory\ArcaneObservatory.mdl
            [atkType1] => normal
            [modelScale] => 0.4
            [weapTp1] => missile
            [acquire] => 800
            [rangeN1] => 800
            [upgrades] => Array
                (
                )

            [cool1] => 1
            [Ubertip] => Has got a direct link to the fifth dimension.
            [abilList] => Array
                (
                )

            [Name] => Dimensional Flux Collector
            [Missileart] => Abilities\Weapons\GryphonRiderMissile\GryphonRiderMissile.mdl
            [Art] => ReplaceableTextures\CommandButtons\BTNArcaneObservatory.blp
            [buildingShadow] => Array
                (
                )

            [sides1] => 1
            [auto] => Array
                (
                )

            [dmgplus1] => 0
            [bldtm] => 1
        )

    [settings] => Array
        (
            [author] => cedi
            [element] => storm
            [authorDisplay] => DreamStrider
            [alpha] => 255
            [balanceTip] => Array
                (
                )

            [rarity] => unique
            [version] => 1.0
            [abil_factor] => 0.0
        )

    [effects] => Array
        (
            [0] => Array
                (
                    [x] => -2.80627
                    [y] => -7.82014
                    [z] => 249.6
                    [scale] => 1
                    [rot] => 6.24828
                    [file] => Abilities\Spells\Other\GeneralAuraTarget\GeneralAuraTarget.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                )

            [1] => Array
                (
                    [x] => 33.3411
                    [y] => 37.5934
                    [z] => 134.4
                    [scale] => 0.8
                    [rot] => 6.24828
                    [file] => Abilities\Spells\Other\GeneralAuraTarget\GeneralAuraTarget.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                )

            [2] => Array
                (
                    [x] => -27.9376
                    [y] => 9.54295
                    [z] => 179.2
                    [scale] => 0.6
                    [rot] => 6.24828
                    [file] => Abilities\Spells\Other\GeneralAuraTarget\GeneralAuraTarget.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                )

            [3] => Array
                (
                    [x] => 24.0811
                    [y] => -38.5625
                    [z] => 12.8
                    [scale] => 1
                    [rot] => 2.54818
                    [file] => Doodads\Cityscape\Props\MagicRunes\MagicRunes0.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                )

        )

    [dmgTable] => Array
        (
        )

    [triggers] => Array
        (
            [0] => Array
                (
                    [name] => On Tower Creation
                    [code] => set tower.userReal = 0.0 //overall damage
    set tower.userReal2 = 0.0 //active?
    set tower.userInt = 0 //buffed creeps
    set tower.userInt2 = 1 //time
    set tower.userInt3 = 0 //Link Target
                    [values] => Array
                        (
                            [icon] => 
                            [visible] => false
                            [name] => 
                            [short_explain] => 
                            [long_explain] => 
                        )

                )

            [1] => Array
                (
                    [name] => On Tower Details
                    [code] => call MB.setValue( 0, formatFloat( tower.userReal / tower.userInt2 * ( 0.15 + tower.getLevel() * 0.006 ), 0 ) )
    return MB
                    [values] => Array
                        (
                            [0] => Array
                                (
                                    [_value] => 0
                                    [typ] => string
                                )

                        )

                )

            [2] => Array
                (
                    [name] => Header
                    [code] => globals
        BuffType BT
        BuffType LINK
        MultiboardValues MB
        
        ProjectileType PT
        
        constant real AURA_RANGE = 2000.00
        
        hashtable TABLE = InitHashtable()
    endglobals
    
    function AddToTheList takes Tower T, Buff B returns nothing
        local integer i = LoadInteger( TABLE, B, 0 ) + 1
        call SaveInteger( TABLE, B, i, T )
        call SaveInteger( TABLE, B, 0, i )
        //In range -> count
        set T.userInt = T.userInt + 1
    endfunction
    
    function IsInTheList takes Tower T, Buff B returns integer
        local integer i = LoadInteger( TABLE, B, 0 )
        
        loop
            if LoadInteger( TABLE, B, i ) == T then
                return i
            endif
            set i = i - 1
            exitwhen i <= 0
        endloop
        
        return 0
    endfunction
    
    function RemoveFromTheList takes Tower T, Buff B returns nothing
        local integer fullcount = LoadInteger( TABLE, B, 0 )
        local integer pos = IsInTheList( T, B )
        
        if pos == 0 then
            //Tower not in the list
            return
        endif
        
        if fullcount == pos then
            //Last element
        else
            //Sorting!
            call SaveInteger( TABLE, B, pos, LoadInteger( TABLE, B, fullcount ) )
        endif
        
        //cleanup
        call RemoveSavedInteger( TABLE, B, fullcount )
        //Save new total
        call SaveInteger( TABLE, B, 0, fullcount - 1 )
        //No longer in range -> don't count
        set T.userInt = T.userInt - 1
    endfunction
    
    function LinkCreate takes Buff B returns nothing
        local Tower T = B.getCaster().userInt3
        local Tower C = B.getCaster()
        local Lightning l = Lightning.createFromPointToUnit( "DRAM", C.getX(), C.getY(), C.getZ() + 220, T )
        set B.userInt = l
    endfunction
    
    function LinkEnd takes Buff B returns nothing
        local Tower tower = B.getCaster()
        local Lightning l = B.userInt
        //Cleanup sfx
        call l.destroy()
        
        //Reset dps
        set tower.userReal = 0.0
        set tower.userInt2 = 1
        
        //clear Link value
        set tower.userInt3 = 0
    endfunction
    
    function BuffCheck takes Buff B returns nothing
        local unit c = B.getBuffedUnit().getUnit()
        local integer i = LoadInteger( TABLE, B, 0 )
        local Tower T
        
        if i <= 0 then
            //can happen, as the aura range != checking range.
            set c = null
            return
        endif
        
        loop
            set T = LoadInteger( TABLE, B, i )
            if not IsUnitInRange( c, T.getUnit(), AURA_RANGE ) then
                //Unit is no longer in range of this tower. Remove the tower from the list
                //Sorting and this shouldn't cause problems, as all sortet items are already
                //checked.
                call RemoveFromTheList( T, B )
            endif
            set i = i - 1
            exitwhen i <= 0 
        endloop
        set c = null
    endfunction
    
    function BuffCreate takes Buff B returns nothing
        //local Tower T = B.getCaster()
        //set T.userInt = T.userInt + 1
        
        //Save the origin
        call SaveInteger( TABLE, B, 0, 0 )
        //call SaveInteger( TABLE, B, 1, T )
    endfunction
    
    //Remove all items from the list
    function BuffEnd takes Buff B returns nothing
        local integer i = LoadInteger( TABLE, B, 0 )
        local Tower T
        
        loop
            set T = LoadInteger( TABLE, B, i )
            call RemoveFromTheList( T, B )
            set i = i - 1
            exitwhen i <= 0
        endloop
    endfunction
    
    function BuffTrigger takes Buff B returns nothing
        local Buff trig = Event.getTarget().getBuffOfType( LINK )
        local Tower T
        
        if Event.isSpellDamage() and trig != 0 then //Spelldamage and attacking tower == linked tower
            set T = trig.getCaster() //the linker
            if IsInTheList( T, B ) != 0 then
                //Only add the damage if the linker is on the list == in range
                set T.userReal = T.userReal + Event.damage //add damage to the linker
            endif
        endif
        
    endfunction
    
    function ProjHit takes Projectile P, Unit U returns nothing
        local Tower T = P.getCaster()
        call T.doCustomAttackDamage( U, T.userReal / T.userInt2 * ( 0.25 + T.getLevel() * 0.01 ), T.calcAttackMulticrit( 0, 0, 0 ), AttackType.ENERGY )
    endfunction
    
    //Do not remove or rename this function!
    //Put your initialization tasks here, this function will be called on map init
    private function init takes nothing returns nothing
        set BT = BuffType.createAuraEffectType( false )
        call BT.addEventOnCreate( BuffCreate )
        call BT.addEventOnCleanup( BuffEnd )
        call BT.addPeriodicEvent( BuffCheck, 1.0 )
        call BT.addEventOnDamaged( BuffTrigger, 1.0, 0.0 )
        call BT.setBuffIcon( '@@0@@' )
        
        set LINK = BuffType.create( -1, 0.0, true )
        call LINK.addEventOnCreate( LinkCreate )
        call LINK.addEventOnCleanup( LinkEnd )
        call LINK.setBuffIcon( '@@1@@' )
        
        set MB = MultiboardValues.create( 1 )
        call MB.setKey( 0, "DPS" )
        
        set PT = ProjectileType.createInterpolate( "Abilities\\Spells\\Undead\\OrbOfDeath\\OrbOfDeathMissile.mdl", 1000.0 )
        call PT.setEventOnInterpolationFinished( ProjHit )
    endfunction
                    [values] => Array
                        (
                            [icon] => 
                            [visible] => false
                            [name] => 
                            [short_explain] => 
                            [long_explain] => 
                        )

                )

            [3] => Array
                (
                    [name] => Periodic
                    [code] => local Iterate I
    local Unit U
    if tower.userInt3 == 0 then
        //NOT LINKED! Do nothing!
        return
    endif
    
    if tower.userReal <= 0.0 then
        //No dmg to deal! Do nothing!
        return
    endif
    
    if tower.userInt > 0 then //at least one unit in range
        set tower.userInt2 = tower.userInt2 + 1
        set tower.userReal2 = 1
        
        //Outsourced
        //At least 10 seconds connected? (counting starts at 1, so 10 seconds are 11)
        //if tower.userInt2 <= 10 then
        //    return
        //endif
        
        //ATTACK 
        //set I = Iterate.overUnitsInRangeOfCaster( tower, TARGET_CREEPS, 800.00 )
        //set U = I.nextRandom()
        
        //if U != 0 then
            //Target Found. Launch Projectile.
        //    call Projectile.createBezierInterpolationFromPointToUnit( PT, tower, 1.0, 1.0, tower.getX(), tower.getY(), tower.getZ(), U, 0.35, 0.0, 0.0, true )
        //    call I.destroy()
        //endif
    else
        //No unit in range, check if there was one in range during last tick
        if tower.userReal2 > 0 then
            set tower.userReal2 = -1
            set tower.userInt2 = tower.userInt2 + 1
        endif
    endif
                    [values] => Array
                        (
                            [icon] => 
                            [visible] => false
                            [PERIODIC_period] => 1.0
                            [name] => 
                            [short_explain] => 
                            [long_explain] => 
                        )

                )

            [4] => Array
                (
                    [name] => Periodic
                    [code] => local Iterate I
    local Unit U
    
    call Event.getCurrentPeriodicEvent().enableAdvanced( tower.getCurrentAttackspeed(), true )
    
    if tower.userInt3 == 0 then
        //NOT LINKED! Do nothing!
        return
    endif
    
    if tower.userReal <= 0.0 then
        //No dmg to deal! Do nothing!
        return
    endif
    
    if tower.userInt > 0 then //at least one unit in range
        //set tower.userInt2 = tower.userInt2 + 1
        //set tower.userReal2 = 1
        
        //Outsourced
        //At least 10 seconds connected? (counting starts at 1, so 10 seconds are 11)
        if tower.userInt2 <= 10 then
            return
        endif
        
        //ATTACK 
        set I = Iterate.overUnitsInRangeOfCaster( tower, TARGET_CREEPS, 800.00 )
        set U = I.nextRandom()
        
        if U != 0 then
            //Target Found. Launch Projectile.
            call Projectile.createBezierInterpolationFromPointToUnit( PT, tower, 1.0, 1.0, tower.getX(), tower.getY(), tower.getZ(), U, 0.35, 0.0, 0.0, true )
            call I.destroy()
        endif
    else
        //No unit in range, check if there was one in range during last tick
        //if tower.userReal2 > 0 then
        //    set tower.userReal2 = -1
        //    set tower.userInt2 = tower.userInt2 + 1
        //endif
    endif
                    [values] => Array
                        (
                            [icon] => 
                            [visible] => false
                            [PERIODIC_period] => 1.0
                            [name] => 
                            [short_explain] => 
                            [long_explain] => 
                        )

                )

            [5] => Array
                (
                    [name] => Autocast
                    [code] => local Tower T
    local Buff B
    
    set B = Event.getTarget().getBuffOfType( LINK )
    if B != 0 then
        //Target is linked to another one of these towers.
        //Destroy that link
        call B.removeBuff()
    endif
    
    //It should be impossible for this to create a double free as this can only be true if the
    //linked tower and the target aren't the same. Else the buff is destroyed before this
    //-> tower.userInt3 == 0 (buff cleanup)
    if tower.userInt3 != 0 then
        //already linked! Cancel first!
        set T = tower.userInt3
        set B = T.getBuffOfType( LINK )
        
        call B.removeBuff()
        
        //Reset dps //Done in the buff's oncleanup, to make sure link is broken in case of selling / up
        //set tower.userReal = 0.0
        //set tower.userInt2 = 1
    endif
    
    set tower.userInt3 = Event.getTarget()
    call LINK.apply( tower, Event.getTarget(), 0 )
                    [values] => Array
                        (
                            [caster_art] => 
                            [icon] => ReplaceableTextures\CommandButtons\BTNManaDrain.blp
                            [AUTOCAST_cooldown] => 1
                            [AUTOCAST_numBuffsBeforeIdle] => 0
                            [AUTOCAST_isExtended] => false
                            [long_explain] => Creates a link between this tower and the target tower. This tower will now monitor any spell damage dealt by the linked tower to creeps within |cffFFFF802000|r range of this tower. If the linked tower is sold, replaced or upgraded the link will dissolve.
                            [AUTOCAST_autocastType] => AC_TYPE_NOAC_PLAYER_TOWER
                            [AUTOCAST_manacost] => 0
                            [AUTOCAST_range] => 800
                            [AUTOCAST_buffType] => 0
                            [name] => Dimensional Link
                            [AUTOCAST_targetSelf] => false
                            [short_explain] => Link with a tower to monitor their spell dps.
                            [AUTOCAST_targetType] => TARGET_TYPE_PLAYER_TOWERS
                            [target_art] => 
                            [AUTOCAST_autoRange] => 800
                        )

                )

            [6] => Array
                (
                    [name] => On Tower Destruction
                    [code] => local Tower targ

    //Remove link on destroy of this tower
    if tower.userInt3 != 0 then
        //Target is linked
        set targ = tower.userInt3
        call targ.getBuffOfType( LINK ).removeBuff()
    endif
                    [values] => Array
                        (
                            [icon] => 
                            [visible] => false
                            [name] => 
                            [short_explain] => 
                            [long_explain] => 
                        )

                )

            [7] => Array
                (
                    [name] => On Unit Comes In Range
                    [code] => //Okay, new creep just came in range of this tower's aura - 1 (to make sure it has the buff)
    //So let's add it to the TABLE, as long as it isn't already added.
    local Creep C = Event.getTarget()
    local Buff B = C.getBuffOfType( BT )
    
    if B != 0 then
        //Buffed unit entered
        if IsInTheList( tower, B ) == 0 then
            //Not in the list
            call AddToTheList( tower, B )
        endif
    endif
                    [values] => Array
                        (
                            [icon] => 
                            [visible] => false
                            [name] => 
                            [short_explain] => 
                            [UNITINRANGE_targetType] => TARGET_TYPE_CREEPS
                            [long_explain] => 
                            [UNITINRANGE_range] => 2000
                        )

                )

            [8] => Array
                (
                    [name] => Tower Aura
                    [code] => Array
                        (
                        )

                    [values] => Array
                        (
                            [icon] => ReplaceableTextures\CommandButtons\BTNNeutralManaShield.blp
                            [visible] => true
                            [AURA_auraEffect] => BT
                            [AURA_power] => 0
                            [long_explain] => Each second this tower attacks a creep within |cffFFFF80800|r range, dealing |cffFFFF8025%|r of the linked tower's spell damage per second as energy damage to the target creep. This tower can only attack if a link exists for at least |cffFFFF8010|r seconds. Benefits from attackspeed bonuses.|n|n|cffFF8000Level Bonus:|r|n|cffFFFF80+1%|r of spell dps as damage
                            [AURA_level] => 0
                            [AURA_auraRange] => 2150.00
                            [AURA_targetType] => TARGET_TYPE_CREEPS
                            [AURA_levelAdd] => 1
                            [AURA_powerAdd] => 1
                            [name] => Dimensional Distortion Field
                            [AURA_targetSelf] => false
                            [short_explain] => Each second this tower attacks a creep in range, dealing a portion of the linked tower's spell damage per second.
                        )

                )

        )

    [abilities] => Array
        (
        )

    [buffs] => Array
        (
            [0] => Array
                (
                    [id] => @@0@@
                    [derivedFrom] => BHfs
                    [oeValues] => Array
                        (
                            [Bufftip] => Dimensional Distorted
                            [Buffubertip] => This unit is in a dimensional distortion field.
                            [Buffart] => ReplaceableTextures\CommandButtons\BTNNeutralManaShield.blp
                            [TargetArt] => Array
                                (
                                )

                            [EditorName] => Dimensional Distorted
                        )

                )

            [1] => Array
                (
                    [id] => @@1@@
                    [derivedFrom] => BHfs
                    [oeValues] => Array
                        (
                            [Bufftip] => Dimensional Link
                            [Buffubertip] => This tower is under the effect of a dimensional link.
                            [Buffart] => ReplaceableTextures\CommandButtons\BTNManaDrain.blp
                            [TargetArt] => Array
                                (
                                )

                            [EditorName] => Dimensional Link
                        )

                )

        )

    [units] => Array
        (
        )

    [references] => Array
        (
        )

)