Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reset game every X raids #162

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RaidCrawler.Tests/TestUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private string GetStringTestResource(string name)

// Read embedded base data and read all raids.
var baseData = GetBinaryTestResource(GetTestResourceName(path, "base"));
var failed = container.ReadAllRaids(baseData, storyPrg, eventPrg, 0);
var failed = container.ReadAllRaids(baseData, storyPrg, 0, eventPrg, 0);
return (failed, container);
}

Expand Down
3 changes: 3 additions & 0 deletions RaidCrawler.WinForms/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class ClientConfig : IDateAdvanceConfig, IWebhookConfig
public int Progress { get; set; } = 0;
public int EventProgress { get; set; } = 0;
public bool EnableFilters { get; set; } = true;
public bool PaldeaScan { get; set; } = true;
public bool KitakamiScan { get; set; } = true;

// Match
public bool FocusWindow { get; set; } = true;
Expand Down Expand Up @@ -44,6 +46,7 @@ public class ClientConfig : IDateAdvanceConfig, IWebhookConfig
public int SystemOvershoot { get; set; } = 0_750;
public int BaseDelay { get; set; } = 0;
public int SaveGameDelay { get; set; } = 0;
public int SystemReset { get; set; } = 30;

// Webhook
public bool EnableEmoji { get; set; } = true;
Expand Down
2 changes: 1 addition & 1 deletion RaidCrawler.WinForms/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 74 additions & 57 deletions RaidCrawler.WinForms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,21 @@ private async Task AdvanceDateClick(CancellationToken token)

var stop = false;
var raids = RaidContainer.Raids;
int skips = 0;

