Skip to content

Commit

Permalink
typo corrected.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu098vm committed May 4, 2021
1 parent dd31070 commit 1134b96
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 10 deletions.
11 changes: 7 additions & 4 deletions SysBot.Pokemon/Actions/PokeRoutineExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,21 @@ public async Task<List<PK8>> 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)
Expand Down
7 changes: 3 additions & 4 deletions SysBot.Pokemon/Idle/PokeTradeHubConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
83 changes: 83 additions & 0 deletions SysBot.Pokemon/SWSH_BotEncounter/EncounterBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<int> 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<bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token)
{
encounterCount++;
Expand Down
10 changes: 10 additions & 0 deletions SysBot.Pokemon/SWSH_BotEncounter/EncounterModes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@ public enum EncounterMode
/// Bot will soft reset Gifts
/// </summary>
Gifts,
/// <summary>
/// Bot will move back and forth in a straight vertical path to encounter Pokémon
/// </summary>
VerticalLine,

/// <summary>
/// Bot will move back and forth in a straight horizontal path to encounter Pokémon
/// </summary>
HorizontalLine,

}
}
4 changes: 2 additions & 2 deletions SysBot.Pokemon/SWSH_OverworldScan/OverworldScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1134b96

Please sign in to comment.