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

Fixed fishing probabilities to account for duplicate entries, non-cat… #15

Merged
merged 1 commit into from
Apr 8, 2024
Merged
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
48 changes: 28 additions & 20 deletions JoysOfEfficiency/Huds/FishingProbabilitiesBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ private static Dictionary<String, double> GetFishes(int waterDepth, Farmer who,

LocationData thisLocData = Game1.currentLocation.GetData();
String jThisLocData = JsonSerializer.Serialize(thisLocData, new JsonSerializerOptions { WriteIndented = true });
Logger.Info($"This LocationData: {jThisLocData}");
//Logger.Info($"This LocationData: {jThisLocData}");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving commented-out code around is not generally advisable.

Perhaps instead consider reducing them from Info to Trace so they are not printed to console unless you're using SMAPI for Developers, or delete them / tie them to a compile-time switch as they will still explode the log file even under Trace (see log level documentation).

Considering the massive quantity of information in these, I'd probably opt for enabling them only in a debug build. It is unkind to performance and the end user's disk to log all that during gameplay.

https://github.com/Hackswell/JoysOfEfficiency/blob/1861eeb9f0520abf3859ddde18789b6b6bbfa3dc/JoysOfEfficiency/Utils/Logger.cs#L23-L31


Dictionary<string, string> allFishData = DataLoader.Fish(Game1.content);

string locName = locationName ?? currLocation.Name;
Logger.Info($"GetFishes: Loc: {locName} ** Season: {season}");
//Logger.Info($"GetFishes: Loc: {locName} ** Season: {season}");

if (locName.Equals("WitchSwamp")
&& !Game1.MasterPlayer.mailReceived.Contains("henchmanGone")
Expand All @@ -124,10 +124,10 @@ private static Dictionary<String, double> GetFishes(int waterDepth, Farmer who,
}

String JSONFishes = JsonSerializer.Serialize(allFishData, new JsonSerializerOptions { WriteIndented = true });
Logger.Info($"All Fishes: {JSONFishes}");
//Logger.Info($"All Fishes: {JSONFishes}");
Dictionary<string, LocationData> dictionary = DataLoader.Locations(Game1.content);
String jDict = JsonSerializer.Serialize(dictionary, new JsonSerializerOptions { WriteIndented = true });
Logger.Info($"All Location Data: {jDict}");
//Logger.Info($"All Location Data: {jDict}");

IEnumerable<SpawnFishData> possibleFish = dictionary["Default"].Fish;
if (thisLocData != null && thisLocData.Fish?.Count > 0)
Expand All @@ -141,23 +141,23 @@ private static Dictionary<String, double> GetFishes(int waterDepth, Farmer who,
return dictFish;
}

Logger.Info($"Finding fish area for farmer: {who.Tile.X},{who.Tile.Y} [bobber] {rod.bobber.X},{rod.bobber.Y} ** {currLocation.locationContextId} ** ");
//Logger.Info($"Finding fish area for farmer: {who.Tile.X},{who.Tile.Y} [bobber] {rod.bobber.X},{rod.bobber.Y} ** {currLocation.locationContextId} ** ");
LocationContextData bubba = currLocation.GetLocationContext();
String jsonBubba = JsonSerializer.Serialize(bubba, new JsonSerializerOptions { WriteIndented = true });
Logger.Info($"GameLocationContext: {jsonBubba}");
//Logger.Info($"GameLocationContext: {jsonBubba}");

currLocation.TryGetFishAreaForTile(who.Tile, out var fishAreaID, out var fishAreaData);
Logger.Info($"FishAreaID: {fishAreaID}");
//Logger.Info($"FishAreaID: {fishAreaID}");
String jsonFishAreaData = JsonSerializer.Serialize(fishAreaData, new JsonSerializerOptions { WriteIndented = true });
Logger.Info($"FishAreaData: {jsonFishAreaData}");
//Logger.Info($"FishAreaData: {jsonFishAreaData}");

possibleFish = from p in possibleFish
orderby p.Precedence, Game1.random.Next()
where (p.FishAreaId == fishAreaID || p.FishAreaId == null) && (p.Season == season || p.Season == null)
select p;

String JSON = JsonSerializer.Serialize(possibleFish, new JsonSerializerOptions{WriteIndented = true});
Logger.Info($"Possibru Fishu:\n{JSON}");
//Logger.Info($"Possibru Fishu:\n{JSON}");

// Reference: https://stardewvalleywiki.com/Modding:Fish_data#Fish_data_and_spawn_criteria
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13
Expand All @@ -179,29 +179,37 @@ 12 fishingLevel */
double chance = 0.0d;
foreach (SpawnFishData f in possibleFish)
{
String id = f.Id;
Logger.Info($"Testing Fish ID: {id}");
// Use ItemId unless its null. Account for mods with non-standard IDs for vanilla records
String id = f.ItemId;
if (id == null) { id = f.Id; }
id = Regex.Replace(id, "\\(O\\)", "");
Logger.Info($"Testing Fish ID: {id}");
//Logger.Info($"Testing Fish ID: {id}");

// Any list item like "(O)167|(O)168|(O)169|(O)170|(O)171|(O)172" is a list of garbage. Skip it.
// Any list item like "(O)167|(O)168|(O)169|(O)170|(O)171|(O)172" is a list of garbage. Handle it.
if (id.Contains('|'))
{
dictFish["168"] = f.Chance;
continue;
}

// Furniture, wrong conditions or the item doesnt exist. Skip it
if (id.Contains("(F)") || !GameStateQuery.CheckConditions(f.Condition) || !ItemRegistry.Exists(id))
{
continue;
}

// If it's not found in the allFishData, assign the chance from possibleFish instead
if (!allFishData.ContainsKey(id))
{
Logger.Info($"\tdictFish: Adding {id} :: {f.Chance}");
dictFish.Add(id, f.Chance);
//Logger.Info($"\tdictFish: Adding {id} :: {f.Chance}");
dictFish[id] = f.Chance;
continue;
}

Logger.Info($"Parsing through allFishData for {f.Id} now...");
//Logger.Info($"Parsing through allFishData for {f.Id} now...");
String[] fishData = allFishData[id].Split('/');
String jFishData = JsonSerializer.Serialize(fishData, new JsonSerializerOptions{WriteIndented = true});
Logger.Info($"\tID: {id} *** {jFishData}");
//Logger.Info($"\tID: {id} *** {jFishData}");

// If the time isn't in the fish's catch times, go on to next fish.
String[] catchTimes = fishData[5].Split(' ');
Expand Down Expand Up @@ -236,11 +244,11 @@ 12 fishingLevel */
spawnMultiplier += who.FishingLevel / 50f;
chance = Math.Min(spawnMultiplier, 0.89999997615814209);

Logger.Info($"dictFish: Adding {id} :: {chance}");
dictFish.Add(id, chance);
//Logger.Info($"dictFish: Adding {id} :: {chance}");
dictFish[id] = chance;
}
String jDictFish = JsonSerializer.Serialize(dictFish, new JsonSerializerOptions{WriteIndented = true});
Logger.Info($"Possible Fish:\n{jDictFish}");
//Logger.Info($"Possible Fish:\n{jDictFish}");

return dictFish;
}
Expand Down