Skip to content

Commit b2c7dc2

Browse files
committed
Fix raid rotation priority logic to prevent infinite loops
The priority system was constantly jumping back to Mystery Raids after every configured raid, preventing configured raids from being played. Also removed stuck detection that conflicted with the priority system's intentional jumps. Changes: - Skip priority checks after finishing a priority raid (Mystery or user-requested) - Remove conflicting stuck detection logic - Add bounds checking to prevent index out of range errors This ensures the proper 3-tier priority: user requests → Mystery Raids → configured raids
1 parent 02e8aa4 commit b2c7dc2

1 file changed

Lines changed: 37 additions & 18 deletions

File tree

SysBot.Pokemon/SV/BotRaid/RotatingRaidBotSV.cs

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,9 @@ private async Task SanitizeRotationCount(CancellationToken token)
18981898

18991899
// Store the current raid to verify we're actually advancing
19001900
int previousRotationCount = RotationCount;
1901-
string previousSpecies = _settings.ActiveRaids[RotationCount].Species.ToString();
1901+
var previousRaid = _settings.ActiveRaids[RotationCount];
1902+
string previousSpecies = previousRaid.Species.ToString();
1903+
bool previousWasPriorityRaid = previousRaid.AddedByRACommand;
19021904

19031905
// Always advance to next raid (this fixes the replay issue)
19041906
int nextEnabledRaidIndex = FindNextEnabledRaidIndex((RotationCount + 1) % _settings.ActiveRaids.Count);
@@ -1923,22 +1925,43 @@ private async Task SanitizeRotationCount(CancellationToken token)
19231925
// Assign the next rotation
19241926
RotationCount = nextEnabledRaidIndex;
19251927

1926-
// Handle random rotation - must be checked BEFORE priority raids
1928+
// Handle random rotation
19271929
if (_settings.RaidSettings.RandomRotation)
19281930
{
19291931
Log("Random rotation enabled. Selecting random raid.");
19301932
ProcessRandomRotation();
1931-
// Verify we got a valid rotation after random selection
19321933
EnsureRotationCountInBounds();
1934+
1935+
// Update RaidUpNext for the next raid
1936+
for (int i = 0; i < _settings.ActiveRaids.Count; i++)
1937+
{
1938+
_settings.ActiveRaids[i].RaidUpNext = i == RotationCount;
1939+
}
1940+
1941+
// Mark first run as complete
1942+
if (_firstRun)
1943+
{
1944+
_firstRun = false;
1945+
}
1946+
1947+
var randomRaid = _settings.ActiveRaids[RotationCount];
1948+
string randomRaidIdentifier = randomRaid.Title.Contains(MysteryRaidTitle)
1949+
? randomRaid.Title
1950+
: randomRaid.Species.ToString();
1951+
Log($"Next raid in the list: {randomRaidIdentifier} (RotationCount: {RotationCount}, Previous: {previousRotationCount}).");
1952+
return;
19331953
}
1934-
else
1954+
1955+
// Check for priority raids (RA commands take precedence) - only in sequential mode
1956+
// Skip priority check if we just finished a priority raid (prevents loops)
1957+
if (!previousWasPriorityRaid)
19351958
{
1936-
// Check for priority raids (RA commands take precedence) - only in sequential mode
19371959
int nextPriorityIndex = FindNextPriorityRaidIndex(RotationCount, _settings.ActiveRaids);
19381960
if (nextPriorityIndex != -1 && nextPriorityIndex != RotationCount)
19391961
{
19401962
Log($"Priority raid found at index {nextPriorityIndex}. Switching from {RotationCount}.");
19411963
RotationCount = nextPriorityIndex;
1964+
EnsureRotationCountInBounds();
19421965
}
19431966
}
19441967

@@ -1954,12 +1977,8 @@ private async Task SanitizeRotationCount(CancellationToken token)
19541977
_firstRun = false;
19551978
}
19561979

1957-
// Verify we're not stuck on the same raid (unless there's only 1 raid)
1958-
if (_settings.ActiveRaids.Count > 1 && RotationCount == previousRotationCount)
1959-
{
1960-
Log($"WARNING: Rotation count did not advance from {previousRotationCount} ({previousSpecies}). Forcing advancement.");
1961-
RotationCount = (RotationCount + 1) % _settings.ActiveRaids.Count;
1962-
}
1980+
// Final bounds check before accessing the raid
1981+
EnsureRotationCountInBounds();
19631982

19641983
var nextRaid = _settings.ActiveRaids[RotationCount];
19651984
string raidIdentifier = nextRaid.Title.Contains(MysteryRaidTitle)
@@ -2002,32 +2021,32 @@ private int FindNextPriorityRaidIndex(int currentRotationCount, List<RotatingRai
20022021

20032022
int count = raids.Count;
20042023

2005-
// First, check for user-requested RA command raids
2006-
for (int i = 0; i < count; i++)
2024+
// Priority 1: Check for user-requested RA command raids (highest priority)
2025+
for (int i = 1; i <= count; i++)
20072026
{
20082027
int index = (currentRotationCount + i) % count;
20092028
RotatingRaidParameters raid = raids[index];
20102029
if (raid.ActiveInRotation && raid.AddedByRACommand && !raid.Title.Contains(MysteryRaidTitle))
20112030
{
2012-
return index; // Prioritize user-requested raids
2031+
return index; // Prioritize user-requested raids first
20132032
}
20142033
}
20152034

2016-
// Next, check for Mystery Shiny Raids if enabled
2035+
// Priority 2: Check for Mystery Shiny Raids (if no user requests found)
20172036
if (_settings.RaidSettings.MysteryRaids)
20182037
{
2019-
for (int i = 0; i < count; i++)
2038+
for (int i = 1; i <= count; i++)
20202039
{
20212040
int index = (currentRotationCount + i) % count;
20222041
RotatingRaidParameters raid = raids[index];
20232042
if (raid.ActiveInRotation && raid.Title.Contains(MysteryRaidTitle))
20242043
{
2025-
return index; // Only consider Mystery Shiny Raids after user-requested raids
2044+
return index; // Prioritize Mystery Shiny Raids over configured raids
20262045
}
20272046
}
20282047
}
20292048

2030-
// Return current rotation count if no priority raids are found
2049+
// Return -1 if no priority raids are found
20312050
return -1;
20322051
}
20332052

0 commit comments

Comments
 (0)