Advertisement
VoxPVoxD

Untitled

Mar 20th, 2021
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var VERBOSE = false;
  2.  
  3. var log = function() {
  4. if (!VERBOSE) {
  5. return;
  6. }
  7. console.log.apply(null, arguments);
  8. }
  9.  
  10.  
  11. var TickChallenge = function() {
  12. this.interval = null;
  13. this.period = 10; // ms
  14. }
  15.  
  16.  
  17. TickChallenge.prototype.start = function() {
  18. if (this.interval !== null) {
  19. clearInterval(this.interval);
  20. }
  21.  
  22. this.interval = setInterval(this.oneTick.bind(this), this.period);
  23. };
  24.  
  25. TickChallenge.prototype.stop = function() {
  26. if (this.interval !== null) {
  27. clearInterval(this.interval);
  28. }
  29. };
  30.  
  31.  
  32. TickChallenge.prototype.oneTick = function() {
  33. var maxTier = this.getTiers();
  34.  
  35. // max out the top dimension to keep the prices spaced.
  36. while (buyManyDimension(maxTier)) {}
  37. log("max tier", maxTier);
  38.  
  39. // TODO should this be >0 or >=0? (i.e. does game 0 index or 1 index)
  40. // loop backwards
  41. for (var tier = maxTier - 1; tier > 0; tier--) {
  42. // buy this dimension until we can't buy anymore, or the price would catch up to the
  43. // next tier's price
  44. while (this.getNextPrice(tier).lessThan(this.getCurrentPrice(tier + 1))) {
  45. var buyResult = buyManyDimension(tier);
  46. if (!buyResult) {
  47. log("breaking due to !buyResult on tier", tier);
  48. break;
  49. }
  50. }
  51. log("finishing tier", tier);
  52. }
  53.  
  54. // buy tick upgrades
  55. var lastTier = tier + 1; // this is the last tier we purchased, i.e. the first tier. I still don't know if we're 0 or 1 indexing ¯\_(ツ)_/¯
  56. log("last tier", lastTier);
  57. while ( (this.getNextTickPrice().lessThan(this.getCurrentPrice(lastTier)))
  58. && buyTickSpeed()) {}
  59. };
  60.  
  61. TickChallenge.prototype.getNextTickPrice = function() {
  62. return player.tickSpeedCost.times(player.tickspeedMultiplier);
  63. }
  64.  
  65. TickChallenge.prototype.getNextPrice = function(tier) {
  66. var currentPrice = this.getCurrentPrice(tier);
  67. multiplier = getDimensionCostMultiplier(tier);
  68. return currentPrice.times(multiplier);
  69. };
  70.  
  71. TickChallenge.prototype.getCurrentPrice = function(tier) {
  72. var name = TIER_NAMES[tier];
  73. var cost = player[name + 'Cost'].times(10);
  74. return cost;
  75. };
  76.  
  77.  
  78. TickChallenge.prototype.getTiers = function() {
  79. var i = 1;
  80. while (canBuyDimension(i)) {
  81. i++;
  82. }
  83.  
  84. var maxCanBuy = i - 1;
  85. // 9 says it can be bought, but buyManyDimension(9) fails?
  86. if (maxCanBuy > 8) {
  87. return 8;
  88. }
  89.  
  90. return maxCanBuy;
  91. };
  92.  
  93. var t = new TickChallenge();
  94. t.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement