Base Record & Rebuild

Record Base

  1. // ==UserScript==
  2. // @name Base Record & Rebuild
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.2
  5. // @author Havy
  6. // @description Record Base
  7. // @match zombs.io
  8. // @icon https://cdn-icons-png.flaticon.com/512/599/599063.png
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. let css2 = `
  13. .button {
  14. background-color: #99FF33;
  15. font-size: 16px;
  16. border: none;
  17. color: black;
  18. padding: 14px 40px;
  19. border-radius: 8px;
  20. box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
  21. text-align: center;
  22. }
  23. .hud-menu-zipp4 {
  24. top: 50%;
  25. left: 50%;
  26. transform: translate(-50%, -50%);
  27. display: none;
  28. position: fixed;
  29. padding: 20px;
  30. width: 640px;
  31. height: 460px;
  32. background: rgba(0, 0, 0, 0.6);
  33. color: #eee;
  34. z-index: 5;
  35. }
  36. .hud-menu-zipp4 .hud-zipp-grid4 {
  37. margin: auto;
  38. display: block;
  39. width: 100%;
  40. height: 100%;
  41. background: rgba(0, 0, 0, 0.2);
  42. }
  43. .hud-spell-icons .hud-spell-icon[data-type="Zippity4"]::before {
  44. background-image: url("https://cdn-icons-png.flaticon.com/512/599/599063.png");
  45. }
  46. .hud-menu-zipp4 .hud-the-tab:hover {
  47. background: rgba(0, 0, 0, 0.2);
  48. color: #eee;
  49. }
  50. `;
  51. let styles = document.createElement("style");
  52. styles.appendChild(document.createTextNode(css2));
  53. document.head.appendChild(styles);
  54. styles.type = "text/css";
  55.  
  56. let spell = document.createElement("div");
  57. spell.classList.add("hud-spell-icon");
  58. spell.setAttribute("data-type", "Zippity4");
  59. spell.classList.add("hud-zipp4-icon");
  60. document.getElementsByClassName("hud-spell-icons")[0].appendChild(spell);
  61.  
  62. let modHTML = `
  63. <div class="hud-menu-zipp4">
  64. <div class="hud-zipp-grid4">
  65. </div>
  66. </div>
  67. `;
  68. document.querySelector('#hud').insertAdjacentHTML("afterbegin", modHTML);
  69. let zipz123 = document.getElementsByClassName("hud-menu-zipp4")[0];
  70.  
  71. document.getElementsByClassName("hud-zipp4-icon")[0].addEventListener("click", () => {
  72. if(["none", ""].includes(zipz123.style.display)) {
  73. zipz123.style.display = "block";
  74. for(let i of Array.from(document.getElementsByClassName("hud-menu"))) {
  75. i.style.display = "none";
  76. };
  77. } else {
  78. zipz123.style.display = "none";
  79. };
  80. });
  81.  
  82. for (let i of Array.from(document.getElementsByClassName("hud-menu-icon"))) {
  83. i.addEventListener('click', function() {
  84. if (document.getElementsByClassName("hud-menu-zipp4")[0].style.display == "block") {
  85. document.getElementsByClassName("hud-menu-zipp4")[0].style.display = "none";
  86. };
  87. });
  88. };
  89.  
  90. for (let i of Array.from(document.getElementsByClassName("hud-spell-icon"))) {
  91. if (i.dataset.type !== "HealTowersSpell" && i.dataset.type !== "TimeoutItem" && i.dataset.type !== "Zippity4") {
  92. i.addEventListener('click', function() {
  93. if (document.getElementsByClassName("hud-menu-zipp4")[0].style.display == "block") {
  94. document.getElementsByClassName("hud-menu-zipp4")[0].style.display = "none";
  95. };
  96. });
  97. };
  98. };
  99.  
  100. document.addEventListener("keyup", e => {
  101. if (document.activeElement.tagName.toLowerCase() !== "input" && document.activeElement.tagName.toLowerCase() !== "textarea") {
  102. if (e.key === "o" || e.key === "p" || e.key === "b" || e.key === "/" || e.keyCode == 27) {
  103. if (zipz123.style.display == "block") {
  104. zipz123.style.display = "none";
  105. }
  106. }
  107. }
  108. })
  109.  
  110. document.getElementsByClassName("hud-zipp-grid4")[0].innerHTML = `
  111. <div style="text-align:center"><br>
  112. <button class="button" onclick="recordBase(1);">Record Base 1</button>
  113. <button class="button" onclick="buildRecordedBase(1);">Build Base 1</button>
  114. <button class="button" onclick="deleteRecordedBase(1);">Delete Base 1</button>
  115.  
  116. <button class="button" onclick="recordBase(2);">Record Base 2</button>
  117. <button class="button" onclick="buildRecordedBase(2);">Build Base 2</button>
  118. <button class="button" onclick="deleteRecordedBase(2);">Delete Base 2</button>
  119.  
  120. <button class="button" onclick="recordBase(3);">Record Base 3</button>
  121. <button class="button" onclick="buildRecordedBase(3);">Build Base 3</button>
  122. <button class="button" onclick="deleteRecordedBase(3);">Delete Base 3</button>
  123.  
  124. <button class="button" onclick="recordBase(4);">Record Base 4</button>
  125. <button class="button" onclick="buildRecordedBase(4);">Build Base 4</button>
  126. <button class="button" onclick="deleteRecordedBase(4);">Delete Base 4</button>
  127.  
  128. <button class="button" onclick="recordBase(5);">Record Base 5</button>
  129. <button class="button" onclick="buildRecordedBase(5);">Build Base 5</button>
  130. <button class="button" onclick="deleteRecordedBase(5);">Delete Base 5</button>
  131.  
  132. <button class="button" onclick="recordBase(6);">Record Base 6</button>
  133. <button class="button" onclick="buildRecordedBase(6);">Build Base 6</button>
  134. <button class="button" onclick="deleteRecordedBase(6);">Delete Base 6</button>
  135.  
  136. <button class="button" onclick="recordBase(7);">Record Base 7</button>
  137. <button class="button" onclick="buildRecordedBase(7);">Build Base 7</button>
  138. <button class="button" onclick="deleteRecordedBase(7);">Delete Base 7</button>
  139.  
  140. <button class="button" onclick="recordBase(8);">Record Base 8</button>
  141. <button class="button" onclick="buildRecordedBase(8);">Build Base 8</button>
  142. <button class="button" onclick="deleteRecordedBase(8);">Delete Base 8</button>
  143. `;
  144.  
  145. var towerCodes = ["Wall", "Door", "SlowTrap", "ArrowTower", "CannonTower", "MeleeTower", "BombTower", "MagicTower", "GoldMine", "Harvester"];
  146.  
  147. function getGoldStash() {
  148. return Object.values(Game.currentGame.ui.buildings).find(building => building.type == "GoldStash");
  149. }
  150.  
  151. window.recordBase = function (num) {
  152. Game.currentGame.ui.getComponent("PopupOverlay").showConfirmation("Are you sure you want to record base " + num + "? If you recorded it twice, the first recorded base will be overwrite.", 1e4, function() {
  153. let baseStr = "";
  154. for (let i in game.ui.buildings) {
  155. const building = game.ui.buildings[i];
  156. if (towerCodes.indexOf(building.type) < 0) continue;
  157.  
  158. let yaw = 0;
  159.  
  160. if (["Harvester", "MeleeTower"].includes(building.type)) {
  161. if (game.world.entities[building.uid] !== undefined) yaw = game.world.entities[building.uid].targetTick.yaw;
  162. }
  163. baseStr += `${towerCodes.indexOf(building.type)},${getGoldStash().x - building.x},${getGoldStash().y - building.y},${yaw};`;
  164. }
  165. localStorage.setItem(num, baseStr)
  166. })
  167. }
  168.  
  169. window.buildRecordedBase = function (num) {
  170. function BuildBase(design) {
  171. if (getGoldStash() === undefined) {
  172. game.ui.getComponent('PopupOverlay').showHint("You must have a gold stash to be able to use this.");
  173. throw new Error("You must have a gold stash to be able to use this.");
  174. }
  175. const towers = design.split(";");
  176.  
  177. for (let towerStr of towers) {
  178. const tower = towerStr.split(",");
  179.  
  180. if (tower[0] === "") continue;
  181. if (tower.length < 4) {
  182. throw new Error(`${JSON.stringify(tower)} contains an issue that must be fixed before this design can be replicated.`);
  183. game.ui.getComponent('PopupOverlay').showHint("You haven't recorded base " + num);
  184. }
  185. Game.currentGame.network.sendRpc({
  186. name: "MakeBuilding",
  187. type: towerCodes[parseInt(tower[0])],
  188. x: getGoldStash().x - parseInt(tower[1]),
  189. y: getGoldStash().y - parseInt(tower[2]),
  190. yaw: parseInt(tower[3])
  191. });
  192. }
  193. }
  194. BuildBase(localStorage.getItem(num));
  195. }
  196. window.deleteRecordedBase = function(num) {
  197. Game.currentGame.ui.getComponent("PopupOverlay").showConfirmation("Are you sure you want to delete base " + num + "?", 1e4, function() {
  198. game.ui.components.PopupOverlay.showHint("Base " + num + " has been successfully deleted!");
  199. localStorage.setItem(num, null);
  200. })
  201. }