Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | None | 0 0
  1. (function(context) {
  2. "use strict";
  3. const pixi = gApp;
  4. const GAME = gGame;
  5. const SERVER = gServer;
  6. const Option = function Option(name, def) {
  7. if (window.localStorage[name] === undefined) {
  8. context.localStorage[name] = def;
  9. }
  10. return context.localStorage[name];
  11. }
  12. Option("forceLevellingMode", false);
  13. const SetMouse = function SetMouse(x, y) {
  14. pixi.renderer.plugins.interaction.mouse.global.x = x;
  15. pixi.renderer.plugins.interaction.mouse.global.y = y;
  16. }
  17. const EnemyManager = function EnemyManager() {
  18. return GAME.m_State.m_EnemyManager;
  19. }
  20. const AttackManager = function AttackManager() {
  21. return GAME.m_State.m_AttackManager;
  22. }
  23. const TryContinue = function Continue() {
  24. let continued = false;
  25. if (GAME.m_State.m_VictoryScreen) {
  26. GAME.m_State.m_VictoryScreen.children.forEach(function(child) {
  27. if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
  28. continued = true;
  29. child.click();
  30. }
  31. })
  32. }
  33. if (GAME.m_State.m_LevelUpScreen) {
  34. continued = false;
  35. GAME.m_State.m_LevelUpScreen.children.forEach(function(child) {
  36. if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
  37. continued = true;
  38. child.click();
  39. }
  40. })
  41. }
  42. if(GAME.m_State instanceof CBootState) { //First screen
  43. GAME.ChangeState( new CBattleSelectionState( context.gPlayerInfo.active_planet ) );
  44. continued = true;
  45. }
  46. return continued;
  47. }
  48. const CanAttack = function CanAttack(attackname) {
  49. let Manager = AttackManager().m_mapCooldowns.get(attackname);
  50. let lastUsed = Manager.m_rtAttackLastUsed;
  51. let canAttack = Manager.BAttack();
  52. Manager.m_rtAttackLastUsed = lastUsed;
  53. return canAttack;
  54. }
  55. const GetBestZone = function GetBestZone() {
  56. let bestZoneIdx;
  57. let highestDifficulty = -1;
  58.  
  59. let isLevelling = context.gPlayerInfo.level < 9 || Option("forceLevellingMode");
  60. let maxProgress = isLevelling ? 10000 : 0;
  61.  
  62. for (let idx = 0; idx < GAME.m_State.m_Grid.m_Tiles.length; idx++) {
  63. let zone = GAME.m_State.m_Grid.m_Tiles[idx].Info;
  64. if (!zone.captured) {
  65. if (zone.boss) {
  66. return idx;
  67. }
  68.  
  69. if(isLevelling) {
  70. if(zone.difficulty > highestDifficulty) {
  71. highestDifficulty = zone.difficulty;
  72. maxProgress = zone.progress;
  73. bestZoneIdx = idx;
  74. } else if(zone.difficulty < highestDifficulty) continue;
  75.  
  76. if(zone.progress < maxProgress) {
  77. maxProgress = zone.progress;
  78. bestZoneIdx = idx;
  79. }
  80. } else {
  81. if(zone.progress > maxProgress) {
  82. maxProgress = zone.progress;
  83. bestZoneIdx = idx;
  84. }
  85. }
  86.  
  87. }
  88. }
  89.  
  90. if(bestZoneIdx !== undefined) {
  91. console.log(`zone ${bestZoneIdx} (${bestZoneIdx % k_NumMapTilesW}, ${(bestZoneIdx / k_NumMapTilesW) | 0}) progress: ${GAME.m_State.m_Grid.m_Tiles[bestZoneIdx].Info.progress} difficulty: ${GAME.m_State.m_Grid.m_Tiles[bestZoneIdx].Info.difficulty}`);
  92. }
  93.  
  94. return bestZoneIdx;
  95. }
  96.  
  97. // Let's challenge ourselves to be human here!
  98. const CLICKS_PER_SECOND = 15;
  99.  
  100. const InGame = function InGame() {
  101. return GAME.m_State.m_bRunning;
  102. }
  103.  
  104. const InZoneSelect = function InZoneSelect() {
  105. return GAME.m_State instanceof CBattleSelectionState;
  106. }
  107.  
  108. const WORST_SCORE = -1 / 0;
  109. const START_POS = pixi.renderer.width;
  110.  
  111. // context.lastZoneIndex;
  112. let isJoining = false;
  113.  
  114. const EnemySpeed = function EnemySpeed(enemy) {
  115. return enemy.m_Sprite.vx;
  116. }
  117. const EnemyDistance = function EnemyDistance(enemy) {
  118. return (enemy.m_Sprite.x - k_nDamagePointx) / (START_POS - k_nDamagePointx);
  119. }
  120.  
  121. const EnemyCenter = function EnemyCenter(enemy) {
  122. return [
  123. enemy.m_Sprite.x + enemy.m_Sprite.width / 2,
  124. enemy.m_Sprite.y + enemy.m_Sprite.height / 2
  125. ];
  126. }
  127.  
  128.  
  129. class Attack {
  130. constructor() {
  131. this.nextAttackDelta = 0;
  132. }
  133. shouldAttack(delta, enemies) {
  134. throw new Error("shouldAttack not implemented");
  135. }
  136. process(enemies) {
  137. throw new Error("process not implemented");
  138. }
  139. getAttackName() {
  140. throw new Error("no current attack name");
  141. }
  142. canAttack() {
  143. return CanAttack(this.getAttackName());
  144. }
  145. getAttackData() {
  146. return AttackManager().m_AttackData[this.getAttackName()];
  147. }
  148. }
  149.  
  150. // Basic clicking attack, attack closest
  151. class ClickAttack extends Attack {
  152. shouldAttack(delta) {
  153. // Can't do basic attack when station is down
  154. if (GAME.m_State.m_PlayerHealth <= 0)
  155. return false;
  156. this.nextAttackDelta -= delta;
  157. return this.nextAttackDelta <= 0;;
  158. }
  159. score(enemy) {
  160. if (enemy.m_bDead)
  161. return WORST_SCORE;
  162. return 1 - EnemyDistance(enemy);
  163. }
  164. process(enemies) {
  165. let target, target_score = WORST_SCORE;
  166.  
  167. enemies.forEach((enemy) => {
  168. if (!enemy.m_Sprite.visible)
  169. return;
  170. let now_score = this.score(enemy);
  171. if (now_score > target_score) {
  172. target = enemy, target_score = now_score;
  173. }
  174. });
  175.  
  176. if (target)
  177. this.attack(target);
  178. }
  179. attack(enemy) {
  180. enemy.m_Sprite.click();
  181. this.nextAttackDelta = 1 / CLICKS_PER_SECOND;
  182. }
  183. }
  184.  
  185. class ProjectileAttack extends Attack {
  186. shouldAttack(delta) {
  187. return CanAttack(this.getAttackName());
  188. }
  189. score(enemy) {
  190. if (enemy.m_bDead)
  191. return WORST_SCORE;
  192. return enemy.m_nHealth;
  193. }
  194. process(enemies) {
  195. let target, target_score = WORST_SCORE;
  196.  
  197. enemies.forEach((enemy) => {
  198. if (!enemy.m_Sprite.visible)
  199. return;
  200. let now_score = this.score(enemy);
  201. if (now_score > target_score) {
  202. target = enemy, target_score = now_score;
  203. }
  204. });
  205.  
  206. if (target)
  207. this.attack.apply(this, EnemyCenter(target));
  208. }
  209. attack(x, y) {
  210. SetMouse(x, y)
  211. AttackManager().m_mapKeyCodeToAttacks.get(this.getAttackData().keycode)()
  212. }
  213. }
  214.  
  215. // the '1' button (SlimeAttack PsychicAttack BeastAttack - depends on body type of your salien)
  216. class SpecialAttack extends ProjectileAttack {
  217. getAttackName() {
  218. if (gSalien.m_BodyType == "slime")
  219. return "slimeattack";
  220. else if (gSalien.m_BodyType == "beast")
  221. return "beastattack";
  222. else
  223. return "psychicattack";
  224. }
  225. }
  226.  
  227. class BombAttack extends ProjectileAttack {
  228. getAttackName() {
  229. return "explosion";
  230. }
  231. }
  232. class BlackholeAttack extends ProjectileAttack {
  233. getAttackName() {
  234. return "blackhole";
  235. }
  236. }
  237.  
  238. class FreezeAttack extends Attack {
  239. getCurrent() {
  240. return "flashfreeze";
  241. }
  242. shouldAttack(delta, enemies) {
  243. let shouldAttack = false;
  244. if (CanAttack(this.getCurrent())) {
  245. enemies.forEach((enemy) => {
  246. if (EnemyDistance(enemy) <= 0.05) {
  247. shouldAttack = true;
  248. }
  249. });
  250. }
  251. return shouldAttack;
  252. }
  253. getData() {
  254. return AttackManager().m_AttackData[this.getCurrent()];
  255. }
  256. process() {
  257. AttackManager().m_mapKeyCodeToAttacks.get(this.getData().keycode)()
  258. }
  259. }
  260.  
  261. let attacks = [
  262. new ClickAttack(),
  263. new SpecialAttack(),
  264. new FreezeAttack(),
  265. new BombAttack(),
  266. new BlackholeAttack()
  267. ]
  268.  
  269. if (context.BOT_FUNCTION) {
  270. pixi.ticker.remove(context.BOT_FUNCTION);
  271. context.BOT_FUNCTION = undefined;
  272. }
  273.  
  274. context.BOT_FUNCTION = function ticker(delta) {
  275. delta /= 100;
  276.  
  277. let buttonsOnErrorMessage = document.getElementsByClassName("btn_grey_white_innerfade btn_medium");
  278. if(buttonsOnErrorMessage.length > 0) {
  279. buttonsOnErrorMessage[0].click();
  280. return;
  281. }
  282.  
  283. if(GAME.m_IsStateLoading || !context.gPlayerInfo) {
  284. return;
  285. }
  286.  
  287. if (InZoneSelect() && !isJoining) {
  288. let bestZoneIdx = GetBestZone();
  289. if(bestZoneIdx > -1) {
  290. isJoining = true;
  291. console.log("join to zone", bestZoneIdx);
  292. SERVER.JoinZone(
  293. bestZoneIdx,
  294. function (results) {
  295. GAME.ChangeState(new CBattleState(GAME.m_State.m_PlanetData, bestZoneIdx));
  296. },
  297. GameLoadError
  298. );
  299.  
  300. return;
  301. }
  302. }
  303.  
  304. if (!InGame()) {
  305. if (TryContinue()) {
  306. console.log("continued!");
  307. }
  308. return;
  309. }
  310.  
  311. isJoining = false;
  312.  
  313. let state = EnemyManager();
  314.  
  315. let enemies = state.m_rgEnemies;
  316.  
  317. for (let attack of attacks)
  318. if (attack.shouldAttack(delta, enemies))
  319. attack.process(enemies);
  320. }
  321.  
  322.  
  323. pixi.ticker.add(context.BOT_FUNCTION);
  324.  
  325. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement