upgrades.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Upgrades = {}
  2. Upgrades.clear = function()
  3. Upgrades.canBuy = function(who, what)
  4. local p = ctx.player
  5. local upgrade = data.unit[who].upgrades[what]
  6. if upgrade.level >= upgrade.maxLevel then return false end
  7. if p.juju < upgrade.costs[upgrade.level + 1] then return false end
  8. return Upgrades.checkPrerequisites(who, what)
  9. end
  10. Upgrades.checkPrerequisites = function(who, what)
  11. local upgrade = data.unit[who].upgrades[what]
  12. if not upgrade.prerequisites then return true end
  13. for key, level in pairs(upgrade.prerequisites) do
  14. if data.unit[who].upgrades[key].level < level then return false end
  15. end
  16. return true
  17. end
  18. Upgrades.unlock = function(who, what)
  19. local upgrade = data.unit[who].upgrades[what]
  20. upgrade.level = upgrade.level + 1
  21. table.each(ctx.units.objects, function(unit)
  22. if unit.class.code == who then
  23. f.exe(upgrade.apply, upgrade, unit)
  24. end
  25. end)
  26. data.unit[who].cost = data.unit[who].cost + config.units.upgradeCostIncrease
  27. end
  28. Upgrades.canBuyAttribute = function(who, what)
  29. local unit = data.unit[who]
  30. local p = ctx.player
  31. return p.juju >= unit.attributeCosts[what]
  32. end
  33. Upgrades.unlockAttribute = function(who, what)
  34. local unit = data.unit[who]
  35. unit.attributes[what] = unit.attributes[what] + 1
  36. unit.attributeCosts[what] = unit.attributeCosts[what] + config.attributes.costIncrease
  37. unit.cost = unit.cost + config.units.attributeCostIncrease
  38. end
  39. end