This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtraTrackersMod.cs
206 lines (190 loc) · 9.09 KB
/
ExtraTrackersMod.cs
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using HarmonyLib.Tools;
using I2.Loc;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using TMPro;
using Unity.IL2CPP.CompilerServices;
using System.Drawing.Printing;
namespace ExtraTrackers
{
public static class ExtraTrackersMod
{
public const int NON_BIOME_INDEX = -1;
public static ManualLogSource log;
public static Dictionary<int, Dictionary<string, float>> biomePollution = new Dictionary<int, Dictionary<string, float>>();
public static BiomeManager nonBiomeManager;
// For autosplitter tracking
public static bool nonBiomeIsComplete = false;
public static bool allHoloBadgesFound = false;
public static bool allLoddleTypesFound = false;
public static bool allGoopyLoddlesCleaned = false;
public static Dictionary<LoddleAI.LoddleType, string> typeRemarkMapping = new Dictionary<LoddleAI.LoddleType, string>()
{
{ LoddleAI.LoddleType.Eel, GoogleSheetsEntryNames.SirenEvoIntro },
{ LoddleAI.LoddleType.Betta, GoogleSheetsEntryNames.BettaEvoIntro },
{ LoddleAI.LoddleType.FlyingFish, GoogleSheetsEntryNames.WingfinEvoIntro },
{ LoddleAI.LoddleType.SeaAngel, GoogleSheetsEntryNames.ButterflyEvoIntro },
{ LoddleAI.LoddleType.Catfish, GoogleSheetsEntryNames.WhiskerEvoIntro },
{ LoddleAI.LoddleType.MantaRay, GoogleSheetsEntryNames.MantaEvoIntro },
{ LoddleAI.LoddleType.Loach, GoogleSheetsEntryNames.SnakeEvoIntro },
{ LoddleAI.LoddleType.SeaBunny, GoogleSheetsEntryNames.BunnyEvoIntro },
{ LoddleAI.LoddleType.Pufferfish, GoogleSheetsEntryNames.PufferEvoIntro },
{ LoddleAI.LoddleType.Axolotl, GoogleSheetsEntryNames.AxoEvoIntro },
{ LoddleAI.LoddleType.Angler, GoogleSheetsEntryNames.AnglerEvoIntro },
{ LoddleAI.LoddleType.Dumbo, GoogleSheetsEntryNames.OctoEvoIntro },
{ LoddleAI.LoddleType.MegaLod, GoogleSheetsEntryNames.JumboEvoIntro },
};
public static Dictionary<LoddleAI.LoddleType, string> typeStringMapping = new Dictionary<LoddleAI.LoddleType, string>()
{
{ LoddleAI.LoddleType.Eel, "Siren" },
{ LoddleAI.LoddleType.Betta, "Betta" },
{ LoddleAI.LoddleType.FlyingFish, "Wingfin" },
{ LoddleAI.LoddleType.SeaAngel, "Butterfly" },
{ LoddleAI.LoddleType.Catfish, "Whisker" },
{ LoddleAI.LoddleType.MantaRay, "Manta" },
{ LoddleAI.LoddleType.Loach, "Snake" },
{ LoddleAI.LoddleType.SeaBunny, "Bunny" },
{ LoddleAI.LoddleType.Pufferfish, "Puffer" },
{ LoddleAI.LoddleType.Axolotl, "Axo" },
{ LoddleAI.LoddleType.Angler, "Angler" },
{ LoddleAI.LoddleType.Dumbo, "Octo" },
{ LoddleAI.LoddleType.MegaLod, "Jumbo" },
};
public static void AddBiomeToDictionary(BiomeManager bm)
{
//log.LogInfo(bm.biomeDisplayName);
//log.LogInfo(bm.currentGoopPollution);
//log.LogInfo(bm.currentPlasticCloudPollution);
//log.LogInfo(bm.currentLitterPollution);
int biomeIndex = bm.biomeIndex;
if (!biomePollution.ContainsKey(biomeIndex))
{
biomePollution.Add(biomeIndex, new Dictionary<string, float>());
}
biomePollution[biomeIndex]["goopPollution"] = bm.currentGoopPollution;
biomePollution[biomeIndex]["plasticCloudPollution"] = bm.currentPlasticCloudPollution;
biomePollution[biomeIndex]["litterPollution"] = bm.currentLitterPollution;
int goopyLoddles = 0;
foreach (LoddleAI loddle in bm.loddlesInBiome)
{
goopyLoddles += loddle.isGoopy ? 1 : 0;
}
biomePollution[biomeIndex]["goopyLoddles"] = goopyLoddles;
}
public static void UpdateBiomePollution(GameEvent e)
{
BiomeManager bm = ((BiomePollutionUpdated)e).biome;
int biomeIndex = bm.biomeIndex;
//log.LogInfo($"Updating biome {biomeIndex}");
if (biomePollution.ContainsKey(biomeIndex))
{
biomePollution[biomeIndex]["goopPollution"] = bm.currentGoopPollution;
biomePollution[biomeIndex]["plasticCloudPollution"] = bm.currentPlasticCloudPollution;
biomePollution[biomeIndex]["litterPollution"] = bm.currentLitterPollution;
int goopyLoddles = 0;
foreach (LoddleAI loddle in bm.loddlesInBiome)
{
goopyLoddles += loddle.isGoopy ? 1 : 0;
}
biomePollution[biomeIndex]["goopyLoddles"] = goopyLoddles;
}
}
public static List<LoddleAI.LoddleType> GetEncounteredLoddleTypes()
{
List<LoddleAI.LoddleType> encounteredLoddleTypes = new List<LoddleAI.LoddleType>();
foreach (KeyValuePair<LoddleAI.LoddleType, string> entry in typeRemarkMapping)
{
if (EngineHub.GameDialogue.DaveRemarks[entry.Value].ReachedDisplayLimit())
{
encounteredLoddleTypes.Add(entry.Key);
}
}
return encounteredLoddleTypes;
}
public static void AddNonBiomeManager()
{
// Create a new BiomeManager just for keeping track of the non-biome pollution
GameObject go = new GameObject("NonBiomeManager");
go.AddComponent<BiomeManager>();
nonBiomeManager = go.GetComponent<BiomeManager>();
GoopPatches.nonBiomeManager = nonBiomeManager;
BiomeManager_Patch.nonBiomeManager = nonBiomeManager;
nonBiomeManager.biomeName = "NonBiome";
//nonBiomeManager.biomeDisplayName = "Non-Biome"; //Can't use a regular string here
nonBiomeManager.biomeIndex = NON_BIOME_INDEX;
nonBiomeManager.pollutionPerLitterPickup = 1.0f;
nonBiomeManager.pollutionPerLitterChunk = 1.0f;
nonBiomeManager.litterContributionToBiomePollution = 0.3f;
nonBiomeManager.plasticCloudContributionToBiomePollution = 0.15f;
}
public static void FixNonBiomeGoop()
{
// Some plants/litter/goop might have a reference to an incorrect biome, so fix it
GameObject nonBiomeParent = GameObject.Find("NonBiome_Decor");
foreach (FoodPlant foodPlant in nonBiomeParent.GetComponentsInChildren<FoodPlant>())
{
if (foodPlant.parentBiome != null)
{
log.LogInfo($"Found non-biome plant {foodPlant.saveID} with reference to {foodPlant.parentBiome}, fixing");
foodPlant.parentBiome = null;
}
}
foreach (Pickup pickup in nonBiomeParent.GetComponentsInChildren<Pickup>())
{
if (pickup.surroundingBiome != null)
{
log.LogInfo($"Found non-biome pickup {pickup.saveID} with reference to {pickup.surroundingBiome}, fixing");
pickup.surroundingBiome = null;
}
}
}
public static float GetGlobalPollutionAmount()
{
float totalPollution = 0.0f;
foreach (int bi in biomePollution.Keys)
{
BiomeManager bm;
bm = bi != -1 ? EngineHub.BiomeSaver.LookUpBiomeByID(bi) : nonBiomeManager;
totalPollution += bm.biomePollution;
}
totalPollution = totalPollution / biomePollution.Count;
return BloopTools.SnapToZero(totalPollution, 1E-06f);
}
public static void GetGoopyLoddlesCount(GameEvent e)
{
allGoopyLoddlesCleaned = GetGoopyLoddlesCount() == 0;
}
public static int GetGoopyLoddlesCount()
{
int goopyLoddles = 0;
LoddleAI[] loddles = UnityEngine.Object.FindObjectsByType<LoddleAI>(FindObjectsSortMode.None);
foreach (LoddleAI loddle in loddles)
{
goopyLoddles += loddle.isGoopy ? 1 : 0;
}
return goopyLoddles;
}
public static void OnHoloBadgeCollected(GameEvent e)
{
allHoloBadgesFound = ((HoloBadgeCollected)e).allHaveBeenCollected;
}
public static void OnLoddleMetPlayer(GameEvent e)
{
EngineHub.GameProgressTracker.StartCoroutine(ExtraTrackersMod.UpdateAllLoddleTypesFound());
}
public static IEnumerator UpdateAllLoddleTypesFound()
{
for (int i = 0; i < 2; i++)
{
yield return new WaitForEndOfFrame();
}
allLoddleTypesFound = GetEncounteredLoddleTypes().Count == typeRemarkMapping.Count;
}
}
}