From 26366f48add28568b2358c6c0070082756b98cf5 Mon Sep 17 00:00:00 2001 From: arnaucube Date: Sun, 16 Jun 2019 15:05:28 +0200 Subject: [PATCH] build flow working (resources, time calculations, buttons en each case, etc) --- buildings.html | 32 ++-- buildings.js | 387 +++++++++++++++++++++++++++++++++++++++---------- calc.js | 9 ++ user.js | 5 +- 4 files changed, 336 insertions(+), 97 deletions(-) diff --git a/buildings.html b/buildings.html index e5d0ec7..1d1e322 100644 --- a/buildings.html +++ b/buildings.html @@ -63,6 +63,9 @@ User Name:
Planet Name: +

+
+
@@ -77,10 +80,9 @@
- Metal Mine (Level 0)
+ Metal Mine
Used in the extraction of metal ore, metal mines are of primary importance to all emerging and established empires.
- Construction Time: 00h 00m 00s
@@ -96,7 +98,7 @@ - Crystal Mine (Level 0)
+ Crystal Mine
Crystals are the main resource used to build electronic circuits and form certain alloy compounds.

@@ -114,7 +116,7 @@
- Deuterium Synthesizer (Level 0)
+ Deuterium Synthesizer
Deuterium is used as fuel for spaceships and is harvested in the deep sea. Deuterium is a rare substance and is thus relatively expensive.

@@ -132,7 +134,7 @@
- Solar Plant (Level 0)
+ Solar Plant
Solar power plants absorb energy from solar radiation. All mines need energy to operate.

@@ -150,7 +152,7 @@
- Fusion Reactor (Level 0)
+ Fusion Reactor
The fusion reactor uses deuterium to produce energy.

@@ -168,7 +170,7 @@
- Robotics Factory (Level 0)
+ Robotics Factory
Robotic factories provide construction robots to aid in the construction of buildings. Each level increases the speed of the upgrade of buildings.

@@ -186,7 +188,7 @@
- Shipyard (Level 0)
+ Shipyard
All types of ships and defensive facilities are built in the planetary shipyard.

@@ -204,7 +206,7 @@
- Metal Storage (Level 0)
+ Metal Storage
Provides storage for excess metal.

@@ -222,7 +224,7 @@
- Crystal Storage (Level 0)
+ Crystal Storage
Provides storage for excess crystal.

@@ -240,7 +242,7 @@
- Deuterium Tank (Level 0)
+ Deuterium Tank
Giant tanks for storing newly-extracted deuterium.

@@ -258,7 +260,7 @@
- Research Lab (Level 0)
+ Research Lab
A research lab is required in order to conduct research into new technologies.

@@ -276,7 +278,7 @@
- Alliance Depot (Level 0)
+ Alliance Depot
The alliance depot supplies fuel to friendly fleets in orbit helping with defense.

@@ -294,7 +296,7 @@
- Missile Silo (Level 0)
+ Missile Silo
Perfect to store missiles

