diff --git a/DataParser.cs b/DataParser.cs index 918538f..f309bd4 100644 --- a/DataParser.cs +++ b/DataParser.cs @@ -58,7 +58,8 @@ public static void PrepareAnalysis() Task.Run(() => ParsePersonalMasterDatas()), Task.Run(() => ParseUIMasterDatas()), Task.Run(() => ParseContestMasterDatas()), - Task.Run(() => TryParseExternalStarters()) + Task.Run(() => TryParseExternalStarters()), + Task.Run(() => TryParseExternalHoneyTrees()) }; ParseDamagaCategories(); ParseGlobalMetadata(); @@ -70,14 +71,20 @@ public static void PrepareAnalysis() GC.Collect(); } + private static void TryParseExternalHoneyTrees() + { + gameData.externalHoneyTrees = null; + List<(string name, HoneyTreeZone obj)> files = fileManager.TryGetExternalJsons($"Encounters\\HoneyTrees"); + if (files.Count == 0) return; + gameData.externalHoneyTrees = files; + } + private static void TryParseExternalStarters() { - List starters = new(); + gameData.externalStarters = null; List<(string name, Starter obj)> files = fileManager.TryGetExternalJsons($"Encounters\\Starter"); if (files.Count == 0) return; - foreach ((string _, Starter obj) in files) - starters.Add(obj); - gameData.starters = starters; + gameData.externalStarters = files; } private static async Task ParseContestMasterDatas() @@ -1976,12 +1983,20 @@ public static void CommitChanges() CommitDprBin(); if (gameData.IsModified(GameDataSet.DataField.ExternalStarters)) CommitExternalStarters(); + if (gameData.IsModified(GameDataSet.DataField.ExternalHoneyTrees)) + CommitExternalHoneyTrees(); + } + + private static void CommitExternalHoneyTrees() + { + foreach ((string name, Starter _) in gameData.externalStarters) + fileManager.CommitExternalJson($"Encounters\\Starter\\{name}.json"); } private static void CommitExternalStarters() { - for (int i = 0; i < gameData.starters.Count; i++) - fileManager.CommitExternalJson($"Encounters\\Starter\\starter_{i}.json"); + foreach ((string name, HoneyTreeZone _) in gameData.externalHoneyTrees) + fileManager.CommitExternalJson($"Encounters\\HoneyTrees\\{name}.json"); } private static void CommitContestMasterDatas() diff --git a/FileManager.cs b/FileManager.cs index a7c3cf7..d273682 100644 --- a/FileManager.cs +++ b/FileManager.cs @@ -663,11 +663,15 @@ private static bool ExportExternalJson(FileData fd, string modRoot) if (!fd.gamePath.StartsWith(externalJsonGamePath)) return false; if (!fd.gamePath.EndsWith(".json")) return false; string externalJsonPath = fd.gamePath[(externalJsonGamePath.Length + 1)..]; + string fileName = Path.GetFileNameWithoutExtension(externalJsonPath); if (externalJsonPath.StartsWith("Encounters\\Starter")) { - string fileName = Path.GetFileNameWithoutExtension(externalJsonPath); - int starterIndex = int.Parse(fileName.Split('_')[1]); - File.WriteAllText(modRoot + "\\" + fd.gamePath, JsonConvert.SerializeObject(gameData.starters[starterIndex], Formatting.Indented)); + File.WriteAllText(modRoot + "\\" + fd.gamePath, JsonConvert.SerializeObject(gameData.externalStarters.First(t => t.name == fileName).obj, Formatting.Indented)); + return true; + } + if (externalJsonPath.StartsWith("Encounters\\HoneyTrees")) + { + File.WriteAllText(modRoot + "\\" + fd.gamePath, JsonConvert.SerializeObject(gameData.externalHoneyTrees.First(t => t.name == fileName).obj, Formatting.Indented)); return true; } return false; diff --git a/GlobalData.cs b/GlobalData.cs index 693401f..e68a84b 100644 --- a/GlobalData.cs +++ b/GlobalData.cs @@ -57,7 +57,8 @@ public class GameDataSet public List contestResultMotion; public AssetBundleDownloadManifest dprBin; - public List starters; + public List<(string name, Starter obj)> externalStarters; + public List<(string name, HoneyTreeZone obj)> externalHoneyTrees; public Dictionary trainerNames; public StringBuilder audioSourceLog; @@ -98,7 +99,8 @@ public enum DataField PokemonInfo, ContestResultMotion, DprBin, - ExternalStarters + ExternalStarters, + ExternalHoneyTrees } public bool IsModified(DataField d) diff --git a/Randomizer.cs b/Randomizer.cs index faef17c..254cb44 100644 --- a/Randomizer.cs +++ b/Randomizer.cs @@ -703,9 +703,9 @@ private void RandomizeWildEncounters(bool randomizeSpecies, IDistribution specie gameData.SetModified(GameDataSet.DataField.UgEncounterLevelSets); gameData.SetModified(GameDataSet.DataField.UgSpecialEncounters); - if (gameData.starters != null) + if (gameData.externalStarters != null) { - foreach (Starter starter in gameData.starters) + foreach ((string _, Starter starter) in gameData.externalStarters) { if (randomizeLevels && IsWithin(AbsoluteBoundary.Level, starter.level)) { @@ -737,6 +737,46 @@ private void RandomizeWildEncounters(bool randomizeSpecies, IDistribution specie } gameData.SetModified(GameDataSet.DataField.ExternalStarters); } + + if (gameData.externalHoneyTrees != null) + { + foreach ((string _, HoneyTreeZone honeyTree) in gameData.externalHoneyTrees) + foreach (HoneyTreeSlot slot in honeyTree.slots) + { + if (randomizeLevels && IsWithin(AbsoluteBoundary.Level, (int)slot.GetAvgLevel())) + { + slot.minlv = Conform(AbsoluteBoundary.Level, levelDistribution.Next(slot.minlv)); + slot.maxlv = Conform(AbsoluteBoundary.Level, levelDistribution.Next(slot.maxlv)); + + if (slot.minlv > slot.maxlv) + (slot.maxlv, slot.minlv) = (slot.minlv, slot.maxlv); + + if (evolveLogic) + { + Pokemon p = FindStage(gameData.GetPokemon(slot.monsNo, slot.formNo), (int)slot.GetAvgLevel(), true); + slot.monsNo = p.dexID; + slot.formNo = p.formID; + } + } + + if (randomizeSpecies) + { + bool acceptLegendary = !legendLogic || P(slot.GetAvgLevel()); + Func resolveStage = evolveLogic ? p => FindStage(p, (int)slot.GetAvgLevel(), true) : p => p; + + do + { + slot.monsNo = speciesDistribution.Next(slot.monsNo); + slot.formNo = rng.Next(gameData.dexEntries[slot.monsNo].forms.Count); + Pokemon p = resolveStage(gameData.GetPokemon(slot.monsNo, slot.formNo)); + slot.monsNo = p.dexID; + slot.formNo = p.formID; + } while (!gameData.GetPokemon(slot.monsNo, slot.formNo).IsValid() || + !acceptLegendary && legendaryDexIDs.Contains(slot.monsNo)); + } + } + gameData.SetModified(GameDataSet.DataField.ExternalHoneyTrees); + } } /// diff --git a/Structs/ExternalJsonStructs.cs b/Structs/ExternalJsonStructs.cs index 8a0753b..a9c4660 100644 --- a/Structs/ExternalJsonStructs.cs +++ b/Structs/ExternalJsonStructs.cs @@ -1,4 +1,6 @@ -namespace ImpostersOrdeal +using System.Collections.Generic; + +namespace ImpostersOrdeal { public static class ExternalJsonStructs { @@ -9,5 +11,23 @@ public class Starter public int level; public int itemNo; } + + public class HoneyTreeZone + { + public List slots; + } + + public class HoneyTreeSlot + { + public int maxlv; + public int minlv; + public int monsNo; + public int formNo; + + public double GetAvgLevel() + { + return (minlv + maxlv) / 2.0; + } + } } }