public static void Initialize() { DatablockDictionary._dataBlocks = new Dictionary <string, int>(); DatablockDictionary._dataBlocksByUniqueID = new Dictionary <int, int>(); DatablockDictionary._lootSpawnLists = new Dictionary <string, LootSpawnList>(); List <ItemDataBlock> itemDataBlocks = new List <ItemDataBlock>(); HashSet <ItemDataBlock> itemDataBlocks1 = new HashSet <ItemDataBlock>(); ItemDataBlock[] itemDataBlockArray = Bundling.LoadAll <ItemDataBlock>(); for (int i = 0; i < (int)itemDataBlockArray.Length; i++) { ItemDataBlock itemDataBlock = itemDataBlockArray[i]; if (itemDataBlocks1.Add(itemDataBlock)) { int count = itemDataBlocks.Count; DatablockDictionary._dataBlocks.Add(itemDataBlock.name, count); DatablockDictionary._dataBlocksByUniqueID.Add(itemDataBlock.uniqueID, count); itemDataBlocks.Add(itemDataBlock); } } DatablockDictionary._all = itemDataBlocks.ToArray(); LootSpawnList[] lootSpawnListArray = Bundling.LoadAll <LootSpawnList>(); for (int j = 0; j < (int)lootSpawnListArray.Length; j++) { LootSpawnList lootSpawnList = lootSpawnListArray[j]; DatablockDictionary._lootSpawnLists.Add(lootSpawnList.name, lootSpawnList); } DatablockDictionary.initializedAtLeastOnce = true; }
public static bool LootSaveFile() { using (StreamWriter writer = File.CreateText(LootsFile)) { foreach (string str in list_0) { LootSpawnList list = DatablockDictionary._lootSpawnLists[str]; writer.WriteLine("[" + list.name + "]"); writer.WriteLine(string.Concat(new object[] { "PackagesToSpawn=", list.minPackagesToSpawn, ",", list.maxPackagesToSpawn })); writer.WriteLine("SpawnOneOfEach=" + list.spawnOneOfEach.ToString()); writer.WriteLine("NoDuplicates=" + list.noDuplicates.ToString()); writer.WriteLine("// Type Weight\tList/Item\t\tMin\tMax"); foreach (LootSpawnList.LootWeightedEntry entry in list.LootPackages) { if (entry.obj != null) { if (entry.obj is ItemDataBlock) { writer.Write("PackageItem="); } else { writer.Write("PackageList="); } writer.Write(entry.weight + "\t"); writer.Write(entry.obj.name + new string('\t', 4 - (entry.obj.name.Length / 8))); writer.Write(entry.amountMin + "\t" + entry.amountMax); writer.WriteLine(); } } writer.WriteLine(); } } return(true); }
public void OnTablesLoaded(Dictionary <string, LootSpawnList> Tables) { if (!Directory.Exists(ModuleFolder + "\\Tables")) { Directory.CreateDirectory(ModuleFolder + "\\Tables"); } ExtractTables(Tables); foreach (var name in Tables.Keys) { IniParser table = new IniParser(ModuleFolder + "\\Tables\\" + name + ".ini"); LootSpawnList realTable = Tables[name]; try { realTable.minPackagesToSpawn = int.Parse(table.GetSetting("TableSettings", "MinToSpawn")); realTable.maxPackagesToSpawn = int.Parse(table.GetSetting("TableSettings", "MaxToSpawn")); realTable.spawnOneOfEach = bool.Parse(table.GetSetting("TableSettings", "OneOfEach")); realTable.noDuplicates = bool.Parse(table.GetSetting("TableSettings", "DuplicatesAllowed")); realTable.noDuplicates = !realTable.noDuplicates; } catch (Exception ex) { Logger.LogError("[DropPP] Failed to convert values from the ini file! (0x1) " + ex); } var c = table.Count() - 1; var packs = new LootSpawnList.LootWeightedEntry[c]; for (var i = 1; i <= c; i++) { try { var pack = new LootSpawnList.LootWeightedEntry(); pack.weight = float.Parse(table.GetSetting("Entry" + i, "Weight")); pack.amountMin = int.Parse(table.GetSetting("Entry" + i, "Min")); pack.amountMax = int.Parse(table.GetSetting("Entry" + i, "Max")); var objName = table.GetSetting("Entry" + i, "Name"); if (Tables.ContainsKey(objName)) { pack.obj = Tables[objName]; } else { pack.obj = Server.GetServer().Items.Find(objName); } packs[i - 1] = pack; } catch (Exception ex) { Logger.LogError("[DropPP] Failed to convert values from the ini file! (0x2) " + ex); } } realTable.LootPackages = packs; } }
private void PopulateInventory_Recurse(ref LootSpawnList.RecursiveInventoryPopulateArgs args) { if (this.maxPackagesToSpawn > (int)this.LootPackages.Length) { this.maxPackagesToSpawn = (int)this.LootPackages.Length; } int num = 0; num = (!this.spawnOneOfEach ? UnityEngine.Random.Range(this.minPackagesToSpawn, this.maxPackagesToSpawn) : (int)this.LootPackages.Length); for (int i = 0; !args.inventoryExausted && i < num; i++) { LootSpawnList.LootWeightedEntry lootWeightedEntry = null; lootWeightedEntry = (!this.spawnOneOfEach ? WeightSelection.RandomPickEntry(this.LootPackages) as LootSpawnList.LootWeightedEntry : this.LootPackages[i]); if (lootWeightedEntry == null) { Debug.Log("Massive fuckup..."); return; } UnityEngine.Object obj = lootWeightedEntry.obj; if (obj) { if (obj is ItemDataBlock) { if (!object.ReferenceEquals(args.inventory.AddItem(obj as ItemDataBlock, Inventory.Slot.Preference.Define(args.spawnCount, false, Inventory.Slot.KindFlags.Default | Inventory.Slot.KindFlags.Belt), UnityEngine.Random.Range(lootWeightedEntry.amountMin, lootWeightedEntry.amountMax + 1)), null)) { args.spawnCount = args.spawnCount + 1; if (args.inventory.noVacantSlots) { args.inventoryExausted = true; } } } else if (obj is LootSpawnList) { ((LootSpawnList)obj).PopulateInventory_Recurse(ref args); } } } }
private static bool smethod_0() { System.Collections.Generic.List <string> list = File.ReadAllLines(LootsFile).ToList <string>(); if (predicate_0 == null) { predicate_0 = new Predicate <string>(Override.smethod_6); } if (!list.Exists(predicate_0)) { ConsoleSystem.PrintError("ERROR: Spawn list for \"AILootList\" not found in \"lootslist.cfg\".", false); return(false); } if (predicate_1 == null) { predicate_1 = new Predicate <string>(Override.smethod_7); } if (!list.Exists(predicate_1)) { ConsoleSystem.PrintError("ERROR: Spawn list for \"AmmoSpawnList\" not found in \"lootslist.cfg\".", false); return(false); } if (predicate_2 == null) { predicate_2 = new Predicate <string>(Override.smethod_8); } if (!list.Exists(predicate_2)) { ConsoleSystem.PrintError("ERROR: Spawn list for \"JunkSpawnList\" not found in \"lootslist.cfg\".", false); return(false); } if (predicate_3 == null) { predicate_3 = new Predicate <string>(Override.smethod_9); } if (!list.Exists(predicate_3)) { ConsoleSystem.PrintError("ERROR: Spawn list for \"MedicalSpawnList\" not found in \"lootslist.cfg\".", false); return(false); } if (predicate_4 == null) { predicate_4 = new Predicate <string>(Override.smethod_10); } if (!list.Exists(predicate_4)) { ConsoleSystem.PrintError("ERROR: Spawn list for \"WeaponSpawnList\" not found in \"lootslist.cfg\".", false); return(false); } if (predicate_5 == null) { predicate_5 = new Predicate <string>(Override.smethod_11); } if (!list.Exists(predicate_5)) { ConsoleSystem.PrintError("ERROR: Spawn list for \"SupplyDropSpawnListMaster\" not found in \"lootslist.cfg\".", false); return(false); } DatablockDictionary._lootSpawnLists.Clear(); Dictionary <string, LootSpawnList> dictionary = new Dictionary <string, LootSpawnList>(); foreach (string str in list) { string str2 = str.Trim(); if (!string.IsNullOrEmpty(str2) && !str2.StartsWith("//")) { if (str2.Contains("//")) { str2 = str2.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries)[0].Trim(); } if ((!string.IsNullOrEmpty(str2) && str2.StartsWith("[")) && str2.EndsWith("]")) { str2 = str2.Substring(1, str2.Length - 2); dictionary[str2] = ScriptableObject.CreateInstance <LootSpawnList>(); } } } LootSpawnList list2 = null; LootSpawnList.LootWeightedEntry item = null; System.Collections.Generic.List <LootSpawnList.LootWeightedEntry> list3 = null; foreach (string str3 in list) { string str4 = str3.Trim(); if (!string.IsNullOrEmpty(str4) && !str4.StartsWith("//")) { if (str4.Contains("//")) { str4 = str4.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries)[0].Trim(); } if (!string.IsNullOrEmpty(str4)) { if (str4.StartsWith("[") && str4.EndsWith("]")) { string str5 = str4.Substring(1, str4.Length - 2); list2 = dictionary[str5]; list2.name = str5; DatablockDictionary._lootSpawnLists.Add(list2.name, list2); list3 = new System.Collections.Generic.List <LootSpawnList.LootWeightedEntry>(); } else if (str4.Contains("=") && (list2 != null)) { string str6; string[] strArray = str4.Split(new char[] { '=' }); if ((strArray.Length >= 2) && ((str6 = strArray[0].ToUpper()) != null)) { if (str6 == "PACKAGESTOSPAWN") { if (strArray[1].Contains(",")) { strArray = strArray[1].Split(new char[] { ',' }); } else { strArray = new string[] { strArray[1], strArray[1] }; } int.TryParse(strArray[0], out list2.minPackagesToSpawn); int.TryParse(strArray[1], out list2.maxPackagesToSpawn); } else if (str6 == "SPAWNONEOFEACH") { bool.TryParse(strArray[1], out list2.spawnOneOfEach); } else if (str6 == "NODUPLICATES") { bool.TryParse(strArray[1], out list2.noDuplicates); } else if (str6 == "PACKAGELIST") { strArray = strArray[1].Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries); item = new LootSpawnList.LootWeightedEntry(); if (!dictionary.ContainsKey(strArray[1])) { ConsoleSystem.LogError(string.Format("Package {0} has a reference to an spawn list named {1}, but it not exist.", list2.name, strArray[1])); } else { item.obj = dictionary[strArray[1]]; float.TryParse(strArray[0], out item.weight); int.TryParse(strArray[2], out item.amountMin); int.TryParse(strArray[3], out item.amountMax); list3.Add(item); list2.LootPackages = list3.ToArray(); } } else if (str6 == "PACKAGEITEM") { strArray = strArray[1].Split(new string[] { "\t" }, StringSplitOptions.RemoveEmptyEntries); item = new LootSpawnList.LootWeightedEntry { obj = DatablockDictionary.GetByName(strArray[1]) }; if (item.obj == null) { ConsoleSystem.LogError(string.Format("Package {0} has a reference to an item named {1}, but it not exist.", list2.name, strArray[1])); } else { float.TryParse(strArray[0], out item.weight); int.TryParse(strArray[2], out item.amountMin); int.TryParse(strArray[3], out item.amountMax); list3.Add(item); list2.LootPackages = list3.ToArray(); } } } } } } } return(true); }