data.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. -- COMES AFTER UI.LUA
  2. Stones = 250.0 -- Current Stone Stock
  3. crafter = {}
  4. for i=0, 50 do
  5. local dig = {}
  6. dig.title = "D"
  7. dig.own = false -- is it bought ?
  8. dig.active = false -- is it active yet ?
  9. dig.readyTime = 10 -- time until active in Sec
  10. dig.ready = 0 -- current time until readyTime
  11. dig.speed = 0.5 -- Speed in Sec
  12. dig.amount = 1 -- Amount by Sec
  13. dig.upCost = 50 -- Stones req to dig twice more
  14. local xg = (i%20)*50
  15. local yg = 50 + math.floor(i/20)*50
  16. dig.ui = {color = colorBlue, x = xg, y = yg, w = 50, h = 50}
  17. dig.uiready = {color = colorOrange, x = xg, y = yg+50, w = 50, h = 0}
  18. table.insert(crafter, dig)
  19. end
  20. function updateStocks(sec)
  21. for i=1, #crafter do
  22. local crft = crafter[i]
  23. if crft.active then
  24. Stones = Stones + (crft.amount * sec * crft.speed)
  25. elseif crft.own then
  26. if crft.ready >= crft.readyTime then
  27. crft.active = true
  28. end
  29. crft.ready = crft.ready + sec
  30. end
  31. end
  32. end
  33. function upgradeCrafter(crft)
  34. -- BUY CRAFTER
  35. if not crft.own then
  36. if pay(50) then
  37. crft.own = true
  38. end
  39. -- UPGRADE CRAFTER
  40. elseif crft.ready == 0 and pay(50) then
  41. crft.amount = crft.amount + 1
  42. end
  43. end
  44. function pay(cost)
  45. if Stones >= cost then
  46. Stones = Stones - cost
  47. return true
  48. else
  49. return false
  50. end
  51. end