Skip to content

Commit

Permalink
Fix Scarlet counts + styling (#166)
Browse files Browse the repository at this point in the history
Closes #164
  • Loading branch information
CardBreaker authored Sep 23, 2023
1 parent 2a702b0 commit 141f2eb
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 207 deletions.
100 changes: 50 additions & 50 deletions RaidCrawler.Core/Extensions/RaidExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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)
Expand All @@ -99,22 +99,22 @@ 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);
_ = rand.NextInt(100);
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;
}
Expand All @@ -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;
}
Expand All @@ -155,16 +155,16 @@ TeraRaidMapParent type
File.Delete(dbgFile);

var count = data.Length / Raid.SIZE;
List<int> possible_groups = new();
List<int> 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);
}
}

Expand All @@ -174,56 +174,56 @@ 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);
}
}

(int delivery, int encounter) failed = (0, 0);
List<Raid> newRaids = new();
List<ITeraRaid> newTera = new();
List<List<(int, int, int)>> 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;
}

if (!raid.IsValid)
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);
failed.delivery++;
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);
Expand All @@ -232,7 +232,7 @@ TeraRaidMapParent type
}

if (raid.IsEvent)
eventct++;
eventCount++;

newRaids.Add(raid);
newTera.Add(encounter);
Expand Down Expand Up @@ -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<int> possible_groups,
int eventct
List<int> possibleGroups,
int eventCount
)
{
if (!raid.IsEvent)
Expand All @@ -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.");
}
Expand Down Expand Up @@ -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,
};

Expand All @@ -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,
};
}
Expand Down
10 changes: 7 additions & 3 deletions RaidCrawler.Core/Structures/RaidBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 5 additions & 4 deletions RaidCrawler.Core/Structures/RaidContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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<IReadOnlyList<RaidFixedRewards>>(
Expand Down
Loading

0 comments on commit 141f2eb

Please sign in to comment.