Skip to content

Commit 27eee76

Browse files
committed
QoL & Specific Marks support.
1 parent 4e5422b commit 27eee76

File tree

3 files changed

+99
-23
lines changed

3 files changed

+99
-23
lines changed

SysBot.Pokemon/Actions/PokeRoutineExecutor.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,8 @@ public async Task StartGame(PokeTradeHubConfig config, CancellationToken token)
318318
for (int i = 0; i < 5; i++)
319319
await Click(A, 1_000, token).ConfigureAwait(false);
320320

321-
while (!await IsOnOverworld(config, token).ConfigureAwait(false) && !await IsInBattle(token))
322-
{
321+
while (!(await IsOnOverworld(config, token).ConfigureAwait(false) || await IsInBattle(token)))
323322
await Task.Delay(2_000, token).ConfigureAwait(false);
324-
await Click(A, 1_000, token).ConfigureAwait(false);
325-
}
326323

327324
Log("Back in the overworld!");
328325
}
@@ -452,14 +449,23 @@ public static uint GetOverworldOffset(ConsoleLanguageParameter value)
452449
};
453450
}
454451

455-
public async Task PokeCamp(CancellationToken token)
452+
public async Task PokeCamp(PokeTradeHubConfig config, CancellationToken token)
456453
{
457454
// Open Poke Camp and return to the overworld
458-
Log("Opening Camp...");
459-
await Click(X, 1_500, token).ConfigureAwait(false);
460-
await Click(A, 8_000, token).ConfigureAwait(false);
461-
await Click(B, 2_000, token).ConfigureAwait(false);
462-
await Click(A, 1_000, token).ConfigureAwait(false);
455+
try
456+
{
457+
Log("Opening Camp...");
458+
await Click(X, 2_500, token).ConfigureAwait(false);
459+
await Click(A, 9_000, token).ConfigureAwait(false);
460+
await Click(B, 2_000, token).ConfigureAwait(false);
461+
await Click(A, 2_000, token).ConfigureAwait(false);
462+
}
463+
catch (Exception e)
464+
{
465+
Log(e + "Exception Caught. Trying to restart.");
466+
await CloseGame(config, token).ConfigureAwait(false);
467+
await StartGame(config, token).ConfigureAwait(false);
468+
}
463469
}
464470
}
465471
}

SysBot.Pokemon/BotEncounter/EncounterBot.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private async Task DoRegiEncounter(CancellationToken token)
164164
}
165165

166166
// Offsets are flickery so make sure we see it 3 times.
167-
for (int i = 0; i < 3; i++)
167+
for (int i = 0; i < 3; i++)
168168
await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);
169169

170170
if (await HandleEncounter(pk, true, token).ConfigureAwait(false))
@@ -237,7 +237,7 @@ private async Task DoJusticeEncounter(CancellationToken token)
237237
await Task.Delay(0_500, token).ConfigureAwait(false);
238238

239239
// Enter and exit Pokecamp in order to respawn the Pokemon
240-
await PokeCamp(token);
240+
await PokeCamp(Hub.Config, token);
241241

242242
//Check position
243243
int i = 0;
@@ -255,6 +255,7 @@ private async Task DoJusticeEncounter(CancellationToken token)
255255
i = 0;
256256
await CloseGame(Hub.Config, token).ConfigureAwait(false);
257257
await StartGame(Hub.Config, token).ConfigureAwait(false);
258+
Log("Continue looping");
258259
}
259260
i++;
260261
}
@@ -272,9 +273,9 @@ private async Task DoJusticeEncounter(CancellationToken token)
272273
continue;
273274
}
274275

275-
// Offsets are flickery so make sure we see it 3 times.
276-
for (i = 0; i < 3; i++)
277-
await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);
276+
// Offsets are flickery so make sure we see it 3 times.
277+
for (i = 0; i < 3; i++)
278+
await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);
278279

279280
if (await HandleEncounter(pk, true, token).ConfigureAwait(false))
280281
return;
@@ -285,6 +286,9 @@ private async Task DoJusticeEncounter(CancellationToken token)
285286
await Task.Delay(1_000, token).ConfigureAwait(false);
286287
await FleeToOverworld(token).ConfigureAwait(false);
287288
}
289+
290+
// Extra delay to be sure we're fully out of the battle.
291+
await Task.Delay(0_250, token).ConfigureAwait(false);
288292
}
289293
}
290294

@@ -323,7 +327,7 @@ private async Task DoGArticunoEncounter(CancellationToken token)
323327
await Click(A, 1_000, token).ConfigureAwait(false);
324328

325329
// Enter and exit Pokecamp in order to respawn the Pokemon
326-
await PokeCamp(token);
330+
await PokeCamp(Hub.Config, token);
327331
}
328332
}
329333

@@ -386,7 +390,7 @@ private async Task<int> StepUntilEncounter(CancellationToken token)
386390
private async Task<bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token)
387391
{
388392
encounterCount++;
389-
Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}");
393+
Log($"Encounter: {encounterCount}{Environment.NewLine}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}{getRibbonsList(pk)}{Environment.NewLine}");
390394
if (legends)
391395
Counts.AddCompletedLegends();
392396
else
@@ -409,6 +413,19 @@ private async Task<bool> HandleEncounter(PK8 pk, bool legends, CancellationToken
409413
return false;
410414
}
411415

