| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- -- COMES AFTER UI.LUA
- Stones = 250.0 -- Current Stone Stock
- crafter = {}
- for i=0, 50 do
- local dig = {}
- dig.title = "D"
- dig.own = false -- is it bought ?
- dig.active = false -- is it active yet ?
- dig.readyTime = 10 -- time until active in Sec
- dig.ready = 0 -- current time until readyTime
- dig.speed = 0.5 -- Speed in Sec
- dig.amount = 1 -- Amount by Sec
- dig.upCost = 50 -- Stones req to dig twice more
- local xg = (i%20)*50
- local yg = 50 + math.floor(i/20)*50
- dig.ui = {color = colorBlue, x = xg, y = yg, w = 50, h = 50}
- dig.uiready = {color = colorOrange, x = xg, y = yg+50, w = 50, h = 0}
- table.insert(crafter, dig)
- end
- function updateStocks(sec)
- for i=1, #crafter do
- local crft = crafter[i]
- if crft.active then
- Stones = Stones + (crft.amount * sec * crft.speed)
- elseif crft.own then
- if crft.ready >= crft.readyTime then
- crft.active = true
- end
- crft.ready = crft.ready + sec
- end
- end
- end
- function upgradeCrafter(crft)
- -- BUY CRAFTER
- if not crft.own then
- if pay(50) then
- crft.own = true
- end
- -- UPGRADE CRAFTER
- elseif crft.ready == 0 and pay(50) then
- crft.amount = crft.amount + 1
- end
- end
- function pay(cost)
- if Stones >= cost then
- Stones = Stones - cost
- return true
- else
- return false
- end
- end
|