Browse Source

build flow working (resources, time calculations, buttons en each case, etc)

master
arnaucube 5 years ago
parent
commit
26366f48ad
4 changed files with 336 additions and 97 deletions
  1. +17
    -15
      buildings.html
  2. +307
    -80
      buildings.js
  3. +9
    -0
      calc.js
  4. +3
    -2
      user.js

+ 17
- 15
buildings.html

@ -63,6 +63,9 @@
User Name: <span id="name"></span> User Name: <span id="name"></span>
<br> <br>
Planet Name: <span id="planetname"></span> Planet Name: <span id="planetname"></span>
<br><br>
<div id="currentBuild"></div>
<br>
<table> <table>
<tbody> <tbody>
@ -77,10 +80,9 @@
<img src="images/buildings/metalmine.png" width="120" height="120" border="0" align="top"> <img src="images/buildings/metalmine.png" width="120" height="120" border="0" align="top">
</td> </td>
<td> <td>
<a href="#">Metal Mine</a> <span id="metalmineLevel">(Level 0)</span><br>
<a href="#">Metal Mine</a> <span id="metalmineLevel"></span><br>
Used in the extraction of metal ore, metal mines are of primary importance to all emerging and established empires.<br> Used in the extraction of metal ore, metal mines are of primary importance to all emerging and established empires.<br>
<div id="metalmineResources"></div> <div id="metalmineResources"></div>
Construction Time: 00h 00m 00s
<br> <br>
</td> </td>
<td> <td>
@ -96,7 +98,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=2">Crystal Mine</a> <span id="crystalmineLevel">(Level 0)</span><br>
<a href="infos.php?gid=2">Crystal Mine</a> <span id="crystalmineLevel"></span><br>
Crystals are the main resource used to build electronic circuits and form certain alloy compounds.<br> Crystals are the main resource used to build electronic circuits and form certain alloy compounds.<br>
<div id="crystalmineResources"></div> <div id="crystalmineResources"></div>
<br> <br>
@ -114,7 +116,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=3">Deuterium Synthesizer</a> <span id="deuteriummineLevel">(Level 0)</span><br>
<a href="infos.php?gid=3">Deuterium Synthesizer</a> <span id="deuteriummineLevel"></span><br>
Deuterium is used as fuel for spaceships and is harvested in the deep sea. Deuterium is a rare substance and is thus relatively expensive.<br> Deuterium is used as fuel for spaceships and is harvested in the deep sea. Deuterium is a rare substance and is thus relatively expensive.<br>
<div id="deuteriummineResources"></div> <div id="deuteriummineResources"></div>
<br> <br>
@ -132,7 +134,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=4">Solar Plant</a> <span id="energymineLevel">(Level 0)</span><br>
<a href="infos.php?gid=4">Solar Plant</a> <span id="energymineLevel"></span><br>
Solar power plants absorb energy from solar radiation. All mines need energy to operate.<br> Solar power plants absorb energy from solar radiation. All mines need energy to operate.<br>
<div id="energymineResources"></div> <div id="energymineResources"></div>
<br> <br>
@ -150,7 +152,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=12">Fusion Reactor</a> <span id="fusionreactorLevel">(Level 0)</span><br>
<a href="infos.php?gid=12">Fusion Reactor</a> <span id="fusionreactorLevel"></span><br>
The fusion reactor uses deuterium to produce energy.<br> The fusion reactor uses deuterium to produce energy.<br>
<div id="fusionreactorResources"></div> <div id="fusionreactorResources"></div>
<br> <br>
@ -168,7 +170,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=14">Robotics Factory</a> <span id="roboticsfactoryLevel">(Level 0)</span><br>
<a href="infos.php?gid=14">Robotics Factory</a> <span id="roboticsfactoryLevel"></span><br>
Robotic factories provide construction robots to aid in the construction of buildings. Each level increases the speed of the upgrade of buildings.<br> Robotic factories provide construction robots to aid in the construction of buildings. Each level increases the speed of the upgrade of buildings.<br>
<div id="roboticsfactoryResources"></div> <div id="roboticsfactoryResources"></div>
<br> <br>
@ -186,7 +188,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=21">Shipyard</a> <span id="shipyardLevel">(Level 0)</span><br>
<a href="infos.php?gid=21">Shipyard</a> <span id="shipyardLevel"></span><br>
All types of ships and defensive facilities are built in the planetary shipyard.<br> All types of ships and defensive facilities are built in the planetary shipyard.<br>
<div id="shipyardResources"></div> <div id="shipyardResources"></div>
<br> <br>
@ -204,7 +206,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=22">Metal Storage</a> <span id="metalstorageLevel">(Level 0)</span><br>
<a href="infos.php?gid=22">Metal Storage</a> <span id="metalstorageLevel"></span><br>
Provides storage for excess metal.<br> Provides storage for excess metal.<br>
<div id="metalstorageResources"></div> <div id="metalstorageResources"></div>
<br> <br>
@ -222,7 +224,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=23">Crystal Storage</a> <span id="crystalstorageLevel">(Level 0)</span><br>
<a href="infos.php?gid=23">Crystal Storage</a> <span id="crystalstorageLevel"></span><br>
Provides storage for excess crystal.<br> Provides storage for excess crystal.<br>
<div id="crystalstorageResources"></div> <div id="crystalstorageResources"></div>
<br> <br>
@ -240,7 +242,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=24">Deuterium Tank</a> <span id="deuteriumstorageLevel">(Level 0)</span><br>
<a href="infos.php?gid=24">Deuterium Tank</a> <span id="deuteriumstorageLevel"></span><br>
Giant tanks for storing newly-extracted deuterium.<br> Giant tanks for storing newly-extracted deuterium.<br>
<div id="deuteriumstorageResources"></div> <div id="deuteriumstorageResources"></div>
<br> <br>
@ -258,7 +260,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=31">Research Lab</a> <span id="ressearchlabLevel">(Level 0)</span><br>
<a href="infos.php?gid=31">Research Lab</a> <span id="ressearchlabLevel"></span><br>
A research lab is required in order to conduct research into new technologies.<br> A research lab is required in order to conduct research into new technologies.<br>
<div id="ressearchlabResources"></div> <div id="ressearchlabResources"></div>
<br> <br>
@ -276,7 +278,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=34">Alliance Depot</a> <span id="alliancedepotLevel">(Level 0)</span><br>
<a href="infos.php?gid=34">Alliance Depot</a> <span id="alliancedepotLevel"></span><br>
The alliance depot supplies fuel to friendly fleets in orbit helping with defense.<br> The alliance depot supplies fuel to friendly fleets in orbit helping with defense.<br>
<div id="alliancedepotResources"></div> <div id="alliancedepotResources"></div>
<br> <br>
@ -294,7 +296,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=44">Missile Silo</a> <span id="missilesiloLevel">(Level 0)</span><br>
<a href="infos.php?gid=44">Missile Silo</a> <span id="missilesiloLevel"></span><br>
Perfect to store missiles<br> Perfect to store missiles<br>
<div id="missilesiloResources"></div> <div id="missilesiloResources"></div>
<br> <br>
@ -312,7 +314,7 @@
</a> </a>
</td> </td>
<td> <td>
<a href="infos.php?gid=80">Spacedock</a> <span id="spacedockLevel">(Level 0)</span><br>
<a href="infos.php?gid=80">Spacedock</a> <span id="spacedockLevel"></span><br>
The space dock offers the possibility to repair destroyed ships that have left a wreckage field as a result of a battle. The maximum repair time is 12 hours, but it takes at least 30 minutes until the ships can be put into service. The space dock offers the possibility to repair destroyed ships that have left a wreckage field as a result of a battle. The maximum repair time is 12 hours, but it takes at least 30 minutes until the ships can be put into service.
<br>From <br>From
the formation of the wreck field there are 3 days time to start the repair. The repaired ships must be actively put back into service after the repair has expired. If this does not happen, they automatically return to service after 3 the formation of the wreck field there are 3 days time to start the repair. The repaired ships must be actively put back into service after the repair has expired. If this does not happen, they automatically return to service after 3

