Jumpaster

Hutter V.1

Oct 17th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.20 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Repeated bullets, continuous power measurement
  3. // @description Repeated bullets. Correspond to Penta, spread shot, octopus
  4. // @version 1
  5. // @author Gokky
  6. // @include http://diep.io/*
  7. // @connect diep.io
  8. // @namespace https://greasyfork.org/users/185493
  9. // ==/UserScript==
  10.  
  11. /*
  12. How to use
  13. How to run a script
  14. Paste and run on console or install on Tampermonkey
  15. Double shot
  16. right click
  17. Tank switching
  18. Shift+T so Penta Shot, Spread Shot, Octo Tank Can be switched.(As for the head tempo after switching, reload 7 premise)
  19. Measurement of launch cycle
  20. In the initial state, it shakes its neck at a tempo based on the interval of continuous fire of reload 7. To change this tempo, measure the fire interval as follows
  21. 1. Shift+M Set the launch speed measurement mode and measure the launch speed for a while
  22. 2. Do not move the machine up, down, left or right while measuring. Also, the measurement may go wrong if another man's shell flies near the aircraft.
  23. 3. When the variation of the average firing interval becomes smaller again Shift+M Cancel measurement mode with
  24. After measurement, shake your neck at a tempo based on the measured firing interval.
  25. + Aim is fixed in the direction when pressing Shift + M on either side during measurement. (So ??it is better to turn your back to the wall and press the Shift + M key to keep the aircraft stationary)
  26. + Even if Reload 7 is considered to have poor accuracy, the accuracy may increase if measured once
  27. Toggle display / hide of text in upper left
  28. I key
  29. Repeated shooting function on / off switching
  30. Shift+Q
  31. */
  32.  
  33. (function(){//info
  34. if(window.updateInfo) return;
  35.  
  36.  
  37. var info = {};
  38. var info_container = document.createElement("div");
  39. info_container.style.position = "fixed";
  40. info_container.style.color = "white";
  41. info_container.style["pointer-events"] = "none";
  42. document.body.appendChild(info_container);
  43.  
  44. function toggle_info_container(e){
  45. if(e.key == "i"){
  46. info_container.style.display = info_container.style.display=="block" ? "none" : "block";
  47. }
  48. }
  49. window.addEventListener("keyup", toggle_info_container);
  50.  
  51. window.updateInfo = function(key, value){
  52. if(!value) delete info[key];
  53. else info[key] = value;
  54. var s = "";
  55. for(var _key in info){
  56. s += info[_key] + "\n";
  57. }
  58. info_container.innerText = s;
  59. };
  60. })();
  61.  
  62. function MeasureCycle(){
  63. var canvas = document.getElementById("canvas");
  64. var ctx = canvas.getContext("2d");
  65. var real_arc = ctx.arc;
  66. var real_setTransform = ctx.setTransform;
  67.  
  68. var a;
  69. var tx = 0, ty = 0;
  70. var a11 = 1;
  71.  
  72. var state = false;
  73. var found = false;
  74. var inA = null;
  75. var direction = 1;
  76.  
  77. var frameRequest;
  78. var intervalEMA = null; // ms
  79.  
  80. function arc(){
  81. real_arc.apply(ctx, arguments);
  82.  
  83. if(!found){
  84. var aimX = window.innerWidth / 2 + 50 * direction;
  85. var aimY = window.innerHeight / 2;
  86. found = (tx - a11 < aimX) && (tx + a11 > aimX) && (ty - a11 < aimY) && (ty + a11 > aimY);
  87. }
  88. }
  89.  
  90. function setTransform(b11, b12, b21, b22, bx, by){
  91. real_setTransform.apply(ctx, arguments);
  92. tx = bx, ty = by, a11 = b11;
  93. }
  94.  
  95. function onFrame(_a){
  96. frameRequest = window.requestAnimationFrame(onFrame);
  97. a = _a;
  98. if(!state && found){
  99. if(inA){
  100. var da = a - inA;
  101. inA = a;
  102. intervalEMA = intervalEMA ? 0.8 * intervalEMA + 0.2 * da : da;
  103. window.updateInfo && window.updateInfo(
  104. "intervalEMA",
  105. "??????: " + intervalEMA.toString().substr(0, 5) + "ms"
  106. );
  107.  
  108. }else{
  109. inA = a;
  110. }
  111. }
  112. state = found;
  113. found = false;
  114. }
  115.  
  116. function onMouseEvent(e){
  117. e.stopPropagation();
  118. }
  119.  
  120. this.start = function(_direction){
  121. _direction = _direction || 1;
  122. direction = _direction > 0 ? 1 : -1;
  123. inA = null;
  124. intervalEMA = null;
  125. state = found = false;
  126.  
  127. ctx.setTransform = setTransform;
  128. ctx.arc = arc;
  129.  
  130. var aimX = window.innerWidth / 2 + 50 * direction;
  131. var aimY = window.innerHeight / 2;
  132. canvas.dispatchEvent(new MouseEvent("mousemove", {clientX: aimX, clientY: aimY}));
  133. canvas.dispatchEvent(new MouseEvent("mousedown", {clientX: aimX, clientY: aimY}));
  134.  
  135. window.addEventListener("mousemove", onMouseEvent, true);
  136. window.addEventListener("mouseup", onMouseEvent, true);
  137. window.addEventListener("mousedown", onMouseEvent, true);
  138. frameRequest = window.requestAnimationFrame(onFrame);
  139.  
  140. window.updateInfo && window.updateInfo("measuring", "?????????");
  141. }
  142.  
  143. this.terminate = function(){
  144. ctx.setTransform = real_setTransform;
  145. ctx.arc = real_arc;
  146.  
  147. window.removeEventListener("mousemove", onMouseEvent, true);
  148. window.removeEventListener("mousedown", onMouseEvent, true);
  149. window.removeEventListener("mouseup", onMouseEvent, true);
  150. window.cancelAnimationFrame(frameRequest);
  151.  
  152. canvas.dispatchEvent(new MouseEvent("mouseup", {clientX: 10, clientY: 10}));
  153.  
  154. window.updateInfo && window.updateInfo("measuring", null);
  155. return intervalEMA;
  156. }
  157. };
  158.  
  159. (function(){
  160. var cycleRate = 0.003125; // ms^-1
  161. var maxAngle = Math.PI * 45 / 180;
  162. var NCANNON = 3;
  163. var angleUnit = maxAngle / (NCANNON - 1);
  164.  
  165. var tankData = [
  166. {name: "Penta", cycleRate: 0.003125, maxAngle: Math.PI * 45 / 180, NCANNON: 3},
  167. {name: "SpreadShot", cycleRate: 0.001555, maxAngle: Math.PI * 75 / 180, NCANNON: 6},
  168. {name: "Octo", cycleRate: 0.003125, maxAngle: Math.PI * 45 / 180, NCANNON: 2}
  169. ];
  170. var tankIndex = 0;
  171.  
  172. var measure = new MeasureCycle();
  173. var measuring = false;
  174.  
  175. var effective = false;
  176. var frameRequest;
  177.  
  178. var canvas = window.document.getElementById("canvas");
  179.  
  180. var mouseX;
  181. var mouseY;
  182. var a = 0;
  183. var startA = 0;
  184. var artificialMouseMove = false;
  185.  
  186. var disabled = false;
  187.  
  188. function onMouseDown(e){
  189. if(e.button == 2){
  190. if(!effective){
  191. startA = a - 50;
  192. mouseX = e.clientX;
  193. mouseY = e.clientY;
  194. canvas.dispatchEvent(new MouseEvent("mousedown", {clientX: mouseX, clientY: mouseY}));
  195. }
  196. effective = true;
  197. }
  198. }
  199.  
  200. function onMouseUp(e){
  201. if(e.button == 2){
  202. if(effective){
  203. canvas.dispatchEvent(new MouseEvent("mouseup", {clientX: mouseX, clientY: mouseY}));
  204. }
  205. effective = false;
  206. }
  207. }
  208.  
  209. function onMouseMove(e){
  210. if(effective){
  211. if(!artificialMouseMove){
  212. e.stopPropagation();
  213. mouseX = e.clientX;
  214. mouseY = e.clientY;
  215. }
  216. }else{
  217. mouseX = e.clientX;
  218. mouseY = e.clientY;
  219. }
  220. }
  221.  
  222. function update(_a){
  223. frameRequest = window.requestAnimationFrame(update);
  224. a = _a;
  225.  
  226. if(effective){
  227. var da = a - startA;
  228. var state = Math.floor(cycleRate * da * NCANNON) % (NCANNON * 2);
  229. var state1 = state % NCANNON;
  230. var state2 = Math.floor(state / NCANNON);
  231. var angle = angleUnit * state1 * (state1 % 2 == state2 ? 1 : -1);
  232.  
  233. var cx = window.innerWidth / 2;
  234. var cy = window.innerHeight / 2;
  235. var sin = Math.sin(angle);
  236. var cos = Math.cos(angle);
  237.  
  238. var x = mouseX - cx;
  239. var y = mouseY - cy;
  240. var _x = cos * x - sin * y;
  241. var _y = sin * x + cos * y;
  242. x = _x + cx;
  243. y = _y + cy;
  244.  
  245. artificialMouseMove = true;
  246. canvas.dispatchEvent(new MouseEvent("mousemove", {clientX: x, clientY: y}));
  247. artificialMouseMove = false;
  248. }
  249. }
  250.  
  251. function onKeyUp(e){
  252. if(e.key == "Q"){
  253. disabled = !disabled;
  254. if(disabled){
  255. if(measuring){
  256. cycleRate = 1 / measure.terminate();
  257. measuring = false;
  258. } else stop();
  259. }else start();
  260. window.updateInfo && window.updateInfo("off", disabled ? "????" : null);
  261. return;
  262. }
  263.  
  264. if(disabled) return;
  265.  
  266. if(e.key == "M"){
  267. if(measuring){
  268. cycleRate = 1 / measure.terminate();
  269. start();
  270. measuring = false;
  271. }else{
  272. stop();
  273. measure.start(mouseX - window.innerWidth / 2);
  274. measuring = true;
  275. }
  276. }else if(e.key == "T"){
  277. changeTank((tankIndex + 1) % tankData.length);
  278. }
  279. }
  280.  
  281. function changeTank(index){
  282. var data = tankData[index];
  283. tankIndex = index;
  284.  
  285. cycleRate = data.cycleRate; // ms^-1
  286. maxAngle = data.maxAngle;
  287. NCANNON = data.NCANNON;
  288. angleUnit = maxAngle / (NCANNON - 1);
  289. window.updateInfo && window.updateInfo("changeTank", "Tank: " + data.name);
  290. }
  291.  
  292. function init(){
  293. window.addEventListener("keyup", onKeyUp);
  294. start();
  295. changeTank(0);
  296. }
  297.  
  298. function start(){
  299. canvas.addEventListener("mousedown", onMouseDown);
  300. canvas.addEventListener("mouseup", onMouseUp);
  301. window.addEventListener("mousemove", onMouseMove, true);
  302. frameRequest = window.requestAnimationFrame(update);
  303. }
  304.  
  305. function stop(){
  306. canvas.removeEventListener("mousedown", onMouseDown);
  307. canvas.removeEventListener("mouseup", onMouseUp);
  308. window.removeEventListener("mousemove", onMouseMove, true);
  309. window.cancelAnimationFrame(frameRequest);
  310. effective = false;
  311. }
  312.  
  313.  
  314. init();
  315.  
  316. })();v
Add Comment
Please, Sign In to add comment