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

            [Art] => ReplaceableTextures\CommandButtons\BTNInvisibility.blp
            [turnRate] => 3
            [dmgplus1] => 760
            [bldtm] => 1
            [goldcost] => 700
            [unitSound] => ElvenGuardTower
            [sides1] => 1
            [Missilearc] => 0.1
            [manaN] => 60
            [acquire] => 1000
            [upgrades] => Array
                (
                )

            [Upgrade] => Array
                (
                )

            [Name] => Magic Mirror
            [weapTp1] => missile
            [impactZ] => 60
            [file] => war3mapImported\Mirror.mdl
            [uberSplat] => YTDG
            [Missilespeed] => 1200
            [Missileart] => Abilities\Weapons\DragonHawkMissile\DragonHawkMissile.mdl
            [dice1] => 1
            [RngBuff1] => 250
            [regenMana] => 2
            [modelScale] => 0.6
            [rangeN1] => 1000
            [propWin] => 10
            [atkType1] => magic
            [cool1] => 2
            [Ubertip] => The reflection that stares back isn't you.
            [abilList] => Array
                (
                )

            [moveHeight] => 55
            [buildingShadow] => Array
                (
                )

            [targs1] => Array
                (
                )

            [weapsOn] => 1
        )

    [settings] => Array
        (
            [balanceTip] => Array
                (
                )

            [abil_factor] => 0.5
            [author] => Ashbringer
            [alpha] => 255
            [authorDisplay] => |cffff6600Ashbringer|r
            [version] => 1.0
            [element] => arcane
            [rarity] => rare
        )

    [effects] => Array
        (
            [0] => Array
                (
                    [x] => -0.316865
                    [y] => -0.423932
                    [z] => 32
                    [scale] => 0.27
                    [rot] => 0.785398
                    [file] => Doodads\Cityscape\Props\City_Oblisk\City_Oblisk.mdl
                    [red] => 75
                    [green] => 75
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => -2.15
                    [advanced] => false
                    [animation] => Array
                        (
                        )

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

            [1] => Array
                (
                    [x] => -0.323411
                    [y] => 0.00345104
                    [z] => 32
                    [scale] => 0.27
                    [rot] => 3.92699
                    [file] => Doodads\Cityscape\Props\City_Oblisk\City_Oblisk.mdl
                    [red] => 75
                    [green] => 75
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => -2.15
                    [advanced] => false
                    [animation] => Array
                        (
                        )

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

            [2] => Array
                (
                    [x] => -0.437684
                    [y] => 0.531451
                    [z] => 32
                    [scale] => 0.27
                    [rot] => 5.49779
                    [file] => Doodads\Cityscape\Props\City_Oblisk\City_Oblisk.mdl
                    [red] => 75
                    [green] => 75
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => -2.15
                    [advanced] => false
                    [animation] => Array
                        (
                        )

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

            [3] => Array
                (
                    [x] => 0.0649099
                    [y] => -0.104123
                    [z] => 32
                    [scale] => 0.27
                    [rot] => 2.3562
                    [file] => Doodads\Cityscape\Props\City_Oblisk\City_Oblisk.mdl
                    [red] => 75
                    [green] => 75
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => -2.15
                    [advanced] => false
                    [animation] => Array
                        (
                        )

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

            [4] => Array
                (
                    [x] => -0.327288
                    [y] => 0.0778644
                    [z] => -6.4
                    [scale] => 0.35
                    [rot] => 0.785398
                    [file] => Doodads\Cityscape\Structures\City_LowWall_TallEndCap\City_LowWall_TallEndCap.mdl
                    [red] => 75
                    [green] => 75
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

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

            [5] => Array
                (
                    [x] => -0.353217
                    [y] => 0.156423
                    [z] => 38.4
                    [scale] => 0.75
                    [rot] => 1.5708
                    [file] => Doodads\Cityscape\Props\MagicRunes\MagicRunes0.mdl
                    [red] => 1
                    [green] => 1
                    [blue] => 1
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

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

            [6] => Array
                (
                    [x] => -0.14972
                    [y] => -0.00658333
                    [z] => -12.8
                    [scale] => 1.25
                    [rot] => 0.715585
                    [file] => Abilities\Spells\Other\GeneralAuraTarget\GeneralAuraTarget.mdl
                    [red] => 110
                    [green] => 110
                    [blue] => 255
                    [alpha] => 255
                    [pitch] => 0
                    [advanced] => false
                    [animation] => Array
                        (
                        )

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

        )

    [dmgTable] => Array
        (
        )

    [triggers] => Array
        (
            [0] => Array
                (
                    [name] => Header
                    [code] => globals
        //@export
        BuffType ashbringer_mirror_buff
        //@export
        BuffType ashbringer_reflect_buff
    endglobals
    
    function ashbringer_mirror_second takes Buff b1, Tower tower, Creep target, real duration, real chance returns Buff
        local Buff b2
        local Iterate i
        local Creep next
        local real hp
        local real highest = 0
        local Creep highest_next = 0
        local integer level = tower.getLevel()
        
        set i = Iterate.overUnitsInRangeOfUnit(tower, TARGET_TYPE_CREEPS, target, 600)
        
        loop
            set next = i.next()
            exitwhen next==0
            set b2 = next.getBuffOfType(ashbringer_mirror_buff)
            set hp = GetUnitState(next.getUnit(), UNIT_STATE_LIFE)
            if (hp > highest or highest_next==0) and b2 == 0 and next != target then
                set highest = hp
                set highest_next = next
            endif
        endloop
        
        if highest_next != 0 and highest_next != target then
            call Effect.createSimpleOnUnit("Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl", highest_next, "origin").setLifetime(1)
            set b2 = ashbringer_mirror_buff.applyAdvanced(tower, highest_next, level, level, duration)
            set b1.userInt = highest_next
            set b2.userReal = chance
            set b2.userInt = target
        endif
        
        return b2
    endfunction
    
    //@export
    function ashbringer_mirror_cast takes Tower tower, Creep target, real duration, real chance returns nothing
        local Buff b1 = target.getBuffOfType(ashbringer_mirror_buff)
        local Buff b2
        local integer level = tower.getLevel()
        
        call Effect.createSimpleOnUnit("Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl", target, "origin").setLifetime(1)
        if b1 == 0 then
            set b1 = ashbringer_mirror_buff.applyAdvanced(tower, target, level, level, duration)
            set b1.userReal = chance
            set b1.userInt = 0
            set b2 = ashbringer_mirror_second(b1, tower, target, duration, chance)
        else
            call b1.refreshDuration()
            if b1.userInt != 0 then
                set b2 = b1.userInt
                call b2.refreshDuration()
            else
                set b2 = ashbringer_mirror_second(b1, tower, target, duration, chance)
            endif
        endif
    endfunction
    
    function ashbringer_mirror_ondamaged takes Buff b1 returns nothing
        local Tower tower = b1.getCaster()
        local Creep buffed = b1.getBuffedUnit()
        local real damage = Event.damage // / tower.getProp_SpellDmgDealt()
        local Creep target
        local Buff b2
        local Playor p = tower.getOwner()
        
        if b1.userInt > 0 then
            set target = b1.userInt
            if target.getUID() >= 0 then
                set b2 = target.getBuffOfType(ashbringer_mirror_buff)
                if b2 != 0 then
                    if tower.calcChance(b1.userReal) then
                        call doRawSpellDamageNoEvents(tower.getUnit(), target.getUnit(), damage)
                        call Lightning.createFromUnitToUnit("PMBZ", buffed, target).setLifetime(0.1)
                        call p.displaySmallFloatingText(I2S(R2I(damage)), target, 255, 115, 255, 20.0)
                    endif
                else
                    set b1.userInt = 0
                endif
            else
                if tower.calcChance(b1.userReal) then
                    call doRawSpellDamageNoEvents(tower.getUnit(), buffed.getUnit(), damage)
                    call p.displaySmallFloatingText(I2S(R2I(damage)), buffed, 255, 115, 255, 20.0)
                endif
            endif
        else
            if tower.calcChance(b1.userReal) then
                call doRawSpellDamageNoEvents(tower.getUnit(), buffed.getUnit(), damage)
                call p.displaySmallFloatingText(I2S(R2I(damage)), buffed, 255, 115, 255, 20.0)
            endif
        endif
    endfunction
    
    function ashbringer_reflect_ondamaged takes Buff b returns nothing
        local Creep target = b.getBuffedUnit()
        local real life_perc = Event.damage / GetUnitState(target.getUnit(), UNIT_STATE_MAX_LIFE)
        
        if life_perc > 0.0001 then
            call target.subtractManaPerc(life_perc, true)
        endif
    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 ashbringer_mirror_buff = BuffType.create(10, 1, false)
        call ashbringer_mirror_buff.setBuffIcon('@@0@@')
        call ashbringer_mirror_buff.addEventOnDamaged(EventHandler.ashbringer_mirror_ondamaged, 1.0, 0.0)
        
        set ashbringer_reflect_buff = BuffType.createAuraEffectType(false)
        call ashbringer_reflect_buff.setBuffIcon('@@1@@')
        call ashbringer_reflect_buff.addEventOnDamaged(EventHandler.ashbringer_reflect_ondamaged, 1.0, 0.0)
    endfunction
                    [values] => Array
                        (
                            [visible] => false
                            [icon] => 
                            [name] => 
                            [short_explain] => 
                            [long_explain] => 
                        )

                )

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

                    [values] => Array
                        (
                            [AURA_powerAdd] => 1
                            [visible] => true
                            [AURA_auraEffect] => ashbringer_reflect_buff
                            [AURA_levelAdd] => 1
                            [AURA_power] => 0
                            [icon] => ReplaceableTextures\CommandButtons\BTNGenericSpellImmunity.blp
                            [AURA_targetType] => TARGET_TYPE_CREEPS
                            [long_explain] => Enemies within |cffFFFF801000|r range will lose a percentage of their mana whenever they are damaged. The mana lost is equal to the percentage of health they lost from the damage taken.
                            [AURA_targetSelf] => false
                            [name] => Mana Reflection
                            [AURA_level] => 0
                            [short_explain] => Enemies within range lose mana when they take damage.
                            [AURA_auraRange] => 1000
                        )

                )

            [2] => Array
                (
                    [name] => Autocast
                    [code] => local real duration = 5 + (tower.getLevel() * 0.2)
    local real chance = 0.15 + (tower.getLevel() * 0.004)

    call ashbringer_mirror_cast(tower, Event.getTarget(), duration, chance)
                    [values] => Array
                        (
                            [AUTOCAST_cooldown] => 2
                            [AUTOCAST_autoRange] => 1000
                            [AUTOCAST_manacost] => 40
                            [icon] => ReplaceableTextures\CommandButtons\BTNSoulGem.blp
                            [AUTOCAST_range] => 1000
                            [AUTOCAST_targetType] => TARGET_TYPE_CREEPS
                            [AUTOCAST_numBuffsBeforeIdle] => 1
                            [caster_art] => 
                            [long_explain] => Applies Fate Mirror to the target and to one other enemy in |cffFFFF80600|r range of the target, lasting |cffFFFF805|r seconds. Damage dealt to either enemy has a |cffFFFF8015%|r chance to be copied to the other as spell damage. If there isn't a second enemy, then Fate Mirror will copy damage to the creep that it is on. Copied damage is not affected by the Magic Mirror's stats and cannot crit.|n|n|cffFF8000Level Bonus:|r|n|cffFFFF80+0.2|r seconds duration|n|cffFFFF80+0.4%|r chance
                            [target_art] => 
                            [AUTOCAST_autocastType] => AC_TYPE_OFFENSIVE_BUFF
                            [AUTOCAST_buffType] => ashbringer_mirror_buff
                            [AUTOCAST_isExtended] => false
                            [name] => Fate Mirror
                            [AUTOCAST_targetSelf] => false
                            [short_explain] => Links two enemies together, duplicating some of the damage they take.
                        )

                )

        )

    [abilities] => Array
        (
        )

    [buffs] => Array
        (
            [0] => Array
                (
                    [id] => @@0@@
                    [derivedFrom] => Binf
                    [oeValues] => Array
                        (
                            [Buffubertip] => Damage is sometimes copied to the linked creep.
                            [TargetArt] => Abilities\Spells\Items\AIso\BIsvTarget.mdl
                            [Bufftip] => Fate Mirror
                            [Buffart] => ReplaceableTextures\CommandButtons\BTNSoulGem.blp
                        )

                )

            [1] => Array
                (
                    [id] => @@1@@
                    [derivedFrom] => Binf
                    [oeValues] => Array
                        (
                            [Targetattach] => Array
                                (
                                )

                            [Buffubertip] => Damage taken is sometimes duplicated and removes mana.
                            [TargetArt] => Array
                                (
                                )

                            [Bufftip] => Mana Reflection
                            [Buffart] => ReplaceableTextures\CommandButtons\BTNGenericSpellImmunity.blp
                        )

                )

        )

    [units] => Array
        (
        )

    [references] => Array
        (
            [0] => Array
                (
                    [export] => true
                    [category] => global
                    [typ] => BuffType
                    [name] => ashbringer_mirror_buff
                )

            [1] => Array
                (
                    [export] => true
                    [category] => global
                    [typ] => BuffType
                    [name] => ashbringer_reflect_buff
                )

        )

    [lightning] => Array
        (
        )

)