Greasy Fork is available in English.

moomoo aim + heal

try to take over the world!

  1. // ==UserScript==
  2. // @name moomoo aim + heal
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match *://moomoo.io/*
  8. // @grant none
  9. // ==/UserScript==
  10. var playersNear = [];
  11. var ws;
  12. var id;
  13. var user;
  14. var canvas = document.querySelector("#gameCanvas");
  15. var hasApple = true;
  16. var currentTarget;
  17. function Player(id, x, y, tribe){
  18. this.id = id;
  19. this.x = x;
  20. this.y = y;
  21. this.tribe = tribe;
  22. }
  23. Player.prototype.getAngle = function(){
  24. return Math.atan2(this.deltaY, this.deltaX);
  25. };
  26. Player.prototype.getDistance = function(){
  27. return Math.sqrt(Math.pow(this.deltaX, 2) + Math.pow(this.deltaY, 2));
  28. };
  29. function lookAtPointRelativeToCharacter(x, y){
  30. var centerX = innerWidth / 2;
  31. var centerY = innerHeight / 2;
  32. canvas.dispatchEvent(new MouseEvent("mousemove", {
  33. clientX: centerX + x,
  34. clientY: centerY + y
  35. }));
  36. }
  37. WebSocket.prototype.oldSend = WebSocket.prototype.send;
  38. WebSocket.prototype.send = function(m){
  39. var parsed = parseWSMsg(m);
  40. if (currentTarget && parsed[0] === "2" && Math.abs(currentTarget.getAngle() - parsed[1]) > 0.0872665){
  41. aimAt(currentTarget);
  42. console.log("mouse moved");
  43. }
  44. this.oldSend(m);
  45. if (!ws){
  46. ws = this;
  47. socketFound(this);
  48. }
  49. };
  50. function socketFound(socket){
  51. console.log("found socket object");
  52. socket.addEventListener('message', function(e){
  53. handleMessage(e);
  54. });
  55. }
  56. function handleMessage(e){
  57. var m = e.data;
  58. //console.log(m);
  59. var parsed = parseWSMsg(m);
  60. if (parsed[0] === "3"){ //position update
  61. playersNear = [];
  62. var data = parsed[1];
  63. for (var i = 0; i < data.length ; i += 11) { //loop to assign chunks of the array to a player
  64. var playerData = data.slice(i, i + 11);
  65. var player = new Player(playerData[0], playerData[1], playerData[2], playerData[6]);
  66. if (player.id !== id) playersNear.push(player);
  67. else user = player;
  68. }
  69. currentTarget = null;
  70. if (playersNear.length > 0){
  71. var closestPlayer = getClosestPlayer();
  72. if (closestPlayer.getDistance() < 200 && (closestPlayer.tribe !== user.tribe || user.tribe === null)) aimAt(closestPlayer);
  73. }
  74. }
  75. if (parsed[0] === "1" && !id){
  76. id = parsed[1];
  77. console.log("id found: " + id);
  78. }
  79. if (parsed[0] === "10" && parsed[1] === id && parsed[2] !== 100){
  80. heal();
  81. }
  82. }
  83. function aimAt(target){
  84. lookAtPointRelativeToCharacter(target.deltaX, target.deltaY);
  85. currentTarget = target;
  86. }
  87. function getClosestPlayer(){
  88. var closestPlayer;
  89. for (var i = 0 ; i < playersNear.length; i++){
  90. var currentPlayer = playersNear[i];
  91. currentPlayer.deltaX = currentPlayer.x - user.x;
  92. currentPlayer.deltaY = currentPlayer.y - user.y;
  93. if (i === 0 || currentPlayer.getDistance() < closestPlayer.getDistance()){
  94. closestPlayer = currentPlayer;
  95. }
  96. }
  97. return closestPlayer;
  98. }
  99. function parseWSMsg(s){
  100. if (s.indexOf("42") === -1) return -1;
  101. var o = s.substring(s.indexOf("["));
  102. return JSON.parse(o);
  103. }
  104. function heal(){
  105. console.log("healing");
  106. if (hasApple){
  107. if (!haveApple()){
  108. heal();
  109. return;
  110. }
  111. else ws.send("42[\"5\",0,null]");
  112. }
  113. else ws.send("42[\"5\",1,null]");
  114. ws.send("42[\"4\",1,null]");
  115. }
  116. function haveApple(){
  117. if (hasApple) hasApple = isElementVisible(document.getElementById("actionBarItem9"));
  118. return hasApple;
  119. }
  120. function isElementVisible(e) {
  121. return (e.offsetParent !== null);
  122. }