data.lua 1.2 KB

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