@@ -312,7 +314,7 @@
- Spacedock (Level 0)
+ Spacedock
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.
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 diff --git a/buildings.js b/buildings.js index c694e95..092be53 100644 --- a/buildings.js +++ b/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) { + let enough = true; let html = ""; html += `Requires:`; if (r.Metal <= user.Resources.Metal) { html += ` Metal: ` + r.Metal + ``; } else { + enough = false; html += ` Metal: ` + r.Metal + ``; } if (r.Crystal <= user.Resources.Crystal) { html += ` Crystal: ` + r.Crystal + ``; } else { + enough = false; html += ` Crystal: ` + r.Crystal + ``; } if (r.Deuterium <= user.Resources.Deuterium) { html += ` Deuterium: ` + r.Deuterium + ``; } else { + enough = false; html += ` Deuterium: ` + r.Deuterium + ``; } if (r.Energy <= user.Resources.Energy) { html += ` Energy: ` + r.Energy + ``; } else { + enough = false; html += ` Energy: ` + r.Energy + ``; } - return html; + return {html, enough}; } function printPlanet(planet) { let r = {}; document.getElementById("planetname").innerHTML = planet.Name; + if (planet.CurrentBuild.Title !== "") { + document.getElementById("currentBuild").innerHTML = ` + Currently building: ` + planet.CurrentBuild.Title + ` +
+ Finishes at: ` + planet.CurrentBuild.Ends + ` + ` + } else { + document.getElementById("currentBuild").innerHTML = ""; + } + // metalmine - document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")"; if (planet.Buildings.metalmine == undefined) { - document.getElementById("btnBuildMetalMine").innerHTML = `
Build building
`; + document.getElementById("btnBuildMetalMine").innerHTML = `
Build building
`; r = metalmineCost(1); - document.getElementById("metalmineResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("metalmineResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildMetalMine").innerHTML = `
Build level ` + (+ (planet.Buildings.metalmine) + + (1)) + `
`; + document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")"; + document.getElementById("btnBuildMetalMine").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildMetalMine").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildMetalMine").innerHTML = `building`; } // crystalmine - document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")"; if (planet.Buildings.crystalmine == undefined) { - document.getElementById("btnBuildCrystalMine").innerHTML = `
Build building
`; + document.getElementById("btnBuildCrystalMine").innerHTML = `
Build building
`; r = crystalmineCost(1); - document.getElementById("crystalmineResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("crystalmineResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildCrystalMine").innerHTML = `
Build level ` + (+ (planet.Buildings.crystalmine) + + (1)) + `
`; + document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")"; + document.getElementById("btnBuildCrystalMine").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildCrystalMine").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildCrystalMine").innerHTML = `building`; } - // deuteriummine - document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")"; + // deuteriummine{ if (planet.Buildings.deuteriummine == undefined) { - document.getElementById("btnBuildDeuteriumMine").innerHTML = `
Build building
`; + document.getElementById("btnBuildDeuteriumMine").innerHTML = `
Build building
`; r = deuteriummineCost(1); - document.getElementById("deuteriummineResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("deuteriummineResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildDeuteriumMine").innerHTML = `
Build level ` + (+ (planet.Buildings.deuteriummine) + + (1)) + `
`; + document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")"; + document.getElementById("btnBuildDeuteriumMine").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildDeuteriumMine").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildDeuteriumMine").innerHTML = `building`; } // energymine - document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")"; if (planet.Buildings.energymine == undefined) { - document.getElementById("btnBuildEnergyMine").innerHTML = `
Build building
`; + document.getElementById("btnBuildEnergyMine").innerHTML = `
Build building
`; r = energymineCost(1); - document.getElementById("energymineResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("energymineResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildEnergyMine").innerHTML = `
Build level ` + (+ (planet.Buildings.energymine) + + (1)) + `
`; + document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")"; + document.getElementById("btnBuildEnergyMine").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildEnergyMine").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildEnergyMine").innerHTML = `building`; } // fusionreactor - document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")"; if (planet.Buildings.fusionreactor == undefined) { - document.getElementById("btnBuildFusionReactor").innerHTML = `
Build building
`; + document.getElementById("btnBuildFusionReactor").innerHTML = `
Build building
`; r = fusionreactorCost(1); - document.getElementById("fusionreactorResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("fusionreactorResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildFusionReactor").innerHTML = `
Build level ` + (+ (planet.Buildings.fusionreactor) + + (1)) + `
`; + document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")"; + document.getElementById("btnBuildFusionReactor").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildFusionReactor").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildFusionReactor").innerHTML = `building`; } // roboticsfactory - document.getElementById("roboticsfactoryLevel").innerHTML = "(Level " + planet.Buildings.roboticsfactory + ")"; if (planet.Buildings.roboticsfactory == undefined) { - document.getElementById("btnBuildRoboticsFactory").innerHTML = `
Build building
`; + document.getElementById("btnBuildRoboticsFactory").innerHTML = `
Build building
`; r = roboticsfactoryCost(1); - document.getElementById("roboticsfactoryResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("roboticsfactoryResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildRoboticsFactory").innerHTML = `
Build level ` + (+ (planet.Buildings.roboticsfactory) + + (1)) + `
`; + document.getElementById("roboticsfactoryLevel").innerHTML = "(Level " + planet.Buildings.roboticsfactory + ")"; + document.getElementById("btnBuildRoboticsFactory").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildRoboticsFactory").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildRoboticsFactory").innerHTML = `building`; } // shipyard - document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")"; if (planet.Buildings.shipyard == undefined) { - document.getElementById("btnBuildShipyard").innerHTML = `
Build building
`; + document.getElementById("btnBuildShipyard").innerHTML = `
Build building
`; r = shipyardCost(1); - document.getElementById("shipyardResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("shipyardResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildShipyard").innerHTML = `
Build level ` + (+ (planet.Buildings.shipyard) + + (1)) + `
`; + document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")"; + document.getElementById("btnBuildShipyard").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildShipyard").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildShipyard").innerHTML = `building`; } // metalstorage - document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")"; if (planet.Buildings.metalstorage == undefined) { - document.getElementById("btnBuildMetalStorage").innerHTML = `
Build building
`; + document.getElementById("btnBuildMetalStorage").innerHTML = `
Build building
`; r = metalstorageCost(1); - document.getElementById("metalstorageResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("metalstorageResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildMetalStorage").innerHTML = `
Build level ` + (+ (planet.Buildings.metalstorage) + + (1)) + `
`; + document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")"; + document.getElementById("btnBuildMetalStorage").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildMetalStorage").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildMetalStorage").innerHTML = `building`; } // crystalstorage - document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")"; if (planet.Buildings.crystalstorage == undefined) { - document.getElementById("btnBuildCrystalStorage").innerHTML = `
Build building
`; + document.getElementById("btnBuildCrystalStorage").innerHTML = `
Build building
`; r = crystalstorageCost(1); - document.getElementById("crystalstorageResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("crystalstorageResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildCrystalStorage").innerHTML = `
Build level ` + (+ (planet.Buildings.crystalstorage) + + (1)) + `
`; + document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")"; + document.getElementById("btnBuildCrystalStorage").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildCrystalStorage").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildCrystalStorage").innerHTML = `building`; } // deuteriumstorage - document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")"; if (planet.Buildings.deuteriumstorage == undefined) { - document.getElementById("btnBuildDeuteriumStorage").innerHTML = `
Build building
`; + document.getElementById("btnBuildDeuteriumStorage").innerHTML = `
Build building
`; r = deuteriumstorageCost(1); - document.getElementById("deuteriumstorageResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("deuteriumstorageResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildDeuteriumStorage").innerHTML = `
Build level ` + (+ (planet.Buildings.deuteriumstorage) + + (1)) + `
`; + document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")"; + document.getElementById("btnBuildDeuteriumStorage").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildDeuteriumStorage").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildDeuteriumStorage").innerHTML = `building`; } // ressearchlab - document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")"; if (planet.Buildings.ressearchlab == undefined) { - document.getElementById("btnBuildRessearchLab").innerHTML = `
Build building
`; + document.getElementById("btnBuildRessearchLab").innerHTML = `
Build building
`; r = ressearchlabCost(1); - document.getElementById("ressearchlabResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("ressearchlabResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildRessearchLab").innerHTML = `
Build level ` + (+ (planet.Buildings.ressearchlab) + + (1)) + `
`; + document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")"; + document.getElementById("btnBuildRessearchLab").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildRessearchLab").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildRessearchLab").innerHTML = `building`; } // alliancedepot - document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")"; if (planet.Buildings.alliancedepot == undefined) { - document.getElementById("btnBuildAllianceDepot").innerHTML = `
Build building
`; + document.getElementById("btnBuildAllianceDepot").innerHTML = `
Build building
`; r = alliancedepotCost(1); - document.getElementById("alliancedepotResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("alliancedepotResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildAllianceDepot").innerHTML = `
Build level ` + (+ (planet.Buildings.alliancedepot) + + (1)) + `
`; + document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")"; + document.getElementById("btnBuildAllianceDepot").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildAllianceDepot").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildAllianceDepot").innerHTML = `building`; } // missilesilo - document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")"; if (planet.Buildings.missilesilo == undefined) { - document.getElementById("btnBuildMissileSilo").innerHTML = `
Build building
`; + document.getElementById("btnBuildMissileSilo").innerHTML = `
Build building
`; r = missilesiloCost(1); - document.getElementById("missilesiloResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("missilesiloResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildMissileSilo").innerHTML = `
Build level ` + (+ (planet.Buildings.missilesilo) + + (1)) + `
`; + document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")"; + document.getElementById("btnBuildMissileSilo").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildMissileSilo").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildMissileSilo").innerHTML = `building`; } // spacedock - document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")"; if (planet.Buildings.spacedock == undefined) { - document.getElementById("btnBuildSpacedock").innerHTML = `
Build building
`; + document.getElementById("btnBuildSpacedock").innerHTML = `
Build building
`; r = spacedockCost(1); - document.getElementById("spacedockResources").innerHTML = printResources(r); + t = constructionTime(r, 1); + resrourcesHtml = printResources(r); + document.getElementById("spacedockResources").innerHTML = resrourcesHtml.html + ` +
+ Construction time: ` + secondsToTime(t); } else { - document.getElementById("btnBuildSpacedock").innerHTML = `
Build level ` + (+ (planet.Buildings.spacedock) + + (1)) + `
`; + document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")"; + document.getElementById("btnBuildSpacedock").innerHTML = `
Build level ` + (+ (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 + ` +
+ Construction time: ` + secondsToTime(t); + } + if (!resrourcesHtml.enough) { + document.getElementById("btnBuildSpacedock").innerHTML = `not enough resources`; + } + if (planet.CurrentBuild.Title !== "") { + document.getElementById("btnBuildSpacedock").innerHTML = `building`; } } let planetid = localStorage.getItem("mainplanet"); let planet = {}; // 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) { console.log("build " + building); diff --git a/calc.js b/calc.js index 0e7e340..63574d8 100644 --- a/calc.js +++ b/calc.js @@ -1,3 +1,5 @@ +const universespeed = 1; + function metalmineCost(lvl) { const base = { Metal: 60, @@ -209,3 +211,10 @@ function spacedockCost(lvl) { cost.Energy = Math.floor(base.Energy * 2**(lvl-1)); 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); +} diff --git a/user.js b/user.js index 292add1..51a1554 100644 --- a/user.js +++ b/user.js @@ -32,12 +32,13 @@ function getUser() { document.getElementById("deuterium").innerHTML = user.Resources.Deuterium; 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]); - } + // } }).catch(function(error) { console.log(error); }); } + getUser(); setInterval(getUser, 5000);