Chrono Jumper v1
770
lvl: 20

ID:

140

Author:

axllow

Rarity:

unique

Status:

Approved

Description:

Space-teleport device. Use it carefully.

Latest Upload Comment:

Restored from 1.10
Chrono Jump
Tower makes a leap through space to a target free location for 10 seconds, then returns to its original position. Increases attackspeed by 10% for the duration.
Download

Toggle Triggers

Autocast

caster_art: AUTOCAST_cooldown: 30 AUTOCAST_numBuffsBeforeIdle: 0 goldcost: 770 AUTOCAST_isExtended: true AUTOCAST_autocastType: AC_TYPE_NOAC_POINT AUTOCAST_manacost: 0 AUTOCAST_range: 1500 AUTOCAST_buffType: 0 AUTOCAST_targetSelf: false AUTOCAST_targetType: 0 target_art: AUTOCAST_autoRange: 1500
    local Tower tower = itm.getCarrier()
    local unit twrUnit = tower.getUnit()
    local integer unitID = GetUnitTypeId(twrUnit)
    local unit FX = tower.effects
    local Playor pl = tower.getOwner()
    local real fromX = GetUnitX(tower.getUnit())
    local real fromY = GetUnitY(tower.getUnit())
    local real toX = fromX + R2I(GetSpellTargetX() - tower.getX() + 32)/64*64
    local real toY = fromY + R2I(GetSpellTargetY() - tower.getY() + 32)/64*64
    local unit ill
    local unit array dummy
    local integer numEffects = 0
    local Buff b = tower.getBuffOfType(Chrono_Jumper_buff)
    local TowerType tt = tower.getUnitType()
    local ListElement l
    local real turnfix = 16.0
    local Effect ef
    local Tele tele        
    local boolean fail = true
    local real sx
    local real sy
    local integer sn = 1
    local real sd
    
    if isTowerAUnit(twrUnit) then
        if toX < fromX then
            set toX = toX - 64.0
        endif
        if toY < fromY then
            set toY = toY - 64.0
        endif
    else
        set turnfix = 0.0
        if fromX > toX then
            set toX = toX - 64.0
        endif
        if fromY > toY then
            set toY = toY - 64.0
        endif
    endif
    
    if isPointBuildableForPlayer(pl, toX-turnfix, toY-turnfix) then
        set fail = false
    else    //If target point is not buildable, check nearby (radially, up to ~288 range away)
        loop
            set sd = 0
            loop
                exitwhen not fail or sd >= 360
                set sx = R2I(toX-turnfix + sn*32 * Sin(sd))/64*64 
                set sy = R2I(toY-turnfix + sn*32 * Cos(sd))/64*64 
                if isPointBuildableForPlayer(pl, sx, sy) then
                    set toX = sx
                    set toY = sy
                    set fail = false
                endif
                set sd = sd + 45/sn     //32 distance: 8 positions checked, 64 distance: 16 positions checked, 96 distance: 24 positions checked, etc.
                                        //note that isPointBuildableForPlayer actually checks for 5 positions, 1 in middle and 4 in the cardinal directions
            endloop
            exitwhen not fail or sn == 8   // 8x32 search radius
            set sn = sn + 1
        endloop
    endif
            
    if fail then
        call tower.getOwner().displaySmallFloatingText("FAIL!", tower, 255, 150, 0, 30)
    else
        //Teleport
        call SFXAtUnit("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl",twrUnit)
        call SetUnitPosition(twrUnit,toX,toY)
        call tower.setPos(toX,toY) 
        call SFXAtUnit("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl",twrUnit)
        loop
            exitwhen FX == null
            call SetUnitX(FX, toX + GetUnitX(FX) - fromX)
            call SetUnitY(FX, toY + GetUnitY(FX) - fromY)
            set FX = LoadUnitHandle(tower.effectTable,tower,GetHandleId(FX))
        endloop
        //Leave illusion behind
        if b == 0 then
            set ill = CreateUnit(pl.getThePlayer(),unitID,fromX,fromY,0)
            call ShowUnit(ill, false)
            call SetUnitX(ill,fromX)
            call SetUnitY(ill,fromY)
            set ef = Effect.createAnimated(unitID,fromX,fromY,GetUnitFlyHeight(twrUnit),GetUnitFacing(twrUnit))
            call ef.setColor(150,150,255,100)
            call ef.noDeathAnimation()
            set tele = Tele.create(fromX, fromY, toX, toY, turnfix, ef, ill)
            if tt.effects != 0 then
                set l = tt.effects.getFirst()
                loop
                    exitwhen l == 0
                    set FX = TowerFXType(l.getContent()).createFX(ill)
                    call SetUnitVertexColor(FX,150,150,255,100)
                    call SetUnitX(FX,GetUnitX(FX) - turnfix)
                    call SetUnitY(FX,GetUnitY(FX) - turnfix)
                    set tele.dummy[tele.numEffects] = FX
                    set tele.numEffects = tele.numEffects + 1
                    set l = l.next
                endloop
            endif
            call block(false,fromX,fromY,turnfix)
            set Chrono_Jumper_buff.apply(tower,tower,0).userInt = tele
        else
            call Chrono_Jumper_buff.apply(tower,tower,0)
        endif
    endif
    set twrUnit = null
    set FX = null
    set ill = null

