Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Bot
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match http://wilds.io/
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. queuedRespawn = false;
  12.  
  13. function log(msg)
  14. {
  15. console.log(msg);
  16. }
  17.  
  18. function d(a, b)
  19. {
  20. let x = b.x-a.x;
  21. let y = b.y-a.y;
  22.  
  23. return { x, y };
  24. }
  25.  
  26. function goTowards(hero, target)
  27. {
  28. let {x, y} = d(hero, target);
  29.  
  30. if ( Math.random() < (1/10) )
  31. {
  32. x = (Math.random()-0.5) * 1000;
  33. y = (Math.random()-0.5) * 1000;
  34.  
  35. console.log('unstuck');
  36. }
  37.  
  38. CLIENT.Game.setMoving(COMMON.FLAG_RIGHT, x>0);
  39. CLIENT.Game.setMoving(COMMON.FLAG_LEFT, x<0);
  40. CLIENT.Game.setMoving(COMMON.FLAG_DOWN, y>0);
  41. CLIENT.Game.setMoving(COMMON.FLAG_UP, y<0);
  42. }
  43.  
  44. function rotateTowards(hero, villain)
  45. {
  46. let {x, y} = d(hero, villain);
  47.  
  48. CLIENT.Game.pointerX = x * 10000;
  49. CLIENT.Game.pointerY = y * 10000;
  50. CLIENT.Game.desiredDirection = Utils.lookAt(hero.x, hero.y-24, villain.x, villain.y-24);
  51. }
  52.  
  53. function attack()
  54. {
  55. CLIENT.Game.send("useSkill", { key: "one" });
  56. }
  57.  
  58. function distance(a, b)
  59. {
  60. let dx = a.x-b.x;
  61. let dy = a.y-b.y;
  62. return Math.sqrt(dx*dx + dy*dy);
  63. }
  64.  
  65. function turn()
  66. {
  67. if ( ! CLIENT.Game.entities )
  68. return;
  69.  
  70. let hero = CLIENT.Game.player;
  71. let enemies = CLIENT.Game.entities.children.filter(e => e instanceof CLIENT.Citizen && e.team != CLIENT.Game.player.team );
  72. enemies.sort(enemy => distance(CLIENT.Game.player, enemy));
  73. let closestEnemy = enemies[0];
  74. let villain = closestEnemy;
  75.  
  76.  
  77. let goTo = { x: CLIENT.Game.modeData.innerWidth/2, y: CLIENT.Game.modeData.innerHeight/2 }; // lub villain
  78. goTowards(hero, goTo);
  79. rotateTowards(hero, villain);
  80. attack();
  81.  
  82. if ( hero.dead && ! queuedRespawn )
  83. {
  84. queuedRespawn = true;
  85. setTimeout( tryRespawn, 5000 );
  86. }
  87.  
  88. if ( Math.random() < (1/100) )
  89. {
  90. console.log('dash');
  91. CLIENT.Game.dash(COMMON.FLAG_UP);
  92. }
  93. }
  94.  
  95. function tryRespawn()
  96. {
  97. console.log("try respawn");
  98. queuedRespawn = false;
  99. app.game.send("respawn", true);
  100. }
  101.  
  102. function go()
  103. {
  104. // Don't rotate to cursor
  105. CLIENT.Game.Desktop.pointermove = () => {};
  106.  
  107. setInterval(turn, 100);
  108. }
  109.  
  110. go();
  111.  
  112. (function() {
  113. 'use strict';
  114.  
  115. let hero = CLIENT.Game.player;
  116. let villain = CLIENT.Game.entities.children.find(e => e instanceof CLIENT.Citizen);
  117.  
  118.  
  119. // Your code here...
  120. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement