Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shitty automation by GenericSkid
- //
- // =============================== //
- // VARIABLES
- // =============================== //
- const HARD = 3,
- MEDIUM = 2,
- EASY = 1;
- const PREFERRED_DIFFICULTY = HARD;
- const TILES_PER_ROW = 12;
- var joining = false;
- // =============================== //
- // MAIN LOOP
- // =============================== //
- // run logic loop
- requestAnimationFrame(mainLoop);
- function mainLoop() {
- // check if in-battle, if update game logic
- if (isInBattle()) {
- // reset joining flag
- joining = false;
- // attack all enemies on the field
- clickAll();
- // battle is over, go back to the planet tile screen
- if (isBattleOver()) {
- gGame.ChangeState(new CBattleSelectionState(gGame.m_State.m_PlanetData.id));
- }
- } else if (!joining && isPlanetScreen()) {
- // find a battle to join
- joinBattle(findZone(PREFERRED_DIFFICULTY));
- joining = true;
- }
- requestAnimationFrame(mainLoop);
- }
- // =============================== //
- // MAIN MENU FUNCTIONS
- // =============================== //
- /**
- * Join zone by it's tile coordinates.
- * click the tile on the main screen.
- */
- function joinBattle(zone) {
- gGame.m_State.m_Grid.click(zone.tileX, zone.tileY);
- }
- /**
- * Find zone with level of difficulty
- */
- function findZone(difficulty) {
- // array of zones
- const zones = gGame.m_State.m_PlanetData.zones;
- var match = undefined;
- var x = 0;
- var y = 0;
- zones.every(function(val) {
- // check for matching value
- if (val.difficulty == difficulty && !val.captured) {
- match = val;
- return false;
- }
- // increment x, increment y + reset x if row maximum is met
- ++x;
- if (x == TILES_PER_ROW) {
- ++y;
- x = 0;
- }
- return true;
- });
- // return wrapper with tileX/tileY so tile data can be passed to grid click function
- return {
- zone: match,
- tileX: x,
- tileY: y
- };
- }
- /**
- * Check if planet screen is visible
- */
- function isPlanetScreen() {
- return !(gGame.m_State.m_PlanetData === undefined) &&
- !(gGame.m_State.m_Grid === undefined);
- }
- // =============================== //
- // BATTLEFIELD FUNCTIONS
- // =============================== //
- /**
- * Check if the game is on the battle field
- */
- function isInBattle() {
- return !(gGame.m_State.m_EnemyManager === undefined);
- }
- /**
- * Check if victory screen is shown
- */
- function isBattleOver() {
- if (gGame.m_State.m_VictoryScreen === undefined) {
- return false;
- }
- return gGame.m_State.m_VictoryScreen.visible;
- }
- /**
- * Click all CEnemy objects on the field
- */
- function clickAll() {
- enemies().forEach(function(value, key, mapObj) {
- value.m_Sprite.pointertap();
- });
- }
- /**
- * Fetch CEnemy map
- */
- function enemies() {
- return gGame.m_State.m_EnemyManager.m_rgEnemies;
- }
Advertisement
Add Comment
Please, Sign In to add comment