416+
private string getRibbonsList(PK8 pk)
417+
{
418+
string ribbonsList = "Ribbons: ";
419+
for (var mark = RibbonIndex.MarkLunchtime; mark <= RibbonIndex.MarkSlump; mark++)
420+
if (pk.GetRibbon((int)mark))
421+
ribbonsList += mark;
422+
423+
if (ribbonsList.Equals("Ribbons: "))
424+
ribbonsList += "[]";
425+
426+
return ribbonsList;
427+
}
428+
412429
private async Task ResetStick(CancellationToken token)
413430
{
414431
// If aborting the sequence, we might have the stick set at some position. Clear it just in case.

SysBot.Pokemon/Settings/StopConditionSettings.cs

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class StopConditionSettings
2121
[Category(StopConditions), Description("Selects the shiny type to stop on.")]
2222
public TargetShinyType ShinyTarget { get; set; } = TargetShinyType.DisableOption;
2323

24-
[Category(StopConditions), Description("Stop only on Pokémon that have a mark.")]
25-
public bool MarkOnly { get; set; } = false;
24+
[Category(StopConditions), Description("If set to \"Any\", the bot will target a Pokémon that has any of the Marks listed. Select a certain Mark if you're hunting for it specifically. No restrictions if set to \"None\".")]
25+
public MarkIndex MarkTarget { get; set; } = MarkIndex.None;
2626

2727
[Category(StopConditions), Description("Holds Capture button to record a 30 second clip when a matching Pokémon is found by EncounterBot or Fossilbot.")]
2828
public bool CaptureVideoClip { get; set; }
@@ -42,8 +42,10 @@ public static bool EncounterFound(PK8 pk, int[] targetIVs, StopConditionSettings
4242
if (settings.TargetNature != Nature.Random && settings.TargetNature != (Nature)pk.Nature)
4343
return false;
4444

45-
if (settings.MarkOnly && !HasMark(pk))
46-
return false;
45+
//If target is Any Mark then do the standard routine otherwise check for a specific Marker
46+
if ((settings.MarkTarget == MarkIndex.Any && !HasMark(pk, settings.MarkTarget, false)) ||
47+
(settings.MarkTarget != MarkIndex.None && settings.MarkTarget != MarkIndex.Any && !HasMark(pk, settings.MarkTarget, true)))
48+
return false;
4749

4850
if (settings.ShinyTarget != TargetShinyType.DisableOption)
4951
{
@@ -98,11 +100,11 @@ public static int[] InitializeTargetIVs(PokeTradeHub<PK8> hub)
98100
return targetIVs;
99101
}
100102

101-
private static bool HasMark(IRibbonIndex pk)
103+
private static bool HasMark(IRibbonIndex pk, MarkIndex target, bool specific)
102104
{
103105
for (var mark = RibbonIndex.MarkLunchtime; mark <= RibbonIndex.MarkSlump; mark++)
104106
{
105-
if (pk.GetRibbon((int)mark))
107+
if ((!specific && pk.GetRibbon((int)mark)) || (specific && pk.GetRibbon((int)mark) && mark.Equals(target)))
106108
return true;
107109
}
108110
return false;
@@ -117,4 +119,55 @@ public enum TargetShinyType
117119
StarOnly, // Match star shiny only
118120
SquareOnly, // Match square shiny only
119121
}
122+
123+
public enum MarkIndex
124+
{
125+
None = 0,
126+
Any = 1,
127+
MarkLunchtime = 53,
128+
MarkSleepyTime = 54,
129+
MarkDusk = 55,
130+
MarkDawn = 56,
131+
MarkCloudy = 57,
132+
MarkRainy = 58,
133+
MarkStormy = 59,
134+
MarkSnowy = 60,
135+
MarkBlizzard = 61,
136+
MarkDry = 62,
137+
MarkSandstorm = 63,
138+
MarkMisty = 64,
139+
MarkDestiny = 65,
140+
MarkFishing = 66,
141+
MarkCurry = 67,
142+
MarkUncommon = 68,
143+
MarkRare = 69,
144+
MarkRowdy = 70,
145+
MarkAbsentMinded = 71,
146+
MarkJittery = 72,
147+
MarkExcited = 73,
148+
MarkCharismatic = 74,
149+
MarkCalmness = 75,
150+
MarkIntense = 76,
151+
MarkZonedOut = 77,
152+
MarkJoyful = 78,
153+
MarkAngry = 79,
154+
MarkSmiley = 80,
155+
MarkTeary = 81,
156+
MarkUpbeat = 82,
157+
MarkPeeved = 83,
158+
MarkIntellectual = 84,
159+
MarkFerocious = 85,
160+
MarkCrafty = 86,
161+
MarkScowling = 87,
162+
MarkKindly = 88,
163+
MarkFlustered = 89,
164+
MarkPumpedUp = 90,
165+
MarkZeroEnergy = 91,
166+
MarkPrideful = 92,
167+
MarkUnsure = 93,
168+
MarkHumble = 94,
169+
MarkThorny = 95,
170+
MarkVigor = 96,
171+
MarkSlump = 97
172+
}
120173
}

0 commit comments

Comments
 (0)