private void OnNewSave() { if (_config.clearOnWipe) { dataFile.Clear(); } }
/// <summary> /// Saves all permissions data to the datafile /// </summary> private void SaveToDatafile() { datafile.Clear(); Dictionary <string, object> grouplist = new Dictionary <string, object>(); Dictionary <string, object> userlist = new Dictionary <string, object>(); datafile["groups"] = grouplist; datafile["users"] = userlist; foreach (var pair in groupdata) { grouplist.Add(pair.Key, new Dictionary <string, object>() { { "Title", pair.Value.Title }, { "Rank", pair.Value.Rank }, { "Perms", new List <object>(pair.Value.Perms.Cast <object>()) } }); } foreach (var pair in userdata) { userlist.Add(pair.Key.UID.ToString(), new Dictionary <string, object>() { { "LastSeenNickname", pair.Value.LastSeenNickname }, { "Usergroup", pair.Value.Usergroup }, { "Perms", new List <object>(pair.Value.Perms.Cast <object>()) } }); } Interface.GetMod().DataFileSystem.SaveDatafile("oxide.permissions"); }
void SaveSignData() { storedData.Clear(); foreach (var signea in signs) { storedData[signea.Key.ToString()] = signea.Value; } Interface.Oxide.DataFileSystem.SaveDatafile("SignTracker"); }
/// <summary> /// Copies and translates the contents of the specified table into the specified config file /// </summary> /// <param name="config"></param> /// <param name="objectInstance"></param> public static void SetConfigFromObject(DynamicConfigFile config, ObjectInstance objectInstance) { config.Clear(); foreach (var property in objectInstance.GetOwnProperties()) { var value = property.Value.Value?.ToObject(); if (value != null) config[property.Key] = value; } }
/// <summary> /// Copies and translates the contents of the specified table into the specified config file /// </summary> /// <param name="config"></param> /// <param name="table"></param> public static void SetConfigFromTable(DynamicConfigFile config, LuaTable table) { config.Clear(); foreach (var key in table.Keys) { var keystr = key as string; if (keystr == null) continue; var value = TranslateLuaItemToConfigItem(table[key]); if (value != null) config[keystr] = value; } }
/// <summary> /// Copies and translates the contents of the specified table into the specified config file /// </summary> /// <param name="config"></param> /// <param name="objectInstance"></param> public static void SetConfigFromObject(DynamicConfigFile config, ObjectInstance objectInstance) { config.Clear(); foreach (var property in objectInstance.GetOwnProperties()) { var value = property.Value.Value?.ToObject(); if (value != null) { config[property.Key] = value; } } }
/// <summary> /// Copies and translates the contents of the specified dictionary into the specified config file /// </summary> /// <param name="config"></param> /// <param name="dict"></param> public static void SetConfigFromDictionary(DynamicConfigFile config, PythonDictionary dict) { config.Clear(); foreach (object key in dict.Keys) { string keystr = key as string; if (keystr != null) { object value = TranslatePythonItemToConfigItem(dict[key]); if (value != null) config[keystr] = value; } } }
private void SaveQuarries() { QuarryData.Clear(); var settings = new JsonSerializerSettings { Formatting = Formatting.None, DefaultValueHandling = DefaultValueHandling.Populate, TypeNameHandling = TypeNameHandling.Auto }; string json = JsonConvert.SerializeObject(Quarries, settings); QuarryData["Quarries"] = json; Interface.GetMod().DataFileSystem.SaveDatafile("WorldQuarryInstances"); }
/// <summary> /// Copies and translates the contents of the specified dictionary into the specified config file /// </summary> /// <param name="config"></param> /// <param name="dict"></param> public static void SetConfigFromDictionary(DynamicConfigFile config, PythonDictionary dict) { config.Clear(); foreach (object key in dict.Keys) { string keystr = key as string; if (keystr != null) { object value = TranslatePythonItemToConfigItem(dict[key]); if (value != null) { config[keystr] = value; } } } }
/// <summary> /// Copies and translates the contents of the specified table into the specified config file /// </summary> /// <param name="config"></param> /// <param name="objectInstance"></param> public static void SetConfigFromObject(DynamicConfigFile config, ObjectInstance objectInstance) { config.Clear(); foreach (var property in objectInstance.Properties) { if (property.Value.Value == null) { continue; } object value = property.Value.Value.Value.ToObject(); if (value != null) { config[property.Key] = value; } } }
/// <summary> /// Copies and translates the contents of the specified table into the specified config file /// </summary> /// <param name="config"></param> /// <param name="table"></param> public static void SetConfigFromTable(DynamicConfigFile config, LuaTable table) { config.Clear(); foreach (object key in table.Keys) { string keystr = key as string; if (keystr != null) { object value = TranslateLuaItemToConfigItem(table[key]); if (value != null) { config[keystr] = value; } } } }
void LoadAllContainers() { try { lootTable = getFile("LootTables"); } catch (JsonReaderException e) { PrintWarning($"JSON error in 'LootTables' > Line: {e.LineNumber} | {e.Path}"); Interface.GetMod().UnloadPlugin(this.Title); return; } lootTables = new Dictionary <string, object>(); lootTables = lootTable["LootTables"] as Dictionary <string, object>; if (lootTables == null) { lootTables = new Dictionary <string, object>(); } bool wasAdded = false; foreach (var lootPrefab in lootPrefabsToUse) { if (!lootTables.ContainsKey((string)lootPrefab)) { var loot = GameManager.server.FindPrefab((string)lootPrefab)?.GetComponent <LootContainer>(); if (loot == null) { continue; } var container = new Dictionary <string, object>(); container.Add("Enabled", ((((string)lootPrefab).Contains("bradley_crate")) || (((string)lootPrefab).Contains("heli_crate"))) ? false : true); container.Add("Scrap", loot.scrapAmount); int slots = 0; if (loot.LootSpawnSlots.Length > 0) { LootContainer.LootSpawnSlot[] lootSpawnSlots = loot.LootSpawnSlots; for (int i = 0; i < lootSpawnSlots.Length; i++) { slots += lootSpawnSlots[i].numberToSpawn; } } else { slots = loot.maxDefinitionsToSpawn; } container.Add("ItemsMin", slots); container.Add("ItemsMax", slots); container.Add("MaxBPs", 1); var itemList = new Dictionary <string, object>(); if (loot.lootDefinition != null) { GetLootSpawn(loot.lootDefinition, ref itemList); } else if (loot.LootSpawnSlots.Length > 0) { LootContainer.LootSpawnSlot[] lootSpawnSlots = loot.LootSpawnSlots; for (int i = 0; i < lootSpawnSlots.Length; i++) { LootContainer.LootSpawnSlot lootSpawnSlot = lootSpawnSlots[i]; GetLootSpawn(lootSpawnSlot.definition, ref itemList); } } container.Add("ItemList", itemList); lootTables.Add((string)lootPrefab, container); wasAdded = true; } } if (wasAdded) { lootTable.Set("LootTables", lootTables); lootTable.Save(); } wasAdded = false; bool wasRemoved = false; int activeTypes = 0; foreach (var lootTable in lootTables.ToList()) { var loot = GameManager.server.FindPrefab(lootTable.Key)?.GetComponent <LootContainer>(); if (loot == null) { lootTables.Remove(lootTable.Key); wasRemoved = true; continue; } var container = lootTable.Value as Dictionary <string, object>; if (!container.ContainsKey("Enabled")) { container.Add("Enabled", true); wasAdded = true; } if ((bool)container["Enabled"]) { activeTypes++; } if (!container.ContainsKey("Scrap")) { container.Add("Scrap", loot.scrapAmount); wasAdded = true; } int slots = 0; if (loot.LootSpawnSlots.Length > 0) { LootContainer.LootSpawnSlot[] lootSpawnSlots = loot.LootSpawnSlots; for (int i = 0; i < lootSpawnSlots.Length; i++) { slots += lootSpawnSlots[i].numberToSpawn; } } else { slots = loot.maxDefinitionsToSpawn; } if (!container.ContainsKey("MaxBPs")) { container.Add("MaxBPs", 1); wasAdded = true; } if (!container.ContainsKey("ItemsMin")) { container.Add("ItemsMin", slots); wasAdded = true; } if (!container.ContainsKey("ItemsMax")) { container.Add("ItemsMax", slots); wasAdded = true; } if (!container.ContainsKey("ItemsMax")) { container.Add("ItemsMax", slots); wasAdded = true; } if (!container.ContainsKey("ItemList")) { var itemList = new Dictionary <string, object>(); if (loot.lootDefinition != null) { GetLootSpawn(loot.lootDefinition, ref itemList); } else if (loot.LootSpawnSlots.Length > 0) { LootContainer.LootSpawnSlot[] lootSpawnSlots = loot.LootSpawnSlots; for (int i = 0; i < lootSpawnSlots.Length; i++) { LootContainer.LootSpawnSlot lootSpawnSlot = lootSpawnSlots[i]; GetLootSpawn(lootSpawnSlot.definition, ref itemList); } } container.Add("ItemList", itemList); wasAdded = true; } Items.Add(lootTable.Key, new List <string> [5]); Blueprints.Add(lootTable.Key, new List <string> [5]); for (var i = 0; i < 5; ++i) { Items[lootTable.Key][i] = new List <string>(); Blueprints[lootTable.Key][i] = new List <string>(); } foreach (var itemEntry in container["ItemList"] as Dictionary <string, object> ) { bool isBP = itemEntry.Key.EndsWith(".blueprint") ? true : false; var def = ItemManager.FindItemDefinition(itemEntry.Key.Replace(".blueprint", "")); if (def != null) { if (isBP && def.Blueprint != null && def.Blueprint.isResearchable) { int index = (int)def.rarity; if (!Blueprints[lootTable.Key][index].Contains(def.shortname)) { Blueprints[lootTable.Key][index].Add(def.shortname); } } else { int index = 0; object indexoverride; if (rarityItemOverride.TryGetValue(def.shortname, out indexoverride)) { index = Convert.ToInt32(indexoverride); } else { index = (int)def.rarity; } if (!Items[lootTable.Key][index].Contains(def.shortname)) { Items[lootTable.Key][index].Add(def.shortname); } } } } totalItemWeight.Add(lootTable.Key, 0); totalBlueprintWeight.Add(lootTable.Key, 0); itemWeights.Add(lootTable.Key, new int[5]); blueprintWeights.Add(lootTable.Key, new int[5]); for (var i = 0; i < 5; ++i) { totalItemWeight[lootTable.Key] += (itemWeights[lootTable.Key][i] = ItemWeight(baseItemRarity, i) * Items[lootTable.Key][i].Count); totalBlueprintWeight[lootTable.Key] += (blueprintWeights[lootTable.Key][i] = ItemWeight(baseItemRarity, i) * Blueprints[lootTable.Key][i].Count); } } if (wasAdded || wasRemoved) { lootTable.Set("LootTables", lootTables); lootTable.Save(); } lootTable.Clear(); Puts($"Using '{activeTypes}' active of '{lootTables.Count}' supported containertypes"); }
private void TestCommand4(IPlayer player, string command, string[] args) { dataFile.Clear(); dataFile.Save(); }