Pocket Emporium v1
777
lvl: 20

ID:

248

Author:

ShyGnome

Rarity:

unique

Status:

Approved

Description:


Latest Upload Comment:

Restored from 1.10
Purchase an Item
Spend a charge to buy a random item for 500 gold. The item will be of level 14-25 and uncommon or higher rarity.

Gains a charge every 5th wave, up to a maximum of 5 charges.
This ability is not affected by item quality.
Download

Toggle Triggers

Autocast

AUTOCAST_cooldown: 1 AUTOCAST_autoRange: 0 AUTOCAST_manacost: 0 goldcost: 777 AUTOCAST_range: 0 AUTOCAST_targetType: 0 AUTOCAST_numBuffsBeforeIdle: 0 caster_art: target_art: AUTOCAST_autocastType: AC_TYPE_NOAC_IMMEDIATE AUTOCAST_buffType: 0 AUTOCAST_isExtended: false AUTOCAST_targetSelf: true
    local integer i = itm.getCharges()
    local Tower tower = itm.getCarrier()
    local Playor p = itm.getOwner()
    local Item new
    local real rnd = GetRandomInt(0,24) //25 cases total
    local integer rarity = 1            //0-1 unique, 2-5 rare, 6-24 uncommon
    if rnd < 2 then
        set rarity = 3
    elseif rnd < 6 then
        set rarity = 2
    endif
    if i > 0 and GetPlayerState(p.getThePlayer(), PLAYER_STATE_RESOURCE_GOLD) >= 500 then
        set itm.userInt2 = itm.userInt2-1
        call p.giveGold(-500,tower.getUnit(),false,true)
        set new = Item.create(p,RandomItemSet.permanent.getRandomItemAtRarityBounded(rarity,14,25),tower.getX(),tower.getY())
        call new.flyToStash(0.0)
    endif
    call checkLevel(itm)

Header

goldcost: 0
    globals
    endglobals
    
    function checkLevel takes Item itm returns nothing
        local integer curLevel = itm.getOwner().getTeam().getLevel()
        if curLevel > itm.userInt3 then 
            set itm.userInt = itm.userInt + (curLevel-itm.userInt3) 
            set itm.userInt3 = curLevel 
        endif
        loop
            exitwhen itm.userInt < 5 or itm.userInt2 >= 5
            set itm.userInt = itm.userInt - 5
            set itm.userInt2 = itm.userInt2 + 1
        endloop
        call itm.setCharges(itm.userInt2)
    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
    endfunction

On Item Creation

goldcost: 0
function onCreate takes Item itm returns nothing
    call itm.setCharges(1)
    set itm.userInt = 0
    set itm.userInt2 = 1
    set itm.userInt3 = itm.getOwner().getTeam().getLevel()
endfunction

On Item Drop

goldcost: 0
function onDrop takes Item itm returns nothing
    call checkLevel(itm)
endfunction

On Item Pickup

goldcost: 0
function onPickup  takes Item itm returns nothing
    call checkLevel(itm)
endfunction

Periodic

goldcost: 0 PERIODIC_period: 10
function periodic takes Item itm returns nothing
    call checkLevel(itm)
endfunction