private static void SetRules(JObject settingsObject, LisbethRetainerRules rules) { foreach (JToken retainerToken in settingsObject["Retainers"]) { int retainerIndex = retainerToken["Index"]?.ToObject <int>() ?? 0; retainerToken["Rules"] = JToken.FromObject(rules.RulesByIndex[retainerIndex]); } }
public static void PopulateSettings(string settingsPath) { if (string.IsNullOrEmpty(settingsPath)) { AutoRetainerSort.LogCritical("Provided Lisbeth settings path is invalid!"); return; } JObject settingsJObject = GetJObject(settingsPath); LisbethRetainerRules knownRules = new LisbethRetainerRules(settingsJObject); foreach (var indexInfoPair in AutoRetainerSortSettings.Instance.InventoryOptions) { if (!knownRules.RulesByIndex.ContainsKey(indexInfoPair.Key)) { continue; } var ruleList = knownRules.RulesByIndex[indexInfoPair.Key]; foreach (uint itemId in indexInfoPair.Value.SpecificItems.Select(x => x.RawItemId).Distinct()) { ruleList.Add(new LisbethRetainerRules.ItemRule(itemId)); } } foreach (CachedInventory cachedInventory in ItemSortStatus.GetAllInventories()) { if (!knownRules.RulesByIndex.ContainsKey(cachedInventory.Index)) { continue; } var ruleList = knownRules.RulesByIndex[cachedInventory.Index]; foreach (ItemSortInfo sortInfo in cachedInventory.ItemCounts.Select(x => ItemSortStatus.GetSortInfo(x.Key)).Distinct()) { if (sortInfo.ItemInfo.Unique || sortInfo.ItemInfo.StackSize <= 1) { continue; } ruleList.Add(new LisbethRetainerRules.ItemRule(sortInfo.RawItemId)); } } SetRules(settingsJObject, knownRules); using (StreamWriter outputFile = new StreamWriter(settingsPath, false)) { outputFile.Write(JsonConvert.SerializeObject(settingsJObject, Formatting.None)); } }