You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

469 lines
23 KiB

  1. function secondsToTime(secs) {
  2. var h = Math.floor(secs / (60 * 60));
  3. var divisor_for_minutes = secs % (60 * 60);
  4. var m = Math.floor(divisor_for_minutes / 60);
  5. var divisor_for_seconds = divisor_for_minutes % 60;
  6. var s = Math.ceil(divisor_for_seconds);
  7. return h + "h " + m + "m " + s + "s";
  8. }
  9. function printNeededResources(r) {
  10. let enough = true;
  11. let enoughEnergy = true;
  12. let html = "";
  13. html += `Requires:`;
  14. if (r.Metal <= planet.Resources.Metal) {
  15. html += ` Metal: <b style="color:lime;">` + r.Metal + `</b>`;
  16. } else {
  17. enough = false;
  18. html += ` Metal: <b style="color:red;">` + r.Metal + `</b>`;
  19. }
  20. if (r.Crystal <= planet.Resources.Crystal) {
  21. html += ` Crystal: <b style="color:lime;">` + r.Crystal + `</b>`;
  22. } else {
  23. enough = false;
  24. html += ` Crystal: <b style="color:red;">` + r.Crystal + `</b>`;
  25. }
  26. if (r.Deuterium <= planet.Resources.Deuterium) {
  27. html += ` Deuterium: <b style="color:lime;">` + r.Deuterium + `</b>`;
  28. } else {
  29. enough = false;
  30. html += ` Deuterium: <b style="color:red;">` + r.Deuterium + `</b>`;
  31. }
  32. if (r.Energy <= planet.Resources.Energy) {
  33. html += ` Energy: <b style="color: lime;">` + r.Energy + `</b>`;
  34. } else {
  35. enough = false;
  36. enoughEnergy = true;
  37. html += ` Energy: <b style="color: red;">` + r.Energy + `</b>`;
  38. }
  39. return {html, enough, enoughEnergy};
  40. }
  41. function printResources(r) {
  42. console.log(r)
  43. document.getElementById("metal").innerHTML = r.Metal;
  44. document.getElementById("crystal").innerHTML = r.Crystal;
  45. document.getElementById("deuterium").innerHTML = r.Deuterium;
  46. document.getElementById("energy").innerHTML = r.Energy;
  47. }
  48. function coundown(t) {
  49. document.getElementById("countdown").innerHTML = `
  50. Countdown: <b>` + secondsToTime(t) + `</b>`;
  51. let timer = setInterval(function() {
  52. if (t > 0) {
  53. t--;
  54. document.getElementById("countdown").innerHTML = `
  55. Countdown: <b>` + secondsToTime(t) + `</b>`;
  56. } else {
  57. clearInterval(timer);
  58. getUser();
  59. }
  60. }, 1000);
  61. }
  62. function printBuildings(planet) {
  63. let r = {};
  64. let resrourcesHtml = {};
  65. document.getElementById("planetname").innerHTML = planet.Name;
  66. if (planet.CurrentBuild.Title !== "") {
  67. document.getElementById("currentBuild").innerHTML = `
  68. Currently building: <b>` + planet.CurrentBuild.Title + `</b>
  69. <br>
  70. Finishes at: <b>` + planet.CurrentBuild.Ends + `</b>
  71. `
  72. coundown(planet.CurrentBuild.CountDown);
  73. } else {
  74. document.getElementById("currentBuild").innerHTML = "";
  75. document.getElementById("countdown").innerHTML = "";
  76. }
  77. // metalmine
  78. if (planet.Buildings.metalmine == undefined) {
  79. document.getElementById("btnBuildMetalMine").innerHTML = `<div class="allowed" onclick="buildBuilding('metalmine')">Build building</div>`;
  80. r = metalmineCost(1);
  81. t = constructionTime(r, 1);
  82. resrourcesHtml = printNeededResources(r);
  83. document.getElementById("metalmineResources").innerHTML = resrourcesHtml.html + `
  84. <br>
  85. Construction time: ` + secondsToTime(t);
  86. } else {
  87. document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")";
  88. document.getElementById("btnBuildMetalMine").innerHTML = `<div class="allowed" onclick="buildBuilding('metalmine')">Build level ` + (+ (planet.Buildings.metalmine) + + (1)) + `</div>`;
  89. r = metalmineCost((+ (planet.Buildings.metalmine) + + (1)));
  90. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  91. resrourcesHtml = printNeededResources(r);
  92. document.getElementById("metalmineResources").innerHTML = resrourcesHtml.html + `
  93. <br>
  94. Construction time: ` + secondsToTime(t);
  95. }
  96. if (!resrourcesHtml.enough) {
  97. document.getElementById("btnBuildMetalMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
  98. }
  99. if (planet.CurrentBuild.Title !== "") {
  100. document.getElementById("btnBuildMetalMine").innerHTML = `<span style="color: red;">building</span>`;
  101. }
  102. // crystalmine
  103. if (planet.Buildings.crystalmine == undefined) {
  104. document.getElementById("btnBuildCrystalMine").innerHTML = `<div class="allowed" onclick="buildBuilding('crystalmine')">Build building</div>`;
  105. r = crystalmineCost(1);
  106. t = constructionTime(r, 1);
  107. resrourcesHtml = printNeededResources(r);
  108. document.getElementById("crystalmineResources").innerHTML = resrourcesHtml.html + `
  109. <br>
  110. Construction time: ` + secondsToTime(t);
  111. } else {
  112. document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")";
  113. document.getElementById("btnBuildCrystalMine").innerHTML = `<div class="allowed" onclick="buildBuilding('crystalmine')">Build level ` + (+ (planet.Buildings.crystalmine) + + (1)) + `</div>`;
  114. r = crystalmineCost((+ (planet.Buildings.crystalmine) + + (1)));
  115. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  116. resrourcesHtml = printNeededResources(r);
  117. document.getElementById("crystalmineResources").innerHTML = resrourcesHtml.html + `
  118. <br>
  119. Construction time: ` + secondsToTime(t);
  120. }
  121. if (!resrourcesHtml.enough) {
  122. document.getElementById("btnBuildCrystalMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
  123. }
  124. if (planet.CurrentBuild.Title !== "") {
  125. document.getElementById("btnBuildCrystalMine").innerHTML = `<span style="color: red;">building</span>`;
  126. }
  127. // deuteriummine{
  128. if (planet.Buildings.deuteriummine == undefined) {
  129. document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div class="allowed" onclick="buildBuilding('deuteriummine')">Build building</div>`;
  130. r = deuteriummineCost(1);
  131. t = constructionTime(r, 1);
  132. resrourcesHtml = printNeededResources(r);
  133. document.getElementById("deuteriummineResources").innerHTML = resrourcesHtml.html + `
  134. <br>
  135. Construction time: ` + secondsToTime(t);
  136. } else {
  137. document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")";
  138. document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div class="allowed" onclick="buildBuilding('deuteriummine')">Build level ` + (+ (planet.Buildings.deuteriummine) + + (1)) + `</div>`;
  139. r = deuteriummineCost((+ (planet.Buildings.deuteriummine) + + (1)));
  140. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  141. resrourcesHtml = printNeededResources(r);
  142. document.getElementById("deuteriummineResources").innerHTML = resrourcesHtml.html + `
  143. <br>
  144. Construction time: ` + secondsToTime(t);
  145. }
  146. if (!resrourcesHtml.enough) {
  147. document.getElementById("btnBuildDeuteriumMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
  148. }
  149. if (planet.CurrentBuild.Title !== "") {
  150. document.getElementById("btnBuildDeuteriumMine").innerHTML = `<span style="color: red;">building</span>`;
  151. }
  152. // energymine
  153. if (planet.Buildings.energymine == undefined) {
  154. document.getElementById("btnBuildEnergyMine").innerHTML = `<div class="allowed" onclick="buildBuilding('energymine')">Build building</div>`;
  155. r = energymineCost(1);
  156. t = constructionTime(r, 1);
  157. resrourcesHtml = printNeededResources(r);
  158. document.getElementById("energymineResources").innerHTML = resrourcesHtml.html + `
  159. <br>
  160. Construction time: ` + secondsToTime(t);
  161. } else {
  162. document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")";
  163. document.getElementById("btnBuildEnergyMine").innerHTML = `<div class="allowed" onclick="buildBuilding('energymine')">Build level ` + (+ (planet.Buildings.energymine) + + (1)) + `</div>`;
  164. r = energymineCost((+ (planet.Buildings.energymine) + + (1)));
  165. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  166. resrourcesHtml = printNeededResources(r);
  167. document.getElementById("energymineResources").innerHTML = resrourcesHtml.html + `
  168. <br>
  169. Construction time: ` + secondsToTime(t);
  170. }
  171. if (!resrourcesHtml.enoughEnergy) {
  172. document.getElementById("btnBuildEnergyMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
  173. }
  174. if (planet.CurrentBuild.Title !== "") {
  175. document.getElementById("btnBuildEnergyMine").innerHTML = `<span style="color: red;">building</span>`;
  176. }
  177. // fusionreactor
  178. if (planet.Buildings.fusionreactor == undefined) {
  179. document.getElementById("btnBuildFusionReactor").innerHTML = `<div class="allowed" onclick="buildBuilding('fusionreactor')">Build building</div>`;
  180. r = fusionreactorCost(1);
  181. t = constructionTime(r, 1);
  182. resrourcesHtml = printNeededResources(r);
  183. document.getElementById("fusionreactorResources").innerHTML = resrourcesHtml.html + `
  184. <br>
  185. Construction time: ` + secondsToTime(t);
  186. } else {
  187. document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")";
  188. document.getElementById("btnBuildFusionReactor").innerHTML = `<div class="allowed" onclick="buildBuilding('fusionreactor')">Build level ` + (+ (planet.Buildings.fusionreactor) + + (1)) + `</div>`;
  189. r = fusionreactorCost((+ (planet.Buildings.fusionreactor) + + (1)));
  190. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  191. resrourcesHtml = printNeededResources(r);
  192. document.getElementById("fusionreactorResources").innerHTML = resrourcesHtml.html + `
  193. <br>
  194. Construction time: ` + secondsToTime(t);
  195. }
  196. if (!resrourcesHtml.enough) {
  197. document.getElementById("btnBuildFusionReactor").innerHTML = `<span style="color: red;">not enough resources</span>`;
  198. }
  199. if (planet.CurrentBuild.Title !== "") {
  200. document.getElementById("btnBuildFusionReactor").innerHTML = `<span style="color: red;">building</span>`;
  201. }
  202. // roboticsfactory
  203. if (planet.Buildings.roboticsfactory == undefined) {
  204. document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div class="allowed" onclick="buildBuilding('roboticsfactory')">Build building</div>`;
  205. r = roboticsfactoryCost(1);
  206. t = constructionTime(r, 1);
  207. resrourcesHtml = printNeededResources(r);
  208. document.getElementById("roboticsfactoryResources").innerHTML = resrourcesHtml.html + `
  209. <br>
  210. Construction time: ` + secondsToTime(t);
  211. } else {
  212. document.getElementById("roboticsfactoryLevel").innerHTML = "(Level " + planet.Buildings.roboticsfactory + ")";
  213. document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div class="allowed" onclick="buildBuilding('roboticsfactory')">Build level ` + (+ (planet.Buildings.roboticsfactory) + + (1)) + `</div>`;
  214. r = roboticsfactoryCost((+ (planet.Buildings.roboticsfactory) + + (1)));
  215. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  216. resrourcesHtml = printNeededResources(r);
  217. document.getElementById("roboticsfactoryResources").innerHTML = resrourcesHtml.html + `
  218. <br>
  219. Construction time: ` + secondsToTime(t);
  220. }
  221. if (!resrourcesHtml.enough) {
  222. document.getElementById("btnBuildRoboticsFactory").innerHTML = `<span style="color: red;">not enough resources</span>`;
  223. }
  224. if (planet.CurrentBuild.Title !== "") {
  225. document.getElementById("btnBuildRoboticsFactory").innerHTML = `<span style="color: red;">building</span>`;
  226. }
  227. // shipyard
  228. if (planet.Buildings.shipyard == undefined) {
  229. document.getElementById("btnBuildShipyard").innerHTML = `<div class="allowed" onclick="buildBuilding('shipyard')">Build building</div>`;
  230. r = shipyardCost(1);
  231. t = constructionTime(r, 1);
  232. resrourcesHtml = printNeededResources(r);
  233. document.getElementById("shipyardResources").innerHTML = resrourcesHtml.html + `
  234. <br>
  235. Construction time: ` + secondsToTime(t);
  236. } else {
  237. document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")";
  238. document.getElementById("btnBuildShipyard").innerHTML = `<div class="allowed" onclick="buildBuilding('shipyard')">Build level ` + (+ (planet.Buildings.shipyard) + + (1)) + `</div>`;
  239. r = shipyardCost((+ (planet.Buildings.shipyard) + + (1)));
  240. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  241. resrourcesHtml = printNeededResources(r);
  242. document.getElementById("shipyardResources").innerHTML = resrourcesHtml.html + `
  243. <br>
  244. Construction time: ` + secondsToTime(t);
  245. }
  246. if (!resrourcesHtml.enough) {
  247. document.getElementById("btnBuildShipyard").innerHTML = `<span style="color: red;">not enough resources</span>`;
  248. }
  249. if (planet.CurrentBuild.Title !== "") {
  250. document.getElementById("btnBuildShipyard").innerHTML = `<span style="color: red;">building</span>`;
  251. }
  252. // metalstorage
  253. if (planet.Buildings.metalstorage == undefined) {
  254. document.getElementById("btnBuildMetalStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('metalstorage')">Build building</div>`;
  255. r = metalstorageCost(1);
  256. t = constructionTime(r, 1);
  257. resrourcesHtml = printNeededResources(r);
  258. document.getElementById("metalstorageResources").innerHTML = resrourcesHtml.html + `
  259. <br>
  260. Construction time: ` + secondsToTime(t);
  261. } else {
  262. document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")";
  263. document.getElementById("btnBuildMetalStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('metalstorage')">Build level ` + (+ (planet.Buildings.metalstorage) + + (1)) + `</div>`;
  264. r = metalstorageCost((+ (planet.Buildings.metalstorage) + + (1)));
  265. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  266. resrourcesHtml = printNeededResources(r);
  267. document.getElementById("metalstorageResources").innerHTML = resrourcesHtml.html + `
  268. <br>
  269. Construction time: ` + secondsToTime(t);
  270. }
  271. if (!resrourcesHtml.enough) {
  272. document.getElementById("btnBuildMetalStorage").innerHTML = `<span style="color: red;">not enough resources</span>`;
  273. }
  274. if (planet.CurrentBuild.Title !== "") {
  275. document.getElementById("btnBuildMetalStorage").innerHTML = `<span style="color: red;">building</span>`;
  276. }
  277. // crystalstorage
  278. if (planet.Buildings.crystalstorage == undefined) {
  279. document.getElementById("btnBuildCrystalStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('crystalstorage')">Build building</div>`;
  280. r = crystalstorageCost(1);
  281. t = constructionTime(r, 1);
  282. resrourcesHtml = printNeededResources(r);
  283. document.getElementById("crystalstorageResources").innerHTML = resrourcesHtml.html + `
  284. <br>
  285. Construction time: ` + secondsToTime(t);
  286. } else {
  287. document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")";
  288. document.getElementById("btnBuildCrystalStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('crystalstorage')">Build level ` + (+ (planet.Buildings.crystalstorage) + + (1)) + `</div>`;
  289. r = crystalstorageCost((+ (planet.Buildings.crystalstorage) + + (1)));
  290. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  291. resrourcesHtml = printNeededResources(r);
  292. document.getElementById("crystalstorageResources").innerHTML = resrourcesHtml.html + `
  293. <br>
  294. Construction time: ` + secondsToTime(t);
  295. }
  296. if (!resrourcesHtml.enough) {
  297. document.getElementById("btnBuildCrystalStorage").innerHTML = `<span style="color: red;">not enough resources</span>`;
  298. }
  299. if (planet.CurrentBuild.Title !== "") {
  300. document.getElementById("btnBuildCrystalStorage").innerHTML = `<span style="color: red;">building</span>`;
  301. }
  302. // deuteriumstorage
  303. if (planet.Buildings.deuteriumstorage == undefined) {
  304. document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('deuteriumstorage')">Build building</div>`;
  305. r = deuteriumstorageCost(1);
  306. t = constructionTime(r, 1);
  307. resrourcesHtml = printNeededResources(r);
  308. document.getElementById("deuteriumstorageResources").innerHTML = resrourcesHtml.html + `
  309. <br>
  310. Construction time: ` + secondsToTime(t);
  311. } else {
  312. document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")";
  313. document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div class="allowed" onclick="buildBuilding('deuteriumstorage')">Build level ` + (+ (planet.Buildings.deuteriumstorage) + + (1)) + `</div>`;
  314. r = deuteriumstorageCost((+ (planet.Buildings.deuteriumstorage) + + (1)));
  315. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  316. resrourcesHtml = printNeededResources(r);
  317. document.getElementById("deuteriumstorageResources").innerHTML = resrourcesHtml.html + `
  318. <br>
  319. Construction time: ` + secondsToTime(t);
  320. }
  321. if (!resrourcesHtml.enough) {
  322. document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<span style="color: red;">not enough resources</span>`;
  323. }
  324. if (planet.CurrentBuild.Title !== "") {
  325. document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<span style="color: red;">building</span>`;
  326. }
  327. // ressearchlab
  328. if (planet.Buildings.ressearchlab == undefined) {
  329. document.getElementById("btnBuildRessearchLab").innerHTML = `<div class="allowed" onclick="buildBuilding('ressearchlab')">Build building</div>`;
  330. r = ressearchlabCost(1);
  331. t = constructionTime(r, 1);
  332. resrourcesHtml = printNeededResources(r);
  333. document.getElementById("ressearchlabResources").innerHTML = resrourcesHtml.html + `
  334. <br>
  335. Construction time: ` + secondsToTime(t);
  336. } else {
  337. document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")";
  338. document.getElementById("btnBuildRessearchLab").innerHTML = `<div class="allowed" onclick="buildBuilding('ressearchlab')">Build level ` + (+ (planet.Buildings.ressearchlab) + + (1)) + `</div>`;
  339. r = ressearchlabCost((+ (planet.Buildings.ressearchlab) + + (1)));
  340. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  341. resrourcesHtml = printNeededResources(r);
  342. document.getElementById("ressearchlabResources").innerHTML = resrourcesHtml.html + `
  343. <br>
  344. Construction time: ` + secondsToTime(t);
  345. }
  346. if (!resrourcesHtml.enough) {
  347. document.getElementById("btnBuildRessearchLab").innerHTML = `<span style="color: red;">not enough resources</span>`;
  348. }
  349. if (planet.CurrentBuild.Title !== "") {
  350. document.getElementById("btnBuildRessearchLab").innerHTML = `<span style="color: red;">building</span>`;
  351. }
  352. // alliancedepot
  353. if (planet.Buildings.alliancedepot == undefined) {
  354. document.getElementById("btnBuildAllianceDepot").innerHTML = `<div class="allowed" onclick="buildBuilding('alliancedepot')">Build building</div>`;
  355. r = alliancedepotCost(1);
  356. t = constructionTime(r, 1);
  357. resrourcesHtml = printNeededResources(r);
  358. document.getElementById("alliancedepotResources").innerHTML = resrourcesHtml.html + `
  359. <br>
  360. Construction time: ` + secondsToTime(t);
  361. } else {
  362. document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")";
  363. document.getElementById("btnBuildAllianceDepot").innerHTML = `<div class="allowed" onclick="buildBuilding('alliancedepot')">Build level ` + (+ (planet.Buildings.alliancedepot) + + (1)) + `</div>`;
  364. r = alliancedepotCost((+ (planet.Buildings.alliancedepot) + + (1)));
  365. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  366. resrourcesHtml = printNeededResources(r);
  367. document.getElementById("alliancedepotResources").innerHTML = resrourcesHtml.html + `
  368. <br>
  369. Construction time: ` + secondsToTime(t);
  370. }
  371. if (!resrourcesHtml.enough) {
  372. document.getElementById("btnBuildAllianceDepot").innerHTML = `<span style="color: red;">not enough resources</span>`;
  373. }
  374. if (planet.CurrentBuild.Title !== "") {
  375. document.getElementById("btnBuildAllianceDepot").innerHTML = `<span style="color: red;">building</span>`;
  376. }
  377. // missilesilo
  378. if (planet.Buildings.missilesilo == undefined) {
  379. document.getElementById("btnBuildMissileSilo").innerHTML = `<div class="allowed" onclick="buildBuilding('missilesilo')">Build building</div>`;
  380. r = missilesiloCost(1);
  381. t = constructionTime(r, 1);
  382. resrourcesHtml = printNeededResources(r);
  383. document.getElementById("missilesiloResources").innerHTML = resrourcesHtml.html + `
  384. <br>
  385. Construction time: ` + secondsToTime(t);
  386. } else {
  387. document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")";
  388. document.getElementById("btnBuildMissileSilo").innerHTML = `<div class="allowed" onclick="buildBuilding('missilesilo')">Build level ` + (+ (planet.Buildings.missilesilo) + + (1)) + `</div>`;
  389. r = missilesiloCost((+ (planet.Buildings.missilesilo) + + (1)));
  390. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  391. resrourcesHtml = printNeededResources(r);
  392. document.getElementById("missilesiloResources").innerHTML = resrourcesHtml.html + `
  393. <br>
  394. Construction time: ` + secondsToTime(t);
  395. }
  396. if (!resrourcesHtml.enough) {
  397. document.getElementById("btnBuildMissileSilo").innerHTML = `<span style="color: red;">not enough resources</span>`;
  398. }
  399. if (planet.CurrentBuild.Title !== "") {
  400. document.getElementById("btnBuildMissileSilo").innerHTML = `<span style="color: red;">building</span>`;
  401. }
  402. // spacedock
  403. if (planet.Buildings.spacedock == undefined) {
  404. document.getElementById("btnBuildSpacedock").innerHTML = `<div class="allowed" onclick="buildBuilding('spacedock')">Build building</div>`;
  405. r = spacedockCost(1);
  406. t = constructionTime(r, 1);
  407. resrourcesHtml = printNeededResources(r);
  408. document.getElementById("spacedockResources").innerHTML = resrourcesHtml.html + `
  409. <br>
  410. Construction time: ` + secondsToTime(t);
  411. } else {
  412. document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")";
  413. document.getElementById("btnBuildSpacedock").innerHTML = `<div class="allowed" onclick="buildBuilding('spacedock')">Build level ` + (+ (planet.Buildings.spacedock) + + (1)) + `</div>`;
  414. r = spacedockCost((+ (planet.Buildings.spacedock) + + (1)));
  415. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  416. resrourcesHtml = printNeededResources(r);
  417. document.getElementById("spacedockResources").innerHTML = resrourcesHtml.html + `
  418. <br>
  419. Construction time: ` + secondsToTime(t);
  420. }
  421. if (!resrourcesHtml.enough) {
  422. document.getElementById("btnBuildSpacedock").innerHTML = `<span style="color: red;">not enough resources</span>`;
  423. }
  424. if (planet.CurrentBuild.Title !== "") {
  425. document.getElementById("btnBuildSpacedock").innerHTML = `<span style="color: red;">building</span>`;
  426. }
  427. }
  428. function buildBuilding(building) {
  429. console.log("build " + building);
  430. const data = {
  431. planetid: planetid,
  432. building: building
  433. }
  434. axios.post(url + "/buildings", data, config).then(function(res) {
  435. console.log("buildings", res.data);
  436. planet = res.data.planet;
  437. // printResources(planet.Resources);
  438. printBuildings(planet);
  439. }).catch(function(error) {
  440. console.log(error);
  441. });
  442. }