+ 307
- 80
buildings.js

@ -1,216 +1,443 @@
function secondsToTime(secs)
{
var h = Math.floor(secs / (60 * 60));
var divisor_for_minutes = secs % (60 * 60);
var m = Math.floor(divisor_for_minutes / 60);
var divisor_for_seconds = divisor_for_minutes % 60;
var s = Math.ceil(divisor_for_seconds);
return h + "h " + m + "m " + s + "s";
}
function printResources(r) { function printResources(r) {
let enough = true;
let html = ""; let html = "";
html += `Requires:`; html += `Requires:`;
if (r.Metal <= user.Resources.Metal) { if (r.Metal <= user.Resources.Metal) {
html += ` Metal: <b style="color:lime;">` + r.Metal + `</b>`; html += ` Metal: <b style="color:lime;">` + r.Metal + `</b>`;
} else { } else {
enough = false;
html += ` Metal: <b style="color:red;">` + r.Metal + `</b>`; html += ` Metal: <b style="color:red;">` + r.Metal + `</b>`;
} }
if (r.Crystal <= user.Resources.Crystal) { if (r.Crystal <= user.Resources.Crystal) {
html += ` Crystal: <b style="color:lime;">` + r.Crystal + `</b>`; html += ` Crystal: <b style="color:lime;">` + r.Crystal + `</b>`;
} else { } else {
enough = false;
html += ` Crystal: <b style="color:red;">` + r.Crystal + `</b>`; html += ` Crystal: <b style="color:red;">` + r.Crystal + `</b>`;
} }
if (r.Deuterium <= user.Resources.Deuterium) { if (r.Deuterium <= user.Resources.Deuterium) {
html += ` Deuterium: <b style="color:lime;">` + r.Deuterium + `</b>`; html += ` Deuterium: <b style="color:lime;">` + r.Deuterium + `</b>`;
} else { } else {
enough = false;
html += ` Deuterium: <b style="color:red;">` + r.Deuterium + `</b>`; html += ` Deuterium: <b style="color:red;">` + r.Deuterium + `</b>`;
} }
if (r.Energy <= user.Resources.Energy) { if (r.Energy <= user.Resources.Energy) {
html += ` Energy: <b style="color: lime;">` + r.Energy + `</b>`; html += ` Energy: <b style="color: lime;">` + r.Energy + `</b>`;
} else { } else {
enough = false;
html += ` Energy: <b style="color: red;">` + r.Energy + `</b>`; html += ` Energy: <b style="color: red;">` + r.Energy + `</b>`;
} }
return html;
return {html, enough};
} }
function printPlanet(planet) { function printPlanet(planet) {
let r = {}; let r = {};
document.getElementById("planetname").innerHTML = planet.Name; document.getElementById("planetname").innerHTML = planet.Name;
if (planet.CurrentBuild.Title !== "") {
document.getElementById("currentBuild").innerHTML = `
Currently building: <b>` + planet.CurrentBuild.Title + `</b>
<br>
Finishes at: <b>` + planet.CurrentBuild.Ends + `</b>
`
} else {
document.getElementById("currentBuild").innerHTML = "";
}
// metalmine // metalmine
document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")";
if (planet.Buildings.metalmine == undefined) { if (planet.Buildings.metalmine == undefined) {
document.getElementById("btnBuildMetalMine").innerHTML = `<div onclick="buildBuilding('metalmine')">Build building</div>`;
document.getElementById("btnBuildMetalMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('metalmine')">Build building</div>`;
r = metalmineCost(1); r = metalmineCost(1);
document.getElementById("metalmineResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("metalmineResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildMetalMine").innerHTML = `<div onclick="buildBuilding('metalmine')">Build level ` + (+ (planet.Buildings.metalmine) + + (1)) + `</div>`;
document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")";
document.getElementById("btnBuildMetalMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('metalmine')">Build level ` + (+ (planet.Buildings.metalmine) + + (1)) + `</div>`;
r = metalmineCost((+ (planet.Buildings.metalmine) + + (1))); r = metalmineCost((+ (planet.Buildings.metalmine) + + (1)));
document.getElementById("metalmineResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.metalmine) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("metalmineResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildMetalMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildMetalMine").innerHTML = `<span style="color: red;">building</span>`;
} }
// crystalmine // crystalmine
document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")";
if (planet.Buildings.crystalmine == undefined) { if (planet.Buildings.crystalmine == undefined) {
document.getElementById("btnBuildCrystalMine").innerHTML = `<div onclick="buildBuilding('crystalmine')">Build building</div>`;
document.getElementById("btnBuildCrystalMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('crystalmine')">Build building</div>`;
r = crystalmineCost(1); r = crystalmineCost(1);
document.getElementById("crystalmineResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("crystalmineResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildCrystalMine").innerHTML = `<div onclick="buildBuilding('crystalmine')">Build level ` + (+ (planet.Buildings.crystalmine) + + (1)) + `</div>`;
document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")";
document.getElementById("btnBuildCrystalMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('crystalmine')">Build level ` + (+ (planet.Buildings.crystalmine) + + (1)) + `</div>`;
r = crystalmineCost((+ (planet.Buildings.crystalmine) + + (1))); r = crystalmineCost((+ (planet.Buildings.crystalmine) + + (1)));
document.getElementById("crystalmineResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.crystalmine) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("crystalmineResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildCrystalMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildCrystalMine").innerHTML = `<span style="color: red;">building</span>`;
} }
// deuteriummine
document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")";
// deuteriummine{
if (planet.Buildings.deuteriummine == undefined) { if (planet.Buildings.deuteriummine == undefined) {
document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div onclick="buildBuilding('deuteriummine')">Build building</div>`;
document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('deuteriummine')">Build building</div>`;
r = deuteriummineCost(1); r = deuteriummineCost(1);
document.getElementById("deuteriummineResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("deuteriummineResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div onclick="buildBuilding('deuteriummine')">Build level ` + (+ (planet.Buildings.deuteriummine) + + (1)) + `</div>`;
document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")";
document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('deuteriummine')">Build level ` + (+ (planet.Buildings.deuteriummine) + + (1)) + `</div>`;
r = deuteriummineCost((+ (planet.Buildings.deuteriummine) + + (1))); r = deuteriummineCost((+ (planet.Buildings.deuteriummine) + + (1)));
document.getElementById("deuteriummineResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.deuteriummine) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("deuteriummineResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildDeuteriumMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildDeuteriumMine").innerHTML = `<span style="color: red;">building</span>`;
} }
// energymine // energymine
document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")";
if (planet.Buildings.energymine == undefined) { if (planet.Buildings.energymine == undefined) {
document.getElementById("btnBuildEnergyMine").innerHTML = `<div onclick="buildBuilding('energymine')">Build building</div>`;
document.getElementById("btnBuildEnergyMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('energymine')">Build building</div>`;
r = energymineCost(1); r = energymineCost(1);
document.getElementById("energymineResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("energymineResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildEnergyMine").innerHTML = `<div onclick="buildBuilding('energymine')">Build level ` + (+ (planet.Buildings.energymine) + + (1)) + `</div>`;
document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")";
document.getElementById("btnBuildEnergyMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('energymine')">Build level ` + (+ (planet.Buildings.energymine) + + (1)) + `</div>`;
r = energymineCost((+ (planet.Buildings.energymine) + + (1))); r = energymineCost((+ (planet.Buildings.energymine) + + (1)));
document.getElementById("energymineResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.energymine) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("energymineResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildEnergyMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildEnergyMine").innerHTML = `<span style="color: red;">building</span>`;
} }
// fusionreactor // fusionreactor
document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")";
if (planet.Buildings.fusionreactor == undefined) { if (planet.Buildings.fusionreactor == undefined) {
document.getElementById("btnBuildFusionReactor").innerHTML = `<div onclick="buildBuilding('fusionreactor')">Build building</div>`;
document.getElementById("btnBuildFusionReactor").innerHTML = `<div style="color:lime;" onclick="buildBuilding('fusionreactor')">Build building</div>`;
r = fusionreactorCost(1); r = fusionreactorCost(1);
document.getElementById("fusionreactorResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("fusionreactorResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildFusionReactor").innerHTML = `<div onclick="buildBuilding('fusionreactor')">Build level ` + (+ (planet.Buildings.fusionreactor) + + (1)) + `</div>`;
document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")";
document.getElementById("btnBuildFusionReactor").innerHTML = `<div style="color:lime;" onclick="buildBuilding('fusionreactor')">Build level ` + (+ (planet.Buildings.fusionreactor) + + (1)) + `</div>`;
r = fusionreactorCost((+ (planet.Buildings.fusionreactor) + + (1))); r = fusionreactorCost((+ (planet.Buildings.fusionreactor) + + (1)));
document.getElementById("fusionreactorResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.fusionreactor) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("fusionreactorResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildFusionReactor").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildFusionReactor").innerHTML = `<span style="color: red;">building</span>`;
} }
// roboticsfactory // roboticsfactory
document.getElementById("roboticsfactoryLevel").innerHTML = "(Level " + planet.Buildings.roboticsfactory + ")";
if (planet.Buildings.roboticsfactory == undefined) { if (planet.Buildings.roboticsfactory == undefined) {
document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div onclick="buildBuilding('roboticsfactory')">Build building</div>`;
document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div style="color:lime;" onclick="buildBuilding('roboticsfactory')">Build building</div>`;
r = roboticsfactoryCost(1); r = roboticsfactoryCost(1);
document.getElementById("roboticsfactoryResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("roboticsfactoryResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div onclick="buildBuilding('roboticsfactory')">Build level ` + (+ (planet.Buildings.roboticsfactory) + + (1)) + `</div>`;
document.getElementById("roboticsfactoryLevel").innerHTML = "(Level " + planet.Buildings.roboticsfactory + ")";
document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div style="color:lime;" onclick="buildBuilding('roboticsfactory')">Build level ` + (+ (planet.Buildings.roboticsfactory) + + (1)) + `</div>`;
r = roboticsfactoryCost((+ (planet.Buildings.roboticsfactory) + + (1))); r = roboticsfactoryCost((+ (planet.Buildings.roboticsfactory) + + (1)));
document.getElementById("roboticsfactoryResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("roboticsfactoryResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildRoboticsFactory").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildRoboticsFactory").innerHTML = `<span style="color: red;">building</span>`;
} }
// shipyard // shipyard
document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")";
if (planet.Buildings.shipyard == undefined) { if (planet.Buildings.shipyard == undefined) {
document.getElementById("btnBuildShipyard").innerHTML = `<div onclick="buildBuilding('shipyard')">Build building</div>`;
document.getElementById("btnBuildShipyard").innerHTML = `<div style="color:lime;" onclick="buildBuilding('shipyard')">Build building</div>`;
r = shipyardCost(1); r = shipyardCost(1);
document.getElementById("shipyardResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("shipyardResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildShipyard").innerHTML = `<div onclick="buildBuilding('shipyard')">Build level ` + (+ (planet.Buildings.shipyard) + + (1)) + `</div>`;
document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")";
document.getElementById("btnBuildShipyard").innerHTML = `<div style="color:lime;" onclick="buildBuilding('shipyard')">Build level ` + (+ (planet.Buildings.shipyard) + + (1)) + `</div>`;
r = shipyardCost((+ (planet.Buildings.shipyard) + + (1))); r = shipyardCost((+ (planet.Buildings.shipyard) + + (1)));
document.getElementById("shipyardResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.shipyard) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("shipyardResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildShipyard").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildShipyard").innerHTML = `<span style="color: red;">building</span>`;
} }
// metalstorage // metalstorage
document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")";
if (planet.Buildings.metalstorage == undefined) { if (planet.Buildings.metalstorage == undefined) {
document.getElementById("btnBuildMetalStorage").innerHTML = `<div onclick="buildBuilding('metalstorage')">Build building</div>`;
document.getElementById("btnBuildMetalStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('metalstorage')">Build building</div>`;
r = metalstorageCost(1); r = metalstorageCost(1);
document.getElementById("metalstorageResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("metalstorageResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildMetalStorage").innerHTML = `<div onclick="buildBuilding('metalstorage')">Build level ` + (+ (planet.Buildings.metalstorage) + + (1)) + `</div>`;
document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")";
document.getElementById("btnBuildMetalStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('metalstorage')">Build level ` + (+ (planet.Buildings.metalstorage) + + (1)) + `</div>`;
r = metalstorageCost((+ (planet.Buildings.metalstorage) + + (1))); r = metalstorageCost((+ (planet.Buildings.metalstorage) + + (1)));
document.getElementById("metalstorageResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.metalstorage) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("metalstorageResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildMetalStorage").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildMetalStorage").innerHTML = `<span style="color: red;">building</span>`;
} }
// crystalstorage // crystalstorage
document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")";
if (planet.Buildings.crystalstorage == undefined) { if (planet.Buildings.crystalstorage == undefined) {
document.getElementById("btnBuildCrystalStorage").innerHTML = `<div onclick="buildBuilding('crystalstorage')">Build building</div>`;
document.getElementById("btnBuildCrystalStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('crystalstorage')">Build building</div>`;
r = crystalstorageCost(1); r = crystalstorageCost(1);
document.getElementById("crystalstorageResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("crystalstorageResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildCrystalStorage").innerHTML = `<div onclick="buildBuilding('crystalstorage')">Build level ` + (+ (planet.Buildings.crystalstorage) + + (1)) + `</div>`;
document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")";
document.getElementById("btnBuildCrystalStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('crystalstorage')">Build level ` + (+ (planet.Buildings.crystalstorage) + + (1)) + `</div>`;
r = crystalstorageCost((+ (planet.Buildings.crystalstorage) + + (1))); r = crystalstorageCost((+ (planet.Buildings.crystalstorage) + + (1)));
document.getElementById("crystalstorageResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.crystalstorage) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("crystalstorageResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildCrystalStorage").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildCrystalStorage").innerHTML = `<span style="color: red;">building</span>`;
} }
// deuteriumstorage // deuteriumstorage
document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")";
if (planet.Buildings.deuteriumstorage == undefined) { if (planet.Buildings.deuteriumstorage == undefined) {
document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div onclick="buildBuilding('deuteriumstorage')">Build building</div>`;
document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('deuteriumstorage')">Build building</div>`;
r = deuteriumstorageCost(1); r = deuteriumstorageCost(1);
document.getElementById("deuteriumstorageResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("deuteriumstorageResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div onclick="buildBuilding('deuteriumstorage')">Build level ` + (+ (planet.Buildings.deuteriumstorage) + + (1)) + `</div>`;
document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")";
document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('deuteriumstorage')">Build level ` + (+ (planet.Buildings.deuteriumstorage) + + (1)) + `</div>`;
r = deuteriumstorageCost((+ (planet.Buildings.deuteriumstorage) + + (1))); r = deuteriumstorageCost((+ (planet.Buildings.deuteriumstorage) + + (1)));
document.getElementById("deuteriumstorageResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.deuteriumstorage) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("deuteriumstorageResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<span style="color: red;">building</span>`;
} }
// ressearchlab // ressearchlab
document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")";
if (planet.Buildings.ressearchlab == undefined) { if (planet.Buildings.ressearchlab == undefined) {
document.getElementById("btnBuildRessearchLab").innerHTML = `<div onclick="buildBuilding('ressearchlab')">Build building</div>`;
document.getElementById("btnBuildRessearchLab").innerHTML = `<div style="color:lime;" onclick="buildBuilding('ressearchlab')">Build building</div>`;
r = ressearchlabCost(1); r = ressearchlabCost(1);
document.getElementById("ressearchlabResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("ressearchlabResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildRessearchLab").innerHTML = `<div onclick="buildBuilding('ressearchlab')">Build level ` + (+ (planet.Buildings.ressearchlab) + + (1)) + `</div>`;
document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")";
document.getElementById("btnBuildRessearchLab").innerHTML = `<div style="color:lime;" onclick="buildBuilding('ressearchlab')">Build level ` + (+ (planet.Buildings.ressearchlab) + + (1)) + `</div>`;
r = ressearchlabCost((+ (planet.Buildings.ressearchlab) + + (1))); r = ressearchlabCost((+ (planet.Buildings.ressearchlab) + + (1)));
document.getElementById("ressearchlabResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.ressearchlab) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("ressearchlabResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildRessearchLab").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildRessearchLab").innerHTML = `<span style="color: red;">building</span>`;
} }
// alliancedepot // alliancedepot
document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")";
if (planet.Buildings.alliancedepot == undefined) { if (planet.Buildings.alliancedepot == undefined) {
document.getElementById("btnBuildAllianceDepot").innerHTML = `<div onclick="buildBuilding('alliancedepot')">Build building</div>`;
document.getElementById("btnBuildAllianceDepot").innerHTML = `<div style="color:lime;" onclick="buildBuilding('alliancedepot')">Build building</div>`;
r = alliancedepotCost(1); r = alliancedepotCost(1);
document.getElementById("alliancedepotResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("alliancedepotResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildAllianceDepot").innerHTML = `<div onclick="buildBuilding('alliancedepot')">Build level ` + (+ (planet.Buildings.alliancedepot) + + (1)) + `</div>`;
document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")";
document.getElementById("btnBuildAllianceDepot").innerHTML = `<div style="color:lime;" onclick="buildBuilding('alliancedepot')">Build level ` + (+ (planet.Buildings.alliancedepot) + + (1)) + `</div>`;
r = alliancedepotCost((+ (planet.Buildings.alliancedepot) + + (1))); r = alliancedepotCost((+ (planet.Buildings.alliancedepot) + + (1)));
document.getElementById("alliancedepotResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.alliancedepot) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("alliancedepotResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildAllianceDepot").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildAllianceDepot").innerHTML = `<span style="color: red;">building</span>`;
} }
// missilesilo // missilesilo
document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")";
if (planet.Buildings.missilesilo == undefined) { if (planet.Buildings.missilesilo == undefined) {
document.getElementById("btnBuildMissileSilo").innerHTML = `<div onclick="buildBuilding('missilesilo')">Build building</div>`;
document.getElementById("btnBuildMissileSilo").innerHTML = `<div style="color:lime;" onclick="buildBuilding('missilesilo')">Build building</div>`;
r = missilesiloCost(1); r = missilesiloCost(1);
document.getElementById("missilesiloResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("missilesiloResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildMissileSilo").innerHTML = `<div onclick="buildBuilding('missilesilo')">Build level ` + (+ (planet.Buildings.missilesilo) + + (1)) + `</div>`;
document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")";
document.getElementById("btnBuildMissileSilo").innerHTML = `<div style="color:lime;" onclick="buildBuilding('missilesilo')">Build level ` + (+ (planet.Buildings.missilesilo) + + (1)) + `</div>`;
r = missilesiloCost((+ (planet.Buildings.missilesilo) + + (1))); r = missilesiloCost((+ (planet.Buildings.missilesilo) + + (1)));
document.getElementById("missilesiloResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.missilesilo) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("missilesiloResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildMissileSilo").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildMissileSilo").innerHTML = `<span style="color: red;">building</span>`;
} }
// spacedock // spacedock
document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")";
if (planet.Buildings.spacedock == undefined) { if (planet.Buildings.spacedock == undefined) {
document.getElementById("btnBuildSpacedock").innerHTML = `<div onclick="buildBuilding('spacedock')">Build building</div>`;
document.getElementById("btnBuildSpacedock").innerHTML = `<div style="color:lime;" onclick="buildBuilding('spacedock')">Build building</div>`;
r = spacedockCost(1); r = spacedockCost(1);
document.getElementById("spacedockResources").innerHTML = printResources(r);
t = constructionTime(r, 1);
resrourcesHtml = printResources(r);
document.getElementById("spacedockResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
} else { } else {
document.getElementById("btnBuildSpacedock").innerHTML = `<div onclick="buildBuilding('spacedock')">Build level ` + (+ (planet.Buildings.spacedock) + + (1)) + `</div>`;
document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")";
document.getElementById("btnBuildSpacedock").innerHTML = `<div style="color:lime;" onclick="buildBuilding('spacedock')">Build level ` + (+ (planet.Buildings.spacedock) + + (1)) + `</div>`;
r = spacedockCost((+ (planet.Buildings.spacedock) + + (1))); r = spacedockCost((+ (planet.Buildings.spacedock) + + (1)));
document.getElementById("spacedockResources").innerHTML = printResources(r);
t = constructionTime(r, (+ (planet.Buildings.spacedock) + + (1)));
resrourcesHtml = printResources(r);
document.getElementById("spacedockResources").innerHTML = resrourcesHtml.html + `
<br>
Construction time: ` + secondsToTime(t);
}
if (!resrourcesHtml.enough) {
document.getElementById("btnBuildSpacedock").innerHTML = `<span style="color: red;">not enough resources</span>`;
}
if (planet.CurrentBuild.Title !== "") {
document.getElementById("btnBuildSpacedock").innerHTML = `<span style="color: red;">building</span>`;
} }
} }
let planetid = localStorage.getItem("mainplanet"); let planetid = localStorage.getItem("mainplanet");
let planet = {}; let planet = {};
// get user data // get user data
axios.get(url + "/planets/" + planetid, config).then(function(res) {
console.log("buildings", res.data);
planet = res.data.planet;
printPlanet(planet);
}).catch(function(error) {
console.log(error);
});
function getPlanet() {
axios.get(url + "/planets/" + planetid, config).then(function(res) {
console.log("buildings", res.data);
planet = res.data.planet;
printPlanet(planet);
}).catch(function(error) {
console.log(error);
});
}
getPlanet();
setInterval(getPlanet, 5000);
function buildBuilding(building) { function buildBuilding(building) {
console.log("build " + building); console.log("build " + building);

+ 9
- 0
calc.js

@ -1,3 +1,5 @@
const universespeed = 1;
function metalmineCost(lvl) { function metalmineCost(lvl) {
const base = { const base = {
Metal: 60, Metal: 60,
@ -209,3 +211,10 @@ function spacedockCost(lvl) {
cost.Energy = Math.floor(base.Energy * 2**(lvl-1)); cost.Energy = Math.floor(base.Energy * 2**(lvl-1));
return cost; return cost;
} }
function constructionTime(r, roboticsLvl) {
const naniteLvl = 1;
// T(h) = (metal + crystal) / (2500 * (1+roboticsLvl) * 2^naniteLvl * universespeed)
tHours = (r.Metal + r.Crystal) / (2500 * (1 + roboticsLvl) * 2**naniteLvl * universespeed);
return Math.floor(tHours * 3600);
}

+ 3
- 2
user.js

@ -32,12 +32,13 @@ function getUser() {
document.getElementById("deuterium").innerHTML = user.Resources.Deuterium; document.getElementById("deuterium").innerHTML = user.Resources.Deuterium;
document.getElementById("energy").innerHTML = user.Resources.Energy; document.getElementById("energy").innerHTML = user.Resources.Energy;
if (localStorage.getItem("mainplanet") === null) {
// if (localStorage.getItem("mainplanet") === null) {
localStorage.setItem("mainplanet", res.data.user.Planets[0]); localStorage.setItem("mainplanet", res.data.user.Planets[0]);
}
// }
}).catch(function(error) { }).catch(function(error) {
console.log(error); console.log(error);
}); });
} }
getUser(); getUser();
setInterval(getUser, 5000); setInterval(getUser, 5000);

Loading…
Cancel
Save