Advertisement
Guest User

Saliens

a guest
Jun 21st, 2018
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.82 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Saliens
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://steamcommunity.com/saliengame/play/
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function(context) {
  12. const pixi = gApp;
  13. const GAME = gGame;
  14. const SERVER = gServer;
  15. const SetMouse = function SetMouse(x, y) {
  16. pixi.renderer.plugins.interaction.mouse.global.x = x;
  17. pixi.renderer.plugins.interaction.mouse.global.y = y;
  18. }
  19. const EnemyManager = function EnemyManager() {
  20. return GAME.m_State.m_EnemyManager;
  21. }
  22. const AttackManager = function AttackManager() {
  23. return GAME.m_State.m_AttackManager;
  24. }
  25. const TryContinue = function Continue() {
  26. let continued = false;
  27. if (GAME.m_State.m_VictoryScreen) {
  28. GAME.m_State.m_VictoryScreen.children.forEach(function(child) {
  29. if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
  30. continued = true;
  31. child.click();
  32. }
  33. })
  34. }
  35. if (GAME.m_State.m_LevelUpScreen) {
  36. continued = false;
  37. GAME.m_State.m_LevelUpScreen.children.forEach(function(child) {
  38. if (child.visible && child.x == 155 && child.y == 300) {// TODO: not this
  39. continued = true;
  40. child.click();
  41. }
  42. })
  43. }
  44. return continued;
  45. }
  46. const CanAttack = function CanAttack(attackname) {
  47. let Manager = AttackManager().m_mapCooldowns.get(attackname);
  48. let lastUsed = Manager.m_rtAttackLastUsed;
  49. let canAttack = Manager.BAttack();
  50. Manager.m_rtAttackLastUsed = lastUsed;
  51. return canAttack;
  52. }
  53.  
  54. // Let's challenge ourselves to be human here!
  55. const CLICKS_PER_SECOND = 10;
  56.  
  57. const InGame = function InGame() {
  58. return GAME.m_State.m_bRunning;
  59. }
  60.  
  61. const InZoneSelect = function InZoneSelect() {
  62. return GAME.m_State instanceof CBattleSelectionState;
  63. }
  64.  
  65. const WORST_SCORE = -1 / 0;
  66. const START_POS = pixi.renderer.width;
  67.  
  68. // context.lastZoneIndex;
  69. let isJoining = false;
  70.  
  71. const EnemySpeed = function EnemySpeed(enemy) {
  72. return enemy.m_Sprite.vx;
  73. }
  74. const EnemyDistance = function EnemyDistance(enemy) {
  75. return (enemy.m_Sprite.x - k_nDamagePointx) / (START_POS - k_nDamagePointx);
  76. }
  77.  
  78.  
  79. class Attack {
  80. constructor() {
  81. this.nextAttackDelta = 0;
  82. }
  83. shouldAttack(delta, enemies) {
  84. throw new Error("shouldAttack not implemented");
  85. }
  86. process(enemies) {
  87. throw new Error("process not implemented");
  88. }
  89. }
  90.  
  91. // Basic clicking attack, attack closest
  92. class ClickAttack extends Attack {
  93. shouldAttack(delta) {
  94. // Can't do basic attack when station is down
  95. if (GAME.m_State.m_PlayerHealth <= 0)
  96. return false;
  97. this.nextAttackDelta -= delta;
  98. return this.nextAttackDelta <= 0;;
  99. }
  100. score(enemy) {
  101. if (enemy.m_bDead)
  102. return WORST_SCORE;
  103. return 1 - EnemyDistance(enemy);
  104. }
  105. process(enemies) {
  106. let target, target_score = WORST_SCORE;
  107.  
  108. enemies.forEach((enemy) => {
  109. if (!enemy.m_Sprite.visible)
  110. return;
  111. let now_score = this.score(enemy);
  112. if (now_score > target_score) {
  113. target = enemy, target_score = now_score;
  114. }
  115. });
  116.  
  117. if (target)
  118. this.attack(target);
  119. }
  120. attack(enemy) {
  121. enemy.m_Sprite.click();
  122. this.nextAttackDelta = 1 / CLICKS_PER_SECOND;
  123. }
  124. }
  125.  
  126. // the '1' button (SlimeAttack PsychicAttack BeastAttack - depends on body type of your salien)
  127. class SpecialAttack extends Attack {
  128. getCurrent() {
  129. if (gSalien.m_BodyType == "slime")
  130. return "slimeattack";
  131. else if (gSalien.m_BodyType == "beast")
  132. return "beastattack";
  133. else
  134. return "psychicattack";
  135. }
  136. getData() {
  137. return AttackManager().m_AttackData[this.getCurrent()];
  138. }
  139. shouldAttack(delta) {
  140. return CanAttack(this.getCurrent());
  141. }
  142. score(enemy) {
  143. if (enemy.m_bDead)
  144. return WORST_SCORE;
  145. return enemy.m_nHealth;
  146. }
  147. process(enemies) {
  148. let target, target_score = WORST_SCORE;
  149.  
  150. enemies.forEach((enemy) => {
  151. if (!enemy.m_Sprite.visible)
  152. return;
  153. let now_score = this.score(enemy);
  154. if (now_score > target_score) {
  155. target = enemy, target_score = now_score;
  156. }
  157. });
  158.  
  159. if (target)
  160. this.attack(target.m_Sprite.x, target.m_Sprite.y);
  161. }
  162. attack(x, y) {
  163. SetMouse(x, y)
  164. AttackManager().m_mapKeyCodeToAttacks.get(this.getData().keycode)()
  165. }
  166. }
  167.  
  168. class BombAttack extends SpecialAttack {
  169. getCurrent() {
  170. return "explosion";
  171. }
  172. }
  173.  
  174. class FreezeAttack extends Attack {
  175. getCurrent() {
  176. return "flashfreeze";
  177. }
  178. shouldAttack(delta, enemies) {
  179. let shouldAttack = false;
  180. if (CanAttack(this.getCurrent())) {
  181. enemies.forEach((enemy) => {
  182. if (EnemyDistance(enemy) <= 0.05) {
  183. shouldAttack = true;
  184. }
  185. });
  186. }
  187. return shouldAttack;
  188. }
  189. getData() {
  190. return AttackManager().m_AttackData[this.getCurrent()];
  191. }
  192. process() {
  193. AttackManager().m_mapKeyCodeToAttacks.get(this.getData().keycode)()
  194. }
  195. }
  196.  
  197. let attacks = [
  198. new ClickAttack(),
  199. new SpecialAttack(),
  200. new FreezeAttack(),
  201. new BombAttack()
  202. ]
  203.  
  204. if (context.BOT_FUNCTION) {
  205. pixi.ticker.remove(context.BOT_FUNCTION);
  206. context.BOT_FUNCTION = undefined;
  207. }
  208.  
  209. context.BOT_FUNCTION = function ticker(delta) {
  210. delta /= 100;
  211.  
  212. if(GAME.m_IsStateLoading) {
  213. return;
  214. }
  215.  
  216. if (InZoneSelect() && context.lastZoneIndex !== undefined && !isJoining) {
  217. isJoining = true;
  218.  
  219. if (GAME.m_State.m_PlanetData.zones[context.lastZoneIndex].captured)
  220. {
  221. context.lastZoneIndex = undefined;
  222. return;
  223. }
  224.  
  225. SERVER.JoinZone(
  226. lastZoneIndex,
  227. function (results) {
  228. GAME.ChangeState(new CBattleState(GAME.m_State.m_PlanetData, context.lastZoneIndex));
  229. },
  230. GameLoadError
  231. );
  232.  
  233. return;
  234. }
  235. 33
  236. if (!InGame()) {
  237. if (TryContinue()) {
  238. console.log("continued!");
  239. }
  240. return;
  241. }
  242.  
  243. isJoining = false;
  244. context.lastZoneIndex = GAME.m_State.m_unZoneIndex;
  245.  
  246. let state = EnemyManager();
  247.  
  248. let enemies = state.m_rgEnemies;
  249.  
  250. for (let attack of attacks)
  251. if (attack.shouldAttack(delta, enemies))
  252. attack.process(enemies);
  253.  
  254. }
  255.  
  256.  
  257. pixi.ticker.add(context.BOT_FUNCTION);
  258.  
  259. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement