private static void ProcessGeysers(WorldGen __instance, ref List <KeyValuePair <Vector2I, TemplateContainer> > templateList, SeededRandom myRandom) { WorldGenReloadedData.CalculateGeysers(myRandom, __instance); List <TemplateContainer> featuresList = TemplateCache.CollectBaseTemplateAssets("features/"); foreach (SubWorld subWorld in __instance.Settings.GetSubWorldList()) { Debug.Log("Processing zone: " + subWorld.name); if (!WorldGenReloadedData.CalculatedGeysers.ContainsKey(subWorld.name)) { continue; } Dictionary <string, int> subworldConfig = WorldGenReloadedData.CalculatedGeysers[subWorld.name]; if (subWorld.pointsOfInterest != null) { foreach (KeyValuePair <string, int> item6 in subworldConfig) { Debug.Log("Processing geyser: [" + item6.Key + "," + item6.Value + "]"); for (int numGeysers = 0; numGeysers < item6.Value; numGeysers++) { List <TerrainCell> terrainCellsForTag2 = __instance.GetTerrainCellsForTag(subWorld.name.ToTag()); for (int num = terrainCellsForTag2.Count - 1; num >= 0; num--) { if (!__instance.IsSafeToSpawnPOI(terrainCellsForTag2[num])) { terrainCellsForTag2.Remove(terrainCellsForTag2[num]); } } /* * if (terrainCellsForTag2.Count <= 0 && WorldGenReloadedData.Config.ForceSpawnGeyserUnsafePlace) * { * terrainCellsForTag2 = WorldGen.GetTerrainCellsForTag(subWorld.name.ToTag()); * } */ Debug.Log("Available cells = " + terrainCellsForTag2.Count); if (terrainCellsForTag2.Count > 0) { string template = null; TemplateContainer templateContainer = null; int num2 = 0; /* * while (templateContainer == null && num2 < item6.Value.Length) * { * template = item6.Value[myRandom.RandomRange(0, item6.Value.Length)]; * templateContainer = list3.Find((TemplateContainer value) => value.name == template); * num2++; * } */ // Constructs a template using the already existing feature generic geyser. first() cause there is only one feature in the folder. TODO templateContainer = GetGeyserTemplate(featuresList.First(), item6.Key); Debug.Log("Adding geyser: " + templateContainer.name + " [" + item6.Key + "]"); if (templateContainer != null) { //list3.Remove(templateContainer); bool geyserPlaced = false; for (int i = 0; i < terrainCellsForTag2.Count; i++) { TerrainCell terrainCell = terrainCellsForTag2[myRandom.RandomRange(0, terrainCellsForTag2.Count)]; if (!terrainCell.node.tags.Contains(WorldGenTags.POI)) { if (!(templateContainer.info.size.Y > terrainCell.poly.MaxY - terrainCell.poly.MinY)) { List <KeyValuePair <Vector2I, TemplateContainer> > list4 = templateList; Vector2 vector3 = terrainCell.poly.Centroid(); int a2 = (int)vector3.x; Vector2 vector4 = terrainCell.poly.Centroid(); list4.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a2, (int)vector4.y), templateContainer)); terrainCell.node.tags.Add(template.ToTag()); terrainCell.node.tags.Add(WorldGenTags.POI); geyserPlaced = true; break; } float num3 = templateContainer.info.size.Y - (terrainCell.poly.MaxY - terrainCell.poly.MinY); float num4 = templateContainer.info.size.X - (terrainCell.poly.MaxX - terrainCell.poly.MinX); if (terrainCell.poly.MaxY + num3 < (float)Grid.HeightInCells && terrainCell.poly.MinY - num3 > 0f && terrainCell.poly.MaxX + num4 < (float)Grid.WidthInCells && terrainCell.poly.MinX - num4 > 0f) { List <KeyValuePair <Vector2I, TemplateContainer> > list5 = templateList; Vector2 vector5 = terrainCell.poly.Centroid(); int a3 = (int)vector5.x; Vector2 vector6 = terrainCell.poly.Centroid(); list5.Add(new KeyValuePair <Vector2I, TemplateContainer>(new Vector2I(a3, (int)vector6.y), templateContainer)); terrainCell.node.tags.Add(template.ToTag()); terrainCell.node.tags.Add(WorldGenTags.POI); geyserPlaced = true; break; } } else { Debug.Log("Cannot find a place for geyser. POI in the way: " + item6.Key); } } if (!geyserPlaced) { Debug.Log("Cannot find a place for geyser. Not enought space: " + item6.Key); } } else { Debug.Log("Cannot build geyser template: " + item6.Key); } } else { Debug.Log("Cannot find a place for geyser. Empty space: " + item6.Key); } } } } } }
private static void Postfix(ref List <GeyserPrefabParams> __result) { Debug.Log(" === WorldGenReloadedMod_GeyserGenericConfig_GenerateConfigs Prefix === "); WorldGenReloadedData.GeyserPrefabParams = new List <GeyserPrefabParams>(__result); if (WorldGenReloadedData.Config.LogGeysersDefaultConfig) { WorldGenReloadedData.LogGeysersDefaults(__result); } //__result.Clear(); List <GeyserPrefabParams> list = new List <GeyserPrefabParams>(); // foreach config geyser foreach (KeyValuePair <string, Dictionary <string, object> > geyser in WorldGenReloadedData.Config.Geysers) { Dictionary <string, object> geyserData = geyser.Value; GeyserPrefabParams? geyserPrefab = WorldGenReloadedData.FindGeyserPrefab(geyser.Key); //int min = 1, max = 1; //float probability = 0; //string[] subworlds = null; GeyserState geyserConfig = new GeyserState(geyser.Key); // foreach config attribute foreach (KeyValuePair <string, object> attribute in geyserData) { //Debug.Log(attribute.Key.ToLower()); //Debug.Log(attribute.Value.GetType()); //Debug.Log(attribute.Value); switch (attribute.Key.ToLower()) { case "properties": //Debug.Log(attribute.Value.GetType()); //Debug.Log("attribute.Value: "+attribute.Value); // Set geyser basic properties foreach (JProperty property in (JToken)attribute.Value) { //Debug.Log(property.Name); FieldInfo fi = AccessTools.Field(typeof(GeyserConfigurator.GeyserType), property.Name); //Debug.Log(fi); fi.SetValue(((GeyserPrefabParams)geyserPrefab).geyserType, (float)property.Value); //Debug.Log(property.Name); } break; case "minimum": geyserConfig.Minimum = Convert.ToInt32(attribute.Value); break; case "maximum": geyserConfig.Maximum = Convert.ToInt32(attribute.Value); break; case "probability": geyserConfig.Probability = (float)Convert.ToDouble(attribute.Value); break; case "subworlds": geyserConfig.SubWorlds = ((JArray)attribute.Value).ToObject <string[]>(); break; default: break; } } WorldGenReloadedData.GeyserConfig.Add(geyser.Key, geyserConfig); } __result = WorldGenReloadedData.GeyserPrefabParams; }