| @@ -19,6 +19,11 @@ let clickVictim = "micro"; | |||
| let lastTime = 0; | |||
| let controlHeld = false; | |||
| let shiftHeld = false; | |||
| let mouseTarget = undefined; | |||
| const activePowerups = []; | |||
| function tickPowerups(delta) { | |||
| @@ -115,18 +120,37 @@ function productivityOf(type) { | |||
| return prod * belongings[type].count; | |||
| } | |||
| function costOfBuilding(type) { | |||
| let baseCost = buildings[type].cost | |||
| let countCost = baseCost * Math.pow(1.15, belongings[type].count); | |||
| function costOfBuilding(type, count = 1) { | |||
| let total = 0; | |||
| while (count > 0) { | |||
| let baseCost = buildings[type].cost; | |||
| let countCost = baseCost * Math.pow(1.15, belongings[type].count + count - 1); | |||
| total += countCost; | |||
| count--; | |||
| } | |||
| return Math.round(countCost); | |||
| return Math.round(total); | |||
| } | |||
| function buyBuilding(type) { | |||
| let cost = costOfBuilding(type); | |||
| function buildingCount() { | |||
| if (controlHeld) { | |||
| return 10; | |||
| } else if (shiftHeld) { | |||
| return 5; | |||
| } else { | |||
| return 1; | |||
| } | |||
| } | |||
| function buyBuilding(type, e) { | |||
| const count = buildingCount(); | |||
| let cost = costOfBuilding(type, count); | |||
| if (resources.food >= cost) { | |||
| belongings[type].count += 1; | |||
| belongings[type].count += count; | |||
| resources.food -= cost; | |||
| } | |||
| @@ -206,6 +230,7 @@ function renderResources() { | |||
| } | |||
| function displayBuildings() { | |||
| const count = buildingCount(); | |||
| for (const [key, value] of Object.entries(belongings)) { | |||
| if (!belongings[key].visible) { | |||
| @@ -224,9 +249,9 @@ function displayBuildings() { | |||
| let cost = document.querySelector("#building-" + key + " > .building-button-cost"); | |||
| name.innerText = value.count + " " + (value.count == 1 ? buildings[key].name : buildings[key].plural); | |||
| cost.innerText = render(costOfBuilding(key)) + " food"; | |||
| if (costOfBuilding(key) > resources.food) { | |||
| cost.innerText = render(costOfBuilding(key, count)) + " food"; | |||
| if (costOfBuilding(key, count) > resources.food) { | |||
| button.classList.add("building-button-disabled"); | |||
| cost.classList.add("building-button-cost-invalid"); | |||
| } else { | |||
| @@ -449,6 +474,22 @@ function registerListeners() { | |||
| document.querySelector("#reset").addEventListener("click", reset); | |||
| document.querySelector("#upgrades").addEventListener("click", switchShowOwnedUpgrades); | |||
| document.addEventListener("keydown", e => { | |||
| shiftHeld = e.shiftKey; | |||
| controlHeld = e.ctrlKey; | |||
| if (mouseTarget) | |||
| mouseTarget.dispatchEvent(new Event("mousemove")); | |||
| return true; | |||
| }); | |||
| document.addEventListener("keyup", e => { | |||
| shiftHeld = e.shiftKey; | |||
| controlHeld = e.ctrlKey; | |||
| if (mouseTarget) | |||
| mouseTarget.dispatchEvent(new Event("mousemove")); | |||
| return true; | |||
| }); | |||
| } | |||
| function createButtons() { | |||
| @@ -476,9 +517,9 @@ function createBuildings() { | |||
| button.appendChild(buttonName); | |||
| button.appendChild(buttonCost); | |||
| button.appendChild(buildingIcon); | |||
| button.addEventListener("mousemove", function(e) { buildingTooltip(key, e); }); | |||
| button.addEventListener("mouseleave", function() { buildingTooltipRemove(); }); | |||
| button.addEventListener("click", function() { buyBuilding(key); }); | |||
| button.addEventListener("mousemove", function(e) { mouseTarget = button; buildingTooltip(key, e); }); | |||
| button.addEventListener("mouseleave", function() { mouseTarget = undefined; buildingTooltipRemove(); }); | |||
| button.addEventListener("click", function(e) { buyBuilding(key, e); }); | |||
| button.addEventListener("click", function(e) { buildingTooltip(key, e); }); | |||
| container.appendChild(button); | |||
| @@ -568,9 +609,9 @@ function createUpgrades() { | |||
| button.appendChild(buttonName); | |||
| button.appendChild(upgradeIcon); | |||
| button.addEventListener("mouseenter", function(e) { upgradeTooltip(key, e); }); | |||
| button.addEventListener("mousemove", function(e) { upgradeTooltip(key, e); }); | |||
| button.addEventListener("mouseleave", function() { upgradeTooltipRemove(); }); | |||
| button.addEventListener("mouseenter", function(e) { mouseTarget = button; upgradeTooltip(key, e); }); | |||
| button.addEventListener("mousemove", function(e) { mouseTarget = button; upgradeTooltip(key, e); }); | |||
| button.addEventListener("mouseleave", function() { mouseTarget = undefined; upgradeTooltipRemove(); }); | |||
| button.addEventListener("click", function(e) { buyUpgrade(key, e); }); | |||
| container.appendChild(button); | |||
| @@ -885,10 +926,12 @@ function buildingTooltip(id, event) { | |||
| let tooltip = document.querySelector("#building-tooltip"); | |||
| tooltip.style.setProperty("display", "inline-block"); | |||
| const count = buildingCount(); | |||
| fillTooltip("building", "name", buildings[id].name); | |||
| fillTooltip("building", "name", (count != 1 ? count +"x " : "") + buildings[id].name); | |||
| fillTooltip("building", "desc", buildings[id].desc); | |||
| fillTooltip("building", "cost", render(costOfBuilding(id)) + " food"); | |||
| fillTooltip("building", "cost", render(costOfBuilding(id, count)) + " food"); | |||
| fillTooltip("building", "prod", prodSummary(id)); | |||
| let xPos = tooltip.parentElement.getBoundingClientRect().x - 450; | |||