samethgo

Untitled

Dec 7th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.52 KB | None | 0 0
  1. setTimeout(function() {
  2. var real_minx = -7071;
  3. var real_miny = -7071;
  4. var real_maxx = 7071;
  5. var real_maxy = 7071;
  6. var lastsent = {
  7. minx: 0,
  8. miny: 0,
  9. maxx: 0,
  10. maxy: 0
  11. };
  12.  
  13. function valcompare(Y, Z) {
  14. return 0.01 > Y - Z && -0.01 < Y - Z
  15. }
  16. window.agar.hooks.dimensionsUpdated = function(server_minx, server_miny, server_maxx, server_maxy) {
  17. if (valcompare(server_maxx - server_minx, server_maxy - server_miny)) {
  18. real_minx = server_minx;
  19. real_miny = server_miny;
  20. real_maxx = server_maxx;
  21. real_maxy = server_maxy
  22. } else {
  23. if (valcompare(server_minx, lastsent.minx)) {
  24. if (0.01 < server_maxx - lastsent.maxx || -0.01 > server_maxx - lastsent.maxx) {
  25. real_minx = server_minx;
  26. real_maxx = server_minx + 14142.135623730952
  27. }
  28. }
  29. if (0.01 < server_minx - lastsent.minx || -0.01 > server_minx - lastsent.minx) {
  30. if (valcompare(server_maxx, lastsent.maxx)) {
  31. real_maxx = server_maxx;
  32. real_minx = server_maxx - 14142.135623730952
  33. }
  34. }
  35. if (0.01 < server_miny - lastsent.miny || -0.01 > server_miny - lastsent.miny) {
  36. if (valcompare(server_maxy, lastsent.maxy)) {
  37. real_maxy = server_maxy;
  38. real_miny = server_maxy - 14142.135623730952
  39. }
  40. }
  41. if (valcompare(server_miny, lastsent.miny)) {
  42. if (0.01 < server_maxy - lastsent.maxy || -0.01 > server_maxy - lastsent.maxy) {
  43. real_miny = server_miny;
  44. real_maxy = server_miny + 14142.135623730952
  45. }
  46. }
  47. if (server_minx < real_minx) {
  48. real_minx = server_minx;
  49. real_maxx = server_minx + 14142.135623730952
  50. }
  51. if (server_maxx > real_maxx) {
  52. real_maxx = server_maxx;
  53. real_minx = server_maxx - 14142.135623730952
  54. }
  55. if (server_miny < real_miny) {
  56. real_miny = server_miny;
  57. real_maxy = server_miny + 14142.135623730952
  58. }
  59. if (server_maxy > real_maxy) {
  60. real_maxy = server_maxy;
  61. real_miny = server_maxy - 14142.135623730952
  62. }
  63. lastsent.minx = server_minx;
  64. lastsent.miny = server_miny;
  65. lastsent.maxy = server_maxy;
  66. lastsent.maxx = server_maxx
  67. }
  68. offset_x = real_minx || -7071;
  69. offset_y = real_miny || -7071
  70. };
  71. var socket = io.connect('ws://127.0.0.1:8081');
  72. var canMove = true;
  73. var movetoMouse = true;
  74. var moveEvent = new Array(2);
  75. var canvas = document.getElementById("canvas");
  76. last_transmited_game_server = null;
  77. socket.on('force-login', function(data) {
  78. socket.emit("login", {
  79. "uuid": client_uuid,
  80. "type": "client"
  81. });
  82. transmit_game_server()
  83. });
  84.  
  85. $( "#canvas" ).after( "<div style='background-color: #000000; -moz-opacity: 0.4; -khtml-opacity: 0.4; opacity: 0.4; filter: alpha(opacity=40); zoom: 1; width: 205px; top: 10px; left: 10px; display: block; position: absolute; text-align: center; font-size: 15px; color: #ffffff; padding: 5px; font-family: Ubuntu;'> <div style='color:#ffffff; display: inline; -moz-opacity:1; -khtml-opacity: 1; opacity:1; filter:alpha(opacity=100); padding: 10px;'><a>CreativeBots</a></div> <div style='color:#ffffff; display: inline; -moz-opacity:1; -khtml-opacity: 1; opacity:1; filter:alpha(opacity=100); padding: 10px;'><br>Minions: <a id='minionCount' >Offline</a> </div> <div style='color:#ffffff; display: inline; -moz-opacity:1; -khtml-opacity: 1; opacity:1; filter:alpha(opacity=100); padding: 10px;'><br>Move To Mouse: <a id='ismoveToMouse' >On</a> </div> <div style='color:#ffffff; display: inline; -moz-opacity:1; -khtml-opacity: 1; opacity:1; filter:alpha(opacity=100); padding: 10px;'><br>Stop Movement: <a id='isStopMove' >Off</a> </div>" );
  86. socket.on('spawn-count', function(data) {
  87. document.getElementById('minionCount').innerHTML = data
  88. });
  89. var client_uuid = localStorage.getItem('client_uuid');
  90. if (client_uuid == null) {
  91. console.log("generating a uuid for this user");
  92. client_uuid = ""; var ranStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  93. for (var ii = 0; ii < 15; ii++) client_uuid += ranStr.charAt(Math.floor(Math.random() * ranStr.length));
  94. localStorage.setItem('client_uuid', client_uuid)
  95. }
  96. socket.emit("login", client_uuid);
  97. $("#instructions").replaceWith('<br><div class="input-group"><span class="input-group-addon" id="basic-addon1">UUID</span><input type="text" value="' + client_uuid + '" readonly class="form-control"</div>');
  98.  
  99. function isMe(cell) {
  100. for (var i = 0; i < window.agar.myCells.length; i++) {
  101. if (window.agar.myCells[i] == cell.id) {
  102. return true
  103. }
  104. }
  105. return false
  106. }
  107.  
  108. function getCell() {
  109. var me = [];
  110. for (var key in window.agar.allCells) {
  111. var cell = window.agar.allCells[key];
  112. if (isMe(cell)) {
  113. me.push(cell)
  114. }
  115. }
  116. return me[0]
  117. }
  118. var skin_var = 0;
  119.  
  120. function emitPosition() {
  121. for (i = 0; i < agar.myCells.length; i++) {}
  122. x = (mouseX - window.innerWidth / 2) / window.agar.drawScale + window.agar.rawViewport.x;
  123. y = (mouseY - window.innerHeight / 2) / window.agar.drawScale + window.agar.rawViewport.y;
  124. if (!movetoMouse) {
  125. x = getCell().x;
  126. y = getCell().y
  127. }
  128. socket.emit("pos", {
  129. "x": x - (real_minx + 7071),
  130. "y": y - (real_miny + 7071),
  131. "dimensions": [-7071, -7071, 7071, 7071]
  132. })
  133. }
  134.  
  135.  
  136. function emitSplit() {
  137. socket.emit("cmd", {
  138. "name": "split"
  139. })
  140. }
  141.  
  142. function emitMassEject() {
  143. socket.emit("cmd", {
  144. "name": "eject"
  145. })
  146. }
  147.  
  148. function toggleMovement() {
  149. canMove = !canMove;
  150. switch (canMove) {
  151. case true:
  152. canvas.onmousemove = moveEvent[0];
  153. moveEvent[0] = null;
  154. canvas.onmousedown = moveEvent[1];
  155. moveEvent[1] = null;
  156. break;
  157. case false:
  158. canvas.onmousemove({
  159. clientX: innerWidth / 2,
  160. clientY: innerHeight / 2
  161. });
  162. moveEvent[0] = canvas.onmousemove;
  163. canvas.onmousemove = null;
  164. moveEvent[1] = canvas.onmousedown;
  165. canvas.onmousedown = null;
  166. break
  167. }
  168. }
  169. interval_id = setInterval(function() {
  170. emitPosition()
  171. }, 100);
  172. interval_id2 = setInterval(function() {
  173. transmit_game_server_if_changed()
  174. }, 5000);
  175. document.addEventListener('keydown', function(e) {
  176. var key = e.keyCode || e.which;
  177. switch (key) {
  178. case 65:
  179. movetoMouse = !movetoMouse;
  180. if(movetoMouse) { document.getElementById('ismoveToMouse').innerHTML = "On"; } else { document.getElementById('ismoveToMouse').innerHTML = "Off"; }
  181. break;
  182. case 68:
  183. toggleMovement();
  184. if(!canMove) { document.getElementById('isStopMove').innerHTML = "On"; } else { document.getElementById('isStopMove').innerHTML = "Off"; }
  185. break;
  186. case 69:
  187. emitSplit();
  188. break;
  189. case 82:
  190. emitMassEject();
  191. break
  192. }
  193. });
  194.  
  195. function transmit_game_server_if_changed() {
  196. if (last_transmited_game_server != window.agar.ws) {
  197. transmit_game_server()
  198. }
  199. }
  200.  
  201. function transmit_game_server() {
  202. last_transmited_game_server = window.agar.ws;
  203. socket.emit("cmd", {
  204. "name": "connect_server",
  205. "ip": last_transmited_game_server
  206. })
  207. }
  208. var mouseX = 0;
  209. var mouseY = 0;
  210. $("body").mousemove(function(event) {
  211. mouseX = event.clientX;
  212. mouseY = event.clientY
  213. });
  214. window.agar.minScale = -30
  215. }, 5000);
Add Comment
Please, Sign In to add comment