UserNameWTF

Browncoat's Mod (For Cam'sPP Dark)

Oct 8th, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.72 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Browncoat's Mod (For Cam'sPP Dark)
  3. // @version 1.1.2
  4. // @description Range of configurable mods for TagPro
  5. // @include http://tagpro-*.koalabeast.com:*
  6. // @include http://tangent.jukejuice.com:*
  7. // @include http://maptest.newcompte.fr:*
  8. // @author Browncoat, Ly, Cumflakes, Cam
  9. // ==/UserScript==
  10.  
  11. /**
  12. * Define a few namespaces to prevent false IDE warnings
  13. * @namespace tagpro
  14. * @namespace tagpro.tiles
  15. * @namespace tagpro.viewPort
  16. * @namespace player.degree
  17. * @namespace player.dead
  18. * @namespace player.flag
  19. */
  20.  
  21. // Main tagpro function
  22. tagpro.ready(function () {
  23.  
  24. if (tagpro.events.drawPlayer)
  25. return;
  26.  
  27. // -------------- Options --------------
  28.  
  29. // Ball textures
  30. // If you want a transparent ball, replace the URL with this: http://i.imgur.com/amo6ZZO.png
  31. // If you want an opaque ball, replace the URL with this (Defualt): http://i.imgur.com/fbWgs3I.png
  32. // Disable drop shadows if you're using the transparent balls!
  33. var image = new Image();
  34. image.src = "http://i.imgur.com/fbWgs3I.png";
  35.  
  36. // Ball drop shadows
  37. var showDropShadows = true;
  38.  
  39. // Show flair in the center of balls and spin it
  40. var centerFlair = true;
  41.  
  42. // set to 2 for twice the particles! Use at own risk
  43. var particleFactor = 1;
  44.  
  45. // Show particles (who would disable this)
  46. var showParticles = true;
  47.  
  48. // ------------ End Options ------------
  49.  
  50. var particles = [];
  51. var drawDropShadowCallbacks = [];
  52. var drawPlayerCallbacks = [];
  53. var drawPlayerInfoCallbacks = [];
  54. var offset = {
  55. x: 0,
  56. y: 0
  57. };
  58. var viewBox = {
  59. left: 0,
  60. top: 0,
  61. right: 0,
  62. bottom: 0,
  63. leftClip: 0,
  64. topClip: 0,
  65. rightClip: 0,
  66. bottomClip: 0
  67. };
  68.  
  69. // Our custom draw function.
  70. var superUiDraw = tagpro.ui.draw;
  71. tagpro.ui.draw = function(context) {
  72. updateViewBox(context);
  73. doAll(drawDropShadowCallbacks);
  74. drawParticles(context, Layer.UNDER_PLAYERS);
  75. doAll(drawPlayerCallbacks);
  76. drawParticles(context, Layer.OVER_PLAYERS);
  77. doAll(drawPlayerInfoCallbacks);
  78. superUiDraw(context);
  79. };
  80.  
  81. function updateViewBox(context) {
  82. var e = 20;
  83. var canvas = $("canvas");
  84. var a = {
  85. x: canvas.attr("width")/2,
  86. y: canvas.attr("height")/2
  87. };
  88. viewBox.left = Math.round(tagpro.viewPort.source.x / tagpro.zoom) * tagpro.zoom - a.x * tagpro.zoom + e;
  89. viewBox.top = Math.round(tagpro.viewPort.source.y / tagpro.zoom) * tagpro.zoom - a.y * tagpro.zoom + e;
  90. viewBox.right = Math.round(tagpro.viewPort.source.x / tagpro.zoom) * tagpro.zoom + a.x * tagpro.zoom + e;
  91. viewBox.bottom = Math.round(tagpro.viewPort.source.y / tagpro.zoom) * tagpro.zoom + a.y * tagpro.zoom + e;
  92. viewBox.leftClip = 0; viewBox.topClip = 0; viewBox.rightClip = 0; viewBox.bottomClip = 0;
  93. viewBox.left < 0 && (viewBox.leftClip = -viewBox.left);
  94. viewBox.top < 0 && (viewBox.topClip = -viewBox.top);
  95. viewBox.right > context.canvas.width && (viewBox.rightClip = viewBox.right - context.canvas.width);
  96. viewBox.bottom > context.canvas.height && (viewBox.bottomClip = viewBox.bottom - context.canvas.height);
  97. }
  98.  
  99. function doAll(callbacks) {
  100. while (callbacks.length > 0) {
  101. (callbacks.shift())();
  102. }
  103. }
  104.  
  105. function drawParticles(context, layer) {
  106. for (var i = 0; i < particles.length; i++) {
  107. var particle = particles[i];
  108. particle.draw(context, offset, layer);
  109. if (particle.shouldBeRemoved()) {
  110. particles.splice(i, 1);
  111. i--;
  112. }
  113. }
  114. }
  115.  
  116. tagpro.events.register({
  117. drawPlayer: function (player, context, drawPos, TILESIZE) {
  118.  
  119. if (tagpro.viewPort.source == player) {
  120. offset.x = drawPos.x - player.x;
  121. offset.y = drawPos.y - player.y;
  122. }
  123.  
  124. drawDropShadowCallbacks.push(function() {
  125. drawDropShadow(context, drawPos);
  126. });
  127.  
  128. drawPlayerCallbacks.push(function () {
  129. drawPlayer(player, context, drawPos, TILESIZE);
  130. });
  131.  
  132. drawPlayerInfoCallbacks.push(function () {
  133. drawPlayerInfo(context, player);
  134. });
  135.  
  136. addParticles(player);
  137. }
  138. });
  139.  
  140. function addParticles(player) {
  141. var centerX = player.x + 20;
  142. var centerY = player.y + 20;
  143.  
  144. if (player.tagpro) {
  145. addParticle(new Particle(centerX + random(-20, 20), centerY + random(-20, 20), 2, "0, 255, 0", 500));
  146. }
  147.  
  148. if (player.bomb) {
  149. // Spark
  150. addParticle(new Particle(centerX + random(-20, 20), centerY + random(-20, 20), 1, "255, 255, 0", 200));
  151.  
  152. //Smoke
  153. var radius = Math.floor(random(3, 7));
  154. addParticle(new Particle(centerX + random(-20, 20), centerY + random(-20, 20), radius, "200, 200, 200", 1000, {x: 0, y: 0}, 0.3));
  155. }
  156.  
  157. if (player.grip) {
  158. if (player.team === 1) {
  159. addParticle(new Particle(centerX, centerY, 18, "255, 0, 0", 325, 0, 0.1, Layer.UNDER_PLAYERS), 1);
  160. } else {
  161. addParticle(new Particle(centerX, centerY, 18, "0, 0, 255", 325, 0, 0.1, Layer.UNDER_PLAYERS), 1);
  162. }
  163. addParticle(new Particle(centerX + random(-20, 20), centerY + random(-20, 20), 1, "255, 255, 255", 250));
  164. }
  165. }
  166.  
  167. function addParticle(particle, overrideFactor) {
  168. if (showParticles) {
  169. var total = 1;
  170. if (overrideFactor) {
  171. total = overrideFactor * total;
  172. } else {
  173. total = total * particleFactor;
  174. }
  175. for (var i = 0; i < total; i++) {
  176. particles.push(particle);
  177. }
  178. }
  179. }
  180.  
  181. function transformPosition(p) {
  182. return {
  183. x: Math.round(p.x * (1 / tagpro.zoom)) - Math.round(viewBox.left * (1 / tagpro.zoom)),
  184. y: Math.round(p.y * (1 / tagpro.zoom)) - Math.round(viewBox.top * (1 / tagpro.zoom))
  185. }
  186. }
  187.  
  188. function drawDropShadow(context, drawPos) {
  189. if (showDropShadows) {
  190. context.save();
  191. context.beginPath();
  192. context.arc(drawPos.x + 20 * (1 / tagpro.zoom), drawPos.y + 20 * (1 / tagpro.zoom), 18 * (1 / tagpro.zoom), 0, Math.PI * 2, true);
  193. context.fillStyle = "rgba(0, 0, 0, 1)";
  194. context.shadowColor = 'rgba(0, 0, 0, 0.5)';
  195. context.shadowBlur = 10;
  196. context.shadowOffsetX = 4;
  197. context.shadowOffsetY = 4;
  198. context.fill();
  199. context.closePath();
  200. context.restore();
  201. }
  202. }
  203.  
  204. function drawPlayer(player, context, drawPos, TILESIZE) {
  205. context.save();
  206.  
  207. if (player.team == 1)
  208. context.drawImage(image, 3 * 40, 0, 40, 40, drawPos.x, drawPos.y, 40 / tagpro.zoom, 40 / tagpro.zoom);
  209. if (player.team == 2)
  210. context.drawImage(image, 1 * 40, 0, 40, 40, drawPos.x, drawPos.y, 40 / tagpro.zoom, 40 / tagpro.zoom);
  211.  
  212. var radian = (Math.PI / 180),
  213. points = [],
  214. angle = (player.angle/radian % 360)+360;
  215.  
  216. for (i = 0; i < 8; i++) {
  217. var iAngle = angle + 360 / 4 * i,
  218. side = ((iAngle + 270) % 360 > 180) ? 0 : -0,
  219. outerAngle = (iAngle + 90) % 180,
  220. outerAngle = (side > 0) ? 180 - outerAngle : outerAngle,
  221. offset = (-8.546e-10 * Math.pow(outerAngle, 5)
  222. + 4.311e-7 * Math.pow(outerAngle, 4)
  223. - 6.669e-5 * Math.pow(outerAngle, 3)
  224. + 0.001099 * Math.pow(outerAngle, 2)
  225. + 0.3462 * outerAngle),
  226. innerX = 18 * Math.cos(iAngle * radian) / tagpro.zoom,
  227. innerY = 18 * Math.sin(iAngle * radian) / tagpro.zoom,
  228. outerX = 30 * Math.cos((iAngle + offset * side) * radian) / tagpro.zoom,
  229. outerY = 30 * Math.sin((iAngle + offset * side) * radian) / tagpro.zoom;
  230.  
  231. points.push({ix: innerX, iy: innerY, ox: outerX, oy: outerY});
  232. }
  233.  
  234. for (i = 0; i < points.length; i += 2) {
  235. var color = (player.team == 1) ? 2 : 0;
  236. first = points[i],
  237. second = points[(i + 1) % points.length];
  238.  
  239. context.save();
  240. context.beginPath();
  241. context.moveTo(drawPos.x + 20 / tagpro.zoom, drawPos.y + 20 / tagpro.zoom);
  242. context.quadraticCurveTo(drawPos.x + first.ix + 20 / tagpro.zoom, drawPos.y + first.iy + 20 / tagpro.zoom, drawPos.x + first.ox + 20 / tagpro.zoom, drawPos.y + first.oy + 20 / tagpro.zoom);
  243. context.lineTo(drawPos.x + second.ox + 20 / tagpro.zoom, drawPos.y + second.oy + 20 / tagpro.zoom);
  244. context.quadraticCurveTo(drawPos.x + second.ix + 20 / tagpro.zoom, drawPos.y + second.iy + 20 / tagpro.zoom, drawPos.x + 20 / tagpro.zoom, drawPos.y + 20 / tagpro.zoom);
  245. context.clip();
  246. context.drawImage(image, color * 40, 0, 40, 40 , drawPos.x, drawPos.y, 40 / tagpro.zoom, 40 / tagpro.zoom);
  247. context.restore();
  248. context.closePath();
  249. }
  250.  
  251. // flair in center
  252. var e = $("#flair").get(0);
  253. if (centerFlair && player.flair && tagpro.zoom <= 1) {
  254. context.drawImage(e, player.flair.x * 16, player.flair.y * 16, 16, 16, drawPos.x + 12 * (1 / tagpro.zoom), drawPos.y + 13 * (1 / tagpro.zoom), 16, 16)
  255. }
  256.  
  257. if (player.bomb && Math.round(Math.random() * 4) == 1) {
  258. context.fillStyle = "rgba(255, 255, 0, .40)";
  259. context.beginPath();
  260. context.arc(drawPos.x + TILESIZE / 2 * (1 / tagpro.zoom), drawPos.y + TILESIZE / 2 * (1 / tagpro.zoom), 19 * (1 / tagpro.zoom), 0, Math.PI * 2, true);
  261. context.closePath();
  262. context.fill();
  263. }
  264.  
  265. if (player.tagpro) {
  266. context.strokeStyle = "#00FF00";
  267. context.fillStyle = "rgba(0, 255, 0, .05)";
  268. context.lineWidth = 2 * (1 / tagpro.zoom);
  269. context.beginPath();
  270. context.arc(drawPos.x + TILESIZE / 2 * (1 / tagpro.zoom), drawPos.y + TILESIZE / 2 * (1 / tagpro.zoom), 18 * (1 / tagpro.zoom), 0, Math.PI * 2, true);
  271. context.closePath();
  272. if (!player.bomb) {
  273. context.fill();
  274. }
  275. context.stroke();
  276. }
  277.  
  278. context.restore();
  279.  
  280. // Flair in default position
  281. if (!centerFlair && player.flair && tagpro.zoom <= 1) {
  282. context.drawImage(e, player.flair.x * 16, player.flair.y * 16, 16, 16, drawPos.x + 12, drawPos.y - 17, 16, 16);
  283. }
  284.  
  285. }
  286.  
  287. // Username, flags and degrees
  288. var flagNames = ["redflag", "blueflag", "yellowflag"];
  289. function drawPlayerInfo(context, player) {
  290. var p = transformPosition(player);
  291. if (!player.dead && player.draw) {
  292.  
  293. // Flag
  294. if (player.flag) {
  295. var flag = "bc_" + flagNames[player.flag - 1];
  296. tagpro.tiles.drawWithZoom(context, flag, {
  297. x: p.x + Math.round(13 * (1 / tagpro.zoom)),
  298. y: p.y - Math.round(32 * (1 / tagpro.zoom))
  299. });
  300. }
  301.  
  302. // Degrees
  303. if (tagpro.zoom <= 1.5 && player.browncoatDegreeCache) {
  304. context.drawImage(
  305. player.browncoatDegreeCache.canvas,
  306. p.x + 20 * (1 / tagpro.zoom),
  307. p.y - Math.round(8 * (1 / tagpro.zoom))
  308. );
  309. }
  310.  
  311. // Name
  312. if (player.name && tagpro.zoom <= 4 && player.browncoatCache) {
  313. context.drawImage(
  314. player.browncoatCache.canvas,
  315. p.x + Math.round(18 * (1 / tagpro.zoom)),
  316. p.y - 20 * (1 / tagpro.zoom)
  317. );
  318. }
  319.  
  320. }
  321. }
  322.  
  323. // Add effects on bomb explosion
  324. onSocketEvent("bomb", function (e) {
  325. // e = top left corner of tile
  326. for (var i = 0; i < 3; i++) {
  327.  
  328. // White fragments
  329. for (var j = 0; j < 3; j++) {
  330. var speed = {
  331. x: random(-7, 7),
  332. y: random(-7, 7)
  333. };
  334. addParticle(new Particle(e.x + 20, e.y + 20, 2, "255, 255, 255", 500, speed));
  335. }
  336.  
  337. // GreyishPurple smoke
  338. var radius = Math.random() * 5 + 10;
  339. var x = e.x + random(0, 40);
  340. var y = e.y + random(0, 40);
  341. addParticle(new Particle(x, y, radius, "180, 100, 255", 1000));
  342. addParticle(new Particle(x, y, radius, "180, 180, 180", 500));
  343.  
  344. // White flash
  345. x = e.x + random(0, 40);
  346. y = e.y + random(0, 40);
  347. addParticle(new Particle(x, y, 10, "255, 255, 255", 200));
  348. }
  349. });
  350.  
  351. // Add effects on player pop
  352. onSocketEvent("splat", function (player) {
  353. for (var i = 0; i < 30; i++) {
  354. var rgb = player.t == 1 ? "255, 0, 0" : "0, 0, 255";
  355. var speed = {
  356. x: random(-4, 4),
  357. y: random(-4, 4)
  358. };
  359. var x = player.x + 20 + speed.x * random(0, 20);
  360. var y = player.y + 20 + speed.y * random(0, 20);
  361. addParticle(new Particle(x, y, 1, rgb, 300, speed));
  362. }
  363. });
  364.  
  365. function onSocketEvent(event, handler) {
  366. tagpro.socket.on(event, function(param) {
  367. try {
  368. handler(param);
  369. } catch (err) {
  370. console.log("Browncoat's mod error handling event '" + event + "': " + err);
  371. }
  372. });
  373. }
  374.  
  375.  
  376. // -------------------------- OVERRIDES --------------------------
  377.  
  378.  
  379. // Don't draw the speed/grip icon over players unless particles are disabled
  380. // Don't draw flags - done in drawPlayerInfo()
  381. var superDrawWithZoom = tagpro.tiles.drawWithZoom;
  382. tagpro.tiles.drawWithZoom = function (context, type, position, r, i, s) {
  383. if ((!showParticles || type != "grip") && type != "yellowflag" && type != "redflag" && type != "blueflag") {
  384. if (type.substr(0, 3) == "bc_") {
  385. type = type.substr(3, type.length);
  386. }
  387. superDrawWithZoom(context, type, position, r, i, s);
  388. }
  389. };
  390.  
  391. tagpro.flair.draw = function (context, drawPos, flair) {
  392. // Do nothing - flair is draw in the drawPlayerInfo() function
  393. // t.drawImage(e, r.x * 16, r.y * 16, 16, 16, n.x + 12, n.y - 17, 16, 16)
  394. };
  395.  
  396. tagpro.ui.createPlayerCache = function(player) {
  397. player.cache = {
  398. canvas: $("<canvas></canvas>").attr("width", 140).attr("height", 35).attr("visible", false).get(0)
  399. };
  400. player.degreeCache = {
  401. canvas: $("<canvas></canvas>").attr("width", 45).attr("height", 35).attr("visible", false).get(0)
  402. };
  403. player.cache.context = player.cache.canvas.getContext("2d");
  404. player.degreeCache.context = player.degreeCache.canvas.getContext("2d");
  405.  
  406. player.browncoatCache = {
  407. canvas: $("<canvas></canvas>").attr("width", 140).attr("height", 35).get(0)
  408. };
  409. player.browncoatDegreeCache = {
  410. canvas: $("<canvas></canvas>").attr("width", 45).attr("height", 35).get(0)
  411. };
  412. player.browncoatCache.context = player.browncoatCache.canvas.getContext("2d");
  413. player.browncoatDegreeCache.context = player.browncoatDegreeCache.canvas.getContext("2d");
  414. player.cache.update = function () {
  415. // Hide default caches and create new caches to draw on to in drawPlayerInfo()
  416. // Couldn't figure out how to override default draw name/flair so we hide default and create new canvases
  417. player.browncoatCache.context.clearRect(0, 0, 140, 35);
  418. player.browncoatDegreeCache.context.clearRect(0, 0, 45, 35);
  419. var nameColor = player.auth ? "#BFFF00" : "#ffffff";
  420. if (tagpro.settings.ui.names) {
  421. tagpro.prettyText(player.name, 15, 15, nameColor, false, false, player.browncoatCache.context);
  422. }
  423. if (player.degree && tagpro.settings.ui.degrees) {
  424. tagpro.prettyText(player.degree + "°", 20, 15, "#ffffff", false, false, player.browncoatDegreeCache.context);
  425. }
  426. };
  427. player.cache.update();
  428. };
  429.  
  430. function random(min, max) {
  431. return Math.random() * (max - min) + min;
  432. }
  433.  
  434. var Layer = {
  435. UNDER_PLAYERS: 1,
  436. OVER_PLAYERS: 2
  437. };
  438.  
  439. /**
  440. *
  441. * Particle class
  442. *
  443. * @constructor
  444. * @param x
  445. * @param y
  446. * @param radius
  447. * @param {String} rgb should be in the form "255, 255, 255"
  448. * @param lifeTime
  449. * @param [speed]
  450. * @param [alpha]
  451. * @param {int} [layer]
  452. */
  453. var Particle = function (x, y, radius, rgb, lifeTime, speed, alpha, layer) {
  454. speed = speed || {x: 0, y: 0};
  455. alpha = alpha || 1;
  456. layer = layer || Layer.OVER_PLAYERS;
  457. this.x = x;
  458. this.y = y;
  459. this.radius = radius;
  460. this.rgb = rgb;
  461. this.alpha = alpha;
  462. this.initialAlpha = alpha;
  463. this.remove = false;
  464. this.lifeTime = lifeTime;
  465. this.timer = 0;
  466. this.speed = speed;
  467. this.layer = layer;
  468. };
  469.  
  470. Particle.prototype.draw = function (context, offset, layer) {
  471. if (!this.remove && this.layer == layer) {
  472. this.x += this.speed.x;
  473. this.y += this.speed.y;
  474. context.save();
  475. context.fillStyle = "rgba(" + this.rgb + ", " + this.alpha + ")";
  476. context.beginPath();
  477. context.arc(this.x + offset.x, this.y + offset.y, this.radius * (1 / tagpro.zoom), 0, Math.PI * 2, true);
  478. context.closePath();
  479. context.fill();
  480. context.restore();
  481.  
  482. this.timer += 1000 / 60;
  483. this.alpha = (1 - (this.timer / this.lifeTime)) * this.initialAlpha;
  484. if (this.alpha < 0.001 || this.timer >= this.lifeTime) {
  485. this.remove = true;
  486. }
  487. }
  488. };
  489.  
  490. Particle.prototype.shouldBeRemoved = function () {
  491. return this.remove;
  492. };
  493.  
  494. });
Advertisement
Add Comment
Please, Sign In to add comment