diff --git a/CoreFarms.cs b/CoreFarms.cs index b7f900936..9444af9c2 100644 --- a/CoreFarms.cs +++ b/CoreFarms.cs @@ -3308,7 +3308,7 @@ void RunDeathPitBrawl(string? item = null, int quant = 1, bool isTemp = false, i // ------------------------- // 1) Faction Rank farming // ------------------------- - while (!Bot.ShouldExit && FactionRank("Death Pit Brawl") < rank) + while (!Bot.ShouldExit && !ForStory && FactionRank("Death Pit Brawl") < rank) { runTimer.Start(); ExecuteOneBrawlRun(); @@ -3324,7 +3324,7 @@ void RunDeathPitBrawl(string? item = null, int quant = 1, bool isTemp = false, i } // ------------------------- - // 2) {item} farming (only AFTER rank is done) + // 2) Item farming // ------------------------- if (item != null) { diff --git a/Other/Various/Potions.cs b/Other/Various/Potions.cs index d1f58f78b..c37efc65e 100644 --- a/Other/Various/Potions.cs +++ b/Other/Various/Potions.cs @@ -31,7 +31,7 @@ private static CoreAdvanced Adv public List Options = new() { new Option("BuyReagents", "Buy Reagents?", "Use gold to buy the reagents for the Potions [this takes ALOT of gold.].", false), - new Option("PotionQuant", "Potion Quantity", "Desired stack amount [max - 300]", 0), + new Option("PotionQuant", "Potion Quantity", "Desired stack amount [1-300]", "0"), new Option("MaxAll", "Max all Potions within the script.", "as the name says", false), CoreBots.Instance.SkipOptions, @@ -75,6 +75,13 @@ public void ScriptMain(IScriptInterface bot) // Determine if MaxAll is enabled bool maxAll = Bot.Config!.Get("MaxAll"); + int potionQuant = 300; + if (!maxAll && (!int.TryParse(Bot.Config!.Get("PotionQuant"), out potionQuant) || potionQuant is < 1 or > 300)) + { + Core.Logger("Enter a Potion Quantity from 1 to 300.", messageBox: true, stopBot: true); + return; + } + // Prepare Potions and PotionsFarm arrays if MaxAll is true string[]? potions = maxAll ? new[] @@ -110,17 +117,6 @@ public void ScriptMain(IScriptInterface bot) ? [.. Enumerable.Repeat(true, potions!.Length)] : null; - string? raw = Bot.Config!.Get("PotionQuant"); - - int potionQuant; - - if (!int.TryParse(raw, out potionQuant)) - { - Core.Logger($"Invalid PotionQuant '{raw}', defaulting to 300"); - potionQuant = 300; - } - - potionQuant = maxAll ? 300 : potionQuant; // Call the main potion farming method INeedYourStrongestPotions( Potions: potions, diff --git a/Story/0AllStories.cs b/Story/0AllStories.cs index b142d4671..61172e1de 100644 --- a/Story/0AllStories.cs +++ b/Story/0AllStories.cs @@ -1768,7 +1768,10 @@ public void CompleteAll() Core.Logger($"Story: SuperDeath - Complete"); ThirdSpell.StoryLine(); - Core.Logger($"Story: Third Spell - Complete"); + if (Core.CheckInventory("Sun Token VIII", toInv: false)) + Core.Logger("Story: Third Spell - Complete"); + else + Core.Logger("Story: Third Spell - Sun Token VIII missing"); TitanAttackStory.DoAll(); Core.Logger($"Story: Titan Attack - Complete"); diff --git a/Story/EtherstormWastes.cs b/Story/EtherstormWastes.cs index def4f7a1b..ea3ba83a5 100644 --- a/Story/EtherstormWastes.cs +++ b/Story/EtherstormWastes.cs @@ -253,7 +253,7 @@ public void FireStorm() if (!Story.QuestProgression(1532)) { Core.EnsureAccept(1532); - Core.HuntMonster("firestorm", "Sulfur Imp", "Sulfuric Core", 10); + Core.HuntMonster("firestorm", "Sulfur Imp", "Sulfuric Core", 8); Core.HuntMonster("firestorm", "Sulfur Imp", "Enchanted Lava Bucket", 1); Core.EnsureComplete(1532); } @@ -342,7 +342,7 @@ public void WaterStorm() { Core.EnsureAccept(1619); Core.GetMapItem(843, 10, "waterstorm"); - Core.HuntMonster("waterstorm", "Living Water", "Aqua Vitae", 15); + Core.HuntMonster("waterstorm", "Living Water", "Aqua Vitae", 12); Core.HuntMonster("waterstorm", "Living Water", "Water Bubble Burst", 10); Core.EnsureComplete(1619); } diff --git a/Story/ThirdSpell.cs b/Story/ThirdSpell.cs index 8f8e511ac..a0321f100 100644 --- a/Story/ThirdSpell.cs +++ b/Story/ThirdSpell.cs @@ -165,6 +165,7 @@ void QuestLogic() break; case 4491: // 4491|Mother Knows The Sun + Core.AddDrop("Heart of the Sun"); Core.HuntMonster("thirdspell", "Solar Incarnation ", "Heart of the Sun Received"); break; @@ -173,6 +174,7 @@ void QuestLogic() break; case 4493: // 4493|See the Hero Run + HeartoftheSun(); Core.GetMapItem(3677, map: "thirdspell"); break; } diff --git a/Tools/FindBestPing.cs b/Tools/FindBestPing.cs index dbcf9e147..f7836f566 100644 --- a/Tools/FindBestPing.cs +++ b/Tools/FindBestPing.cs @@ -1,12 +1,16 @@ /* -name: Find Best Server Ping -description: will spit out the best server ( ping wise) into the logs ( diagnostics > logs ) +name: Find Top 3 Best Server Pings +description: measures AQW handshake latency and logs the three fastest servers ( diagnostics > logs ) tags: server, ping, ultra */ //cs_include Scripts/CoreBots.cs using Skua.Core.Interfaces; +using Skua.Core.Models.Servers; +using System.Diagnostics; +using System.Net.Sockets; +using System.Text; public class FindBestPing { @@ -19,7 +23,7 @@ public async Task ScriptMain(IScriptInterface Bot) try { - string result = await Core.FindBestServer(); + string result = await FindTopThreeServers(); Bot.Log(result); } finally @@ -28,8 +32,88 @@ public async Task ScriptMain(IScriptInterface Bot) } } + /// + /// Finds the three fastest game servers by measuring actual AQW handshake latency. + /// Uses three samples per server and ranks servers by their median successful latency. + /// + private async Task FindTopThreeServers() + { + List servers = await Bot.Servers.GetServers(true); + byte[] versionCheck = Encoding.UTF8.GetBytes("\0"); + List<(Server Server, long Ping)> pingResults = new(); -} + foreach (Server server in servers.Where(server => + server.Online && !string.IsNullOrWhiteSpace(server.IP) && server.Port > 0)) + { + List samples = new(3); + + for (int sample = 0; sample < 3; sample++) + { + try + { + Stopwatch stopwatch = Stopwatch.StartNew(); + using TcpClient client = new(); + await client.ConnectAsync(server.IP, server.Port).WaitAsync(TimeSpan.FromMilliseconds(2500)); + + using NetworkStream stream = client.GetStream(); + await stream.WriteAsync(versionCheck.AsMemory()); + await stream.FlushAsync(); + + using CancellationTokenSource timeout = new(2500); + byte[] buffer = new byte[1]; + StringBuilder response = new(); + + while (!timeout.IsCancellationRequested) + { + int bytesRead = await stream.ReadAsync(buffer.AsMemory(), timeout.Token); + if (bytesRead == 0) + break; + + if (buffer[0] != 0) + { + response.Append((char)buffer[0]); + continue; + } + string message = response.ToString(); + response.Clear(); + if (message.Contains("action='apiOK'", StringComparison.OrdinalIgnoreCase) || + message.Contains("action=\"apiOK\"", StringComparison.OrdinalIgnoreCase)) + { + stopwatch.Stop(); + samples.Add(stopwatch.Elapsed.TotalMilliseconds); + break; + } + if (message.Contains("action='apiKO'", StringComparison.OrdinalIgnoreCase) || + message.Contains("action=\"apiKO\"", StringComparison.OrdinalIgnoreCase)) + break; + } + } + catch (OperationCanceledException) { } + catch (Exception) { } + } + + if (samples.Count == 0) + continue; + + samples.Sort(); + long medianPing = (long)Math.Round(samples[samples.Count / 2], MidpointRounding.AwayFromZero); + pingResults.Add((server, medianPing)); + } + + List<(Server Server, long Ping)> bestServers = pingResults + .OrderBy(result => result.Ping) + .ThenBy(result => result.Server.Name, StringComparer.OrdinalIgnoreCase) + .Take(3) + .ToList(); + + if (bestServers.Count == 0) + return "Could not determine an optimal server, all hosts failed their AQW handshake."; + + return $"Top {bestServers.Count} servers by AQW handshake latency:{Environment.NewLine}" + + string.Join(Environment.NewLine, bestServers.Select((result, index) => + $"{index + 1}. {result.Server.Name} ({result.Server.IP}) - {result.Ping}ms")); + } +} diff --git a/Tools/ForDevelopers/FetchGameFiles/.last_version b/Tools/ForDevelopers/FetchGameFiles/.last_version index 3691f3266..eb3acaa42 100644 --- a/Tools/ForDevelopers/FetchGameFiles/.last_version +++ b/Tools/ForDevelopers/FetchGameFiles/.last_version @@ -1 +1 @@ -4000r8 \ No newline at end of file +4000r9 \ No newline at end of file diff --git a/scripts.json b/scripts.json index 5345d0cc8..f49c761c9 100644 --- a/scripts.json +++ b/scripts.json @@ -42,8 +42,8 @@ "null" ], "path": "CoreFarms.cs", - "size": 166230, - "sha256": "0e031b1e29a3eb75344571bca6724d09c0cf90971f8561c2e46d37e1ec395bd7", + "size": 166215, + "sha256": "f088bdc5f3526b90f71ee33472e701e66820e1b296de91c9f282fb8d4a558829", "fileName": "CoreFarms.cs", "downloadUrl": "https://raw.githubusercontent.com/auqw/Scripts/Skua/CoreFarms.cs" }, @@ -543,8 +543,8 @@ "thirdspell" ], "path": "Story/ThirdSpell.cs", - "size": 22641, - "sha256": "b2c9db51d6ad76d5d3b8c34fb250f5af921fc224275e1a38d2cf5e76a27a914c", + "size": 22740, + "sha256": "c1914c6c866c4c562eae9794c902bef892d08d43d4620b74d9343011ec672690", "fileName": "ThirdSpell.cs", "downloadUrl": "https://raw.githubusercontent.com/auqw/Scripts/Skua/Story/ThirdSpell.cs" }, @@ -1553,8 +1553,8 @@ "etherstorm-wastes" ], "path": "Story/EtherstormWastes.cs", - "size": 20377, - "sha256": "80d627138f125ce6463719e5d05587d32e8bdec0cc11517844faccdca106cceb", + "size": 20376, + "sha256": "2493e5b4e4cfb40e31118aebb7df2f71a8a365242be22950069629ec9ffcfce5", "fileName": "EtherstormWastes.cs", "downloadUrl": "https://raw.githubusercontent.com/auqw/Scripts/Skua/Story/EtherstormWastes.cs" }, @@ -2027,8 +2027,8 @@ "all" ], "path": "Story/0AllStories.cs", - "size": 53768, - "sha256": "6cded52f5ed37c4ef0df1fc7e0f22acbae091bea59b2412cd467739502945e01", + "size": 53921, + "sha256": "08d827da65b6fd9d459d2c35ff34f30b829c3d81650d20dfb1cc18d42a448a3f", "fileName": "0AllStories.cs", "downloadUrl": "https://raw.githubusercontent.com/auqw/Scripts/Skua/Story/0AllStories.cs" }, @@ -2371,16 +2371,16 @@ "downloadUrl": "https://raw.githubusercontent.com/auqw/Scripts/Skua/Tools/KPHandItemCounter.cs" }, { - "name": "Find Best Server Ping", - "description": "will spit out the best server ( ping wise) into the logs ( diagnostics > logs )", + "name": "Find Top 3 Best Server Pings", + "description": "measures AQW handshake latency and logs the three fastest servers ( diagnostics > logs )", "tags": [ "server", "ping", "ultra" ], "path": "Tools/FindBestPing.cs", - "size": 672, - "sha256": "7a9090e3aa83c3c3e374b505a47d018284497118e965419b12da36517d67ae2b", + "size": 4504, + "sha256": "acc11db3f48f1b1825ba9be7957ee4485838dac020e0cd8183178a9611c90b7b", "fileName": "FindBestPing.cs", "downloadUrl": "https://raw.githubusercontent.com/auqw/Scripts/Skua/Tools/FindBestPing.cs" }, @@ -16607,8 +16607,8 @@ "minecraft" ], "path": "Other/Various/Potions.cs", - "size": 21219, - "sha256": "e0e0ed1750049ad154c6a54fd879a1046c00f724806fded37e94c2e9e3346fe8", + "size": 21204, + "sha256": "8944efe8329f7e67edd5b8b03dc261d88e6508cf9a8a7fdfc18c7638bef75177", "fileName": "Potions.cs", "downloadUrl": "https://raw.githubusercontent.com/auqw/Scripts/Skua/Other/Various/Potions.cs" },