From 1134b963ef7696bd4c316188b49c0c6839b77243 Mon Sep 17 00:00:00 2001 From: Manu098vm Date: Tue, 4 May 2021 21:41:50 +0200 Subject: [PATCH] typo corrected. --- SysBot.Pokemon/Actions/PokeRoutineExecutor.cs | 11 ++- SysBot.Pokemon/Idle/PokeTradeHubConfig.cs | 7 +- .../SWSH_BotEncounter/EncounterBot.cs | 83 +++++++++++++++++++ .../SWSH_BotEncounter/EncounterModes.cs | 10 +++ .../SWSH_OverworldScan/OverworldScan.cs | 4 +- 5 files changed, 105 insertions(+), 10 deletions(-) diff --git a/SysBot.Pokemon/Actions/PokeRoutineExecutor.cs b/SysBot.Pokemon/Actions/PokeRoutineExecutor.cs index 42eeed49..1f708c6c 100644 --- a/SysBot.Pokemon/Actions/PokeRoutineExecutor.cs +++ b/SysBot.Pokemon/Actions/PokeRoutineExecutor.cs @@ -210,18 +210,21 @@ public async Task> ReadOwPokemonFromBlock(byte[] KCoordinates, SAV8 sa { data = await Connection.ReadBytesAsync(offset, 56, token).ConfigureAwait(false); species = (Species)BitConverter.ToUInt16(data.Slice(0, 2), 0); - //Log($"Target: {target}, Encountered: {species}"); + Log($"Target: {target}, Encountered: {species}"); offset += 192; i++; - } while (target != 0 && species != 0 && target != species && i <= 20); - if (i == 20) + } while (target != 0 && species != 0 && target != species && i <= 300); + if (i > 100) + { data = null; + Log("Above 100"); + } } else if (mondata != null) { data = mondata; species = (Species)BitConverter.ToUInt16(data.Slice(0, 2), 0); - //Log($"Encountered: {species}"); + Log($"Encountered: {species}"); } if (data != null && data[20] == 1) diff --git a/SysBot.Pokemon/Idle/PokeTradeHubConfig.cs b/SysBot.Pokemon/Idle/PokeTradeHubConfig.cs index 2615db99..24747080 100644 --- a/SysBot.Pokemon/Idle/PokeTradeHubConfig.cs +++ b/SysBot.Pokemon/Idle/PokeTradeHubConfig.cs @@ -49,18 +49,17 @@ public sealed class PokeTradeHubConfig [Category(Bots)] [TypeConverter(typeof(ExpandableObjectConverter))] - public DynaAdventureSettings SWSH_DynaAdventure { get; set; } = new(); + public EncounterSettings SWSH_Encounter { get; set; } = new(); [Category(Bots)] [TypeConverter(typeof(ExpandableObjectConverter))] - public FossilSettings SWSH_Fossil { get; set; } = new(); + public DynaAdventureSettings SWSH_DynaAdventure { get; set; } = new(); [Category(Bots)] [TypeConverter(typeof(ExpandableObjectConverter))] - public EncounterSettings SWSH_Encounter { get; set; } = new(); + public FossilSettings SWSH_Fossil { get; set; } = new(); // Integration - [Category(Integration)] [TypeConverter(typeof(ExpandableObjectConverter))] public DiscordSettings Discord { get; set; } = new(); diff --git a/SysBot.Pokemon/SWSH_BotEncounter/EncounterBot.cs b/SysBot.Pokemon/SWSH_BotEncounter/EncounterBot.cs index aadf04e3..e2a8ef80 100644 --- a/SysBot.Pokemon/SWSH_BotEncounter/EncounterBot.cs +++ b/SysBot.Pokemon/SWSH_BotEncounter/EncounterBot.cs @@ -48,6 +48,8 @@ public override async Task MainLoop(CancellationToken token) EncounterMode.Eternatus => DoRestartingEncounter(token), EncounterMode.Dogs_or_Calyrex => DoDogEncounter(token), EncounterMode.Keldeo => DoKeldeoEncounter(token), + EncounterMode.VerticalLine => WalkInLine(token), + EncounterMode.HorizontalLine => WalkInLine(token), _ => DoLiveStatsChecking(token), }; await task.ConfigureAwait(false); @@ -215,6 +217,87 @@ private async Task DoKeldeoEncounter(CancellationToken token) } } + private async Task WalkInLine(CancellationToken token) + { + while (!token.IsCancellationRequested) + { + var attempts = await StepUntilEncounter(token).ConfigureAwait(false); + if (attempts < 0) // aborted + continue; + + Log($"Encounter found after {attempts} attempts! Checking details..."); + + // Reset stick while we wait for the encounter to load. + await ResetStick(token).ConfigureAwait(false); + + var pk = await ReadUntilPresent(WildPokemonOffset, 2_000, 0_200, token).ConfigureAwait(false); + if (pk == null) + { + Log("Invalid data detected. Restarting loop."); + + // Flee and continue looping. + await FleeToOverworld(token).ConfigureAwait(false); + continue; + } + + // Offsets are flickery so make sure we see it 3 times. + for (int i = 0; i < 3; i++) + await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false); + + if (await HandleEncounter(pk, false, token).ConfigureAwait(false)) + return; + + Log("Running away..."); + await FleeToOverworld(token).ConfigureAwait(false); + } + } + + private async Task StepUntilEncounter(CancellationToken token) + { + Log("Walking around until an encounter..."); + int attempts = 0; + while (!token.IsCancellationRequested && Config.NextRoutineType == PokeRoutineType.SWSH_EncounterBot) + { + if (!await IsInBattle(token).ConfigureAwait(false)) + { + switch (Hub.Config.SWSH_Encounter.EncounteringType) + { + case EncounterMode.VerticalLine: + await SetStick(LEFT, 0, -30000, 2_400, token).ConfigureAwait(false); + await SetStick(LEFT, 0, 0, 0_100, token).ConfigureAwait(false); // reset + + // Quit early if we found an encounter on first sweep. + if (await IsInBattle(token).ConfigureAwait(false)) + break; + + await SetStick(LEFT, 0, 30000, 2_400, token).ConfigureAwait(false); + await SetStick(LEFT, 0, 0, 0_100, token).ConfigureAwait(false); // reset + break; + case EncounterMode.HorizontalLine: + await SetStick(LEFT, -30000, 0, 2_400, token).ConfigureAwait(false); + await SetStick(LEFT, 0, 0, 0_100, token).ConfigureAwait(false); // reset + + // Quit early if we found an encounter on first sweep. + if (await IsInBattle(token).ConfigureAwait(false)) + break; + + await SetStick(LEFT, 30000, 0, 2_400, token).ConfigureAwait(false); + await SetStick(LEFT, 0, 0, 0_100, token).ConfigureAwait(false); // reset + break; + } + + attempts++; + if (attempts % 10 == 0) + Log($"Tried {attempts} times, still no encounters."); + } + + if (await IsInBattle(token).ConfigureAwait(false)) + return attempts; + } + + return -1; // aborted + } + private async Task HandleEncounter(PK8 pk, bool legends, CancellationToken token) { encounterCount++; diff --git a/SysBot.Pokemon/SWSH_BotEncounter/EncounterModes.cs b/SysBot.Pokemon/SWSH_BotEncounter/EncounterModes.cs index 19e1f328..7c6249c2 100644 --- a/SysBot.Pokemon/SWSH_BotEncounter/EncounterModes.cs +++ b/SysBot.Pokemon/SWSH_BotEncounter/EncounterModes.cs @@ -46,5 +46,15 @@ public enum EncounterMode /// Bot will soft reset Gifts /// Gifts, + /// + /// Bot will move back and forth in a straight vertical path to encounter Pokémon + /// + VerticalLine, + + /// + /// Bot will move back and forth in a straight horizontal path to encounter Pokémon + /// + HorizontalLine, + } } \ No newline at end of file diff --git a/SysBot.Pokemon/SWSH_OverworldScan/OverworldScan.cs b/SysBot.Pokemon/SWSH_OverworldScan/OverworldScan.cs index 4198b8f4..e1b69696 100644 --- a/SysBot.Pokemon/SWSH_OverworldScan/OverworldScan.cs +++ b/SysBot.Pokemon/SWSH_OverworldScan/OverworldScan.cs @@ -186,12 +186,12 @@ private async Task DoSeededEncounter(CancellationToken token) dexn = (Species)144; offset = CrownTundraSnowslideSlopeSpawns; } - else if (type == ScanMode.G_Moltres) + else if (type == ScanMode.G_Zapdos) { dexn = (Species)145; offset = WildAreaMotostokeSpawns; } - else if (type == ScanMode.G_Zapdos) + else if (type == ScanMode.G_Moltres) { dexn = (Species)146; offset = IsleOfArmorStationSpaws;