-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommon.cs
More file actions
137 lines (113 loc) · 5.26 KB
/
Copy pathCommon.cs
File metadata and controls
137 lines (113 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using Chameleon.Info;
using Chameleon.Overrides.Interior;
using DunGen;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace Chameleon
{
internal class Common
{
internal static bool INSTALLED_ARTIFICE_BLIZZARD, CAN_REPLACE_CAVE_TAGS;
// * ----- REFERENCES ----- *
// string matching the name of the current interior ("Level1Flow", "Level2Flow", or "Level3Flow")
internal static string interior;
// see LevelCosmeticInfo.cs
internal static LevelCosmeticInfo currentLevelCosmeticInfo;
// ArtificeBlizzard compatibility
internal static GameObject artificeBlizzard;
static BreakerBox breakerBox;
internal static BreakerBox BreakerBox
{
get
{
if (breakerBox == null)
breakerBox = Object.FindAnyObjectByType<BreakerBox>();
return breakerBox;
}
}
internal static bool breakerBoxHasReset;
internal static GameObject dungeonRoot;
internal static void GetReferences()
{
DungeonGenerator generator = RoundManager.Instance?.dungeonGenerator?.Generator;
interior = StartOfRound.Instance.currentLevel.name != "CompanyBuildingLevel" ? generator?.DungeonFlow?.name : string.Empty;
Plugin.Logger.LogDebug($"Current interior: \"{interior}\"");
if (!VanillaLevelsInfo.predefinedLevels.TryGetValue(StartOfRound.Instance.currentLevel.name, out currentLevelCosmeticInfo))
currentLevelCosmeticInfo = null;
if (StartOfRound.Instance.currentLevel.name == "ArtificeLevel" && INSTALLED_ARTIFICE_BLIZZARD)
{
artificeBlizzard = GameObject.Find("/Systems/Audio/BlizzardAmbience");
if (artificeBlizzard != null)
Plugin.Logger.LogInfo("Artifice Blizzard compatibility success");
}
dungeonRoot = generator?.Root ?? GameObject.Find("/Systems/LevelGeneration/LevelGenerationRoot");
}
internal static void BuildWeightLists()
{
Plugin.Logger.LogInfo("List of all indexed moons (Use this to set up your config!):");
foreach (SelectableLevel level in StartOfRound.Instance.levels)
{
if (level.name != "CompanyBuildingLevel")
Plugin.Logger.LogInfo($"\"{level.name}\"");
}
RoundManager roundManager = RoundManager.Instance ?? Object.FindAnyObjectByType<RoundManager>();
if (roundManager != null)
{
Plugin.Logger.LogInfo("List of all indexed interiors:");
foreach (IndoorMapType indoorMapType in roundManager.dungeonFlowTypes)
{
if (indoorMapType.dungeonFlow != null)
Plugin.Logger.LogInfo($"\"{indoorMapType.dungeonFlow.name}\"");
}
}
Plugin.Logger.LogDebug("Now assembling final weighted lists");
AssembleWeightedList<CavernType>(ref RetextureCaverns.cavernWeightLists, ref Configuration.cavernMappings);
AssembleWeightedList<WindowType>(ref ManorWindows.windowWeightLists, ref Configuration.windowMappings);
}
static void AssembleWeightedList<T>(ref Dictionary<string, IntWithRarity[]> weightLists, ref List<Configuration.MoonTypeMapping> mappings)
{
weightLists.Clear();
foreach (SelectableLevel level in StartOfRound.Instance.levels)
{
if (level.name == "CompanyBuildingLevel")
continue;
try
{
List<IntWithRarity> tempWeights = [];
foreach (Configuration.MoonTypeMapping mapping in mappings.Where(x => level.name.ToLower().StartsWith(x.moon) || x.moon == "ALL"))
{
tempWeights.Add(new(mapping.type, mapping.weight, null));
Plugin.Logger.LogDebug($"{level.name} - {(T)(object)mapping.type} @ {mapping.weight}");
}
if (tempWeights.Count > 0)
weightLists.Add(level.name, [.. tempWeights]);
}
catch
{
Plugin.Logger.LogError("Failed to finish assembling weighted lists. If you are encountering this error, it's likely there is a problem with your config - look for warnings further up in your log!");
}
}
}
// * ----- ASSETS ----- *
// solid black material
internal static Material black;
internal static void GetSharedAssets()
{
if (black != null)
return;
try
{
AssetBundle lightMats = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "chameleon"));
black = lightMats.LoadAsset<Material>("black");
lightMats.Unload(false);
}
catch
{
Plugin.Logger.LogError("Encountered some error loading assets from bundle \"chameleon\". Did you install the plugin correctly?");
}
}
}
}