Advertisement
Guest User

eggpromouseedit

a guest
Mar 26th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.11 KB | None | 0 0
  1. // ==UserScript==
  2. // @name EggProMouse
  3. // @version 1.5
  4. // @description Tweaks for Egg Ball
  5. // @author Catalyst
  6. // @match *://*.koalabeast.com/game
  7. // @include http://*.koalabeast.com:*
  8. // @include http://*.jukejuice.com:*
  9. // @include http://*.newcompte.fr:*
  10. // @updateURL https://gist.github.com/catalyst518/f28accf3d14385470a330ab80c768ee1/raw/EggPro.user.js
  11. // @downloadURL https://gist.github.com/catalyst518/f28accf3d14385470a330ab80c768ee1/raw/EggPro.user.js
  12. // ==/UserScript==
  13.  
  14. //--------------CHANGELOG--------------
  15. /*
  16. Note: All new features are opt-in and will continue to be so in any future updates. This means your settings will be reset to their defaults upon updating.
  17.  
  18. ~~~Version 1.4 (July 12, 2019)~~~
  19.  
  20. Added support for new SWJ servers.
  21. Added option to highlight your own ball.
  22. Added option to lock the camera to your ball, just like in regular TagPro. The script used to do this automatically until something changed in the game code.
  23. Now you can play either way, but the default is the old script behavior of locked to ball.
  24. Fixed the aiming line to work with the current version of the game/servers.
  25. Fixed the autoshoot aim to work with the current version of the game/servers.
  26. Adjusted the autoshoot rate limiter so you won't get kicked from games for painting the wall. This might need further adjustments.
  27. Added some checks to disable the effects of this script in regular TagPro games.
  28. Updated the default imgur urls to use https instead of http so TagPro maintains a secure connection.
  29.  
  30. Added default settings:
  31. highlight=false
  32. highlight_url="https://i.imgur.com/h23oRYI.png"
  33. lock_ball=true
  34.  
  35. ~~~Version 1.3 (June 19, 2017)~~~
  36.  
  37. Added ability to autoshoot when picking up the egg. Activated by holding Left Shift by default (reassign the key in settings).
  38. Added custom crosshair support.
  39. Added aiming line.
  40.  
  41. Added default settings:
  42. auto_shoot=false
  43. custom_crosshair=false
  44. aim_line=false
  45. crosshair_url="http://i.imgur.com/Pjxxh20.png"
  46. auto_key=16
  47. aim_line_color=0xFF00FF
  48. aim_line_alpha=1
  49.  
  50. */
  51. //-----------END OF CHANGELOG-----------
  52.  
  53.  
  54. //--------------SETTINGS--------------
  55. //Put a pink ring around your ball so it doesn't get lost in the chaos.
  56. var highlight=false;
  57.  
  58. //Lock the camera to your ball like in regular tagpro. In eggball, the camera is by default vertically locked to the field giving an out-of-ball sensation.
  59. var lock_ball=true;
  60.  
  61. //Set the value to false to expand viewport while playing. Set the value to true to expand only when spectating.
  62. var spec_only=false;
  63.  
  64. //Set true/false to toggle auto-zoom level when spectating.
  65. var auto_zoom=true;
  66.  
  67. //Set the value to true to use a pixel perfect egg. Set to false to use the vanilla egg.
  68. var pp_egg=true;
  69.  
  70. //Set the value to true to use the custom, improved map. Set to false to use the vanilla map.
  71. var imp_map=true;
  72.  
  73. //Set the value to true to enable autoshooting when picking up the egg. Set to false to disable.
  74. var auto_shoot=true;
  75.  
  76. //Set the value to true to use a custom crosshair. Set to false to use the default crosshair.
  77. var custom_crosshair=true;
  78.  
  79. //Set the value to true to enable an aiming line to your cursor position. Set to false to disable.
  80. var aim_line=true;
  81.  
  82. //Set url of custom egg image (23x23 for pixel perfect). Only applies if pp_egg=true.
  83. var egg_url="https://i.imgur.com/B1F1BI5.png";
  84.  
  85. //Set url of custom egg team indicator image (29x29). Only applies if pp_egg=true.
  86. var egg_team_url="https://i.imgur.com/P0l0yVA.png";
  87.  
  88. //Set url of custom field image. Only applies if imp_map=true.
  89. var field_url="https://i.imgur.com/vF0f6g0.png";
  90.  
  91. //Set url of custom crosshair image (designed for 32x32). Only applies if custom_crosshair=true.
  92. var crosshair_url="https://i.imgur.com/Pjxxh20.png";
  93.  
  94. //Set url of the highlight ring around your ball. Only applies if highlight=true.
  95. var highlight_url="https://i.imgur.com/h23oRYI.png"
  96.  
  97. //Set autoshoot key. Default is Left Shift (16). Only applies if auto_shoot=true.
  98. //Use this app to get the correct keycode: https://codepen.io/chriscoyier/full/mPgoYJ/ or see https://msdn.microsoft.com/en-us/library/aa243025(v=vs.60).aspx
  99. var auto_key=16;
  100.  
  101. //Set the color of the aiming line in hex with 0x prefix. Default is 0xFF00FF (matches the custom crosshair). Only applies if aim_line=true.
  102. var aim_line_color=0xFF00FF;
  103.  
  104. //Set the transparency of the aiming line. Ranges from 0 (transparent) to 1 (opaque). Only applies if aim_line=true.
  105. var aim_line_alpha=1;
  106. //-----------END OF SETTINGS-----------
  107.  
  108.  
  109. var oldh=0;
  110. var oldw=0;
  111. var eggball=false;
  112. tagpro.ready(function() {
  113. tagpro.socket.on('map', function(data) {
  114. if (data.info.name=="Egg Ball"){
  115. eggball=true;
  116. if(custom_crosshair) {
  117. $("<style type='text/css'>canvas{cursor: url("+crosshair_url+") 16 16, crosshair !important;}</style>").appendTo("head");
  118. }
  119. }
  120. });
  121.  
  122. tagpro.socket.on("eggBall", function(data) {
  123. gameState = data.state;
  124. eggHolder = tagpro.players[data.holder];
  125. if(auto_shoot && auto && eggHolder===tagpro.players[tagpro.playerId]){
  126. autoShoot();
  127. }
  128. updateTeamWithEgg();
  129. eggball=true;
  130. });
  131.  
  132. var stage = tagpro.renderer.stage;
  133. var container = tagpro.renderer.gameContainer;
  134. var MousePos = { x: 0, y: 0 };
  135. var auto=false;
  136. stage.interactive = true;
  137. stage.mousemove = function(e) {
  138. MousePos.x = e.data.global.x;
  139. MousePos.y = e.data.global.y;
  140. };
  141.  
  142. onmousemove=function(e){
  143. if(!tagpro.spectator && aim_line && eggball){
  144. var player = tagpro.players[tagpro.playerId];
  145. try {
  146. player.sprites.aim.clear();
  147. player.sprites.aim.lineStyle(2, aim_line_color, aim_line_alpha);
  148. player.sprites.aim.moveTo(20,20);
  149. if (spec_only){
  150. player.sprites.aim.lineTo((e.clientX-window.innerWidth/2)*1280/$('#viewport').width()+20, (e.clientY-window.innerHeight/2)*800/$('#viewport').height()+20);
  151. }
  152. else {
  153. player.sprites.aim.lineTo((e.clientX-window.innerWidth/2)+20, (e.clientY-window.innerHeight/2)+20);
  154. }
  155. }
  156. catch (err){
  157. player.sprites.aim = new PIXI.Graphics();
  158. player.sprites.ball.addChild(player.sprites.aim);
  159. }
  160. }
  161. };
  162.  
  163. if (lock_ball){
  164. tagpro.renderer.updateCameraPosition = function (player) {
  165. if (player.sprite.x !== -1000 && player.sprite.y !== -1000) {
  166. tagpro.renderer.centerContainerToPoint(player.sprite.x + 19, player.sprite.y + 19);
  167. }
  168. };
  169. }
  170.  
  171. document.onkeydown = function(e){
  172. if(e.keyCode===auto_key){
  173. auto=true;
  174. }
  175. };
  176. document.onkeyup = function(e){
  177. if(e.keyCode===auto_key){
  178. auto=false;
  179. }
  180. };
  181.  
  182. document.onmousedown = function(e){
  183. auto=true;
  184. };
  185. document.onmouseup = function(e){
  186. auto=false;
  187. };
  188.  
  189. var gameState = null;
  190. var eggHolder = null;
  191. var realUpdatePlayerPowerUps = tagpro.renderer.updatePlayerPowerUps;
  192.  
  193. if (imp_map){
  194. tagpro.renderer.afterDrawBackground = function() {
  195. if(eggball){
  196. const fieldSprite = new PIXI.Sprite.fromImage(field_url);
  197. fieldSprite.x = 40;
  198. fieldSprite.y = 40;
  199. tagpro.renderer.layers.foreground.addChildAt(fieldSprite, 0);}
  200. };
  201. }
  202.  
  203. try{
  204. tagpro.renderer.updatePlayerPowerUps = function (player, context, drawPos) {
  205. realUpdatePlayerPowerUps(player, context, drawPos);
  206. if (pp_egg && eggball){
  207. if (!player.sprites.egg2) {
  208. player.sprites.egg2 = new PIXI.Sprite.fromImage(egg_url);
  209. player.sprites.egg2.width = 23;
  210. player.sprites.egg2.height = 23;
  211. player.sprites.egg2.x = 8;
  212. player.sprites.egg2.y = 8;
  213. player.sprite.addChildAt(player.sprites.egg2,1);
  214. }
  215. player.sprites.egg2.alpha = eggHolder === player ? 1 : 0;
  216. if (player.sprites.egg){
  217. player.sprites.egg.alpha = 0;}
  218. }
  219. };}
  220. catch(err){
  221. //Not egg mode
  222. }
  223. var eggTeam = new PIXI.Sprite.fromImage("events/easter-2016/images/egg.png");
  224. if (pp_egg){
  225. eggTeam = new PIXI.Sprite.fromImage(egg_team_url);}
  226. eggTeam.width = 29;
  227. eggTeam.height = 29;
  228. eggTeam.anchor.x = 0.5;
  229. eggTeam.anchor.y = 0.5;
  230. eggTeam.alpha = 0.75;
  231. eggTeam.visible = false;
  232. try{
  233. tagpro.renderer.layers.ui.addChildAt(eggTeam,1);
  234. tagpro.renderer.layers.ui.removeChildAt(0);}
  235. catch(err){
  236. //Not egg mode
  237. }
  238.  
  239. var rate=true;
  240. function autoShoot(){
  241. if (!rate) return;
  242. rate=false;
  243. var clickPos = {
  244. x: (MousePos.x * (1 / container.scale.x)) - (container.position.x * (1 / container.scale.x)),
  245. y: (MousePos.y * (1 / container.scale.y)) - (container.position.y * (1 / container.scale.y))
  246. };
  247. tagpro.socket.emit("click", clickPos);
  248. setTimeout(function(){rate = true;}, 15);//needed to avoid kick for too many server requests
  249. }
  250.  
  251. function updateTeamWithEgg() {
  252. if (!tagpro.ui.sprites["yellowFlagTakenByRed"]) {
  253. return setTimeout(updateTeamWithEgg.bind(this), 50);
  254. }
  255. if (!eggHolder) {
  256. eggTeam.visible = false;
  257. }
  258. else {
  259. eggTeam.visible = true;
  260. if (eggHolder.team === 1) {
  261. const pos = tagpro.ui.sprites["yellowFlagTakenByRed"];
  262. eggTeam.x = pos.x;
  263. eggTeam.y = pos.y;
  264. }
  265. else {
  266. const pos = tagpro.ui.sprites["yellowFlagTakenByBlue"];
  267. eggTeam.x = pos.x;
  268. eggTeam.y = pos.y;
  269. }
  270. }
  271. }
  272.  
  273. var oldUpdateMarsball = tagpro.renderer.updateMarsBall.bind(tagpro.updateMarsBall);
  274. var oldDrawMarsball = tagpro.renderer.drawMarsball.bind(tagpro.renderer);
  275.  
  276. tagpro.renderer.updateMarsBall = function(object, position) {
  277. if (object.type == "egg") {
  278. position.x = position.x + 20;
  279. position.y = position.y + 20;
  280. }
  281.  
  282. oldUpdateMarsball(object, position);
  283. };
  284.  
  285. tagpro.renderer.drawMarsball = function (object, position) {
  286. if (object.type == "marsball") {
  287. return oldDrawMarsball(object, position);
  288. }
  289. if (object.type !== "egg") {
  290. return;
  291. }
  292. if (tagpro.spectator) {
  293. object.draw = true;
  294. }
  295. if (pp_egg){
  296. object.sprite = new PIXI.Sprite.fromImage(egg_url);}
  297. else {
  298. object.sprite = new PIXI.Sprite.fromImage("events/easter-2016/images/egg.png");}
  299. object.sprite.position.x = position.x;
  300. object.sprite.position.y = position.y;
  301. object.sprite.width = 23;
  302. object.sprite.height = 23;
  303. object.sprite.pivot.set(23*0.5, 23*0.5);
  304. tagpro.renderer.layers.foreground.addChild(object.sprite);
  305. object.sprite.keep = true;
  306. if (!object.draw) {
  307. object.sprite.visible = false;
  308. }
  309. };
  310.  
  311. var defaultUpdatePlayerSpritePosition = tagpro.renderer.updatePlayerSpritePosition;
  312. tagpro.renderer.updatePlayerSpritePosition = function (player) {
  313. // Create highlight
  314. if (eggball && highlight && player==tagpro.players[tagpro.playerId] && !player.sprites.highlight) {
  315. player.sprites.highlight = new PIXI.Sprite.fromImage(highlight_url);
  316. player.sprites.highlight.x = -5;
  317. player.sprites.highlight.y = -5;
  318. player.sprites.ball.addChild(player.sprites.highlight);
  319. }
  320. defaultUpdatePlayerSpritePosition(player);
  321. };
  322.  
  323. function waitForId() {
  324. if (!tagpro.playerId) {
  325. return setTimeout(waitForId, 100);
  326. }
  327. if((tagpro.spectator || !spec_only) && eggball)
  328. {
  329. //Resize viewport
  330. resize();
  331. if(tagpro.spectator){
  332. tagpro.viewport.followPlayer=false;
  333. }
  334. //Check for resizing and update FOV and zoom accordingly
  335. setInterval(updateFOV, 500);
  336. }
  337. }
  338. waitForId();
  339. });
  340.  
  341. function resize(){
  342. tagpro.renderer.canvas_width = window.innerWidth;
  343. tagpro.renderer.canvas_height = window.innerHeight;
  344. tagpro.renderer.resizeView();
  345. tagpro.renderer.centerView();
  346. }
  347.  
  348. function updateFOV() {
  349. var h = $('#viewport').height();
  350. var w = $('#viewport').width();
  351. //Resize viewport
  352. if (h!=window.innerHeight||w!=window.innerWidth){
  353. resize();
  354. h = $('#viewport').height();
  355. w = $('#viewport').width();
  356. }
  357. //Auto-zoom to fill viewport
  358. if(tagpro.spectator && auto_zoom && (oldh!=h ||oldw!=w))
  359. {
  360. var yzoom=tagpro.map[0].length*40/h;
  361. var xzoom=tagpro.map.length*40/w;
  362. tagpro.zoom=Math.max(xzoom,yzoom,1);
  363. }
  364. oldh=h;
  365. oldw=w;
  366. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement