public void RollSockets() { if (Type == null || Type.MaxSocketCount == 0) { return; } if (IsPreviouslyOwned || !Flags.HasFlag(ItemFlags.HasRandomSocketCount)) { return; } var table = new RandomizerTable(); var total = Type.MaxSocketCount * 100f; table.Add(new RandomizerNullValue(total)); for (var i = 1; i <= Type.MaxSocketCount; i++) { table.Add(new RandomizerIntValue(i, total / (2 * i))); } var result = table.Evaluate().FirstOrDefault() as RandomizerIntValue; if (result == null) { return; } for (var i = 0; i < result.Value; i++) { AddSocket(); } }
public static void PrefabInitGenericGeysers(GameObject go) { #if DEBUG_1 Debug.Log("[CustomizeGeyser] PrefabInitGenericGeysers"); #endif if (RandomizerTable.sum > 0) { string geyserTag = RandomizerTable.GetRandomGeyserType(go.transform); if (CustomizeGeyserState.StateManager.State.RandomizerPopupGeyserDiscoveryInfo) { KMod.Manager.Dialog(null, "Geysers discovered", "You just discovered a geyser: " + geyserTag); } Debug.Log("[CustomizeGeyser] Discovered a new geyser: " + geyserTag); GameUtil.KInstantiate(Assets.GetPrefab( (Tag)("GeyserGeneric_" + geyserTag) //change Tag to whatever you want to spawn; Tag is "GeyserGeneric_" + geyserType.id ), go.transform.GetPosition(), Grid.SceneLayer.BuildingBack, (string)null, 0).SetActive(true); go.DeleteObject(); } else { Debug.Log("[CustomizeGeyser] RandomizerTable was empty..."); } }
[HarmonyPriority(410)] //slightly higher priority since it clears events and other might want to hook in as well public static void Postfix(GeyserGenericConfig __instance, ref List <GameObject> __result) { GameObject geyserGenericOrg = __result.Find(x => x.name == "GeyserGeneric"); if (geyserGenericOrg == null) { Debug.LogWarning("[CustomizeGeyser] RandomizerPatch critical error: Did not find GeyserGeneric"); return; } GameObject geyserGeneric = EntityTemplates.CreatePlacedEntity(id: "GeyserGeneric", name: "Random Geyser Spawner", desc: GeyserGenericDescription, mass: 2000f, anim: Assets.GetAnim(GeyserGenericKAnim), initialAnim: GeyserGenericInitialState, sceneLayer: Grid.SceneLayer.BuildingBack, width: 3, height: 3, decor: TUNING.BUILDINGS.DECOR.BONUS.TIER1, noise: TUNING.NOISE_POLLUTION.NOISY.TIER6, element: SimHashes.Katairite, additionalTags: null, defaultTemperature: 372.15f); geyserGeneric.AddOrGet <SaveLoadRoot>(); geyserGeneric.AddOrGet <KPrefabID>().prefabInitFn += PrefabInitGenericGeysers; __result.Remove(geyserGenericOrg); __result.Add(geyserGeneric); #if DEBUG_1 Debug.Log("[CustomizeGeyser] Attached to GeyserGeneric"); #endif if (RandomizerTable.geysers == null) { RandomizerTable.Initialize(); } }
private IRandomizerTable CreateTable( LootData data, float probability, bool unique, bool guaranteed, bool enabled) { var table = new RandomizerTable(data.Count, probability, unique, guaranteed, enabled); foreach (var item in data.Items) { switch (item.Type) { case LootItemType.Null: table.Contents.Add(new RandomizerNullValue(item.Probability)); break; case LootItemType.Table: table.Contents.Add( CreateTable( this.lootDataRepository.FindOrFail(item.TableId), item.Probability, item.Unique, item.Guaranteed, item.Enabled ) ); break; case LootItemType.Item: table.Contents.Add(CreateItem(item)); break; case LootItemType.Random: table.Contents.Add(CreateRandom(item)); break; default: throw new ArgumentOutOfRangeException(nameof(item.Type), item.Type, null); } } return(table); }
private List <GameObject> FromTable(EncounterData data) { var table = new RandomizerTable(data.UnitTable.Count); foreach (var episodeUnitData in data.UnitTable.Units) { var value = new RandomizerValue <int>( episodeUnitData.UnitId, episodeUnitData.Probability, episodeUnitData.IsUnique, episodeUnitData.IsGuaranteed, episodeUnitData.IsEnabled ); table.Add(value); } return(table.Evaluate() .OfType <RandomizerValue <int> >() .Select(value => value.Value) .Select(unitId => this.unitRepository.Find(unitId)) .ToList()); }
public static void Prefix() { Debug.Log("[CustomizeGeyser] Re-initializing RandomizerTable..."); RandomizerTable.Reinitialize(); }