Advertisement
Guest User

real code

a guest
Jun 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.26 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Saliens bot
  3. // @namespace http://tampermonkey.net/
  4. // @version 15
  5. // @description Beat all the saliens levels
  6. // @author https://github.com/meepen/salien-bot
  7. // @match https://steamcommunity.com/saliengame
  8. // @match https://steamcommunity.com/saliengame/
  9. // @match https://steamcommunity.com/saliengame/play
  10. // @match https://steamcommunity.com/saliengame/play/
  11. // @downloadURL https://github.com/meepen/salien-bot/raw/master/index.user.js
  12. // @updateURL https://github.com/meepen/salien-bot/raw/master/index.user.js
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. if (typeof GM_info !== "undefined" && (GM_info.scriptHandler || "Greasemonkey") == "Greasemonkey") {
  17. alert("It's not possible to support Greasemonkey, please try Tampermonkey or ViolentMonkey.");
  18. }
  19.  
  20. (function(context) {
  21. "use strict";
  22.  
  23. // when the error is fixed we should remove the following
  24. CSalien.prototype.UpdateCustomizations = function()
  25. {
  26. this.SetBodyType(BODY_TYPES[gSalienData.body_type]);
  27. this.LoadAttachments();
  28. }
  29. const APP = context.gApp;
  30. const GAME = context.gGame;
  31. const SERVER = context.gServer;
  32. const PIXI = context.PIXI;
  33.  
  34. const Option = function Option(name, def) {
  35. if (window.localStorage[name] === undefined) {
  36. context.localStorage[name] = def;
  37. }
  38. return context.localStorage[name];
  39. }
  40. Option("forceLevellingMode", false);
  41. const SetMouse = function SetMouse(x, y) {
  42. APP.renderer.plugins.interaction.mouse.global.x = x;
  43. APP.renderer.plugins.interaction.mouse.global.y = y;
  44. }
  45. const EnemyManager = function EnemyManager() {
  46. return GAME.m_State.m_EnemyManager;
  47. }
  48. const AttackManager = function AttackManager() {
  49. return GAME.m_State.m_AttackManager;
  50. }
  51.  
  52. let isJoining = false;
  53. const TryContinue = function TryContinue() {
  54. let continued = false;
  55. if (GAME.m_State.m_VictoryScreen) {
  56. GAME.m_State.m_VictoryScreen.children.forEach(function(child) {
  57. if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
  58. continued = true;
  59. child.click();
  60. }
  61. })
  62. }
  63. if (GAME.m_State.m_LevelUpScreen) {
  64. continued = false;
  65. GAME.m_State.m_LevelUpScreen.children.forEach(function(child) {
  66. if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
  67. continued = true;
  68. child.click();
  69. }
  70. })
  71. }
  72. if (GAME.m_State instanceof CBootState) { // First screen
  73. gGame.m_State.button.click();
  74. }
  75. if (GAME.m_State instanceof CPlanetSelectionState && !isJoining) { // Planet Selectiong
  76. GAME.m_State.m_rgPlanetSprites[0].click();
  77. isJoining = true;
  78. setTimeout(() => isJoining = false, 1000);
  79. continued = true;
  80. }
  81. if (GAME.m_State instanceof CBattleSelectionState && !isJoining) {
  82. let bestZoneIdx = GetBestZone();
  83. if(bestZoneIdx) {
  84. console.log(GAME.m_State.m_SalienInfoBox.m_LevelText.text, GAME.m_State.m_SalienInfoBox.m_XPValueText.text);
  85. console.log("join to zone", bestZoneIdx);
  86. isJoining = true;
  87. SERVER.JoinZone(
  88. bestZoneIdx,
  89. (results) => {
  90. GAME.ChangeState(new CBattleState(GAME.m_State.m_PlanetData, bestZoneIdx));
  91. isJoining = false;
  92. console.log(results);
  93. },
  94. () => {
  95. console.log("fail");
  96. isJoining = false;
  97. }
  98. );
  99. }
  100. console.log(bestZoneIdx);
  101. return;
  102. }
  103. return continued;
  104. }
  105. const CanAttack = function CanAttack(attackname) {
  106. let Manager = AttackManager().m_mapCooldowns.get(attackname);
  107. let lastUsed = Manager.m_rtAttackLastUsed;
  108. let canAttack = Manager.BAttack();
  109. Manager.m_rtAttackLastUsed = lastUsed;
  110. return canAttack;
  111. }
  112. const GetBestZone = function GetBestZone() {
  113. let bestZoneIdx = 86;
  114.  
  115. return bestZoneIdx;
  116.  
  117.  
  118. }
  119. const GetBestPlanet = function GetBestPlanet() {
  120. let bestPlanet;
  121. let maxProgress = 0;
  122.  
  123. if (!GAME.m_State.m_mapPlanets)
  124. return;
  125.  
  126. for (let planetKV of GAME.m_State.m_mapPlanets) {
  127. let planet = planetKV[1];
  128. if(planet.state.active && !planet.state.captured && planet.state.capture_progress > maxProgress) {
  129. maxProgress = planet.state.capture_progress;
  130. bestPlanet = planet;
  131. }
  132.  
  133. }
  134.  
  135. if(bestPlanet) {
  136. console.log(`selecting planet ${bestPlanet.state.name} with progress: ${bestPlanet.state.capture_progress}`);
  137. return bestPlanet.id;
  138. }
  139. }
  140.  
  141. // Let's challenge ourselves to be human here!
  142. const CLICKS_PER_SECOND = 15;
  143.  
  144. const InGame = function InGame() {
  145. return GAME.m_State.m_bRunning;
  146. }
  147.  
  148. const WORST_SCORE = -1 / 0;
  149. const START_POS = APP.renderer.width;
  150.  
  151.  
  152. const EnemySpeed = function EnemySpeed(enemy) {
  153. return enemy.m_Sprite.vx;
  154. }
  155. const EnemyDistance = function EnemyDistance(enemy) {
  156. return (enemy.m_Sprite.x - k_nDamagePointx) / (START_POS - k_nDamagePointx);
  157. }
  158.  
  159. const EnemyCenter = function EnemyCenter(enemy) {
  160. return [
  161. enemy.m_Sprite.x + enemy.m_Sprite.width / 2,
  162. enemy.m_Sprite.y + enemy.m_Sprite.height / 2
  163. ];
  164. }
  165.  
  166.  
  167. class Attack {
  168. constructor() {
  169. this.nextAttackDelta = 0;
  170. }
  171. shouldAttack(delta, enemies) {
  172. throw new Error("shouldAttack not implemented");
  173. }
  174. process(enemies) {
  175. throw new Error("process not implemented");
  176. }
  177. getAttackName() {
  178. throw new Error("no current attack name");
  179. }
  180. canAttack() {
  181. return CanAttack(this.getAttackName());
  182. }
  183. getAttackData() {
  184. return AttackManager().m_AttackData[this.getAttackName()];
  185. }
  186. }
  187.  
  188. // Basic clicking attack, attack closest
  189. class ClickAttack extends Attack {
  190. shouldAttack(delta) {
  191. // Can't do basic attack when station is down
  192. if (GAME.m_State.m_PlayerHealth <= 0)
  193. return false;
  194. this.nextAttackDelta -= delta;
  195. return this.nextAttackDelta <= 0;;
  196. }
  197. score(enemy) {
  198. if (enemy.m_bDead)
  199. return WORST_SCORE;
  200. return 1 - EnemyDistance(enemy);
  201. }
  202. process(enemies) {
  203. let target, target_score = WORST_SCORE;
  204.  
  205. enemies.forEach((enemy) => {
  206. if (!enemy.m_Sprite.visible)
  207. return;
  208. let now_score = this.score(enemy);
  209. if (now_score > target_score) {
  210. target = enemy, target_score = now_score;
  211. }
  212. });
  213.  
  214. if (target)
  215. this.attack(target);
  216. }
  217. attack(enemy) {
  218. enemy.m_Sprite.click();
  219. this.nextAttackDelta = 1 / CLICKS_PER_SECOND;
  220. }
  221. }
  222.  
  223. class ProjectileAttack extends Attack {
  224. shouldAttack(delta) {
  225. return CanAttack(this.getAttackName());
  226. }
  227. score(enemy) {
  228. if (enemy.m_bDead)
  229. return WORST_SCORE;
  230. return enemy.m_nHealth;
  231. }
  232. process(enemies) {
  233. let target, target_score = WORST_SCORE;
  234.  
  235. enemies.forEach((enemy) => {
  236. if (!enemy.m_Sprite.visible)
  237. return;
  238. let now_score = this.score(enemy);
  239. if (now_score > target_score) {
  240. target = enemy, target_score = now_score;
  241. }
  242. });
  243.  
  244. if (target)
  245. this.attack.apply(this, EnemyCenter(target));
  246. }
  247. attack(x, y) {
  248. SetMouse(x, y)
  249. AttackManager().m_mapKeyCodeToAttacks.get(this.getAttackData().keycode)()
  250. }
  251. }
  252.  
  253. // the '1' button (SlimeAttack PsychicAttack BeastAttack - depends on body type of your salien)
  254. class SpecialAttack extends ProjectileAttack {
  255. getAttackName() {
  256. if (gSalien.m_BodyType == "slime")
  257. return "slimeattack";
  258. else if (gSalien.m_BodyType == "beast")
  259. return "beastattack";
  260. else
  261. return "psychicattack";
  262. }
  263. }
  264.  
  265. class BombAttack extends ProjectileAttack {
  266. getAttackName() {
  267. return "explosion";
  268. }
  269. }
  270. class BlackholeAttack extends ProjectileAttack {
  271. getAttackName() {
  272. return "blackhole";
  273. }
  274. }
  275.  
  276. class FreezeAttack extends Attack {
  277. getCurrent() {
  278. return "flashfreeze";
  279. }
  280. shouldAttack(delta, enemies) {
  281. let shouldAttack = false;
  282. if (CanAttack(this.getCurrent())) {
  283. enemies.forEach((enemy) => {
  284. if (EnemyDistance(enemy) <= 0.05) {
  285. shouldAttack = true;
  286. }
  287. });
  288. }
  289. return shouldAttack;
  290. }
  291. getData() {
  292. return AttackManager().m_AttackData[this.getCurrent()];
  293. }
  294. process() {
  295. AttackManager().m_mapKeyCodeToAttacks.get(this.getData().keycode)()
  296. }
  297. }
  298.  
  299. let attacks = [
  300. new ClickAttack(),
  301. new SpecialAttack(),
  302. new FreezeAttack(),
  303. new BombAttack(),
  304. new BlackholeAttack()
  305. ]
  306.  
  307. if (context.BOT_FUNCTION) {
  308. APP.ticker.remove(context.BOT_FUNCTION);
  309. context.BOT_FUNCTION = undefined;
  310. }
  311.  
  312. let reloadingPage = false;
  313.  
  314. context.BOT_FUNCTION = function ticker(delta) {
  315. delta /= 100;
  316.  
  317. let difficulties = PIXI.loader.resources['level_config'];
  318. if (difficulties)
  319. for (let difficulty in difficulties.data) {
  320. let freq = difficulties.data[difficulty].enemies.spawn_frequency;
  321. freq.min = freq.max;
  322. }
  323.  
  324. let buttonsOnErrorMessage = document.getElementsByClassName("btn_grey_white_innerfade btn_medium");
  325. if(buttonsOnErrorMessage[0] != null) {
  326. if (!reloadingPage) {
  327. setTimeout(() => buttonsOnErrorMessage[0].click(), 1000);
  328. }
  329.  
  330. return;
  331. }
  332.  
  333. if(GAME.m_IsStateLoading || !context.gPlayerInfo) {
  334. return;
  335. }
  336.  
  337. if (!InGame()) {
  338. if (TryContinue()) {
  339. console.log("continued!");
  340. }
  341. return;
  342. }
  343.  
  344.  
  345.  
  346. let state = EnemyManager();
  347.  
  348. let enemies = state.m_rgEnemies;
  349.  
  350. for (let attack of attacks)
  351. if (attack.shouldAttack(delta, enemies))
  352. attack.process(enemies);
  353.  
  354. }
  355.  
  356.  
  357. APP.ticker.add(context.BOT_FUNCTION);
  358.  
  359. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement