Even More Magical Hammer v1
1000
lvl: 28

ID:

201

Author:

cedi

Rarity:

unique

Status:

Approved

Description:

The professional version.

Latest Upload Comment:

Restored from 1.10
Even More Magical Weapon
Every 5th instance of spell damage is a critical hit.
Download

Toggle Triggers

Header

goldcost: 1000
    globals
        BuffType Hammer_Mark
        BuffType Hammer_Aura
    endglobals
    
    function Mark_Setup takes Buff B returns nothing
        set B.userInt = 5
        set B.userInt2 = 5
        set B.userInt3 = 5
        
        set B.userReal = 50
        set B.userReal2 = 50
        set B.userReal3 = 50
    endfunction
    
    function Hammer_Aura_Trig takes Buff B returns nothing
        local Tower T = Event.getTarget()
        local integer lvl
        if Event.isSpellDamage() then
            //Has attacker the mark buff?
            set B = T.getBuffOfType( Hammer_Mark )
            if B != 0 then
                set lvl = B.getLevel()
            
                //Attacking tower carries a hammer
                //Hammer 1
                set B.userInt = B.userInt - 1
                if B.userInt <= 0 then
                    set B.userInt = 5
                    call T.addSpellCrit()
                endif
                
                //Hammer 2
                if lvl >= 2 then
                    set B.userInt2 = B.userInt2 - 1
                    if B.userInt2 <= 0 then
                        set B.userInt2 = 5
                        call T.addSpellCrit()
                    endif
                else
                    //Only 1 hammer
                    return
                endif
                
                //Hammer 3
                if lvl >= 3 then
                    set B.userInt3 = B.userInt3 - 1
                    if B.userInt3 <= 0 then
                        set B.userInt3 = 5
                        call T.addSpellCrit()
                    endif
                else
                    //Only 2 hammer
                    return
                endif
                
                //Hammer 4
                if lvl >= 4 then
                    set B.userReal = B.userReal - 10
                    if B.userReal < 5 then //Because real are realy not accurate at all.
                        set B.userReal = 50
                        call T.addSpellCrit()
                    endif
                else
                    //Only 3 hammer
                    return
                endif
                
                //Hammer 5
                if lvl >= 5 then
                    set B.userReal2 = B.userReal2 - 10
                    if B.userReal2 < 5 then //Because real are realy not accurate at all.
                        set B.userReal2 = 50
                        call T.addSpellCrit()
                    endif
                else
                    //Only 4 hammer
                    return
                endif
                
                //Hammer 6
                if lvl >= 6 then
                    set B.userReal3 = B.userReal3 - 10
                    if B.userReal3 < 5 then //Because real are realy not accurate at all.
                        set B.userReal3 = 50
                        call T.addSpellCrit()
                    endif
                endif
            endif
        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 Hammer_Mark = BuffType.create( -1, 0, true )
        call Hammer_Mark.setBuffIcon( '@@0@@' )
        call Hammer_Mark.addEventOnCreate( Mark_Setup )
        
        set Hammer_Aura = BuffType.create( -1, 0, false )
        call Hammer_Aura.setBuffIcon( '@@1@@' )
        call Hammer_Aura.addEventOnDamaged( Hammer_Aura_Trig, 1.0, 0.0 )
    endfunction

On Item Drop

goldcost: 0
function onDrop takes Item itm returns nothing
    local Tower T = itm.getCarrier()
    local Buff B = T.getBuffOfType( Hammer_Mark )
    
    if B != 0 then
        //First hammer on tower
        if B.getLevel() == 1 then
            call B.removeBuff() //Only one hammer was on the tower.
        else
            call B.setLevel( B.getLevel() - 1 )
        endif
    else
        //No buff, although there is still a hammer on the tower! Shit happened!
    endif
endfunction

On Item Pickup

goldcost: 0
function onPickup  takes Item itm returns nothing
    local Tower T = itm.getCarrier()
    local Buff B = T.getBuffOfType( Hammer_Mark )
    
    if B == 0 then
        //First hammer on tower
        call Hammer_Mark.apply( T, T, 1 )
    else
        //Already a hammer on the tower
        call B.setLevel( B.getLevel() + 1 )
    endif
endfunction

On Unit Comes In Range

goldcost: 0 UNITINRANGE_targetType: TARGET_TYPE_CREEPS UNITINRANGE_range: 2000
function onUnitInRange takes Item itm returns nothing
    local Unit U = Event.getTarget()
    if U.getBuffOfType( Hammer_Aura ) == 0 then
        call Hammer_Aura.apply( itm.getCarrier(), U, 0 )
    endif
endfunction