Guest User

timers

a guest
Apr 15th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.02 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TagPro Timers (Pubs Only)
  3. // @description Timers for powerups, bombs, and boosts. Shows the second it will spawn then a countdown at 10 seconds.
  4. // Players show how much time is left on their active powerups. Blue = juke juice, yellow = rolling bomb, green = tagpro.
  5. //
  6. // Will not show timers on things that happened out of view, or if the spawn date is greater than the time left in the game.
  7. // All timers are cleared on game end.
  8. // This special version is a pub only version
  9. // @version 1.3
  10. // @grant none
  11. // @include http://tagpro-*.koalabeast.com:*
  12. // @include http://tangent.jukejuice.com:*
  13. // @include http://*.newcompte.fr:*
  14. // @author CFlakes, modified by Catalyst
  15. // @namespace http://www.reddit.com/user/Cumflakes
  16. // @license 2014
  17. // ==/UserScript==
  18.  
  19. tagpro.ready(function timers() {
  20. if (!tagpro.playerId) {
  21. return setTimeout(timers, 250);
  22. }
  23.  
  24. if(!tagpro.spectator){
  25. return;
  26. }
  27.  
  28. //if (tagpro.group.socket) return;
  29.  
  30. var tr = tagpro.renderer,
  31. self = tagpro.players[tagpro.playerId],
  32. tileTimer = [],
  33. ballTimer = [],
  34. gameEnd = false,
  35. playerCount = 0;
  36.  
  37. tagpro.socket.on("mapupdate", function(data) {
  38. if (data.length > 1) {
  39. for (var i=0, l=data.length; i<l; i++) {
  40. switch (data[i].v) {
  41. case 6.1:
  42. case 6.2:
  43. case 6.3:
  44. case 10:
  45. case 5:
  46. case 14:
  47. case 15:
  48. handleTiles(data[i], 0);
  49. break;
  50. case 6:
  51. handleTiles(data[i], 59999, '#00FF00');
  52. break;
  53. case '10.1':
  54. handleTiles(data[i], 29999, '#D0A9F5');
  55. break;
  56. case '5.1':
  57. case '14.1':
  58. case '15.1':
  59. handleTiles(data[i], 9999);
  60. break;
  61. }
  62. }
  63. } else {
  64. data = data[0] || data;
  65. switch (data.v) {
  66. case 6.1:
  67. case 6.2:
  68. case 6.3:
  69. case 10:
  70. case 5:
  71. case 14:
  72. case 15:
  73. handleTiles(data, 0);
  74. break;
  75. case 6:
  76. handleTiles(data, 59999, '#00FF00');
  77. break;
  78. case '10.1':
  79. handleTiles(data, 29999, '#D0A9F5');
  80. break;
  81. case '5.1':
  82. case '14.1':
  83. case '15.1':
  84. handleTiles(data, 9999);
  85. break;
  86. }
  87. }
  88. });
  89.  
  90. tagpro.socket.on("p", function(data) {
  91. data = data.u || data;
  92. for (var i = 0, l = data.length; i !== l; i++) {
  93. handlePlayerUpdate(data[i], data[i].id);
  94. }
  95. });
  96.  
  97. function handlePlayerUpdate(data, id) {
  98. var player = tagpro.players[id];
  99. if (!player.countCheck) {
  100. player.countCheck = true;
  101. playerCount++;
  102. }
  103. if (data.grip !== undefined || data.bomb !== undefined || data.tagpro !== undefined || data.draw !== undefined || data.dead !== undefined) {
  104. ballTimer[id] = ballTimer[id] || {jj: {}, rb: {}, tp: {}};
  105. handlePlayers(data.id);
  106. }
  107. }
  108.  
  109. tagpro.socket.on('playerLeft', function() {
  110. playerCount--;
  111. });
  112.  
  113. tagpro.socket.on('end', function() {
  114. gameEnd = true;
  115. if (tagpro.renderer.layers.foreground.children.length > playerCount) {
  116. tagpro.renderer.layers.foreground.removeChildren(playerCount);
  117. }
  118. });
  119.  
  120. function getTiles(onlyPups) {
  121. for (var x=0, xl=tagpro.map.length, yl=tagpro.map[0].length; x<xl; x++) {
  122. tileTimer[x] = tileTimer[x] || [];
  123. for (var y=0; y<yl; y++) {
  124. if (onlyPups) {
  125. switch (tagpro.map[x][y]) {
  126. case 6:
  127. case 6.1:
  128. case 6.2:
  129. case 6.3:
  130. tileTimer[x][y].v = tagpro.map[x][y];
  131. break;
  132. }
  133. } else {
  134. switch (tagpro.map[x][y]) {
  135. case 6:
  136. case 6.1:
  137. case 6.2:
  138. case 6.3:
  139. case 5:
  140. case '5.1':
  141. case 14:
  142. case '14.1':
  143. case 15:
  144. case '15.1':
  145. case 10:
  146. case '10.1':
  147. tileTimer[x][y] = {v: tagpro.map[x][y]};
  148. break;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. getTiles();
  155.  
  156. function getPlayers() {
  157. for (var id in tagpro.players) {
  158. if (tagpro.players.hasOwnProperty(id)) {
  159. var player = tagpro.players[id];
  160. if (!player.countCheck) {
  161. player.countCheck = true;
  162. playerCount++;
  163. }
  164. ballTimer[id] = ballTimer[id] || {jj: {}, rb: {}, tp: {}};
  165. if (player.draw) {
  166. if (!player.grip) ballTimer[id].jj.check = true;
  167. if (!player.bomb) ballTimer[id].rb.check = true;
  168. if (!player.tagpro) ballTimer[id].tp.check = true;
  169. } else {
  170. ballTimer[id].jj.check = false;
  171. ballTimer[id].rb.check = false;
  172. ballTimer[id].tp.check = false;
  173. }
  174. }
  175. }
  176. }
  177. getPlayers();
  178.  
  179. tr.basicText = function(text, color, size) {
  180. return new PIXI.Text(text, {
  181. font: size || "20pt Arial",
  182. fill: color || "#FFFFFF",
  183. stroke: "#000000",
  184. strokeThickness: 3
  185. });
  186. };
  187.  
  188. tr.drawTileTimer = function(tile, color) {
  189. if (gameEnd) return;
  190. var timeLeft = tile.spawn - Date.now(),
  191. timer = tileTimer[tile.x][tile.y];
  192. if (timeLeft > 10000) {
  193. if (!timer.second) {
  194. timer.second = tr.basicText(tile.time.substr(tile.time.length - 2, 2), color);
  195. timer.second.x = tile.x*40 + 3;
  196. timer.second.y = tile.y*40 + 7;
  197. tr.layers.foreground.addChild(timer.second);
  198. }
  199. timer.timeout = setTimeout(function() {
  200. tr.drawTileTimer(tile, color);
  201. }, timeLeft - 10000);
  202. } else {
  203. if (timer.second) {
  204. clearTimeout(timer.timeout);
  205. tr.layers.foreground.removeChild(timer.second);
  206. timer.second = undefined;
  207. }
  208. if (timeLeft > 0) {
  209. var tenths = Math.floor(timeLeft/100)/10 + '.0';
  210. if (!timer.countdown) {
  211. timer.countdown = tr.basicText(tenths.substr(0, 3), color, '18pt Arial');
  212. timer.countdown.x = tile.x*40 + 1;
  213. timer.countdown.y = tile.y*40 + 9;
  214. tr.layers.foreground.addChild(timer.countdown);
  215. }
  216. timer.countdown.setText(tenths.substr(0, 3));
  217. timer.timeout = setTimeout(function() {
  218. tr.drawTileTimer(tile, color);
  219. }, 50);
  220. } else {
  221. if (timer.countdown) {
  222. clearTimeout(timer.timeout);
  223. tr.layers.foreground.removeChild(timer.countdown);
  224. timer.countdown = undefined;
  225. }
  226. }
  227. }
  228. };
  229.  
  230. tr.drawBallTimer = function(timer, id, i, color) {
  231. var offset = [],
  232. actPup = [tagpro.players[id].grip, tagpro.players[id].bomb, tagpro.players[id].tagpro];
  233. offset[0] = tagpro.players[id].degree ? 11 : 0;
  234. offset[1] = ballTimer[id].jj.sprite ? offset[0]+11 : offset[0];
  235. offset[2] = ballTimer[id].rb.sprite ? offset[1]+11 : offset[1];
  236. if (color && !gameEnd) {
  237. timer.expires = Date.now() + 19999;
  238. timer.left = Math.floor((timer.expires - Date.now())/1000);
  239. if (!timer.sprite && actPup[i]) {
  240. timer.sprite = tr.prettyText(timer.left, color);
  241. timer.sprite.x = 40;
  242. timer.sprite.y = -5 + offset[i];
  243. tagpro.players[id].sprites.info.addChild(timer.sprite);
  244. timer.timeout = setTimeout(function() {tr.drawBallTimer(timer, id, i);}, 50);
  245. }
  246. } else {
  247. if (actPup[i] && timer.expires - Date.now() > 0 && !gameEnd) {
  248. if (timer.expires - Date.now() > 10000) {
  249. timer.left = Math.floor((timer.expires - Date.now())/1000);
  250. } else {
  251. timer.left = (Math.floor((timer.expires - Date.now())/100)/10 + '.0').substr(0, 3);
  252. }
  253. timer.sprite.setText(timer.left);
  254. timer.sprite.y = -5 + offset[i];
  255. timer.timeout = setTimeout(function() {tr.drawBallTimer(timer, id, i);}, 50);
  256. } else {
  257. if (timer.timeout) {
  258. clearTimeout(timer.timeout);
  259. }
  260. if (timer.sprite) {
  261. tagpro.players[id].sprites.info.removeChild(timer.sprite);
  262. timer.sprite = undefined;
  263. timer.expires = 0;
  264. timer.left = 0;
  265. }
  266. }
  267. }
  268. };
  269.  
  270. function handleTiles(tile, spawn, color) {
  271. var timer = tileTimer[tile.x][tile.y];
  272. if (spawn) {
  273. var gameTimeLeft = tagpro.gameEndsAt - Date.now(),
  274. tileDist = {x: Math.abs(self.x - tile.x*40), y: Math.abs(self.y - tile.y*40)},
  275. inRange = ((tagpro.spectator || (tileDist.x < 655 && tileDist.y < 415)) && gameTimeLeft - spawn > 0) ? true : false;
  276. if (inRange) {
  277. tile.spawn = Date.now() + spawn;
  278. if (color) {
  279. tile.time = '0' + Math.floor((gameTimeLeft + spawn)/1000 % 60);
  280. }
  281. if (timer.second === undefined && timer.countdown === undefined) {
  282. tr.drawTileTimer(tile, color);
  283. }
  284. }
  285. } else {
  286. if (timer.timeout) {
  287. clearTimeout(timer.timeout);
  288. }
  289. if (timer.second) {
  290. tr.layers.foreground.removeChild(timer.second);
  291. timer.second = undefined;
  292. }
  293. if (timer.countdown) {
  294. tr.layers.foreground.removeChild(timer.countdown);
  295. timer.countdown = undefined;
  296. }
  297. }
  298. if (Math.floor(tile.v) === 6) {
  299. if (tile.v === 6) {
  300. getRepeatGrabs(tile.x, tile.y);
  301. }
  302. getTiles(true);
  303. }
  304. }
  305.  
  306. function handlePlayers(id) {
  307. var player = tagpro.players[id];
  308. if (player.draw) {
  309. if (!player.grip) ballTimer[id].jj.check = true;
  310. if (!player.bomb) ballTimer[id].rb.check = true;
  311. if (!player.tagpro) ballTimer[id].tp.check = true;
  312. } else {
  313. ballTimer[id].jj.check = false;
  314. ballTimer[id].rb.check = false;
  315. ballTimer[id].tp.check = false;
  316. }
  317. if (player.grip) {
  318. if (ballTimer[id].jj.check) {
  319. getNearestPup(player.x, player.y);
  320. tr.drawBallTimer(ballTimer[id].jj, id, 0, '#58FAF4');
  321. ballTimer[id].jj.check = false;
  322. }
  323. }
  324. if (player.bomb) {
  325. if (ballTimer[id].rb.check) {
  326. getNearestPup(player.x, player.y);
  327. tr.drawBallTimer(ballTimer[id].rb, id, 1, '#FFFF00');
  328. ballTimer[id].rb.check = false;
  329. }
  330. }
  331. if (player.tagpro) {
  332. if (ballTimer[id].tp.check) {
  333. getNearestPup(player.x, player.y);
  334. tr.drawBallTimer(ballTimer[id].tp, id, 2, '#81F781');
  335. ballTimer[id].tp.check = false;
  336. }
  337. }
  338. }
  339.  
  340. function getRepeatGrabs(x, y) {
  341. var oldPowerup = tileTimer[x][y].v;
  342. for (var id in tagpro.players) {
  343. if (tagpro.players.hasOwnProperty(id) && tagpro.players[id].draw && !tagpro.players[id].dead) {
  344. var player = tagpro.players[id],
  345. distance = Math.sqrt(Math.pow((player.x + player.lx*7) - x*40, 2) + Math.pow((player.y + player.ly*7) - y*40, 2));
  346. if (distance < 40) {
  347. switch (oldPowerup) {
  348. case 6.1:
  349. if (player.grip) {
  350. ballTimer[id].jj.check = true;
  351. handlePlayers(id);
  352. }
  353. break;
  354. case 6.2:
  355. if (player.bomb) {
  356. ballTimer[id].rb.check = true;
  357. handlePlayers(id);
  358. }
  359. break;
  360. case 6.3:
  361. if (player.tagpro) {
  362. ballTimer[id].tp.check = true;
  363. handlePlayers(id);
  364. }
  365. break;
  366. }
  367. }
  368. }
  369. }
  370. }
  371.  
  372. function getNearestPup(px, py) {
  373. var tile,
  374. timer,
  375. distance,
  376. nearest = 9999;
  377. for (var x=0, xl=tagpro.map.length, yl=tagpro.map[0].length; x<xl; x++) {
  378. for (var y=0; y<yl; y++) {
  379. if (Math.floor(tagpro.map[x][y]) === 6) {
  380. distance = Math.sqrt(Math.pow(px - x*40, 2) + Math.pow(py - y*40, 2));
  381. if (distance < nearest) {
  382. nearest = distance;
  383. timer = tileTimer[x][y];
  384. tile = {x: x, y: y};
  385. }
  386. }
  387. }
  388. }
  389. if (timer.second === undefined && timer.countdown === undefined) {
  390. tile.spawn = Date.now() + 59999;
  391. tile.time = '0' + Math.floor((tagpro.gameEndsAt - Date.now() + 59999)/1000 % 60);
  392. tile.color = '#00FF00';
  393. if (tagpro.gameEndsAt - tile.spawn > 0) {
  394. tr.drawTileTimer(tile, tile.color);
  395. }
  396. }
  397. }
  398. });
Add Comment
Please, Sign In to add comment