bool PopulateContainer(LootContainer container) { Dictionary <string, object> con; object containerobj; int lootitemcount; if (!lootTables.TryGetValue(container.PrefabName, out containerobj)) { return(false); } con = containerobj as Dictionary <string, object>; if (!(bool)con["Enabled"]) { return(false); } lootitemcount = (int)(con["ItemList"] as Dictionary <string, object>).Count(); int itemCount = Mathf.RoundToInt(UnityEngine.Random.Range(Convert.ToSingle(Mathf.Min((int)con["ItemsMin"], (int)con["ItemsMax"])) * 100f, Convert.ToSingle(Mathf.Max((int)con["ItemsMin"], (int)con["ItemsMax"])) * 100f) / 100f); if (lootitemcount > 0 && itemCount > lootitemcount && lootitemcount < 36) { itemCount = lootitemcount; } if (container.inventory == null) { container.inventory = new ItemContainer(); container.inventory.ServerInitialize(null, 36); container.inventory.GiveUID(); } else { while (container.inventory.itemList.Count > 0) { var item = container.inventory.itemList[0]; item.RemoveFromContainer(); item.Remove(0f); } container.inventory.capacity = 36; } var items = new List <Item>(); var itemNames = new List <string>(); var itemBlueprints = new List <int>(); var maxRetry = 10; for (int i = 0; i < itemCount; ++i) { if (maxRetry == 0) { break; } var item = MightyRNG(container.PrefabName, itemCount, (bool)(itemBlueprints.Count >= (int)con["MaxBPs"])); if (item == null) { --maxRetry; --i; continue; } if (itemNames.Contains(item.info.shortname) || (item.IsBlueprint() && itemBlueprints.Contains(item.blueprintTarget))) { item.Remove(0f); --maxRetry; --i; continue; } else if (item.IsBlueprint()) { itemBlueprints.Add(item.blueprintTarget); } else { itemNames.Add(item.info.shortname); } items.Add(item); } foreach (var item in items.Where(x => x != null && x.IsValid())) { item.MoveToContainer(container.inventory, -1, false); } if ((int)con["Scrap"] > 0) { int scrapCount = (int)con["Scrap"]; Item item = ItemManager.Create(ItemManager.FindItemDefinition("scrap"), scrapCount, 0uL); item.MoveToContainer(container.inventory, -1, false); } container.inventory.capacity = container.inventory.itemList.Count; container.inventory.MarkDirty(); container.SendNetworkUpdate(); populatedContainers++; return(true); }