Tank-Randomizer

Bring an element of surprise to your tank customization experience with the Tank Randomizer!

当前为 2024-01-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Tank-Randomizer
  3. // @author Kamarov
  4. // @description Bring an element of surprise to your tank customization experience with the Tank Randomizer!
  5. // @version 0.0.19
  6. // @namespace https://github.com/kamarov-therussiantank
  7. // @license GPL-3.0
  8. // @match https://*.tanktrouble.com/*
  9. // @desc Randomize your tank in style!
  10. // @run-at document-end
  11. // @grant GM_addStyle
  12. // @require https://update.greasyfork.org/scripts/482092/1297984/TankTrouble%20Development%20Library.js
  13. // @noframes
  14. // ==/UserScript==
  15.  
  16. GM_addStyle(`
  17. .randomize-button {
  18. margin-bottom: 10px;
  19. }
  20. `);
  21.  
  22. whenContentInitialized().then(() => {
  23. var id = Users.getAllPlayerIds()[0];
  24. var turret = [];
  25. var back = [];
  26. var barrel = [];
  27. var front = [];
  28. var colours = [];
  29. var baseColor = '';
  30.  
  31. function randomize() {
  32. randomizePaint();
  33. randomizeTankcessories();
  34. }
  35.  
  36. function randomizeTankcessories() {
  37. randomizeTankcessoriesA();
  38. }
  39.  
  40. function randomizeTankcessoriesA() {
  41. Backend.getInstance().setAccessory(
  42. function (result) {
  43. Users.updateUser(id, true, false);
  44. },
  45. null,
  46. null,
  47. id,
  48. 'back',
  49. back[Math.floor(Math.random() * back.length)],
  50. Caches.getPlayerDetailsCache()
  51. );
  52.  
  53. Backend.getInstance().setAccessory(
  54. function (result) {
  55. Users.updateUser(id, true, false);
  56. },
  57. null,
  58. null,
  59. id,
  60. 'turret',
  61. turret[Math.floor(Math.random() * turret.length)],
  62. Caches.getPlayerDetailsCache()
  63. );
  64.  
  65. Backend.getInstance().setAccessory(
  66. function (result) {
  67. Users.updateUser(id, true, false);
  68. },
  69. null,
  70. null,
  71. id,
  72. 'front',
  73. front[Math.floor(Math.random() * front.length)],
  74. Caches.getPlayerDetailsCache()
  75. );
  76.  
  77. Backend.getInstance().setAccessory(
  78. function (result) {
  79. Users.updateUser(id, true, false);
  80. },
  81. null,
  82. null,
  83. id,
  84. 'tread',
  85. Math.floor(Math.random() * 25) + 1,
  86. Caches.getPlayerDetailsCache()
  87. );
  88.  
  89. Backend.getInstance().setAccessory(
  90. function (result) {
  91. Users.updateUser(id, true, false);
  92. },
  93. null,
  94. null,
  95. id,
  96. 'barrel',
  97. barrel[Math.floor(Math.random() * barrel.length)],
  98. Caches.getPlayerDetailsCache()
  99. );
  100. }
  101.  
  102. function randomizePaint() {
  103. randomizePaintC();
  104. }
  105.  
  106. function randomizePaintC() {
  107. var selectedBaseColor = getRandomColorFromGarage();
  108. var selectedTurretColor = getRandomColorFromGarage();
  109. var selectedTreadColor = getRandomColorFromGarage();
  110.  
  111. function setColorForPart(part, color) {
  112. Backend.getInstance().setColour(
  113. function (result) {
  114. Users.updateUser(id, true, false);
  115. },
  116. function (result) { },
  117. function (result) { },
  118. id,
  119. part,
  120. color,
  121. Caches.getPlayerDetailsCache()
  122. );
  123. }
  124.  
  125. setColorForPart('base', selectedBaseColor);
  126. setColorForPart('turret', selectedTurretColor);
  127. setColorForPart('tread', selectedTreadColor);
  128. }
  129.  
  130. Backend.getInstance().getGarageContent(
  131. function (result) {
  132. boxes = result['boxes'];
  133. for (box in boxes) {
  134. accessories = boxes[box]['accessories'];
  135. sprays = boxes[box]['sprayCans'];
  136. for (accessory in accessories) {
  137. thing = accessories[accessory];
  138. if (thing['type'] == 'front') {
  139. front.push(thing['value']);
  140. }
  141. if (thing['type'] == 'back') {
  142. back.push(thing['value']);
  143. }
  144. if (thing['type'] == 'barrel') {
  145. barrel.push(thing['value']);
  146. }
  147. if (thing['type'] == 'turret') {
  148. turret.push(thing['value']);
  149. }
  150. }
  151. for (spray in sprays) {
  152. thing = sprays[spray]['colour'];
  153. if (thing['type']) {
  154. colours.push(thing['rawValue']);
  155. }
  156. }
  157. }
  158.  
  159. // Randomly select the base color
  160. baseColor = colours[Math.floor(Math.random() * colours.length)];
  161. },
  162. function (res) { },
  163. function (res) { },
  164. id,
  165. Caches.getGarageContentCache()
  166. );
  167.  
  168. var snippet = $(`
  169. <div id="randomizerSnippet" class="snippet">
  170. <div class="header">Tank Randomizer</div>
  171. Inject a dash of unpredictability into your tank's appearance
  172. <hr>
  173. <div class="header" style="color: #e7c811;">Randomize</div>
  174. </div>
  175. `);
  176. var content = $('<div></div>');
  177. var allPartsButton = $('<button class="randomize-button button" type="button" tabindex="-1">All Parts</button>');
  178. var accessoriesButton = $('<button class="randomize-button button" type="button" tabindex="-1">Accessories</button>');
  179. var paintsButton = $('<button class="randomize-button button" type="button" tabindex="-1">Paints</button>');
  180.  
  181. allPartsButton.on('mouseup', () => randomize());
  182. accessoriesButton.on('mouseup', () => randomizeTankcessoriesA());
  183. paintsButton.on('mouseup', () => randomizePaintC());
  184.  
  185. content.append([allPartsButton, accessoriesButton, paintsButton]);
  186. snippet.append(content);
  187. $('#secondaryContent').append(snippet);
  188.  
  189. function getRandomColorFromGarage() {
  190. return colours[Math.floor(Math.random() * colours.length)];
  191. }
  192. });