while (!stop)
{
if (skips >= Config.SystemReset)
{
await ConnectionWrapper.CloseGame(token).ConfigureAwait(false);
await ConnectionWrapper.StartGame(token).ConfigureAwait(false);
RaidBlockOffsetBase = 0;
RaidBlockOffsetKitakami = 0;
skips = 0;
}

var previousSeeds = raids.Select(z => z.Seed).ToList();
UpdateStatus("Changing date...");

bool streamer = Config.StreamerView && teraRaidView is not null;
Action<int>? action = streamer ? teraRaidView!.UpdateProgressBar : null;
await ConnectionWrapper
Expand All @@ -591,7 +601,7 @@ await ConnectionWrapper
Invoke(DisplayPrettyRaid);

stop = StopAdvanceDate(previousSeeds);

skips++;
var advanceText =
$"Day Skip Successes {GetStatDaySkipSuccess()} / {GetStatDaySkipTries()}";
Invoke(() => Label_DayAdvance.Text = advanceText);
Expand Down Expand Up @@ -1694,6 +1704,12 @@ private bool StopAdvanceDate(List<uint> previousSeeds)

private async Task ReadRaids(CancellationToken token)
{
if (!Config.PaldeaScan && !Config.KitakamiScan)
{
await ErrorHandler.DisplayMessageBox(this, Webhook, "Please select a location to scan in your General Settings.", token, "No locations selected").ConfigureAwait(false);
return;
}

if (RaidBlockOffsetBase == 0)
{
UpdateStatus("Caching the raid block pointers...");
Expand All @@ -1709,74 +1725,75 @@ private async Task ReadRaids(CancellationToken token)
RaidContainer.ClearEncounters();
RaidContainer.ClearRewards();

// Base
UpdateStatus("Reading Paldea raid block...");
var data = await ConnectionWrapper.Connection
.ReadBytesAbsoluteAsync(
RaidBlockOffsetBase + RaidBlock.HEADER_SIZE,
(int)(RaidBlock.SIZE_BASE - RaidBlock.HEADER_SIZE),
token
)
.ConfigureAwait(false);

// Base
byte[]? data = null!;
var msg = string.Empty;
(int delivery, int enc) = RaidContainer.ReadAllRaids(
data,
Config.Progress,
Config.EventProgress,
GetRaidBoost(),
RaidSerializationFormat.BaseROM
);
if (enc > 0)
msg += $"Failed to find encounters for {enc} raid(s).\n";
int delivery, enc;

if (delivery > 0)
msg +=
$"Invalid delivery group ID for {delivery} raid(s). Try deleting the \"cache\" folder.\n";

if (msg != string.Empty)
if (Config.PaldeaScan)
{
msg += "\nMore info can be found in the \"raid_dbg.txt\" file.";
await ErrorHandler
.DisplayMessageBox(this, Webhook, msg, token, "Raid Read Error")
.ConfigureAwait(false);
UpdateStatus("Reading Paldea raid block...");
data = await ConnectionWrapper.Connection
.ReadBytesAbsoluteAsync(RaidBlockOffsetBase + RaidBlock.HEADER_SIZE, (int)(RaidBlock.SIZE_BASE - RaidBlock.HEADER_SIZE), token).ConfigureAwait(false);

(delivery, enc) = RaidContainer.ReadAllRaids(data, Config.Progress, Config.EventProgress, GetRaidBoost(), RaidSerializationFormat.BaseROM);
if (enc > 0)
msg += $"Failed to find encounters for {enc} raid(s).\n";

if (delivery > 0)
msg +=
$"Invalid delivery group ID for {delivery} raid(s). Try deleting the \"cache\" folder.\n";

if (msg != string.Empty)
{
msg += "\nMore info can be found in the \"raid_dbg.txt\" file.";
await ErrorHandler
.DisplayMessageBox(this, Webhook, msg, token, "Raid Read Error")
.ConfigureAwait(false);
}
}

var raids = RaidContainer.Raids;
var encounters = RaidContainer.Encounters;
var rewards = RaidContainer.Rewards;
RaidContainer.ClearRaids();
RaidContainer.ClearEncounters();
RaidContainer.ClearRewards();

// Kitakami
UpdateStatus("Reading Kitakami raid block...");
data = await ConnectionWrapper.Connection
.ReadBytesAbsoluteAsync(
RaidBlockOffsetKitakami,
(int)RaidBlock.SIZE_KITAKAMI,
token
)
.ConfigureAwait(false);
if (Config.KitakamiScan)
{
UpdateStatus("Reading Kitakami raid block...");
data = await ConnectionWrapper.Connection
.ReadBytesAbsoluteAsync(
RaidBlockOffsetKitakami,
(int)RaidBlock.SIZE_KITAKAMI,
token
)
.ConfigureAwait(false);

msg = string.Empty;
(delivery, enc) = RaidContainer.ReadAllRaids(
data,
Config.Progress,
Config.EventProgress,
GetRaidBoost(),
RaidSerializationFormat.KitakamiROM
);
if (enc > 0)
msg += $"Failed to find encounters for {enc} raid(s).\n";
msg = string.Empty;
(delivery, enc) = RaidContainer.ReadAllRaids(
data,
Config.Progress,
Config.EventProgress,
GetRaidBoost(),
RaidSerializationFormat.KitakamiROM
);
if (enc > 0)
msg += $"Failed to find encounters for {enc} raid(s).\n";

if (delivery > 0)
msg +=
$"Invalid delivery group ID for {delivery} raid(s). Try deleting the \"cache\" folder.\n";
if (delivery > 0)
msg +=
$"Invalid delivery group ID for {delivery} raid(s). Try deleting the \"cache\" folder.\n";

if (msg != string.Empty)
{
msg += "\nMore info can be found in the \"raid_dbg.txt\" file.";
await ErrorHandler
.DisplayMessageBox(this, Webhook, msg, token, "Raid Read Error")
.ConfigureAwait(false);
if (msg != string.Empty)
{
msg += "\nMore info can be found in the \"raid_dbg.txt\" file.";
await ErrorHandler
.DisplayMessageBox(this, Webhook, msg, token, "Raid Read Error")
.ConfigureAwait(false);
}
}

var allRaids = raids.Concat(RaidContainer.Raids).ToList().AsReadOnly();
Expand Down
Loading
Loading