Skip to content

Commit

Permalink
Added randomizer support for honey trees via external jsons patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Nifyr committed Oct 30, 2023
1 parent 15eabfb commit e25eea8
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 15 deletions.
29 changes: 22 additions & 7 deletions DataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<HoneyTreeZone>($"Encounters\\HoneyTrees");
if (files.Count == 0) return;
gameData.externalHoneyTrees = files;
}

private static void TryParseExternalStarters()
{
List<Starter> starters = new();
gameData.externalStarters = null;
List<(string name, Starter obj)> files = fileManager.TryGetExternalJsons<Starter>($"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()
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 7 additions & 3 deletions FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions GlobalData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public class GameDataSet
public List<ResultMotion> contestResultMotion;
public AssetBundleDownloadManifest dprBin;

public List<Starter> starters;
public List<(string name, Starter obj)> externalStarters;
public List<(string name, HoneyTreeZone obj)> externalHoneyTrees;

public Dictionary<string, string> trainerNames;
public StringBuilder audioSourceLog;
Expand Down Expand Up @@ -98,7 +99,8 @@ public enum DataField
PokemonInfo,
ContestResultMotion,
DprBin,
ExternalStarters
ExternalStarters,
ExternalHoneyTrees
}

public bool IsModified(DataField d)
Expand Down
44 changes: 42 additions & 2 deletions Randomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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<Pokemon, Pokemon> 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);
}
}

/// <summary>
Expand Down
22 changes: 21 additions & 1 deletion Structs/ExternalJsonStructs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace ImpostersOrdeal
using System.Collections.Generic;

namespace ImpostersOrdeal
{
public static class ExternalJsonStructs
{
Expand All @@ -9,5 +11,23 @@ public class Starter
public int level;
public int itemNo;
}

public class HoneyTreeZone
{
public List<HoneyTreeSlot> slots;
}

public class HoneyTreeSlot
{
public int maxlv;
public int minlv;
public int monsNo;
public int formNo;

public double GetAvgLevel()
{
return (minlv + maxlv) / 2.0;
}
}
}
}

0 comments on commit e25eea8

Please sign in to comment.