From 23ba4222f235c2f94ec632b631df219a849fbefd Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Sat, 12 Oct 2024 08:43:20 +0200 Subject: [PATCH 01/11] Update BattleOrders.js Adjusts the giveBo() function in BattleOrders.js to ensure that the script waits only for players who are explicitly defined as getters in the configuration, regardless of any additional players present. --- d2bs/kolbot/libs/scripts/BattleOrders.js | 172 +++++++++++++---------- 1 file changed, 97 insertions(+), 75 deletions(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index 763cb4cf6..abb995061 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -56,7 +56,7 @@ const BattleOrders = new Runnable( continue; } else { console.error(e); - // emptry game, don't wait + // empty game, don't wait return true; } } @@ -92,16 +92,18 @@ const BattleOrders = new Runnable( return false; // Not late; wait. } - // bo is AoE, lets build a list of all players near us so we can know who we boed function giveBO () { - // more players might be showing up, give a moment and lets wait until the nearby player count is static - let nearPlayers = 0; let tick = getTickCount(); - - // if we haven't already given a bo, lets wait to see if more players show up + + // check nearby players + const playersToBo = getUnits(sdk.unittype.Player) + .filter(p => boGetters.has(p.name.toLowerCase()) && p.distance < 20); + + // wait for players from boGetters list only, ignoring extra players if (!BattleOrders.gaveBo) { - nearPlayers = Misc.getNearbyPlayerCount(); - while (nearPlayers !== boGetters.size) { + let boGettersNearby = new Set(playersToBo.map(p => p.name.toLowerCase())); + + while (boGettersNearby.size !== boGetters.size) { if (getTickCount() - tick >= Time.seconds(30)) { log("Begin"); @@ -110,16 +112,23 @@ const BattleOrders = new Runnable( me.overhead( "Waiting " + Math.round(((tick + Time.seconds(30)) - getTickCount()) / 1000) - + " for all players to show up" + + " seconds for all BO getters." ); - nearPlayers = Misc.getNearbyPlayerCount(); + + // update nearby players to check only the ones in the getters list + boGettersNearby = new Set( + getUnits(sdk.unittype.Player) + .filter(p => boGetters.has(p.name.toLowerCase()) && p.distance < 20) + .map(p => p.name.toLowerCase()) + ); + delay(1000); } } let boed = false; - const playersToBo = getUnits(sdk.unittype.Player) - .filter(p => boGetters.has(p.name.toLowerCase()) && p.distance < 20); + + // cast BO on the relevant players playersToBo.forEach(p => { tick = getTickCount(); @@ -206,79 +215,79 @@ const BattleOrders = new Runnable( } switch (Config.BattleOrders.Mode) { - case boMode.Give: - // check if anyone is near us - nearPlayer = Game.getPlayer(); - - if (nearPlayer) { - do { - if (nearPlayer.name !== me.name) { - let nearPlayerName = nearPlayer.name.toLowerCase(); - // there is a player near us and they are in the list of players to bo and in my party - if (boGetters.has(nearPlayerName) - && !totalBoed.has(nearPlayerName) - && Misc.inMyParty(nearPlayerName)) { - let result = giveBO(); - if (result.success) { - if (result.count === boGetters.size - || totalBoed.size === boGetters.size) { - // we bo-ed everyone we are set to, don't wait around any longer - break MainLoop; + case boMode.Give: + // check if anyone is near us + nearPlayer = Game.getPlayer(); + + if (nearPlayer) { + do { + if (nearPlayer.name !== me.name) { + let nearPlayerName = nearPlayer.name.toLowerCase(); + // there is a player near us and they are in the list of players to bo and in my party + if (boGetters.has(nearPlayerName) + && !totalBoed.has(nearPlayerName) + && Misc.inMyParty(nearPlayerName)) { + let result = giveBO(); + if (result.success) { + if (result.count === boGetters.size + || totalBoed.size === boGetters.size) { + // we bo-ed everyone we are set to, don't wait around any longer + break MainLoop; + } + // reset fail tick + tick = getTickCount(); + // shorten waiting time since we've already started giving out bo's + BattleOrders.gaveBo = true; } - // reset fail tick - tick = getTickCount(); - // shorten waiting time since we've already started giving out bo's - BattleOrders.gaveBo = true; + } + } else { + me.overhead( + "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) + + " Seconds for other players" + ); + + if (getTickCount() - tick >= failTimer) { + log("ÿc1Give BO timeout fail."); + log("Failed to bo: " + getFailedToBO().join(", ")); + Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); + + break MainLoop; } } - } else { - me.overhead( - "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) - + " Seconds for other players" - ); - - if (getTickCount() - tick >= failTimer) { - log("ÿc1Give BO timeout fail."); - log("Failed to bo: " + getFailedToBO().join(", ")); - Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); - - break MainLoop; - } - } - } while (nearPlayer.getNext()); - } else { - me.overhead( - "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) - + " Seconds for other players" - ); + } while (nearPlayer.getNext()); + } else { + me.overhead( + "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) + + " Seconds for other players" + ); - if (getTickCount() - tick >= failTimer) { - log("ÿc1Give BO timeout fail."); - log("Failed to bo: " + getFailedToBO().join(", ")); - Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); + if (getTickCount() - tick >= failTimer) { + log("ÿc1Give BO timeout fail."); + log("Failed to bo: " + getFailedToBO().join(", ")); + Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); - break MainLoop; + break MainLoop; + } } - } - break; - case boMode.Receive: - if (me.getState(sdk.states.BattleOrders)) { - log("Got bo-ed"); - say("got-bo"); - delay(1000); + break; + case boMode.Receive: + if (me.getState(sdk.states.BattleOrders)) { + log("Got bo-ed"); + say("got-bo"); + delay(1000); - break MainLoop; - } + break MainLoop; + } - if (getTickCount() - tick >= failTimer) { - log("ÿc1BO timeout fail."); - Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); + if (getTickCount() - tick >= failTimer) { + log("ÿc1BO timeout fail."); + Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); - break MainLoop; - } + break MainLoop; + } - break; + break; } delay(500); @@ -299,10 +308,23 @@ const BattleOrders = new Runnable( } } - return true; + if (Config.BattleOrders.Getters.length > 0) { + const failedToBo = getFailedToBO(); + if (failedToBo.length > 0) { + log("Failed to bo: " + failedToBo.join(", ")); + } else { + log("All designated players received BO."); + } + } + + } catch (e) { + console.error(e); } finally { + BattleOrders.gaveBo = false; removeEventListener("chatmsg", chatEvent); } + + return true; }, { startArea: sdk.areas.CatacombsLvl2 From 781d02311aa6b43ddc593e9fbed2d4bff1c15631 Mon Sep 17 00:00:00 2001 From: theBGuy <60308670+theBGuy@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:03:37 -0400 Subject: [PATCH 02/11] Formatted --- d2bs/kolbot/libs/scripts/BattleOrders.js | 110 +++++++++++------------ 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index abb995061..a0f327a20 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -215,79 +215,79 @@ const BattleOrders = new Runnable( } switch (Config.BattleOrders.Mode) { - case boMode.Give: - // check if anyone is near us - nearPlayer = Game.getPlayer(); - - if (nearPlayer) { - do { - if (nearPlayer.name !== me.name) { - let nearPlayerName = nearPlayer.name.toLowerCase(); - // there is a player near us and they are in the list of players to bo and in my party - if (boGetters.has(nearPlayerName) + case boMode.Give: + // check if anyone is near us + nearPlayer = Game.getPlayer(); + + if (nearPlayer) { + do { + if (nearPlayer.name !== me.name) { + let nearPlayerName = nearPlayer.name.toLowerCase(); + // there is a player near us and they are in the list of players to bo and in my party + if (boGetters.has(nearPlayerName) && !totalBoed.has(nearPlayerName) && Misc.inMyParty(nearPlayerName)) { - let result = giveBO(); - if (result.success) { - if (result.count === boGetters.size + let result = giveBO(); + if (result.success) { + if (result.count === boGetters.size || totalBoed.size === boGetters.size) { - // we bo-ed everyone we are set to, don't wait around any longer - break MainLoop; - } - // reset fail tick - tick = getTickCount(); - // shorten waiting time since we've already started giving out bo's - BattleOrders.gaveBo = true; + // we bo-ed everyone we are set to, don't wait around any longer + break MainLoop; } + // reset fail tick + tick = getTickCount(); + // shorten waiting time since we've already started giving out bo's + BattleOrders.gaveBo = true; } - } else { - me.overhead( - "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) + } + } else { + me.overhead( + "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) + " Seconds for other players" - ); + ); - if (getTickCount() - tick >= failTimer) { - log("ÿc1Give BO timeout fail."); - log("Failed to bo: " + getFailedToBO().join(", ")); - Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); + if (getTickCount() - tick >= failTimer) { + log("ÿc1Give BO timeout fail."); + log("Failed to bo: " + getFailedToBO().join(", ")); + Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); - break MainLoop; - } + break MainLoop; } - } while (nearPlayer.getNext()); - } else { - me.overhead( - "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) + } + } while (nearPlayer.getNext()); + } else { + me.overhead( + "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) + " Seconds for other players" - ); + ); - if (getTickCount() - tick >= failTimer) { - log("ÿc1Give BO timeout fail."); - log("Failed to bo: " + getFailedToBO().join(", ")); - Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); + if (getTickCount() - tick >= failTimer) { + log("ÿc1Give BO timeout fail."); + log("Failed to bo: " + getFailedToBO().join(", ")); + Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); - break MainLoop; - } + break MainLoop; } + } - break; - case boMode.Receive: - if (me.getState(sdk.states.BattleOrders)) { - log("Got bo-ed"); - say("got-bo"); - delay(1000); + break; + case boMode.Receive: + if (me.getState(sdk.states.BattleOrders)) { + log("Got bo-ed"); + say("got-bo"); + delay(1000); - break MainLoop; - } + break MainLoop; + } - if (getTickCount() - tick >= failTimer) { - log("ÿc1BO timeout fail."); - Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); + if (getTickCount() - tick >= failTimer) { + log("ÿc1BO timeout fail."); + Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); - break MainLoop; - } + break MainLoop; + } - break; + break; } delay(500); From 619973c369ff8adff0b4dc82f5e24e1abb6669ee Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Sun, 22 Dec 2024 11:05:01 +0100 Subject: [PATCH 03/11] Keep track of boGetters If some of our getters are missing in game, remove them from the boGetters list and proceed. --- d2bs/kolbot/libs/scripts/BattleOrders.js | 77 ++++++++++++------------ 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index a0f327a20..2c65fbe7c 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -13,7 +13,7 @@ const BattleOrders = new Runnable( /** @type {Set} */ const totalBoed = new Set(); /** @type {Set} */ - const boGetters = new Set(Config.BattleOrders.Getters.map(name => name.toLowerCase())); + let boGetters = new Set(Config.BattleOrders.Getters.map(name => name.toLowerCase())); const boMode = { Give: 0, @@ -39,13 +39,13 @@ const BattleOrders = new Runnable( } catch (e) { if (Config.BattleOrders.Wait) { let counter = 0; - console.log("Waiting " + Config.BattleOrders.Wait + " seconds for other players..."); + console.log("Waiting " + Config.BattleOrders.Wait + " seconds for other boGetters..."); Misc.poll(() => { counter++; me.overhead( "Waiting " + Math.round(((tick + Time.seconds(Config.BattleOrders.Wait)) - getTickCount()) / 1000) - + " Seconds for other players" + + " seconds for other getters" ); if (counter % 5 === 0) { return checkForPlayers(); @@ -92,38 +92,37 @@ const BattleOrders = new Runnable( return false; // Not late; wait. } + // if some getters are not in the game, remove them from the getters list + function removeMissing () { + const activePlayers = new Set(getUnits(sdk.unittype.Player).map(p => p.name.toLowerCase())); + boGetters = new Set([...boGetters].filter(name => activePlayers.has(name))); + } + function giveBO () { let tick = getTickCount(); // check nearby players - const playersToBo = getUnits(sdk.unittype.Player) + let playersToBo = getUnits(sdk.unittype.Player) .filter(p => boGetters.has(p.name.toLowerCase()) && p.distance < 20); // wait for players from boGetters list only, ignoring extra players - if (!BattleOrders.gaveBo) { - let boGettersNearby = new Set(playersToBo.map(p => p.name.toLowerCase())); - - while (boGettersNearby.size !== boGetters.size) { - if (getTickCount() - tick >= Time.seconds(30)) { - log("Begin"); + while (new Set(playersToBo.map(p => p.name.toLowerCase())).size !== boGetters.size) { + if (getTickCount() - tick >= Time.seconds(30)) { + log("Begin"); - break; - } + break; + } - me.overhead( - "Waiting " + Math.round(((tick + Time.seconds(30)) - getTickCount()) / 1000) - + " seconds for all BO getters." - ); + me.overhead( + "Waiting " + Math.round(((tick + Time.seconds(30)) - getTickCount()) / 1000) + + " seconds for all getters to show up" + ); - // update nearby players to check only the ones in the getters list - boGettersNearby = new Set( - getUnits(sdk.unittype.Player) - .filter(p => boGetters.has(p.name.toLowerCase()) && p.distance < 20) - .map(p => p.name.toLowerCase()) - ); + // update nearby players to check only the ones in the getters list + playersToBo = getUnits(sdk.unittype.Player) + .filter(p => boGetters.has(p.name.toLowerCase()) && p.distance < 20); - delay(1000); - } + delay(1000); } let boed = false; @@ -154,9 +153,10 @@ const BattleOrders = new Runnable( } }); + /* if (boed) { - delay(5000); - } + delay(5000); // Giving the barb a coffee break? + } */ return { success: boed, @@ -210,6 +210,12 @@ const BattleOrders = new Runnable( MainLoop: while (true) { + removeMissing(); // remove missing players from the list of getters + /* + if (me.classid === sdk.player.class.Barbarian) { + console.debug("Getters in game: " + [...boGetters].join(", ")); + } */ + if (Config.BattleOrders.SkipIfTardy && tardy()) { break; } @@ -225,12 +231,12 @@ const BattleOrders = new Runnable( let nearPlayerName = nearPlayer.name.toLowerCase(); // there is a player near us and they are in the list of players to bo and in my party if (boGetters.has(nearPlayerName) - && !totalBoed.has(nearPlayerName) - && Misc.inMyParty(nearPlayerName)) { + && !totalBoed.has(nearPlayerName) + && Misc.inMyParty(nearPlayerName)) { let result = giveBO(); if (result.success) { if (result.count === boGetters.size - || totalBoed.size === boGetters.size) { + || totalBoed.size === boGetters.size) { // we bo-ed everyone we are set to, don't wait around any longer break MainLoop; } @@ -243,7 +249,7 @@ const BattleOrders = new Runnable( } else { me.overhead( "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) - + " Seconds for other players" + + " seconds for other getters" ); if (getTickCount() - tick >= failTimer) { @@ -258,7 +264,7 @@ const BattleOrders = new Runnable( } else { me.overhead( "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) - + " Seconds for other players" + + " seconds for other getters" ); if (getTickCount() - tick >= failTimer) { @@ -308,15 +314,6 @@ const BattleOrders = new Runnable( } } - if (Config.BattleOrders.Getters.length > 0) { - const failedToBo = getFailedToBO(); - if (failedToBo.length > 0) { - log("Failed to bo: " + failedToBo.join(", ")); - } else { - log("All designated players received BO."); - } - } - } catch (e) { console.error(e); } finally { From 48a98f3ed39f03d7035ddb31ca5a0693d9241929 Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:06:37 +0100 Subject: [PATCH 04/11] Fix removeMissing() Last change dropped all getters from the list who were not present at the bo spot. Now, it removes only those from the list who are not in the game. --- d2bs/kolbot/libs/scripts/BattleOrders.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index 2c65fbe7c..111981759 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -94,7 +94,13 @@ const BattleOrders = new Runnable( // if some getters are not in the game, remove them from the getters list function removeMissing () { - const activePlayers = new Set(getUnits(sdk.unittype.Player).map(p => p.name.toLowerCase())); + const activePlayers = new Set(); + let player = getParty(); + if (player) { + do { + activePlayers.add(player.name.toLowerCase()); + } while (player.getNext()); + } boGetters = new Set([...boGetters].filter(name => activePlayers.has(name))); } From d9bc3547244bea092db8a0ee54242f990df4d58e Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Sun, 22 Dec 2024 22:13:57 +0100 Subject: [PATCH 05/11] Move removeMissing() call inside boMode.Give case --- d2bs/kolbot/libs/scripts/BattleOrders.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index 111981759..b24b55f38 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -92,7 +92,7 @@ const BattleOrders = new Runnable( return false; // Not late; wait. } - // if some getters are not in the game, remove them from the getters list + // remove those from the getters list who are not in game function removeMissing () { const activePlayers = new Set(); let player = getParty(); @@ -216,12 +216,6 @@ const BattleOrders = new Runnable( MainLoop: while (true) { - removeMissing(); // remove missing players from the list of getters - /* - if (me.classid === sdk.player.class.Barbarian) { - console.debug("Getters in game: " + [...boGetters].join(", ")); - } */ - if (Config.BattleOrders.SkipIfTardy && tardy()) { break; } @@ -231,6 +225,9 @@ const BattleOrders = new Runnable( // check if anyone is near us nearPlayer = Game.getPlayer(); + removeMissing(); // remove missing getters from the list + //console.debug("Getters in game: " + [...boGetters].join(", ")); + if (nearPlayer) { do { if (nearPlayer.name !== me.name) { From f100955a2f25c0751542fbd99750e3e261dfc477 Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Fri, 27 Dec 2024 16:25:15 +0100 Subject: [PATCH 06/11] Fix boGiver waiting issue with late-arriving getters Fixes an issue where the boGiver would continue to wait even after successfully casting bo on a late-arriving getter after the wait timer had expired. - remove getters from the list after they receive bo - giveBO() function returns immediately once all getters have received bo - stop the main loop once all getters have received bo --- d2bs/kolbot/libs/scripts/BattleOrders.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index b24b55f38..153f0e9c1 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -154,6 +154,7 @@ const BattleOrders = new Runnable( } totalBoed.add(p.name.toLowerCase()); + boGetters.delete(p.name.toLowerCase()); console.debug("Bo-ed " + p.name); boed = true; } @@ -164,6 +165,13 @@ const BattleOrders = new Runnable( delay(5000); // Giving the barb a coffee break? } */ + if (boGetters.size === 0) { + return { + success: boed, + count: playersToBo.length + }; + } + return { success: boed, count: playersToBo.length @@ -224,10 +232,8 @@ const BattleOrders = new Runnable( case boMode.Give: // check if anyone is near us nearPlayer = Game.getPlayer(); - removeMissing(); // remove missing getters from the list //console.debug("Getters in game: " + [...boGetters].join(", ")); - if (nearPlayer) { do { if (nearPlayer.name !== me.name) { @@ -238,8 +244,7 @@ const BattleOrders = new Runnable( && Misc.inMyParty(nearPlayerName)) { let result = giveBO(); if (result.success) { - if (result.count === boGetters.size - || totalBoed.size === boGetters.size) { + if (boGetters.size === 0) { // we bo-ed everyone we are set to, don't wait around any longer break MainLoop; } From 170318ba21068405f3631f197807d10cefc089da Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Mon, 22 Dec 2025 04:12:11 +0100 Subject: [PATCH 07/11] Update BattleOrders.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Renamed `removeMissing()` to `getGetters()` - `getGiver()`: Additional function for boGetters to determine whether the boGiver is in-game and in the same party. If the giver is not in-game and not in our party after a certain time, BattleOrders.js is terminated. - `@param {string} Config.BattleOrders.Giver` and - `@param {int} Config.BattleOrders.WaitForGiver` are required in the character configuration. - `getGetters()`: Filter not only boGetters that are in-game, but additionally boGetters that still need to be buffed. - `giveBo()`: Additionally filter `playersToBo` to exclude boGetters that have already been BOed. - `failTimer`: Reduced timeout for boGetters and boGiver to appear from 2 minutes to 40 seconds. - `chatEvent()`: Bitwise `|` → logical OR `||` --- d2bs/kolbot/libs/scripts/BattleOrders.js | 99 +++++++++++++++++------- 1 file changed, 71 insertions(+), 28 deletions(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index 153f0e9c1..26249745d 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -1,9 +1,9 @@ /** -* @filename BattleOrders.js -* @author kolton, jmichelsen, theBGuy -* @desc give or receive Battle Orders buff -* -*/ + * @filename BattleOrders.js + * @author kolton, jmichelsen, theBGuy + * @desc give or receive Battle Orders buff + * + */ // todo - define bo-er name, so bots who are getting bo know who is supposed to give it // todo - use profile <-> profile communication so we don't need to set char names, Maybe shout global? @@ -45,7 +45,7 @@ const BattleOrders = new Runnable( counter++; me.overhead( "Waiting " + Math.round(((tick + Time.seconds(Config.BattleOrders.Wait)) - getTickCount()) / 1000) - + " seconds for other getters" + + " seconds for other boGetters" ); if (counter % 5 === 0) { return checkForPlayers(); @@ -92,16 +92,49 @@ const BattleOrders = new Runnable( return false; // Not late; wait. } - // remove those from the getters list who are not in game - function removeMissing () { - const activePlayers = new Set(); + /** Check for getters in game. */ + function getGetters () { + const activeGetters = new Set(); let player = getParty(); if (player) { do { - activePlayers.add(player.name.toLowerCase()); + activeGetters.add(player.name.toLowerCase()); } while (player.getNext()); } - boGetters = new Set([...boGetters].filter(name => activePlayers.has(name))); + boGetters = new Set(Config.BattleOrders.Getters + .map(name => name.toLowerCase()) + .filter(name => activeGetters.has(name) && !totalBoed.has(name)) + ); + } + + /** + * Checks if the giver is in game. + * @returns {boolean} + */ + function getGiver () { + const giver = Config.BattleOrders.Giver.toLowerCase(); + const wait = Time.seconds(Config.BattleOrders.WaitForGiver); + const tick = getTickCount(); + + //console.debug("Start checking for boGiver: " + giver); + + while (getTickCount() - tick < wait) { + const timeout = Math.floor(((tick + wait) - getTickCount()) / 1000); + let player = getParty(); + if (player) { + do { + if (player.name && player.name.toLowerCase() === giver) { + return true; + } + } while (player.getNext()); + } + + me.overhead("Waiting " + timeout + " seconds for " + giver); + delay(250); + } + + log("ÿc1BO Giver not in game. Moving on..."); + return false; } function giveBO () { @@ -109,7 +142,11 @@ const BattleOrders = new Runnable( // check nearby players let playersToBo = getUnits(sdk.unittype.Player) - .filter(p => boGetters.has(p.name.toLowerCase()) && p.distance < 20); + .filter(p => + boGetters.has(p.name.toLowerCase()) + && p.distance < 20 + && !totalBoed.has(p.name.toLowerCase()) + ); // wait for players from boGetters list only, ignoring extra players while (new Set(playersToBo.map(p => p.name.toLowerCase())).size !== boGetters.size) { @@ -154,17 +191,13 @@ const BattleOrders = new Runnable( } totalBoed.add(p.name.toLowerCase()); - boGetters.delete(p.name.toLowerCase()); console.debug("Bo-ed " + p.name); boed = true; + delay(250); + boGetters.delete(p.name.toLowerCase()); } }); - /* - if (boed) { - delay(5000); // Giving the barb a coffee break? - } */ - if (boGetters.size === 0) { return { success: boed, @@ -193,7 +226,7 @@ const BattleOrders = new Runnable( Pather.moveTo(me.x + 6, me.y + 6); let tick = getTickCount(); - let failTimer = Time.minutes(2); + let failTimer = Time.seconds(40); let nearPlayer; // Ready @@ -204,7 +237,7 @@ const BattleOrders = new Runnable( * @param {string} msg */ function chatEvent (name, msg) { - if (!msg | !name) return; + if (!msg || !name) return; if (!boGetters.has(name.toLowerCase())) return; if (msg === "got-bo") { console.log(name + " got bo"); @@ -232,8 +265,8 @@ const BattleOrders = new Runnable( case boMode.Give: // check if anyone is near us nearPlayer = Game.getPlayer(); - removeMissing(); // remove missing getters from the list - //console.debug("Getters in game: " + [...boGetters].join(", ")); + getGetters(); + console.debug("Getters in game: " + [...boGetters].join(", ")); if (nearPlayer) { do { if (nearPlayer.name !== me.name) { @@ -242,6 +275,7 @@ const BattleOrders = new Runnable( if (boGetters.has(nearPlayerName) && !totalBoed.has(nearPlayerName) && Misc.inMyParty(nearPlayerName)) { + delay(1000); let result = giveBO(); if (result.success) { if (boGetters.size === 0) { @@ -257,7 +291,7 @@ const BattleOrders = new Runnable( } else { me.overhead( "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) - + " seconds for other getters" + + " seconds for other boGetters" ); if (getTickCount() - tick >= failTimer) { @@ -272,7 +306,7 @@ const BattleOrders = new Runnable( } else { me.overhead( "Waiting " + Math.round(((tick + failTimer) - getTickCount()) / 1000) - + " seconds for other getters" + + " seconds for other boGetters" ); if (getTickCount() - tick >= failTimer) { @@ -294,11 +328,20 @@ const BattleOrders = new Runnable( break MainLoop; } - if (getTickCount() - tick >= failTimer) { - log("ÿc1BO timeout fail."); - Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); + if (Config.BattleOrders.Giver) { + if (!getGiver()) { + console.log("ÿc1BO timeout fail."); + Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); - break MainLoop; + break MainLoop; + } + } else { + if (getTickCount() - tick >= failTimer) { + log("ÿc1BO timeout fail."); + Config.BattleOrders.QuitOnFailure && scriptBroadcast("quit"); + + break MainLoop; + } } break; From c4b1ab4ed890d988228ca13d364a24dcb1a03bdf Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Mon, 22 Dec 2025 17:25:20 +0100 Subject: [PATCH 08/11] Remove `gaveBo` flag Removed 'gaveBo' property from BattleOrders.js since it's not needed anymore. --- d2bs/kolbot/libs/scripts/BattleOrders.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index 26249745d..91e418e01 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -9,7 +9,6 @@ // todo - use profile <-> profile communication so we don't need to set char names, Maybe shout global? const BattleOrders = new Runnable( function BattleOrders () { - this.gaveBo = false; /** @type {Set} */ const totalBoed = new Set(); /** @type {Set} */ @@ -284,8 +283,6 @@ const BattleOrders = new Runnable( } // reset fail tick tick = getTickCount(); - // shorten waiting time since we've already started giving out bo's - BattleOrders.gaveBo = true; } } } else { @@ -368,7 +365,6 @@ const BattleOrders = new Runnable( } catch (e) { console.error(e); } finally { - BattleOrders.gaveBo = false; removeEventListener("chatmsg", chatEvent); } From ce2de3b1c164fc4b1af226b849c75d7c6ae12ea4 Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Thu, 25 Dec 2025 12:46:48 +0100 Subject: [PATCH 09/11] Update BattleOrders.js - added role-specific wait timers in `tardy()` function for `Config.BattleOrders.Wait` me.overhead messages - removed redundant return for `boed` flag and `playersToBo` count - throw an error if `boGiver` hasn't specified any `boGetters` - added guard for `boMode.Give` case to exit the `MainLoop` if `boGetters` is empty - formatting --- d2bs/kolbot/libs/scripts/BattleOrders.js | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index 91e418e01..b0fa8b818 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -38,17 +38,22 @@ const BattleOrders = new Runnable( } catch (e) { if (Config.BattleOrders.Wait) { let counter = 0; - console.log("Waiting " + Config.BattleOrders.Wait + " seconds for other boGetters..."); + console.log( + "Waiting " + Config.BattleOrders.Wait + " seconds for other " + + (Config.BattleOrders.Mode === boMode.Give ? "boGetters..." : "boGiver...") + ); Misc.poll(() => { counter++; me.overhead( "Waiting " + Math.round(((tick + Time.seconds(Config.BattleOrders.Wait)) - getTickCount()) / 1000) - + " seconds for other boGetters" + + " seconds for other " + (Config.BattleOrders.Mode === boMode.Give ? "boGetters..." : "boGiver...") ); + if (counter % 5 === 0) { return checkForPlayers(); } + return false; }, Time.seconds(Config.BattleOrders.Wait), Time.seconds(1)); @@ -197,19 +202,18 @@ const BattleOrders = new Runnable( } }); - if (boGetters.size === 0) { - return { - success: boed, - count: playersToBo.length - }; - } - return { success: boed, count: playersToBo.length }; } + if (Config.BattleOrders.Mode === boMode.Give) { + if (Config.BattleOrders.Getters.length === 0) { + throw new Error("No BO getters defined."); + } + } + // START try { Pather.useWaypoint(sdk.areas.CatacombsLvl2, true); @@ -232,9 +236,9 @@ const BattleOrders = new Runnable( Precast.enabled = true; /** - * @param {string} name - * @param {string} msg - */ + * @param {string} name + * @param {string} msg + */ function chatEvent (name, msg) { if (!msg || !name) return; if (!boGetters.has(name.toLowerCase())) return; From acf4dfd3e4c1fea0ab58133c12c9366fd5cbd6f5 Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Thu, 25 Dec 2025 12:57:02 +0100 Subject: [PATCH 10/11] Add guard to `boMode.Give` case for empty `boGetters` Add guard in `boMode.Give` case to exit the MainLoop if `boGetters` is empty. --- d2bs/kolbot/libs/scripts/BattleOrders.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index b0fa8b818..f2a6d5a9b 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -266,6 +266,9 @@ const BattleOrders = new Runnable( switch (Config.BattleOrders.Mode) { case boMode.Give: + if (boGetters.size === 0) { + break MainLoop; + } // check if anyone is near us nearPlayer = Game.getPlayer(); getGetters(); From 4455f8a39b7c3a30e47c71e9c45bb3b36280dc2d Mon Sep 17 00:00:00 2001 From: Antiwarden <125026215+Antiwarden@users.noreply.github.com> Date: Thu, 19 Feb 2026 09:09:08 +0100 Subject: [PATCH 11/11] Formatting --- d2bs/kolbot/libs/scripts/BattleOrders.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/d2bs/kolbot/libs/scripts/BattleOrders.js b/d2bs/kolbot/libs/scripts/BattleOrders.js index f2a6d5a9b..fe0d86a73 100644 --- a/d2bs/kolbot/libs/scripts/BattleOrders.js +++ b/d2bs/kolbot/libs/scripts/BattleOrders.js @@ -39,15 +39,15 @@ const BattleOrders = new Runnable( if (Config.BattleOrders.Wait) { let counter = 0; console.log( - "Waiting " + Config.BattleOrders.Wait + " seconds for other " - + (Config.BattleOrders.Mode === boMode.Give ? "boGetters..." : "boGiver...") + "Waiting " + Config.BattleOrders.Wait + " seconds for " + + (Config.BattleOrders.Mode === boMode.Give ? "other boGetters..." : "boGiver...") ); Misc.poll(() => { counter++; me.overhead( "Waiting " + Math.round(((tick + Time.seconds(Config.BattleOrders.Wait)) - getTickCount()) / 1000) - + " seconds for other " + (Config.BattleOrders.Mode === boMode.Give ? "boGetters..." : "boGiver...") + + " seconds for " + (Config.BattleOrders.Mode === boMode.Give ? "other boGetters..." : "boGiver...") ); if (counter % 5 === 0) { @@ -116,18 +116,16 @@ const BattleOrders = new Runnable( * @returns {boolean} */ function getGiver () { - const giver = Config.BattleOrders.Giver.toLowerCase(); + const giver = Config.BattleOrders.Giver; const wait = Time.seconds(Config.BattleOrders.WaitForGiver); const tick = getTickCount(); - //console.debug("Start checking for boGiver: " + giver); - while (getTickCount() - tick < wait) { const timeout = Math.floor(((tick + wait) - getTickCount()) / 1000); let player = getParty(); if (player) { do { - if (player.name && player.name.toLowerCase() === giver) { + if (player.name && player.name.toLowerCase() === giver.toLowerCase()) { return true; } } while (player.getNext());