From 141f2eb9f20ab0cf0114d0bcbdce27356cb12786 Mon Sep 17 00:00:00 2001 From: CardBreaker <43624643+CardBreaker@users.noreply.github.com> Date: Fri, 22 Sep 2023 21:30:44 -0400 Subject: [PATCH] Fix Scarlet counts + styling (#166) Closes #164 --- RaidCrawler.Core/Extensions/RaidExtensions.cs | 100 +++++----- RaidCrawler.Core/Structures/RaidBlock.cs | 10 +- RaidCrawler.Core/Structures/RaidContainer.cs | 9 +- .../Structures/TeraDistribution.cs | 80 ++++---- RaidCrawler.Core/Structures/TeraEncounter.cs | 34 ++-- RaidCrawler.WinForms/MainWindow.cs | 177 +++++++++--------- 6 files changed, 203 insertions(+), 207 deletions(-) diff --git a/RaidCrawler.Core/Extensions/RaidExtensions.cs b/RaidCrawler.Core/Extensions/RaidExtensions.cs index df84f59..1b5e41f 100644 --- a/RaidCrawler.Core/Extensions/RaidExtensions.cs +++ b/RaidCrawler.Core/Extensions/RaidExtensions.cs @@ -20,29 +20,29 @@ int id public static ITeraRaid? GetEncounterBase( this Raid raid, RaidContainer container, - int stage, - bool black + int progress, + bool isBlack ) { var clone = new Xoroshiro128Plus(raid.Seed); - var starcount = black ? 6 : raid.GetStarCount((uint)clone.NextInt(100), stage, false); + var starCount = isBlack ? 6 : raid.GetStarCount((uint)clone.NextInt(100), progress, false); var total = container.Game == "Scarlet" - ? GetRateTotalBaseSL(starcount) - : GetRateTotalBaseVL(starcount); - var speciesroll = clone.NextInt((ulong)total); + ? GetRateTotalBaseSL(starCount) + : GetRateTotalBaseVL(starCount); + var speciesRoll = clone.NextInt((ulong)total); if (container.GemTeraRaidsBase is not null) { foreach (TeraEncounter enc in container.GemTeraRaidsBase) { - if (enc.Stars != starcount) + if (enc.Stars != starCount) continue; var minimum = container.Game == "Scarlet" ? enc.Entity.RandRateMinScarlet : enc.Entity.RandRateMinViolet; - if (minimum >= 0 && (uint)((int)speciesroll - minimum) < enc.Entity.RandRate) + if (minimum >= 0 && (uint)((int)speciesRoll - minimum) < enc.Entity.RandRate) return enc; } } @@ -52,29 +52,29 @@ bool black public static ITeraRaid? GetEncounterKitakami( this Raid raid, RaidContainer container, - int stage, - bool black + int progress, + bool isBlack ) { var clone = new Xoroshiro128Plus(raid.Seed); - var starcount = black ? 6 : raid.GetStarCount((uint)clone.NextInt(100), stage, false); + var starCount = isBlack ? 6 : raid.GetStarCount((uint)clone.NextInt(100), progress, false); var total = container.Game == "Scarlet" - ? GetRateTotalKitakamiSL(starcount) - : GetRateTotalKitakamiVL(starcount); - var speciesroll = clone.NextInt((ulong)total); + ? GetRateTotalKitakamiSL(starCount) + : GetRateTotalKitakamiVL(starCount); + var speciesRoll = clone.NextInt((ulong)total); if (container.GemTeraRaidsKitakami is not null) { foreach (TeraEncounter enc in container.GemTeraRaidsKitakami) { - if (enc.Stars != starcount) + if (enc.Stars != starCount) continue; var minimum = container.Game == "Scarlet" ? enc.Entity.RandRateMinScarlet : enc.Entity.RandRateMinViolet; - if (minimum >= 0 && (uint)((int)speciesroll - minimum) < enc.Entity.RandRate) + if (minimum >= 0 && (uint)((int)speciesRoll - minimum) < enc.Entity.RandRate) return enc; } } @@ -84,12 +84,12 @@ bool black public static ITeraRaid? GetDistributionEncounter( this Raid raid, RaidContainer container, - int stage, + int progress, bool isFixed, - int groupid + int groupID ) { - if (stage < 0) + if (progress < 0) return null; if (!isFixed) @@ -99,13 +99,13 @@ int groupid foreach (TeraDistribution enc in container.DistTeraRaids) { - if (enc.DeliveryGroupID != groupid) + if (enc.DeliveryGroupID != groupID) continue; var total = container.Game == "Scarlet" - ? enc.Entity.GetRandRateTotalScarlet(stage) - : enc.Entity.GetRandRateTotalViolet(stage); + ? enc.Entity.GetRandRateTotalScarlet(progress) + : enc.Entity.GetRandRateTotalViolet(progress); if (total > 0) { var rand = new Xoroshiro128Plus(raid.Seed); @@ -113,8 +113,8 @@ int groupid var val = rand.NextInt(total); var min = container.Game == "Scarlet" - ? enc.Entity.GetRandRateMinScarlet(stage) - : enc.Entity.GetRandRateMinViolet(stage); + ? enc.Entity.GetRandRateMinScarlet(progress) + : enc.Entity.GetRandRateMinViolet(progress); if ((uint)((int)val - min) < enc.RandRate) return enc; } @@ -127,13 +127,13 @@ int groupid foreach (TeraMight enc in container.MightTeraRaids) { - if (enc.DeliveryGroupID != groupid) + if (enc.DeliveryGroupID != groupID) continue; var total = container.Game == "Scarlet" - ? enc.Entity.GetRandRateTotalScarlet(stage) - : enc.Entity.GetRandRateTotalViolet(stage); + ? enc.Entity.GetRandRateTotalScarlet(progress) + : enc.Entity.GetRandRateTotalViolet(progress); if (total > 0) return enc; } @@ -155,16 +155,16 @@ TeraRaidMapParent type File.Delete(dbgFile); var count = data.Length / Raid.SIZE; - List possible_groups = new(); + List possibleGroups = new(); if (container.DistTeraRaids is not null) { foreach (TeraDistribution e in container.DistTeraRaids) { if ( TeraDistribution.AvailableInGame(e.Entity, container.Game) - && !possible_groups.Contains(e.DeliveryGroupID) + && !possibleGroups.Contains(e.DeliveryGroupID) ) - possible_groups.Add(e.DeliveryGroupID); + possibleGroups.Add(e.DeliveryGroupID); } } @@ -174,9 +174,9 @@ TeraRaidMapParent type { if ( TeraMight.AvailableInGame(e.Entity, container.Game) - && !possible_groups.Contains(e.DeliveryGroupID) + && !possibleGroups.Contains(e.DeliveryGroupID) ) - possible_groups.Add(e.DeliveryGroupID); + possibleGroups.Add(e.DeliveryGroupID); } } @@ -184,14 +184,14 @@ TeraRaidMapParent type List newRaids = new(); List newTera = new(); List> newRewards = new(); - int eventct = 0; + int eventCount = 0; for (int i = 0; i < count; i++) { var raid = new Raid(data.AsSpan(i * Raid.SIZE, Raid.SIZE), type); if (raid.Den == 0) { - eventct++; + eventCount++; continue; } @@ -199,19 +199,19 @@ TeraRaidMapParent type continue; var progress = raid.IsEvent ? eventPrg : storyPrg; - var raid_delivery_group_id = -1; + var raidDeliveryGroupID = -1; try { - raid_delivery_group_id = raid.GetDeliveryGroupID( + raidDeliveryGroupID = raid.GetDeliveryGroupID( container.DeliveryRaidPriority, - possible_groups, - eventct + possibleGroups, + eventCount ); } catch (Exception ex) { var extra = - $"Group ID: {raid_delivery_group_id}\nisFixed: {raid.Flags == 3}\nisBlack: {raid.IsBlack}\nisEvent: {raid.IsEvent}\n\n"; + $"Group ID: {raidDeliveryGroupID}\nisFixed: {raid.Flags == 3}\nisBlack: {raid.IsBlack}\nisEvent: {raid.IsEvent}\n\n"; var msg = $"{ex.Message}\nDen: {raid.Den}\nProgress: {progress}\nDifficulty: {raid.Difficulty}\n{extra}"; File.AppendAllText(dbgFile, msg); @@ -219,11 +219,11 @@ TeraRaidMapParent type continue; } - var encounter = raid.GetTeraEncounter(container, progress, raid_delivery_group_id); + var encounter = raid.GetTeraEncounter(container, progress, raidDeliveryGroupID); if (encounter is null) { var extra = - $"Group ID: {raid_delivery_group_id}\nisFixed: {raid.Flags == 3}\nisBlack: {raid.IsBlack}\nisEvent: {raid.IsEvent}\n\n"; + $"Group ID: {raidDeliveryGroupID}\nisFixed: {raid.Flags == 3}\nisBlack: {raid.IsBlack}\nisEvent: {raid.IsEvent}\n\n"; var msg = $"No encounters found.\nDen: {raid.Den}\nProgress: {progress}\nDifficulty: {raid.Difficulty}\n{extra}"; File.AppendAllText(dbgFile, msg); @@ -232,7 +232,7 @@ TeraRaidMapParent type } if (raid.IsEvent) - eventct++; + eventCount++; newRaids.Add(raid); newTera.Add(encounter); @@ -321,8 +321,8 @@ public static int GetStarCount(this Raid _, uint difficulty, int progress, bool public static int GetDeliveryGroupID( this Raid raid, DeliveryGroupID ids, - List possible_groups, - int eventct + List possibleGroups, + int eventCount ) { if (!raid.IsEvent) @@ -333,12 +333,12 @@ int eventct for (int i = 0; i < groups.Table_Length; i++) { - var ct = groups.Table(i); - if (!possible_groups.Contains(i + 1)) + var count = groups.Table(i); + if (!possibleGroups.Contains(i + 1)) continue; - if (eventct < ct) + if (eventCount < count) return i + 1; - eventct -= ct; + eventCount -= count; } throw new Exception("Found event out of priority range."); } @@ -375,7 +375,7 @@ private static short GetRateTotalKitakamiSL(int star) => 3 => 2500, 4 => 2100, 5 => 2250, - 6 => 2575, // Scarlet has one more + 6 => 2475, // Scarlet has one less encounter _ => 0, }; @@ -387,7 +387,7 @@ private static short GetRateTotalKitakamiVL(int star) => 3 => 2500, 4 => 2100, 5 => 2250, - 6 => 2574, // Violet has one less + 6 => 2574, // Violet has one more encounter _ => 0, }; } diff --git a/RaidCrawler.Core/Structures/RaidBlock.cs b/RaidCrawler.Core/Structures/RaidBlock.cs index 8567dc5..8bd118e 100644 --- a/RaidCrawler.Core/Structures/RaidBlock.cs +++ b/RaidCrawler.Core/Structures/RaidBlock.cs @@ -2,10 +2,14 @@ { public class RaidBlock { - public const uint HEADER_SIZE = 0x10; - public const uint SIZE_BASE = 0x910; - public const uint SIZE_KITAKAMI = 0xC80; + public const uint RAID_BLOCK_SIZE = 0x20; + + public const uint HEADER_SIZE_BASE = 0x10; public const uint MAX_COUNT_BASE = 72; + public const uint TOTAL_SIZE_BASE = HEADER_SIZE_BASE + (RAID_BLOCK_SIZE * MAX_COUNT_BASE); + + public const uint HEADER_SIZE_KITAKAMI = 0; public const uint MAX_COUNT_KITAKAMI = 100; + public const uint TOTAL_SIZE_KITAKAMI = HEADER_SIZE_KITAKAMI + (RAID_BLOCK_SIZE * MAX_COUNT_KITAKAMI); } } diff --git a/RaidCrawler.Core/Structures/RaidContainer.cs b/RaidCrawler.Core/Structures/RaidContainer.cs index 20ad818..9aab17c 100644 --- a/RaidCrawler.Core/Structures/RaidContainer.cs +++ b/RaidCrawler.Core/Structures/RaidContainer.cs @@ -23,7 +23,8 @@ public record RaidContainer public string Game { get; private set; } = "Scarlet"; public GameStrings Strings { get; private set; } - private readonly string[] Raid_data_base = new[] + // Files containing serialized data for all possible 1 through 6 star raids + private readonly string[] RaidDataBase = new[] { "raid_enemy_01_array.bin", "raid_enemy_02_array.bin", @@ -33,7 +34,7 @@ public record RaidContainer "raid_enemy_06_array.bin", }; - private readonly string[] Raid_data_su1 = new[] + private readonly string[] RaidDataKitakami = new[] { "su1_raid_enemy_01_array.bin", "su1_raid_enemy_02_array.bin", @@ -48,11 +49,11 @@ public RaidContainer(string game) Game = game; Strings = GameInfo.GetStrings(1); GemTeraRaidsBase = TeraEncounter.GetAllEncounters( - Raid_data_base, + RaidDataBase, TeraRaidMapParent.Paldea ); GemTeraRaidsKitakami = TeraEncounter.GetAllEncounters( - Raid_data_su1, + RaidDataKitakami, TeraRaidMapParent.Kitakami ); BaseFixedRewards = JsonSerializer.Deserialize>( diff --git a/RaidCrawler.Core/Structures/TeraDistribution.cs b/RaidCrawler.Core/Structures/TeraDistribution.cs index b530694..2504a02 100644 --- a/RaidCrawler.Core/Structures/TeraDistribution.cs +++ b/RaidCrawler.Core/Structures/TeraDistribution.cs @@ -26,8 +26,8 @@ public class TeraDistribution : ITeraRaid public ushort Move2 => Entity.Moves.Move2; public ushort Move3 => Entity.Moves.Move3; public ushort Move4 => Entity.Moves.Move4; - public byte Stars => Entity is ITeraRaid9 t9 ? t9.Stars : (byte)0; - public byte RandRate => Entity is ITeraRaid9 t9 ? t9.RandRate : (byte)0; + public byte Stars => Entity.Stars; + public byte RandRate => Entity.RandRate; ushort[] ITeraRaid.ExtraMoves => ExtraMoves; public static bool AvailableInGame(ITeraRaid9 enc, string game) @@ -69,15 +69,15 @@ public static bool AvailableInGame(ITeraRaid9 enc, string game) public TeraDistribution( EncounterDist9 enc, - ulong fixedrewards, - ulong lotteryrewards, + ulong fixedRewards, + ulong lotteryRewards, ushort[] extras, sbyte group ) { Entity = enc; - DropTableFix = fixedrewards; - DropTableRandom = lotteryrewards; + DropTableFix = fixedRewards; + DropTableRandom = lotteryRewards; ExtraMoves = extras .Where(z => z != 0 && !Entity.Moves.Contains(z)) .Distinct() @@ -129,40 +129,40 @@ public static ushort[] GetExtraMoves(byte[] extra) public static List<(int, int, int)> GetRewards( TeraDistribution enc, uint seed, - int teratype, - IReadOnlyList? fixed_rewards, - IReadOnlyList? lottery_rewards, + int teraType, + IReadOnlyList? fixedRewards, + IReadOnlyList? lotteryRewards, int boost ) { List<(int, int, int)> result = new(); - if (lottery_rewards is null) + if (lotteryRewards is null) return result; - if (fixed_rewards is null) + if (fixedRewards is null) return result; - var fixed_table = fixed_rewards.Where(z => z.TableName == enc.DropTableFix).First(); - if (fixed_table is null) + var fixedTable = fixedRewards.Where(z => z.TableName == enc.DropTableFix).First(); + if (fixedTable is null) return result; - var lottery_table = lottery_rewards + var lotteryTable = lotteryRewards .Where(z => z.TableName == enc.DropTableRandom) .First(); - if (lottery_table is null) + if (lotteryTable is null) return result; // fixed reward for (int i = 0; i < DeliveryRaidFixedRewardItem.Count; i++) { - var item = fixed_table.GetReward(i); + var item = fixedTable.GetReward(i); if (item.Category == 0 && item.ItemID == 0) continue; result.Add( ( item.ItemID == 0 ? item.Category == 2 - ? Rewards.GetTeraShard(teratype) + ? Rewards.GetTeraShard(teraType) : Rewards.GetMaterial(enc.Species) : item.ItemID, item.Num, @@ -174,7 +174,7 @@ int boost // lottery reward var total = 0; for (int i = 0; i < DeliveryRaidLotteryRewardItem.RewardItemCount; i++) - total += lottery_table.GetRewardItem(i).Rate; + total += lotteryTable.GetRewardItem(i).Rate; var rand = new Xoroshiro128Plus(seed); var count = (int)rand.NextInt(100); @@ -185,7 +185,7 @@ int boost var roll = (int)rand.NextInt((ulong)total); for (int j = 0; j < DeliveryRaidLotteryRewardItem.RewardItemCount; j++) { - var item = lottery_table.GetRewardItem(j); + var item = lotteryTable.GetRewardItem(j); if (roll < item.Rate) { if (item.Category == 0) @@ -199,7 +199,7 @@ int boost else result.Add( item.ItemID == 0 - ? (Rewards.GetTeraShard(teratype), item.Num, 0) + ? (Rewards.GetTeraShard(teraType), item.Num, 0) : (item.ItemID, item.Num, 0) ); break; @@ -232,8 +232,8 @@ public class TeraMight : ITeraRaid public ushort Move2 => Entity.Moves.Move2; public ushort Move3 => Entity.Moves.Move3; public ushort Move4 => Entity.Moves.Move4; - public byte Stars => Entity is ITeraRaid9 t9 ? t9.Stars : (byte)0; - public byte RandRate => Entity is ITeraRaid9 t9 ? t9.RandRate : (byte)0; + public byte Stars => Entity.Stars; + public byte RandRate => Entity.RandRate; ushort[] ITeraRaid.ExtraMoves => ExtraMoves; public static bool AvailableInGame(ITeraRaid9 enc, string game) @@ -275,15 +275,15 @@ public static bool AvailableInGame(ITeraRaid9 enc, string game) public TeraMight( EncounterMight9 enc, - ulong fixedrewards, - ulong lotteryrewards, + ulong fixedRewards, + ulong lotteryRewards, ushort[] extras, sbyte group ) { Entity = enc; - DropTableFix = fixedrewards; - DropTableRandom = lotteryrewards; + DropTableFix = fixedRewards; + DropTableRandom = lotteryRewards; ExtraMoves = extras .Where(z => z != 0 && !Entity.Moves.Contains(z)) .Distinct() @@ -335,40 +335,40 @@ public static ushort[] GetExtraMoves(byte[] extra) public static List<(int, int, int)> GetRewards( TeraMight enc, uint seed, - int teratype, - IReadOnlyList? fixed_rewards, - IReadOnlyList? lottery_rewards, + int teraType, + IReadOnlyList? fixedRewards, + IReadOnlyList? lotteryRewards, int boost ) { List<(int, int, int)> result = new(); - if (lottery_rewards is null) + if (lotteryRewards is null) return result; - if (fixed_rewards is null) + if (fixedRewards is null) return result; - var fixed_table = fixed_rewards.Where(z => z.TableName == enc.DropTableFix).First(); - if (fixed_table is null) + var fixedTable = fixedRewards.Where(z => z.TableName == enc.DropTableFix).First(); + if (fixedTable is null) return result; - var lottery_table = lottery_rewards + var lotteryTable = lotteryRewards .Where(z => z.TableName == enc.DropTableRandom) .First(); - if (lottery_table is null) + if (lotteryTable is null) return result; // fixed reward for (int i = 0; i < DeliveryRaidFixedRewardItem.Count; i++) { - var item = fixed_table.GetReward(i); + var item = fixedTable.GetReward(i); if (item.Category == 0 && item.ItemID == 0) continue; result.Add( ( item.ItemID == 0 ? item.Category == 2 - ? Rewards.GetTeraShard(teratype) + ? Rewards.GetTeraShard(teraType) : Rewards.GetMaterial(enc.Species) : item.ItemID, item.Num, @@ -380,7 +380,7 @@ int boost // lottery reward var total = 0; for (int i = 0; i < DeliveryRaidLotteryRewardItem.RewardItemCount; i++) - total += lottery_table.GetRewardItem(i).Rate; + total += lotteryTable.GetRewardItem(i).Rate; var rand = new Xoroshiro128Plus(seed); var count = (int)rand.NextInt(100); @@ -391,7 +391,7 @@ int boost var roll = (int)rand.NextInt((ulong)total); for (int j = 0; j < DeliveryRaidLotteryRewardItem.RewardItemCount; j++) { - var item = lottery_table.GetRewardItem(j); + var item = lotteryTable.GetRewardItem(j); if (roll < item.Rate) { if (item.Category == 0) @@ -405,7 +405,7 @@ int boost else result.Add( item.ItemID == 0 - ? (Rewards.GetTeraShard(teratype), item.Num, 0) + ? (Rewards.GetTeraShard(teraType), item.Num, 0) : (item.ItemID, item.Num, 0) ); break; diff --git a/RaidCrawler.Core/Structures/TeraEncounter.cs b/RaidCrawler.Core/Structures/TeraEncounter.cs index dac2183..55da711 100644 --- a/RaidCrawler.Core/Structures/TeraEncounter.cs +++ b/RaidCrawler.Core/Structures/TeraEncounter.cs @@ -27,14 +27,14 @@ public class TeraEncounter : ITeraRaid public TeraEncounter( EncounterTera9 enc, - ulong fixedrewards, - ulong lotteryrewards, + ulong fixedRewards, + ulong lotteryRewards, ushort[] extras ) { Entity = enc; - DropTableFix = fixedrewards; - DropTableRandom = lotteryrewards; + DropTableFix = fixedRewards; + DropTableRandom = lotteryRewards; ExtraMoves = extras .Where(z => z != 0 && !Entity.Moves.Contains(z)) .Distinct() @@ -63,30 +63,30 @@ public static TeraEncounter[] GetAllEncounters(string[] resources, TeraRaidMapPa public static List<(int, int, int)> GetRewards( TeraEncounter enc, uint seed, - int teratype, - IReadOnlyList? fixed_rewards, - IReadOnlyList? lottery_rewards, + int teraType, + IReadOnlyList? fixedRewards, + IReadOnlyList? lotteryRewards, int boost ) { List<(int, int, int)> result = new(); - if (lottery_rewards is null || fixed_rewards is null) + if (lotteryRewards is null || fixedRewards is null) return result; - var fixed_table = fixed_rewards.Where(z => z.TableName == enc.DropTableFix).First(); - if (fixed_table is null) + var fixedTable = fixedRewards.Where(z => z.TableName == enc.DropTableFix).First(); + if (fixedTable is null) return result; - var lottery_table = lottery_rewards + var lotteryTable = lotteryRewards .Where(z => z.TableName == enc.DropTableRandom) .First(); - if (lottery_table is null) + if (lotteryTable is null) return result; // fixed reward for (int i = 0; i < RaidFixedRewards.Count; i++) { - var item = fixed_table.GetReward(i); + var item = fixedTable.GetReward(i); if (item is null || item.Category == 0 && item.ItemID == 0) continue; @@ -94,7 +94,7 @@ int boost ( item.ItemID == 0 ? item.Category == 2 - ? Rewards.GetTeraShard(teratype) + ? Rewards.GetTeraShard(teraType) : Rewards.GetMaterial(enc.Species) : item.ItemID, item.Num, @@ -106,7 +106,7 @@ int boost // lottery reward var total = 0; for (int i = 0; i < RaidLotteryRewards.RewardItemCount; i++) - total += lottery_table.GetRewardItem(i)!.Rate; + total += lotteryTable.GetRewardItem(i)!.Rate; var rand = new Xoroshiro128Plus(seed); var count = (int)rand.NextInt(100); // sandwich = extra rolls? how does this work? is this even 100? @@ -116,7 +116,7 @@ int boost var roll = (int)rand.NextInt((ulong)total); for (int j = 0; j < DeliveryRaidLotteryRewardItem.RewardItemCount; j++) { - var item = lottery_table.GetRewardItem(j); + var item = lotteryTable.GetRewardItem(j); if (roll < item!.Rate) { if (item.Category == 0) @@ -130,7 +130,7 @@ int boost else result.Add( item.ItemID == 0 - ? (Rewards.GetTeraShard(teratype), item.Num, 0) + ? (Rewards.GetTeraShard(teraType), item.Num, 0) : (item.ItemID, item.Num, 0) ); break; diff --git a/RaidCrawler.WinForms/MainWindow.cs b/RaidCrawler.WinForms/MainWindow.cs index 0b4654a..deeda3b 100644 --- a/RaidCrawler.WinForms/MainWindow.cs +++ b/RaidCrawler.WinForms/MainWindow.cs @@ -35,14 +35,14 @@ public partial class MainWindow : Form private readonly NotificationHandler Webhook; private List RaidFilters = new(); - private static readonly Image map_base = Image.FromStream( + private static readonly Image MapBase = Image.FromStream( new MemoryStream(Utils.GetBinaryResource("paldea.png")) ); - private static readonly Image map_kitakami = Image.FromStream( + private static readonly Image MapKitakami = Image.FromStream( new MemoryStream(Utils.GetBinaryResource("kitakami.png")) ); - private static Dictionary? den_locations_base; - private static Dictionary? den_locations_kitakami; + private static Dictionary? DenLocationsBase; + private static Dictionary? DenLocationsKitakami; // statistics public int StatDaySkipTries = 0; @@ -71,37 +71,28 @@ public MainWindow() build = $" (dev-{date:yyyyMMdd})"; #endif var v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version!; - var filterpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "filters.json"); - if (File.Exists(filterpath)) + var filterPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "filters.json"); + if (File.Exists(filterPath)) RaidFilters = - JsonSerializer.Deserialize>(File.ReadAllText(filterpath)) + JsonSerializer.Deserialize>(File.ReadAllText(filterPath)) ?? new List(); - den_locations_base = JsonSerializer.Deserialize>( + DenLocationsBase = JsonSerializer.Deserialize>( Utils.GetStringResource("den_locations_base.json") ?? "{}" ); - den_locations_kitakami = JsonSerializer.Deserialize>( + DenLocationsKitakami = JsonSerializer.Deserialize>( Utils.GetStringResource("den_locations_kitakami.json") ?? "{}" ); - var configpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"); - if (File.Exists(configpath)) + var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"); + if (File.Exists(configPath)) { - var text = File.ReadAllText(configpath); + var text = File.ReadAllText(configPath); Config = JsonSerializer.Deserialize(text)!; } else Config = new(); - formTitle = - "RaidCrawler v" - + v.Major - + "." - + v.Minor - + "." - + v.Build - + build - + " " - + Config.InstanceName; + formTitle = $"RaidCrawler v{v.Major}.{v.Minor}.{v.Build} {Config.InstanceName}"; Text = formTitle; // load raids @@ -637,7 +628,7 @@ await ConnectionWrapper { return RaidBoost.SelectedIndex; }); - var satisfied_filters = + var satisfiedFilters = new List<(RaidFilter, ITeraRaid, Raid, IReadOnlyList<(int, int, int)>)>(); for (int i = 0; i < raids.Count; i++) { @@ -655,7 +646,7 @@ await ConnectionWrapper ) ) { - satisfied_filters.Add( + satisfiedFilters.Add( (filter, encounters[i], raids[i], rewards[i]) ); if (InvokeRequired) @@ -671,7 +662,7 @@ await ConnectionWrapper if (Config.EnableNotification) { - foreach (var satisfied in satisfied_filters) + foreach (var satisfied in satisfiedFilters) { var teraType = satisfied.Item3.GetTeraType(satisfied.Item2); var color = TypeColor.GetTypeSpriteColor((byte)teraType); @@ -702,7 +693,7 @@ await Webhook } // Save game on match. - if (Config.SaveOnMatch && satisfied_filters.Count > 0) + if (Config.SaveOnMatch && satisfiedFilters.Count > 0) await ConnectionWrapper.SaveGame(Config, token).ConfigureAwait(false); if (Config.EnableAlertWindow) @@ -865,7 +856,7 @@ ConnectionWrapper is not null var data = ConnectionWrapper.Connection .ReadBytesAbsoluteAsync( RaidBlockOffsetBase, - (int)RaidBlock.SIZE_BASE, + (int)RaidBlock.TOTAL_SIZE_BASE, Source.Token ) .Result; @@ -1029,17 +1020,17 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) private async Task ReadEventRaids(CancellationToken token, bool force = false) { - var prio_file = Path.Combine( + var priorityFile = Path.Combine( Directory.GetCurrentDirectory(), "cache", "raid_priority_array" ); - if (!force && File.Exists(prio_file)) + if (!force && File.Exists(priorityFile)) { (_, var version) = FlatbufferDumper.DumpDeliveryPriorities( - File.ReadAllBytes(prio_file) + File.ReadAllBytes(priorityFile) ); - var blk = await ConnectionWrapper + var block = await ConnectionWrapper .ReadBlockDefault( BCATRaidPriorityLocation, "raid_priority_array.tmp", @@ -1047,35 +1038,35 @@ private async Task ReadEventRaids(CancellationToken token, bool force = false) token ) .ConfigureAwait(false); - (_, var v2) = FlatbufferDumper.DumpDeliveryPriorities(blk); + (_, var v2) = FlatbufferDumper.DumpDeliveryPriorities(block); if (version != v2) force = true; - var tmp_file = Path.Combine( + var tempFile = Path.Combine( Directory.GetCurrentDirectory(), "cache", "raid_priority_array.tmp" ); - if (File.Exists(tmp_file)) - File.Delete(tmp_file); + if (File.Exists(tempFile)) + File.Delete(tempFile); if (v2 == 0) // raid reset return; } - var delivery_raid_prio = await ConnectionWrapper + var deliveryRaidPriorityBlock = await ConnectionWrapper .ReadBlockDefault(BCATRaidPriorityLocation, "raid_priority_array", force, token) .ConfigureAwait(false); (var group_id, var priority) = FlatbufferDumper.DumpDeliveryPriorities( - delivery_raid_prio + deliveryRaidPriorityBlock ); if (priority == 0) return; - var delivery_raid_fbs = await ConnectionWrapper + var deliveryRaidBlock = await ConnectionWrapper .ReadBlockDefault(BCATRaidBinaryLocation, "raid_enemy_array", force, token) .ConfigureAwait(false); - var delivery_fixed_rewards = await ConnectionWrapper + var deliveryFixedRewardBlock = await ConnectionWrapper .ReadBlockDefault( BCATRaidFixedRewardLocation, "fixed_reward_item_array", @@ -1083,7 +1074,7 @@ private async Task ReadEventRaids(CancellationToken token, bool force = false) token ) .ConfigureAwait(false); - var delivery_lottery_rewards = await ConnectionWrapper + var deliveryLotteryRewardBlock = await ConnectionWrapper .ReadBlockDefault( BCATRaidLotteryRewardLocation, "lottery_reward_item_array", @@ -1092,14 +1083,14 @@ private async Task ReadEventRaids(CancellationToken token, bool force = false) ) .ConfigureAwait(false); - RaidContainer.DistTeraRaids = TeraDistribution.GetAllEncounters(delivery_raid_fbs); - RaidContainer.MightTeraRaids = TeraMight.GetAllEncounters(delivery_raid_fbs); + RaidContainer.DistTeraRaids = TeraDistribution.GetAllEncounters(deliveryRaidBlock); + RaidContainer.MightTeraRaids = TeraMight.GetAllEncounters(deliveryRaidBlock); RaidContainer.DeliveryRaidPriority = group_id; RaidContainer.DeliveryRaidFixedRewards = FlatbufferDumper.DumpFixedRewards( - delivery_fixed_rewards + deliveryFixedRewardBlock ); RaidContainer.DeliveryRaidLotteryRewards = FlatbufferDumper.DumpLotteryRewards( - delivery_lottery_rewards + deliveryLotteryRewardBlock ); } @@ -1119,23 +1110,23 @@ private void DisplayRaid() $"{Areas.GetArea((int)(raid.Area - 1), raid.MapParent)} - Den {raid.Den}"; labelEvent.Visible = raid.IsEvent; - var teratype = raid.GetTeraType(encounter); - TeraType.Text = RaidContainer.Strings.types[teratype]; + var teraType = raid.GetTeraType(encounter); + TeraType.Text = RaidContainer.Strings.types[teraType]; - int StarCount = encounter switch + int starCount = encounter switch { TeraDistribution => encounter.Stars, TeraMight => encounter.Stars, _ => raid.GetStarCount(raid.Difficulty, Config.Progress, raid.IsBlack) }; - Difficulty.Text = string.Concat(Enumerable.Repeat("☆", StarCount)); + Difficulty.Text = string.Concat(Enumerable.Repeat("☆", starCount)); var param = encounter.GetParam(); var blank = new PK9 { Species = encounter.Species, Form = encounter.Form }; Encounter9RNG.GenerateData(blank, param, EncounterCriteria.Unrestricted, raid.Seed); var img = blank.Sprite(); - img = ApplyTeraColor((byte)teratype, img, SpriteBackgroundType.BottomStripe); + img = ApplyTeraColor((byte)teraType, img, SpriteBackgroundType.BottomStripe); var form = ShowdownParsing.GetStringFromForm( encounter.Form, @@ -1148,31 +1139,31 @@ private void DisplayRaid() Species.Text = $"{RaidContainer.Strings.Species[encounter.Species]}{form}"; Sprite.Image = img; - GemIcon.Image = GetDisplayGemImage(teratype, raid); + GemIcon.Image = GetDisplayGemImage(teraType, raid); Gender.Text = $"{(Gender)blank.Gender}"; var nature = blank.Nature; Nature.Text = $"{RaidContainer.Strings.Natures[nature]}"; Ability.Text = $"{RaidContainer.Strings.Ability[blank.Ability]}"; - var extra_moves = new ushort[] { 0, 0, 0, 0 }; + var extraMoves = new ushort[] { 0, 0, 0, 0 }; for (int i = 0; i < encounter.ExtraMoves.Length; i++) { - if (i < extra_moves.Length) - extra_moves[i] = encounter.ExtraMoves[i]; + if (i < extraMoves.Length) + extraMoves[i] = encounter.ExtraMoves[i]; } Move1.Text = ShowExtraMoves - ? RaidContainer.Strings.Move[extra_moves[0]] + ? RaidContainer.Strings.Move[extraMoves[0]] : RaidContainer.Strings.Move[encounter.Move1]; Move2.Text = ShowExtraMoves - ? RaidContainer.Strings.Move[extra_moves[1]] + ? RaidContainer.Strings.Move[extraMoves[1]] : RaidContainer.Strings.Move[encounter.Move2]; Move3.Text = ShowExtraMoves - ? RaidContainer.Strings.Move[extra_moves[2]] + ? RaidContainer.Strings.Move[extraMoves[2]] : RaidContainer.Strings.Move[encounter.Move3]; Move4.Text = ShowExtraMoves - ? RaidContainer.Strings.Move[extra_moves[3]] + ? RaidContainer.Strings.Move[extraMoves[3]] : RaidContainer.Strings.Move[encounter.Move4]; IVs.Text = IVsString(Utils.ToSpeedLast(blank.IVs)); @@ -1196,8 +1187,8 @@ await ErrorHandler private static Image? GetDisplayGemImage(int teratype, Raid raid) { - var display_black = raid.IsBlack || raid.Flags == 3; - var baseImg = display_black + var shouldDisplayBlack = raid.IsBlack || raid.Flags == 3; + var baseImg = shouldDisplayBlack ? (Image?)Properties.Resources.ResourceManager.GetObject($"black_{teratype:D2}") : (Image?)Properties.Resources.ResourceManager.GetObject($"gem_{teratype:D2}"); if (baseImg is null) @@ -1226,7 +1217,7 @@ await ErrorHandler baseImg.Height, baseImg.PixelFormat ); - if (display_black) + if (shouldDisplayBlack) { var color = Color.Indigo; SpriteUtil.GetSpriteGlow(baseImg, color.B, color.G, color.R, out var glow, false); @@ -1280,9 +1271,9 @@ await ErrorHandler teraRaidView.Area.Text = $"{Areas.GetArea((int)(raid.Area - 1), raid.MapParent)} - Den {raid.Den}"; - var teratype = raid.GetTeraType(encounter); + var teraType = raid.GetTeraType(encounter); teraRaidView.TeraType.Image = (Bitmap) - Properties.Resources.ResourceManager.GetObject("gem_text_" + teratype)!; + Properties.Resources.ResourceManager.GetObject($"gem_text_{teraType}")!; int StarCount = encounter switch { @@ -1319,18 +1310,18 @@ await ErrorHandler encounter.Move4 > 0 ? RaidContainer.Strings.Move[encounter.Move4] : "---"; var length = encounter.ExtraMoves.Length < 4 ? 4 : encounter.ExtraMoves.Length; - var extra_moves = new ushort[length]; + var extraMoves = new ushort[length]; for (int i = 0; i < encounter.ExtraMoves.Length; i++) - extra_moves[i] = encounter.ExtraMoves[i]; + extraMoves[i] = encounter.ExtraMoves[i]; teraRaidView.Move5.Text = - extra_moves[0] > 0 ? RaidContainer.Strings.Move[extra_moves[0]] : "---"; + extraMoves[0] > 0 ? RaidContainer.Strings.Move[extraMoves[0]] : "---"; teraRaidView.Move6.Text = - extra_moves[1] > 0 ? RaidContainer.Strings.Move[extra_moves[1]] : "---"; + extraMoves[1] > 0 ? RaidContainer.Strings.Move[extraMoves[1]] : "---"; teraRaidView.Move7.Text = - extra_moves[2] > 0 ? RaidContainer.Strings.Move[extra_moves[2]] : "---"; + extraMoves[2] > 0 ? RaidContainer.Strings.Move[extraMoves[2]] : "---"; teraRaidView.Move8.Text = - extra_moves[3] > 0 ? RaidContainer.Strings.Move[extra_moves[3]] : "---"; + extraMoves[3] > 0 ? RaidContainer.Strings.Move[extraMoves[3]] : "---"; var ivs = Utils.ToSpeedLast(blank.IVs); @@ -1382,7 +1373,7 @@ await ErrorHandler else if (teraRaidView.SPEED.Text is "00") teraRaidView.SPEED.BackColor = Color.DarkRed; - var map = GenerateMap(raid, teratype); + var map = GenerateMap(raid, teraType); if (map is null) Task.Run( async () => @@ -1610,20 +1601,20 @@ byte opacBack 0 ); if ( - den_locations_base is null - || den_locations_base.Count == 0 - || den_locations_kitakami is null - || den_locations_kitakami.Count == 0 + DenLocationsBase is null + || DenLocationsBase.Count == 0 + || DenLocationsKitakami is null + || DenLocationsKitakami.Count == 0 ) return null; double x, y; - var loc_data = + var locData = raid.MapParent == TeraRaidMapParent.Paldea - ? den_locations_base - : den_locations_kitakami; - var map = raid.MapParent == TeraRaidMapParent.Paldea ? map_base : map_kitakami; + ? DenLocationsBase + : DenLocationsKitakami; + var map = raid.MapParent == TeraRaidMapParent.Paldea ? MapBase : MapKitakami; try { x = @@ -1633,7 +1624,7 @@ den_locations_base is null raid.MapParent == TeraRaidMapParent.Paldea ? 1 : 2.766970605475146 - ) * loc_data[$"{raid.Area}-{raid.DisplayType}-{raid.Den}"][0] + ) * locData[$"{raid.Area}-{raid.DisplayType}-{raid.Den}"][0] ) + ( raid.MapParent == TeraRaidMapParent.Paldea @@ -1650,7 +1641,7 @@ den_locations_base is null raid.MapParent == TeraRaidMapParent.Paldea ? 1 : 2.5700782642623805 - ) * loc_data[$"{raid.Area}-{raid.DisplayType}-{raid.Den}"][2] + ) * locData[$"{raid.Area}-{raid.DisplayType}-{raid.Den}"][2] ) + ( raid.MapParent == TeraRaidMapParent.Paldea @@ -1672,10 +1663,10 @@ private bool StopAdvanceDate(List previousSeeds) { var raids = RaidContainer.Raids; var curSeeds = raids.Select(x => x.Seed).ToArray(); - var sameraids = curSeeds.Except(previousSeeds).ToArray().Length == 0; + var didRaidsChange = curSeeds.Except(previousSeeds).ToArray().Length == 0; StatDaySkipTries++; - if (sameraids) + if (didRaidsChange) return false; StatDaySkipSuccess++; @@ -1733,7 +1724,7 @@ private async Task ReadRaids(CancellationToken token) { UpdateStatus("Reading Paldea raid block..."); data = await ConnectionWrapper.Connection - .ReadBytesAbsoluteAsync(RaidBlockOffsetBase + RaidBlock.HEADER_SIZE, (int)(RaidBlock.SIZE_BASE - RaidBlock.HEADER_SIZE), token).ConfigureAwait(false); + .ReadBytesAbsoluteAsync(RaidBlockOffsetBase + RaidBlock.HEADER_SIZE_BASE, (int)(RaidBlock.TOTAL_SIZE_BASE - RaidBlock.HEADER_SIZE_BASE), token).ConfigureAwait(false); (delivery, enc) = RaidContainer.ReadAllRaids(data, Config.Progress, Config.EventProgress, GetRaidBoost(), TeraRaidMapParent.Paldea); if (enc > 0) @@ -1766,7 +1757,7 @@ await ErrorHandler data = await ConnectionWrapper.Connection .ReadBytesAbsoluteAsync( RaidBlockOffsetKitakami, - (int)RaidBlock.SIZE_KITAKAMI, + (int)RaidBlock.TOTAL_SIZE_KITAKAMI, token ) .ConfigureAwait(false); @@ -1918,8 +1909,8 @@ await ErrorHandler var raid = raids[ComboIndex.SelectedIndex]; var encounter = RaidContainer.Encounters[ComboIndex.SelectedIndex]; - var teratype = raid.GetTeraType(encounter); - var map = GenerateMap(raid, teratype); + var teraType = raid.GetTeraType(encounter); + var map = GenerateMap(raid, teraType); if (map is null) { Task.Run( @@ -2018,21 +2009,21 @@ await ErrorHandler ); var length = encounter.ExtraMoves.Length < 4 ? 4 : encounter.ExtraMoves.Length; - var extra_moves = new ushort[length]; + var extraMoves = new ushort[length]; for (int i = 0; i < encounter.ExtraMoves.Length; i++) - extra_moves[i] = encounter.ExtraMoves[i]; + extraMoves[i] = encounter.ExtraMoves[i]; Move1.Text = ShowExtraMoves - ? RaidContainer.Strings.Move[extra_moves[0]] + ? RaidContainer.Strings.Move[extraMoves[0]] : RaidContainer.Strings.Move[encounter.Move1]; Move2.Text = ShowExtraMoves - ? RaidContainer.Strings.Move[extra_moves[1]] + ? RaidContainer.Strings.Move[extraMoves[1]] : RaidContainer.Strings.Move[encounter.Move2]; Move3.Text = ShowExtraMoves - ? RaidContainer.Strings.Move[extra_moves[2]] + ? RaidContainer.Strings.Move[extraMoves[2]] : RaidContainer.Strings.Move[encounter.Move3]; Move4.Text = ShowExtraMoves - ? RaidContainer.Strings.Move[extra_moves[3]] + ? RaidContainer.Strings.Move[extraMoves[3]] : RaidContainer.Strings.Move[encounter.Move4]; } @@ -2087,7 +2078,7 @@ private void SearchTimer_Elapsed(object sender, EventArgs e) timeSpan.Seconds ); - Invoke(() => Text = formTitle + " [Searching for " + time + "]"); + Invoke(() => Text = $"{formTitle} [Searching for {time}]"); if (Config.StreamerView && teraRaidView is not null) Invoke(() => teraRaidView.textSearchTime.Text = time); } @@ -2168,7 +2159,7 @@ public void ToggleStreamerView() if (Config.StreamerView) { teraRaidView = new(); - teraRaidView.Map.Image = map_base; + teraRaidView.Map.Image = MapBase; teraRaidView.Show(); } else if (!Config.StreamerView && teraRaidView is not null)