Header

goldcost: 0
    globals
        BuffType Chrono_Jumper_buff 
    endglobals    
    
    struct Tele
        real fromX
        real fromY
        real toX
        real toY
        real turnfix
        Effect ef
        integer numEffects = 0
        unit array dummy[100]
        unit ill
    
        static method create takes real fromX, real fromY, real toX, real toY, real turnfix, Effect ef, unit ill returns Tele
            local Tele t = Tele.allocate()
            set t.fromX = fromX
            set t.fromY = fromY
            set t.toX = toX
            set t.toY = toY
            set t.turnfix = turnfix
            set t.ef = ef
            set t.ill = ill
            return t
        endmethod
        
        private method onDestroy takes nothing returns nothing
            call .ef.destroy()
            call RemoveUnit(.ill)
            set .ill = null
            loop
                set .numEffects = .numEffects - 1
                exitwhen .numEffects < 0
                call RemoveUnit(.dummy[.numEffects])
                set .dummy[.numEffects] = null
            endloop
        endmethod
    endstruct
    
    function block takes boolean bl, real fromX, real fromY, real turnfix returns nothing
        local integer i = 0
        local integer j = 0
        loop
            loop
                call SetTerrainPathable(fromX - 48 - turnfix + j,fromY + 48 - turnfix - i,PATHING_TYPE_BUILDABILITY,bl)
                set j = j + 16
                exitwhen j > 96 - turnfix
            endloop
            set j = 0
            set i = i + 16
            exitwhen i > 96
        endloop
    endfunction
    
    function chrono_jumper_onCleanup takes Buff b returns nothing
        local Tele tele = b.userInt
        local Tower tower = b.getBuffedUnit()
        local unit twrUnit = tower.getUnit()
        local unit FX = tower.effects
        call block(true,tele.fromX,tele.fromY,tele.turnfix)
        call SFXAtUnit("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportCaster.mdl",twrUnit)
        loop
            exitwhen FX == null
            call SetUnitX(FX, tele.fromX + GetUnitX(FX) - tele.toX)
            call SetUnitY(FX, tele.fromY + GetUnitY(FX) - tele.toY)
            set FX = LoadUnitHandle(tower.effectTable,tower,GetHandleId(FX))
        endloop
        call SetUnitPosition(twrUnit,tele.fromX,tele.fromY)
        call tower.setPos(tele.fromX,tele.fromY)
        call SFXAtUnit("Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl",twrUnit)
        call tele.destroy()
        set twrUnit = null
    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() 
        call m.addModification(MOD_ATTACKSPEED,0.1,0.0) 
        set Chrono_Jumper_buff = BuffType.create(10,0,true)
        call Chrono_Jumper_buff.setBuffModifier(m)
        call Chrono_Jumper_buff.setBuffIcon('@@0@@')
        call Chrono_Jumper_buff.addEventOnCleanup(chrono_jumper_onCleanup)
    endfunction