LordPankake

Salien auto-play

Jun 22nd, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Shitty automation by GenericSkid
  2. //
  3. // =============================== //
  4. //            VARIABLES
  5. // =============================== //
  6. const HARD = 3,
  7.     MEDIUM = 2,
  8.     EASY = 1;
  9. const PREFERRED_DIFFICULTY = HARD;
  10. const TILES_PER_ROW = 12;
  11. var joining = false;
  12. // =============================== //
  13. //            MAIN LOOP
  14. // =============================== //
  15. // run logic loop
  16. requestAnimationFrame(mainLoop);
  17. function mainLoop() {
  18.     // check if in-battle, if update game logic
  19.     if (isInBattle()) {
  20.         // reset joining flag
  21.         joining = false;
  22.         // attack all enemies on the field
  23.         clickAll();
  24.         // battle is over, go back to the planet tile screen
  25.         if (isBattleOver()) {
  26.             gGame.ChangeState(new CBattleSelectionState(gGame.m_State.m_PlanetData.id));
  27.         }
  28.     } else if (!joining && isPlanetScreen()) {
  29.         // find a battle to join
  30.         joinBattle(findZone(PREFERRED_DIFFICULTY));
  31.         joining = true;
  32.     }
  33.     requestAnimationFrame(mainLoop);
  34. }
  35.  
  36. // =============================== //
  37. //      MAIN MENU FUNCTIONS
  38. // =============================== //
  39. /**
  40.  * Join zone by it's tile coordinates.
  41.  * click the tile on the main screen.
  42.  */
  43. function joinBattle(zone) {
  44.     gGame.m_State.m_Grid.click(zone.tileX, zone.tileY);
  45. }
  46. /**
  47.  * Find zone with level of difficulty
  48.  */
  49. function findZone(difficulty) {
  50.     // array of zones
  51.     const zones = gGame.m_State.m_PlanetData.zones;
  52.     var match = undefined;
  53.     var x = 0;
  54.     var y = 0;
  55.     zones.every(function(val) {
  56.         // check for matching value
  57.         if (val.difficulty == difficulty && !val.captured) {
  58.             match = val;
  59.             return false;
  60.         }
  61.         // increment x, increment y + reset x if row maximum is met
  62.         ++x;
  63.         if (x == TILES_PER_ROW) {
  64.             ++y;
  65.             x = 0;
  66.         }
  67.         return true;
  68.     });
  69.     // return wrapper with tileX/tileY so tile data can be passed to grid click function
  70.     return {
  71.         zone: match,
  72.         tileX: x,
  73.         tileY: y
  74.     };
  75. }
  76. /**
  77.  * Check if planet screen is visible
  78.  */
  79. function isPlanetScreen() {
  80.     return !(gGame.m_State.m_PlanetData === undefined) &&
  81.            !(gGame.m_State.m_Grid === undefined);
  82. }
  83. // =============================== //
  84. //      BATTLEFIELD FUNCTIONS
  85. // =============================== //
  86. /**
  87.  * Check if the game is on the battle field
  88.  */
  89. function isInBattle() {
  90.     return !(gGame.m_State.m_EnemyManager === undefined);
  91. }
  92. /**
  93.  * Check if victory screen is shown
  94.  */
  95. function isBattleOver() {
  96.     if (gGame.m_State.m_VictoryScreen === undefined) {
  97.         return false;
  98.     }
  99.     return gGame.m_State.m_VictoryScreen.visible;
  100. }
  101. /**
  102.  * Click all CEnemy objects on the field
  103.  */
  104. function clickAll() {
  105.     enemies().forEach(function(value, key, mapObj) {
  106.         value.m_Sprite.pointertap();
  107.     });
  108. }
  109. /**
  110.  * Fetch CEnemy map
  111.  */
  112. function enemies() {
  113.     return gGame.m_State.m_EnemyManager.m_rgEnemies;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment