Array
(
    [scriptVersion] => 8
    [oeValues] => Array
        (
            [Farea1] => 400
            [auto] => Array
                (
                )

            [Art] => ReplaceableTextures\CommandButtons\BTNHeartOfAszune.blp
            [dmgplus1] => 948
            [bldtm] => 1
            [goldcost] => 4000
            [unitSound] => MoonWell
            [sides1] => 1
            [manaN] => 100
            [launchZ] => 80
            [acquire] => 1000
            [upgrades] => Array
                (
                )

            [Upgrade] => Array
                (
                )

            [Name] => Heart of the Wild
            [weapTp1] => missile
            [MissileHoming] => 1
            [file] => .mdl
            [uberSplat] => ESMB
            [Harea1] => 400
            [Missileart] => Abilities\Spells\NightElf\Tranquility\TranquilityTarget.mdl
            [Missilespeed] => 1200
            [Qfact1] => 1
            [Qarea1] => 400
            [dice1] => 1
            [Hfact1] => 1
            [modelScale] => 0.8
            [rangeN1] => 1000
            [atkType1] => chaos
            [cool1] => 2
            [Ubertip] => The heart of nature, the balance of life, the wrath of the wild.
            [abilList] => Array
                (
                )

            [buildingShadow] => Array
                (
                )

            [targs1] => Array
                (
                )

            [weapsOn] => 1
        )

    [settings] => Array
        (
            [balanceTip] => |cffFFFF00+4% |rmana regen/lvl
            [abil_factor] => 0.1
            [author] => Ashbringer
            [alpha] => 0
            [authorDisplay] => |cffff6600Ashbringer|r
            [version] => 1.0
            [element] => nature
            [rarity] => unique
        )

    [effects] => Array
        (
            [0] => Array
                (
                    [x] => 0.498478
                    [y] => -45.8328
                    [z] => 57.6
                    [scale] => 0.13
                    [rot] => 4.71239
                    [file] => Doodads\Ruins\Structures\RuinsArchway0_\RuinsArchway0_0.mdl
                    [red] => 100
                    [green] => 155
                    [blue] => 100
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [1] => Array
                (
                    [x] => 46.2081
                    [y] => 2.20732
                    [z] => 57.6
                    [scale] => 0.13
                    [rot] => 0
                    [file] => Doodads\Ruins\Structures\RuinsArchway0_\RuinsArchway0_0.mdl
                    [red] => 100
                    [green] => 155
                    [blue] => 100
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [2] => Array
                (
                    [x] => -46.7418
                    [y] => 1.98865
                    [z] => 57.6
                    [scale] => 0.13
                    [rot] => 0
                    [file] => Doodads\Ruins\Structures\RuinsArchway0_\RuinsArchway0_0.mdl
                    [red] => 100
                    [green] => 155
                    [blue] => 100
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [3] => Array
                (
                    [x] => 0.351337
                    [y] => 47.5186
                    [z] => 57.6
                    [scale] => 0.13
                    [rot] => 4.71239
                    [file] => Doodads\Ruins\Structures\RuinsArchway0_\RuinsArchway0_0.mdl
                    [red] => 100
                    [green] => 155
                    [blue] => 100
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [4] => Array
                (
                    [x] => -47.6789
                    [y] => -46.0876
                    [z] => 0
                    [scale] => 0.2
                    [rot] => 0.785398
                    [file] => Doodads\Cityscape\Structures\City_ColumnSingle\City_ColumnSingle.mdl
                    [red] => 125
                    [green] => 190
                    [blue] => 80
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [5] => Array
                (
                    [x] => 45.6536
                    [y] => 47.8959
                    [z] => 0
                    [scale] => 0.2
                    [rot] => 0.785398
                    [file] => Doodads\Cityscape\Structures\City_ColumnSingle\City_ColumnSingle.mdl
                    [red] => 125
                    [green] => 190
                    [blue] => 80
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [6] => Array
                (
                    [x] => 46.5608
                    [y] => -45.3634
                    [z] => 0
                    [scale] => 0.2
                    [rot] => 2.3562
                    [file] => Doodads\Cityscape\Structures\City_ColumnSingle\City_ColumnSingle.mdl
                    [red] => 125
                    [green] => 190
                    [blue] => 80
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [7] => Array
                (
                    [x] => -46.7618
                    [y] => 47.8548
                    [z] => 0
                    [scale] => 0.2
                    [rot] => 2.3562
                    [file] => Doodads\Cityscape\Structures\City_ColumnSingle\City_ColumnSingle.mdl
                    [red] => 125
                    [green] => 190
                    [blue] => 80
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [8] => Array
                (
                    [x] => -0.220853
                    [y] => 3.98363
                    [z] => 121.6
                    [scale] => 0.12
                    [rot] => 0
                    [file] => Doodads\Ruins\Structures\RuinsArchway0_\RuinsArchway0_0.mdl
                    [red] => 100
                    [green] => 155
                    [blue] => 100
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [9] => Array
                (
                    [x] => -0.220853
                    [y] => 3.98363
                    [z] => 121.6
                    [scale] => 0.12
                    [rot] => 4.71239
                    [file] => Doodads\Ruins\Structures\RuinsArchway0_\RuinsArchway0_0.mdl
                    [red] => 100
                    [green] => 155
                    [blue] => 100
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [10] => Array
                (
                    [x] => -0.382353
                    [y] => 15.5991
                    [z] => -6.4
                    [scale] => 0.1
                    [rot] => 4.71239
                    [file] => Doodads\Cityscape\Structures\City_ColumnSemiCircle\City_ColumnSemiCircle.mdl
                    [red] => 100
                    [green] => 190
                    [blue] => 80
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [11] => Array
                (
                    [x] => -0.754775
                    [y] => -12.0342
                    [z] => -6.4
                    [scale] => 0.1
                    [rot] => 1.5708
                    [file] => Doodads\Cityscape\Structures\City_ColumnSemiCircle\City_ColumnSemiCircle.mdl
                    [red] => 100
                    [green] => 190
                    [blue] => 80
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [12] => Array
                (
                    [x] => 52.871
                    [y] => -6.80444
                    [z] => 6.4
                    [scale] => 0.5
                    [rot] => 0
                    [file] => Doodads\Ruins\Terrain\CityCliffVines1\CityCliffVines1.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [13] => Array
                (
                    [x] => -49.1717
                    [y] => -19.6342
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 3.14159
                    [file] => Doodads\Ruins\Terrain\CityCliffVines1\CityCliffVines1.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [14] => Array
                (
                    [x] => -15.6774
                    [y] => -47.8024
                    [z] => 0
                    [scale] => 0.48
                    [rot] => 4.71239
                    [file] => Doodads\Ruins\Terrain\CityCliffVines0\CityCliffVines0.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [15] => Array
                (
                    [x] => 15.2396
                    [y] => 51.0268
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 1.5708
                    [file] => Doodads\Ruins\Terrain\CityCliffVines0\CityCliffVines0.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [16] => Array
                (
                    [x] => -39.6513
                    [y] => -27.6204
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 3.92699
                    [file] => Doodads\Ruins\Plants\VinyPlant\VinyPlant0.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [17] => Array
                (
                    [x] => 29.1068
                    [y] => -26.4766
                    [z] => 96
                    [scale] => 0.5
                    [rot] => 4.59244
                    [file] => Doodads\Ruins\Plants\VinyPlant\VinyPlant0.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [18] => Array
                (
                    [x] => -41.8082
                    [y] => 44.391
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 0.0523599
                    [file] => Doodads\Ruins\Plants\VinyPlant\VinyPlant3.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [19] => Array
                (
                    [x] => 39.1189
                    [y] => -40.8498
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 3.35103
                    [file] => Doodads\Ruins\Plants\VinyPlant\VinyPlant3.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [20] => Array
                (
                    [x] => 40.4319
                    [y] => 38.7451
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 0.366519
                    [file] => Doodads\Ruins\Plants\VinyPlant\VinyPlant3.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [21] => Array
                (
                    [x] => -26.1166
                    [y] => 23.6252
                    [z] => 115.2
                    [scale] => 0.5
                    [rot] => 4.28639
                    [file] => Doodads\Ruins\Plants\VinyPlant\VinyPlant3.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [22] => Array
                (
                    [x] => 23.5777
                    [y] => 30.7979
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 2.33874
                    [file] => Doodads\Northrend\Plants\North_Thorns\North_Thorns4.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [23] => Array
                (
                    [x] => -15.8216
                    [y] => -29.1176
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 1.44862
                    [file] => Doodads\Northrend\Plants\North_Thorns\North_Thorns4.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [24] => Array
                (
                    [x] => -49.3563
                    [y] => -34.8014
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 3.40339
                    [file] => Doodads\Northrend\Plants\North_Thorns\North_Thorns4.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [25] => Array
                (
                    [x] => 35.5945
                    [y] => 36.6286
                    [z] => 115.2
                    [scale] => 0.5
                    [rot] => 0.15708
                    [file] => Doodads\Northrend\Plants\North_Thorns\North_Thorns4.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [26] => Array
                (
                    [x] => 23.67
                    [y] => 17.966
                    [z] => 0
                    [scale] => 0.5
                    [rot] => 3.83976
                    [file] => Doodads\Ruins\Terrain\CityCliffVines0\CityCliffVines0.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [27] => Array
                (
                    [x] => -0.14786
                    [y] => 0.820974
                    [z] => 0
                    [scale] => 0.7
                    [rot] => 6.27516
                    [file] => Abilities\Spells\NightElf\EntanglingRoots\EntanglingRootsTarget.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [28] => Array
                (
                    [x] => -25.9074
                    [y] => -1.28739
                    [z] => 134.4
                    [scale] => 0.2
                    [rot] => 4.74939
                    [file] => Doodads\Ruins\Terrain\CityCliffVines1\CityCliffVines1.mdl
                    [red] => 255
                    [green] => 255
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

            [29] => Array
                (
                    [x] => -0.178468
                    [y] => 1.90442
                    [z] => 57.6
                    [scale] => 2.3
                    [rot] => 2.75762
                    [file] => Abilities\Spells\NightElf\BattleRoar\RoarTarget.mdl
                    [red] => 110
                    [green] => 255
                    [blue] => 185
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

                    [aniSpeed] => 50
                    [pcolor] => 255
                )

        )

    [dmgTable] => Array
        (
            [0] => Array
                (
                    [id] => MOD_MANA_REGEN_PERC
                    [base] => 0
                    [add] => 0.04
                )

        )

    [triggers] => Array
        (
            [0] => Array
                (
                    [name] => On Attack
                    [code] => local real aspect_chance = 0.1 + (tower.getLevel() * 0.004)
    local Unit target = Event.getTarget()
    local real mana_perc = GetUnitState(tower.getUnit(), UNIT_STATE_MANA) / GetUnitState(tower.getUnit(), UNIT_STATE_MAX_MANA)
    local Buff b = tower.getBuffOfType(ashbringer_primal_active)
    
    set tower.userInt2 = target
    set tower.userInt3 = target.getUID()
    set tower.userReal2 = 3
    
    if(tower.calcChance(aspect_chance)) then
        call ashbringer_aspect_activate(tower)
    endif
    
    if mana_perc>=1 and b==0 then
        call ashbringer_primal_start(tower)
    endif
                    [values] => Array
                        (
                            [visible] => true
                            [icon] => ReplaceableTextures\CommandButtons\BTNReplenishHealth.blp
                            [name] => Unleash Aspects
                            [short_explain] => Attacks can temporarily release aspects which follow enemies and deal spell damage.
                            [ONATTACK_chance] => 1.0
                            [ONATTACK_chanceLevelAdd] => 0.0
                            [long_explain] => Attacks have a |cffffff8010%|r chance to release one of its four aspects for |cffffff808|r seconds. Aspects will follow enemies, repeatedly dealing |cffffff804500|r spell damage. If all aspects are already active, then the duration of the next one to return is instead refreshed.|n|nMana regeneration is increased by |cffffff801|r per second for each active aspect.|n|n|cffFF8000Level Bonus:|r|n|cffffff80+0.4%|r chance|n|cffffff80+180|r damage
                        )

                )

            [1] => Array
                (
                    [name] => Header
                    [code] => globals
        BuffType ashbringer_gift_aura
        BuffType ashbringer_primal_active
        BuffType ashbringer_primal_buff
        ProjectileType ashbringer_aspect
        ProjectileType ashbringer_aspect_return
        ProjectileType ashbringer_primal_projectile
        ProjectileType ashbringer_primal_projectile_secondary
    endglobals
    
    struct Aspects
        Projectile array p[5]
        string array m[5]
        real array s[5]
        real array a[5]
        Effect array e[5]
        boolean array t[5]
        real array x[5]
        real array y[5]
        integer array d[5]
        integer array b[5]
    endstruct
    
    function ashbringer_aspect_interpolation_finish takes Projectile p, Unit target returns nothing
        local Tower tower = p.getCaster()
        local Unit u = tower.userInt2
        local real dx
        local real dy
		local real x
		local real y
		local real z
        local real spread = 280.    // higher = more spread
        local real steep = 0.2
        local real divider = 4  // divides the difference between p and target; higher = slower approach, below 0 = jump to opposite side
        local real angle
        local real anglediff
        local integer temporary
        local Iterate it
           
 //       if tower == 0 then //this check is used by non-arrayed moths, which do not exist
 //         call p.destroy()  //(note that p.getCaster() has the UID check in it, so it returns either the original caster or 0
 //         return         //they would've had timed life, and tower could've disappeared in the meantime
  //      endif
  
        //Check if the tower target is alive or if the FireFly is returning; 
        //Start return and acquire nearby targets
		if u.getUID() != tower.userInt3 or tower.userInt2 == tower then
            set it = Iterate.overUnitsInRange(tower, TARGET_CREEPS, p.x, p.y, 375+p.userReal)
            set tower.userInt2 = tower
			set tower.userInt3 = tower.getUID()
            set u = it.nextRandom()
			if u == 0 then  
                set u = tower   // no target acquired, going to move towards tower this time
            else
                call it.destroy()   // Target acquired, move towards it
            endif
		endif
		set dx = u.getX()-p.x
		set dy = u.getY()-p.y
        set p.speed = 150
        
        //Creep targeted; Faster and more precise movement towards target
        if u.isACreep() then
            set divider = 2
            if RMaxBJ(dx,dy) > 1200 then
                set spread = 150.
                set p.speed = 300
            elseif RMaxBJ(dx,dy) > 400 then
                set spread = 175.
                set p.speed = 350
                set divider = 1.5
            else
                set spread = 200.
                set p.speed = 400
                set divider = 0.85  
            endif
        endif
        
		set x = p.x + GetRandomReal(-spread-p.userReal,spread-p.userReal) + dx/divider
		set y = p.y + GetRandomReal(-spread-p.userReal,spread-p.userReal) + dy/divider
		set z = p.z + GetRandomReal(-(RMinBJ(35,p.z-35)),65) - p.z/10/divider
        
        set angle = Atan2(y - p.y, x -p.x)*bj_RADTODEG
        set anglediff = angle - p.direction 
        if anglediff > 180 then
            set anglediff = anglediff - 360
        elseif anglediff < -180 then 
            set anglediff = anglediff + 360 
        endif
        if anglediff > 120 or anglediff < -120 then
            set steep = 1
        endif
        
		call p.startBezierInterpolationToPoint(x,y,z,0.1,GetRandomReal(-1,1),steep)
		
        call p.avertDestruction()
        if p.userReal > 1 then
            set p.userReal = (p.userReal - 1)/1.5
        endif
	endfunction
    
    function ashbringer_aspect_damage takes DummyUnit d returns nothing
        local Unit target = Event.getTarget()
        local Tower tower = d.getCaster()
        local real damage = (4500 + (tower.getLevel() * 180))
        
        call tower.doSpellDamage(target, damage, tower.calcSpellCritNoBonus())
    endfunction
    
    function ashbringer_aspect_activate takes Tower tower returns nothing
        local integer aspects = 4
        local integer valid_count = 0
        local integer array valid_aspects
        local integer i = 0
        local integer min_duration = 1000
        local integer chosen
        local Projectile p
        local Aspects a = tower.userInt
        local EventHandler ev = ashbringer_aspect_damage
        
        //find inactive aspects
        loop
            if a.t[i]==false then
                set valid_count = valid_count + 1
                set valid_aspects[valid_count] = i
            endif
            
            set i = i + 1
            exitwhen i == aspects
        endloop
        if valid_count==0 then
            //if all are active, find oldest
            set i = 0
            loop
                if a.d[i]=0 and chosen<=3 then
            set a.d[chosen] = R2I(8 * tower.getProp_BuffDuration())
            if a.t[chosen]==false then
                set a.t[chosen] = true
                call a.e[chosen].destroy()
                set p = Projectile.createBezierInterpolationFromUnitToPoint(ashbringer_aspect, tower, 1, 1, tower, a.x[chosen], a.y[chosen], 175, 0.4, 0.4, 0.4)
                call p.setModel(a.m[chosen])
                call p.setScale(a.s[chosen])
                set p.userReal = 1
                set p.userInt2 = chosen
                call p.addAbility(a.b[chosen])
                call p.setDamageEvent(ev) 
                set a.p[chosen] = p
                call tower.modifyProperty(MOD_MANA_REGEN, 1.0)
            else
            endif
        endif
    endfunction
    
    function ashbringer_aspect_periodic takes Projectile p returns nothing
        local Tower tower = p.getCaster()
        local Aspects a = tower.userInt
        local integer aspect_num = p.userInt2
        local Projectile np
        
        set a.d[aspect_num] = a.d[aspect_num] - 1
        if a.d[aspect_num]<=0 then
            set np = Projectile.createLinearInterpolationFromPointToPoint(ashbringer_aspect_return, tower, 1.0, 1.0, p.x, p.y, 200, a.x[aspect_num], a.y[aspect_num], 200, 0.0)
            call np.setModel(a.m[aspect_num])
            call np.setScale(a.s[aspect_num])
            set np.userInt2 = aspect_num
            call a.p[aspect_num].destroy()
        endif
    endfunction
    
    function ashbringer_aspect_return_finish takes Projectile p, Unit target returns nothing
        local Tower tower = p.getCaster()
        local Aspects a = tower.userInt
        local Unit u = tower.userInt2
        local integer aspect_num = p.userInt2
        
        if tower.getUID()!=0 then
            set a.t[aspect_num] = false
            if tower.getUID()==R2I(tower.userReal) then
                set tower.userInt2 = tower
                set tower.userInt3 = tower.getUID()
                set a.e[aspect_num] = Effect.createScaled(a.m[aspect_num], a.x[aspect_num], a.y[aspect_num], 175, a.a[aspect_num], a.s[aspect_num])
                call a.e[aspect_num].noDeathAnimation()
                call tower.modifyProperty(MOD_MANA_REGEN, -1.0)
            endif
        endif
    endfunction
    
    function ashbringer_gift_update takes Buff b returns nothing
        local Tower tower = b.getBuffedUnit()
        local Tower caster = b.getCaster()
        local real tower_level = caster.getLevel()
        local real caster_level_factor = 0.5 + (tower_level * 0.02)
        
        call tower.modifyProperty(MOD_SPELL_DAMAGE_DEALT, -b.userReal)
        call tower.modifyProperty(MOD_SPELL_CRIT_CHANCE, -b.userReal2)
        call tower.modifyProperty(MOD_SPELL_CRIT_DAMAGE, -b.userReal3)
        call tower.modifyProperty(MOD_ATTACKSPEED, -(b.userInt/1000.0))
        call tower.modifyProperty(MOD_TRIGGER_CHANCES, -(b.userInt2/1000.0))
        
        set b.userReal = (caster.getProp_SpellDmgDealt() - 1.0)*caster_level_factor
        set b.userReal2 = (caster.getProp_SpellCritChance() - (0.0125 + (tower_level * 0.0015)))*caster_level_factor
        set b.userReal3 = (caster.getProp_SpellCritDamage() - (1.25 + (tower_level * 0.02)))*caster_level_factor
        set b.userInt = R2I((caster.getProp_Attackspeed() - (0.00 + (tower_level * 0.012)))*caster_level_factor*1000.0)
        set b.userInt2 = R2I((caster.getProp_TriggerChances()- 1.0)*caster_level_factor*1000.0)
        
        call tower.modifyProperty(MOD_SPELL_DAMAGE_DEALT, b.userReal)
        call tower.modifyProperty(MOD_SPELL_CRIT_CHANCE, b.userReal2)
        call tower.modifyProperty(MOD_SPELL_CRIT_DAMAGE, b.userReal3)
        call tower.modifyProperty(MOD_ATTACKSPEED, (b.userInt/1000.0))
        call tower.modifyProperty(MOD_TRIGGER_CHANCES, (b.userInt2/1000.0))
    endfunction

    function ashbringer_gift_create takes Buff b returns nothing
        set b.userReal = 0
        set b.userReal2 = 0
        set b.userReal3 = 0
        set b.userInt = 0
        set b.userInt2 = 0
        call ashbringer_gift_update(b)
    endfunction

    function ashbringer_gift_cleanup takes Buff b returns nothing
        local Tower tower = b.getBuffedUnit()
        call tower.modifyProperty(MOD_SPELL_DAMAGE_DEALT, -b.userReal)
        call tower.modifyProperty(MOD_SPELL_CRIT_CHANCE, -b.userReal2)
        call tower.modifyProperty(MOD_SPELL_CRIT_DAMAGE, -b.userReal3)
        call tower.modifyProperty(MOD_ATTACKSPEED, -b.userInt/1000.0)
        call tower.modifyProperty(MOD_TRIGGER_CHANCES, -b.userInt2/1000.0)
    endfunction
    
    function ashbringer_primal_attack takes Buff b returns nothing
        local Tower tower = b.getCaster()
        local Tower attacker = b.getBuffedUnit()
        local Unit target = Event.getTarget()
        local Projectile primal = b.userInt
        local Projectile p
        
        set p = Projectile.createLinearInterpolationFromPointToUnit(ashbringer_primal_projectile_secondary, tower, 0, 0, primal.x, primal.y, primal.z, target, 0, true)
        call p.setScale(b.userReal)
        call p.setModel(primal.getModel())
        set p.userReal = (5000 + (tower.getLevel() * 200)) * attacker.getCurrentAttackspeed() / (attacker.getRange() / 1000.00)
    endfunction
    
    function ashbringer_primal_interpolation_finish takes Projectile p, Unit target returns nothing
        local Tower tower = p.getCaster()
        
        call tower.doSpellDamage(target, p.userReal, tower.calcSpellCritNoBonus())
    endfunction
    
    function ashbringer_primal_update takes Buff b returns nothing
        local Tower tower = b.getCaster()
        local Iterate i
        local Unit next
        local Buff bt
        local Projectile p = b.userInt
        local real mana = GetUnitState(tower.getUnit(), UNIT_STATE_MANA)
        local integer power = R2I(mana / 5)
        local real mana_cost = b.userReal2
        
        if mana >= mana_cost then
            set b.userReal2 = b.userReal2 * 1.1
            call tower.subtractMana(mana_cost, true)
            set p.remainingLifetime = 2
            call b.refreshDuration()
            set i = Iterate.overUnitsInRangeOfUnit(tower, TARGET_TOWERS, tower, 350)
            set next = i.next()
            loop
                exitwhen next==0
                if next != tower then
                    set bt = next.getBuffOfType(ashbringer_primal_buff)
                    if bt!=0 then
                        call bt.setLevel(power)
                        call bt.setPower(power)
                        call bt.refreshDuration()
                    else
                        set bt = ashbringer_primal_buff.apply(tower, next, power)
                        set bt.userReal = b.userReal
                    endif
                    set bt.userInt = p
                endif
                set next = i.next()
            endloop
        else
            //projectile is destroyed by cleanup
            call b.removeBuff()
        endif
    endfunction
    
    function ashbringer_primal_start takes Tower tower returns nothing
        local Buff b
        local Projectile p
        local real turning_rate = 350 / ((bj_PI * 700) / 200) / 25
        local Aspects a = tower.userInt
        
        set b = ashbringer_primal_active.apply(tower, tower, tower.getLevel())
        set b.userReal = a.s[4]
        
        set p = Projectile.create(ashbringer_primal_projectile, tower, 0, 0, tower.getX()+350, tower.getY(), 300, 270)
        call p.setModel(a.m[4])
        set p.rotation = -turning_rate
        call p.setScale(a.s[4]*2.6)
        
        set b.userInt = p
        set b.userReal2 = 10
        
        call ashbringer_primal_update(b)
    endfunction
    
    function ashbringer_primal_cleanup takes Buff b returns nothing
        local Tower tower = b.getCaster()
        local Iterate i = Iterate.overUnitsInRangeOfUnit(tower, TARGET_TOWERS, tower, 350)
        local Unit next = i.next()
        local Buff bt
        local Projectile p = b.userInt
        
        loop
            exitwhen next==0
            set bt = next.getBuffOfType(ashbringer_primal_buff)
            if bt!=0 then
                call bt.removeBuff()
            endif
            set next = i.next()
        endloop
        
        call p.destroy()
    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
        local Modifier m = Modifier.create()
        local AuraType at
        
        set ashbringer_gift_aura = BuffType.createAuraEffectType(true)
        call ashbringer_gift_aura.setBuffIcon('@@5@@')
        call ashbringer_gift_aura.addEventOnCreate(ashbringer_gift_create)
        call ashbringer_gift_aura.addEventOnCleanup(ashbringer_gift_cleanup)
        call ashbringer_gift_aura.addPeriodicEvent(ashbringer_gift_update, 5)
        
        set ashbringer_aspect = ProjectileType.createInterpolate("", 225)
        call ashbringer_aspect.setEventOnInterpolationFinished(ashbringer_aspect_interpolation_finish)
        call ashbringer_aspect.enablePeriodic(ashbringer_aspect_periodic, 1.0)
        call ashbringer_aspect.disableExplodeOnExpiration()
        
        set ashbringer_aspect_return = ProjectileType.createInterpolate("", 700)
        call ashbringer_aspect_return.setEventOnInterpolationFinished(ashbringer_aspect_return_finish)
        call ashbringer_aspect_return.disableExplodeOnExpiration()
        
        set ashbringer_primal_active = BuffType.create(5.0, 0.0, true)
        call ashbringer_primal_active.setBuffIcon('@@7@@')
        call ashbringer_primal_active.addPeriodicEvent(ashbringer_primal_update, 1.0)
        
        set ashbringer_primal_buff = BuffType.create(1.2, 0.0, true)
        call m.addModification(MOD_ATTACKSPEED, 0.0, 0.01)
        call ashbringer_primal_buff.setBuffModifier(m)
        call ashbringer_primal_buff.setBuffIcon('@@6@@')
        call ashbringer_primal_buff.addEventOnAttack(EventHandler.ashbringer_primal_attack, 0.05, 0)
        
        set ashbringer_primal_projectile_secondary = ProjectileType.createInterpolate("", 1000)
        call ashbringer_primal_projectile_secondary.setEventOnInterpolationFinished(ashbringer_primal_interpolation_finish)
        
        set ashbringer_primal_projectile = ProjectileType.create("", 10, 200)
        //call ashbringer_primal_projectile.enablePeriodic(ashbringer_primal_periodic, 1.0)
    endfunction
                    [values] => Array
                        (
                            [visible] => true
                            [icon] => ReplaceableTextures\CommandButtons\BTNBearBlink.blp
                            [name] => Primal Aspect
                            [short_explain] => Summons a very powerful aspect when reaching maximum mana.
                            [long_explain] => When this tower has maximum mana and attacks an enemy, the Primal Aspect is summoned. Every second, the Primal Aspect drains |cffffff8010|r mana from the heart to increase the attack speed of every other tower within |cffffff80350|r range by |cffffff801%|r for every |cffffff805|r mana remaining. The mana drain increases exponentially by |cffffff8010%|r each second. The aspect lasts until there is insufficient mana.|n|nAdditionally, the aspect has a |cffffff805%|r chance to assist a buffed tower's attack, dealing |cffffff805000|r spell damage to the target. This damage is attack speed and range adjusted.|n|n|cffFF8000Level Bonus:|r|n|n|cffffff80+200|r damage
                        )

                )

            [2] => Array
                (
                    [name] => On Tower Destruction
                    [code] => local integer aspects = 4
    local Aspects a = tower.userInt
    local Projectile p
    local Effect e
    local integer i = 0 
    loop 
        set p = a.p[i]
        set e = a.e[i]
        if a.t[i]==true then
            call p.destroy()
        else
            call e.destroy()
        endif
        set i = i + 1 
        exitwhen i == aspects
    endloop 
    call a.destroy()
                    [values] => Array
                        (
                            [visible] => false
                            [icon] => 
                            [name] => 
                            [short_explain] => 
                            [long_explain] => 
                        )

                )

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

                    [values] => Array
                        (
                            [AURA_powerAdd] => 0
                            [visible] => true
                            [AURA_auraEffect] => ashbringer_gift_aura
                            [AURA_levelAdd] => 0
                            [AURA_power] => 1
                            [icon] => ReplaceableTextures\CommandButtons\BTNElunesBlessing.blp
                            [AURA_targetType] => TARGET_TYPE_TOWERS + TARGET_TYPE_ELEMENT_NATURE + TARGET_TYPE_RARITY_UNCOMMON + TARGET_TYPE_RARITY_COMMON
                            [long_explain] => Attack speed, trigger chances, spell damage, spell crit chance and spell crit damage bonuses on this tower are applied to |cffFFFFFFCommon|r and |cff0080FFUncommon|r |cFF80FF00Nature|r towers in |cffffff80350|r range at a rate of |cffffff8050%|r.|n|n|cffFF8000Level Bonus:|r|n|cffFFFF80+2%|r stats
                            [AURA_targetSelf] => false
                            [name] => Gift of the Wild
                            [AURA_level] => 1
                            [short_explain] => Certain bonuses on this tower affect nearby |cffFFFFFFCommon|r and |cff0080FFUncommon|r |cFF80FF00Nature|r towers.
                            [AURA_auraRange] => 350
                        )

                )

            [4] => Array
                (
                    [name] => Periodic
                    [code] => if tower.userReal2 > 0 then
        set tower.userReal2 = tower.userReal2 - 1
    else
        set tower.userInt2 = tower                          
        set tower.userInt3 = tower.getUID()
    endif
    
    if tower.userReal3 > 0 then 
        set tower.userReal3 = tower.userReal3 - 1
    else
        set tower.userReal3 = 5
    endif
                    [values] => Array
                        (
                            [visible] => false
                            [PERIODIC_period] => 1
                            [icon] => 
                            [name] => 
                            [short_explain] => 
                            [long_explain] => 
                        )

                )

            [5] => Array
                (
                    [name] => On Tower Creation
                    [code] => local string array aspect_names
    local string array aspect_models
    local integer array aspect_abilities
    local real array aspect_scale
    local integer aspects = 4
    local real x = tower.getX()
    local real y = tower.getY()
    local Aspects aspect_struct = Aspects.create()
    local integer i = 0
    local integer count = 0
    local integer aspect = GetRandomInt(0, 2) // one of the 5 models becomes the aspect, is moved to end of struct array. higher chance for yellow because reasons
    
    if aspect > 0 then
        set aspect = GetRandomInt(0, 4)
    endif
    
    set aspect_models[0] = "Abilities\\Weapons\\SorceressMissile\\SorceressMissile.mdl"
    set aspect_abilities[0] = '@@2@@'
    set aspect_scale[0] = 1.15
    set aspect_models[1] = "Abilities\\Weapons\\KeeperGroveMissile\\KeeperGroveMissile.mdl"
    set aspect_abilities[1] = '@@3@@'
    set aspect_scale[1] = 0.75
    set aspect_models[2] = "Abilities\\Weapons\\PriestMissile\\PriestMissile.mdl"
    set aspect_abilities[2] = '@@1@@'
    set aspect_scale[2] = 1.15
    set aspect_models[3] = "Abilities\\Weapons\\BlackKeeperMissile\\BlackKeeperMissile.mdl"
    set aspect_abilities[3] = '@@0@@'
    set aspect_scale[3] = 0.8
    set aspect_models[4] = "Abilities\\Weapons\\MurgulMagicMissile\\MurgulMagicMissile.mdl"
    set aspect_abilities[4] = '@@4@@'
    set aspect_scale[4] = 1.15
    
    set tower.userInt = aspect_struct
    set tower.userInt2 = tower
    set tower.userInt3 = tower.getUID()
    set tower.userReal = I2R(tower.getUID())
    set tower.userReal2 = 1 // Used in periodic
    set tower.userReal3 = 5 // Used in periodic
    loop
        if aspect != count then
            set aspect_struct.a[i] = (360 / aspects * i) + 45
            set aspect_struct.x[i] = x + 60 * Cos(Deg2Rad(aspect_struct.a[i]))
            set aspect_struct.y[i] = y + 60 * Sin(Deg2Rad(aspect_struct.a[i]))
            set aspect_struct.e[i] = Effect.createScaled(aspect_models[count], aspect_struct.x[i], aspect_struct.y[i], 175, aspect_struct.a[i], aspect_scale[count])
            call aspect_struct.e[i].noDeathAnimation()
            set aspect_struct.m[i] = aspect_models[count]
            set aspect_struct.b[i] = aspect_abilities[count]
            set aspect_struct.s[i] = aspect_scale[count]
            set aspect_struct.t[i] = false
            set aspect_struct.d[i] = 0
            
            set i = i + 1
        endif
        set count = count + 1
        exitwhen i == aspects
    endloop
    //set aspect model
    set aspect_struct.m[i] = aspect_models[aspect]
    set aspect_struct.s[i] = aspect_scale[aspect]
                    [values] => Array
                        (
                            [visible] => false
                            [icon] => 
                            [name] => 
                            [short_explain] => 
                            [long_explain] => 
                        )

                )

        )

    [abilities] => Array
        (
            [0] => Array
                (
                    [id] => @@0@@
                    [derivedFrom] => Apxf
                    [oeValues] => Array
                        (
                            [Art] => ReplaceableTextures\CommandButtons\BTNMarkOfFire.blp
                            [HeroDur1] => 0.01
                            [DataA3] => 1
                            [DataA1] => 1
                            [Area2] => 350
                            [BuffID1] => @@7@@
                            [Area1] => 350
                            [DataA2] => 1
                            [DataB1] => 0
                            [Area3] => 350
                            [Name] => Pink
                            [Dur1] => 0.01
                            [Ubertip] => Pink
                            [Missileart] => Abilities\Weapons\BlackKeeperMissile\BlackKeeperMissile.mdl
                            [Missilespeed] => 2000
                            [Tip] => Pink
                        )

                )

            [1] => Array
                (
                    [id] => @@1@@
                    [derivedFrom] => Apxf
                    [oeValues] => Array
                        (
                            [Art] => ReplaceableTextures\CommandButtons\BTNMarkOfFire.blp
                            [HeroDur1] => 0.01
                            [DataA3] => 1
                            [DataA1] => 75
                            [Area2] => 350
                            [BuffID1] => @@7@@
                            [Area1] => 350
                            [DataA2] => 1
                            [DataB1] => 0
                            [Area3] => 350
                            [Name] => Blue
                            [Dur1] => 0.01
                            [Ubertip] => Blue
                            [Missileart] => Abilities\Weapons\PriestMissile\PriestMissile.mdl
                            [Missilespeed] => 2000
                            [Tip] => Blue
                        )

                )

            [2] => Array
                (
                    [id] => @@2@@
                    [derivedFrom] => Apxf
                    [oeValues] => Array
                        (
                            [Art] => ReplaceableTextures\CommandButtons\BTNMarkOfFire.blp
                            [HeroDur1] => 0.01
                            [DataA3] => 1
                            [DataA1] => 75
                            [Area2] => 350
                            [BuffID1] => @@7@@
                            [Area1] => 350
                            [DataA2] => 1
                            [DataB1] => 0
                            [Area3] => 350
                            [Name] => Yellow
                            [Dur1] => 0.01
                            [Ubertip] => Yellow
                            [Missileart] => Abilities\Weapons\SorceressMissile\SorceressMissile.mdl
                            [Missilespeed] => 2000
                            [Tip] => Yellow
                        )

                )

            [3] => Array
                (
                    [id] => @@3@@
                    [derivedFrom] => Apxf
                    [oeValues] => Array
                        (
                            [Art] => ReplaceableTextures\CommandButtons\BTNMarkOfFire.blp
                            [HeroDur1] => 0.01
                            [DataA3] => 1
                            [DataA1] => 75
                            [Area2] => 350
                            [BuffID1] => @@7@@
                            [Area1] => 350
                            [DataA2] => 1
                            [DataB1] => 0
                            [Area3] => 350
                            [Name] => Green
                            [Dur1] => 0.01
                            [Ubertip] => Green
                            [Missileart] => Abilities\Weapons\KeeperGroveMissile\KeeperGroveMissile.mdl
                            [Missilespeed] => 2000
                            [Tip] => Green
                        )

                )

            [4] => Array
                (
                    [id] => @@4@@
                    [derivedFrom] => Apxf
                    [oeValues] => Array
                        (
                            [Art] => ReplaceableTextures\CommandButtons\BTNMarkOfFire.blp
                            [HeroDur1] => 0.01
                            [DataA3] => 1
                            [DataA1] => 75
                            [Area2] => 350
                            [BuffID1] => @@7@@
                            [Area1] => 350
                            [DataA2] => 1
                            [DataB1] => 0
                            [Area3] => 350
                            [Name] => Teal
                            [Dur1] => 0.01
                            [Ubertip] => Teal
                            [Missileart] => Abilities\Weapons\MurgulMagicMissile\MurgulMagicMissile.mdl
                            [Missilespeed] => 2000
                            [Tip] => Teal
                        )

                )

        )

    [buffs] => Array
        (
            [0] => Array
                (
                    [id] => @@5@@
                    [derivedFrom] => BHab
                    [oeValues] => Array
                        (
                            [Targetattach] => Array
                                (
                                )

                            [Buffubertip] => Stats increased by nearby tower.
                            [TargetArt] => Array
                                (
                                )

                            [Bufftip] => Gift of the Wild
                            [Buffart] => ReplaceableTextures\CommandButtons\BTNElunesBlessing.blp
                        )

                )

            [1] => Array
                (
                    [id] => @@6@@
                    [derivedFrom] => BHab
                    [oeValues] => Array
                        (
                            [Buffubertip] => Increased attack speed.
                            [TargetArt] => Abilities\Spells\Undead\ReplenishHealth\ReplenishHealthCaster.mdl
                            [Bufftip] => Primal Aspect
                            [Buffart] => ReplaceableTextures\CommandButtons\BTNBearBlink.blp
                        )

                )

            [2] => Array
                (
                    [id] => @@7@@
                    [derivedFrom] => BHab
                    [oeValues] => Array
                        (
                            [Targetattach] => Array
                                (
                                )

                            [Buffubertip] => Array
                                (
                                )

                            [TargetArt] => Array
                                (
                                )

                            [Bufftip] => Aspect
                            [Buffart] => ReplaceableTextures\CommandButtons\BTNUltravision.blp
                        )

                )

        )

    [units] => Array
        (
        )

    [references] => Array
        (
        )

    [lightning] => Array
        (
        )

)