From d4463734485ec1f7f2cba6bf66dc4f6bc4d5ffc9 Mon Sep 17 00:00:00 2001 From: davidryan59 Date: Thu, 6 Jan 2022 09:10:08 +0700 Subject: [PATCH 1/4] fix-simultaneous-attack --- .../productivity/simultaneous-attack/index.md | 2 +- .../simultaneous-attack/plugin.js | 28 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/content/productivity/simultaneous-attack/index.md b/content/productivity/simultaneous-attack/index.md index fbb022a4..ff1b65c9 100644 --- a/content/productivity/simultaneous-attack/index.md +++ b/content/productivity/simultaneous-attack/index.md @@ -1,6 +1,6 @@ --- title: Simultaneous attack date: 2021-07-16 -subtitle: Attack or reinforce a planet by automatically scheduling moves arrive at the same time +subtitle: Attack or reinforce a planet by automatically scheduling up to 6 moves to arrive at the same time version: 0.6.4 --- diff --git a/content/productivity/simultaneous-attack/plugin.js b/content/productivity/simultaneous-attack/plugin.js index e557b0c2..3afcba7c 100644 --- a/content/productivity/simultaneous-attack/plugin.js +++ b/content/productivity/simultaneous-attack/plugin.js @@ -1,6 +1,12 @@ // Simultaneous attack // -// attack thing with many thing at the same time +// Attack or reinforce a planet by automatically scheduling up to 6 moves to arrive at the same time + + +// User configurable parameters +const DEFAULT_ENERGY_PERCENT = 75; +const RECALCULATION_INTERVAL_SECONDS = 15; + var pg = df.getProcgenUtils(); @@ -45,7 +51,7 @@ var planetRatelimited = (planet) => { // attacks from the sources to the planet // does not take tx or gwei or anything like that into account, but in my testing (which did not include 40 gwei gas prices) the moves only landed a max of 3-4 seconds apart // returns the timeoutId of the scheduled moves, in case they need to be cancelled -var simultaneousAttack = (target, sources) => { +const simultaneousAttack = (target, sources, energyPercent) => { const attackTimeouts = []; const planetsMoveLengths = sources.map((p) => { return { "planet": p, "time": df.getTimeForMove(p.locationId, target.locationId) }; @@ -64,7 +70,7 @@ var simultaneousAttack = (target, sources) => { // maybe somehow show the plugin user this error? if (Math.floor(energyArriving) <= 0) return; - df.move(attacker.locationId, target.locationId, Math.floor(attacker.energy * 0.5), 0); + df.move(attacker.locationId, target.locationId, Math.floor(attacker.energy * energyPercent * 0.01), 0); // waits for the duration of the longest move - the duration of the move itself to be sent. * 1k is to convert seconds to ms }, (longestMove - planetMove.time) * 1e3)); } @@ -75,7 +81,7 @@ class SimultaneousAttack { constructor() { this.planetAttackers = []; this.moveTimeoutIds = []; - this.planetEnergySendingPercent = 50; + this.planetEnergySendingPercent = DEFAULT_ENERGY_PERCENT; } async render(container) { // thingamabob which shows you current selected target planet @@ -130,9 +136,11 @@ class SimultaneousAttack { planetAttackersContainer.style.marginBottom = "20px"; // label for showing you how much % energy you are sending const planetSendingPercent = document.createElement("div"); - planetSendingPercent.innerText = "Sending 50.0% energy"; - // slider for changing how much energy you send. default is 50% + const percentLabelText = pcv => `Sending ${pcv.toFixed(1)}% energy` + planetSendingPercent.innerText = percentLabelText(this.planetEnergySendingPercent); + // slider for changing how much energy you send const planetSendingPercentSlider = document.createElement("input"); + planetSendingPercentSlider.value = this.planetEnergySendingPercent; planetSendingPercentSlider.type = "range"; planetSendingPercentSlider.max = "100"; // step is .5 so it's twice as good as the client 8) @@ -140,7 +148,7 @@ class SimultaneousAttack { planetSendingPercentSlider.addEventListener("input", () => { const percentValue = parseFloat(planetSendingPercentSlider.value); this.planetEnergySendingPercent = percentValue; - planetSendingPercent.innerText = `Sending ${percentValue.toFixed(1)}% energy`; + planetSendingPercent.innerText = percentLabelText(percentValue); this.updateDamageCalculations(energyCalculations); }); // container for showing how much energy arrives and how much dmg it will do @@ -150,11 +158,11 @@ class SimultaneousAttack { const attackButton = document.createElement("button"); attackButton.innerText = "Attack!"; attackButton.addEventListener("click", () => { - this.moveTimeoutIds.push(...simultaneousAttack(df.getPlanetWithId(this.planetTarget), this.planetAttackers.map((p) => df.getPlanetWithId(p)))); + this.moveTimeoutIds.push(...simultaneousAttack(df.getPlanetWithId(this.planetTarget), this.planetAttackers.map((p) => df.getPlanetWithId(p)), this.planetEnergySendingPercent)); }); - // re-calculate every 15 sec - this.calculationsInterval = setInterval(() => this.updateDamageCalculations(energyCalculations), 15 * 1000); + // re-calculate every few seconds + this.calculationsInterval = setInterval(() => this.updateDamageCalculations(energyCalculations), RECALCULATION_INTERVAL_SECONDS * 1000); // haha wall of text >:D container.appendChild(targetPlanetContainer); From 62c2c8b032cdc1bc0084ac2dead93dc4a5baf88e Mon Sep 17 00:00:00 2001 From: Cristobal Dabed Date: Thu, 31 Mar 2022 13:59:20 +0200 Subject: [PATCH 2/4] Make simultaneous attack compatible with v0.6.5 --- content/productivity/simultaneous-attack/index.md | 2 +- content/productivity/simultaneous-attack/plugin.js | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/content/productivity/simultaneous-attack/index.md b/content/productivity/simultaneous-attack/index.md index ff1b65c9..1e47db5e 100644 --- a/content/productivity/simultaneous-attack/index.md +++ b/content/productivity/simultaneous-attack/index.md @@ -2,5 +2,5 @@ title: Simultaneous attack date: 2021-07-16 subtitle: Attack or reinforce a planet by automatically scheduling up to 6 moves to arrive at the same time -version: 0.6.4 +version: 0.6.5 --- diff --git a/content/productivity/simultaneous-attack/plugin.js b/content/productivity/simultaneous-attack/plugin.js index 3afcba7c..b82012b1 100644 --- a/content/productivity/simultaneous-attack/plugin.js +++ b/content/productivity/simultaneous-attack/plugin.js @@ -1,15 +1,14 @@ // Simultaneous attack // // Attack or reinforce a planet by automatically scheduling up to 6 moves to arrive at the same time - +import { + getPlanetName +} from "https://cdn.skypack.dev/@darkforest_eth/procedural"; // User configurable parameters const DEFAULT_ENERGY_PERCENT = 75; const RECALCULATION_INTERVAL_SECONDS = 15; - -var pg = df.getProcgenUtils(); - // removes all the child nodes of an element var removeAllChildNodes = (parent) => { while (parent.firstChild) { @@ -22,7 +21,7 @@ var removeAllChildNodes = (parent) => { var planetLink = (locationId, clickable = true) => { const planet = df.getPlanetWithId(locationId); const planetElement = document.createElement(clickable ? "button" : "span"); - planetElement.innerText = `L${planet.planetLevel}R${planet.upgradeState.reduce((a, b) => a + b, 0)} ${pg.getPlanetName(planet)}`; + planetElement.innerText = `L${planet.planetLevel}R${planet.upgradeState.reduce((a, b) => a + b, 0)} ${getPlanetName(planet)}`; planetElement.title = locationId; planetElement.style.textDecoration = "underline"; planetElement.style.background = "none"; From 0c3ab6fa7d91096a03401df32585865d63ed18de Mon Sep 17 00:00:00 2001 From: Cristobal Dabed Date: Thu, 31 Mar 2022 14:03:47 +0200 Subject: [PATCH 3/4] Make simultaneous attack compatible with v0.6.5 --- content/productivity/simultaneous-attack/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/productivity/simultaneous-attack/index.md b/content/productivity/simultaneous-attack/index.md index 1e47db5e..ff1b65c9 100644 --- a/content/productivity/simultaneous-attack/index.md +++ b/content/productivity/simultaneous-attack/index.md @@ -2,5 +2,5 @@ title: Simultaneous attack date: 2021-07-16 subtitle: Attack or reinforce a planet by automatically scheduling up to 6 moves to arrive at the same time -version: 0.6.5 +version: 0.6.4 --- From 242df6485c331c272c6e486afd8b6681395ae812 Mon Sep 17 00:00:00 2001 From: David Ryan Date: Sat, 2 Apr 2022 08:36:13 +0700 Subject: [PATCH 4/4] Update content/productivity/simultaneous-attack/index.md Co-authored-by: Ivan Chub --- content/productivity/simultaneous-attack/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/productivity/simultaneous-attack/index.md b/content/productivity/simultaneous-attack/index.md index ff1b65c9..1e47db5e 100644 --- a/content/productivity/simultaneous-attack/index.md +++ b/content/productivity/simultaneous-attack/index.md @@ -2,5 +2,5 @@ title: Simultaneous attack date: 2021-07-16 subtitle: Attack or reinforce a planet by automatically scheduling up to 6 moves to arrive at the same time -version: 0.6.4 +version: 0.6.5 ---