Ejemplo n.º 1
0
        public static string GetSettingsPath()
        {
            TypeInfo botType = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(i => i.FullName.Contains("Lisbeth.Reborn"))?.DefinedTypes.FirstOrDefault(i => i.Name == "Directories")
                               ?? AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(i => i.FullName.Contains("Lisbeth"))?.DefinedTypes.FirstOrDefault(i => i.Name == "Directories");

            if (botType == null)
            {
                AutoRetainerSort.LogCritical($"Couldn't find our Lisbeth install, but we're supposed to generate rules for it...?");
                return(string.Empty);
            }

            AutoRetainerSort.Log($"Lisbeth Type {botType.FullName}");

            string assemblyLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location ?? string.Empty);
            string settingsPath     = botType.GetProperty("SettingsPath")?.GetValue(null) as string ?? string.Empty;

            if (string.IsNullOrEmpty(assemblyLocation) || string.IsNullOrEmpty(settingsPath))
            {
                return(string.Empty);
            }

            string settingsFilePath = Path.Combine(assemblyLocation, settingsPath);

            return(settingsFilePath);
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        private void Delete_Click(object sender, EventArgs e)
        {
            var selectedItem = (KeyValuePair <int, InventorySortInfo>)listBoxInventoryOptions.SelectedItem;

            if (selectedItem.Key >= ItemSortStatus.SaddlebagInventoryIndex)
            {
                DialogResult dr = MessageBox.Show(
                    $"Are you sure you want to delete {selectedItem.Value.Name}?",
                    "Really Delete?",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Exclamation);
                if (dr != DialogResult.Yes)
                {
                    return;
                }
            }
            else
            {
                DialogResult dr = MessageBox.Show(
                    $"Are you REALLY sure you want to delete the Player Inventory from being sorted?{Environment.NewLine}This is probably going to break things... don't blame me.",
                    Strings.WarningCaption,
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Hand);
                if (dr != DialogResult.Yes)
                {
                    return;
                }
            }

            if (AutoRetainerSortSettings.Instance.InventoryOptions.Remove(selectedItem.Key))
            {
                AutoRetainerSort.LogSuccess($"We've removed {selectedItem.Value.Name} from the list. Good bye, so long!");
            }
            else
            {
                AutoRetainerSort.LogCritical($"Something went wrong with trying to remove {selectedItem.Value.Name} from the list... Index: {selectedItem.Key.ToString()}");
            }
            AutoRetainerSortSettings.Instance.Save();
            ResetBindingSource();
        }
Ejemplo n.º 4
0
        public LisbethRetainerRules(JObject lisbethSettings)
        {
            RulesByIndex = new Dictionary <int, HashSet <ItemRule> >();
            JToken retainerSettings = lisbethSettings["Retainers"];

            if (retainerSettings == null)
            {
                AutoRetainerSort.LogCritical("No retainers found in Lisbeth's settings!");
                return;
            }

            foreach (JToken retainerInfo in retainerSettings)
            {
                int index = retainerInfo["Index"]?.ToObject <int>() ?? 0;
                RulesByIndex.Add(index, new HashSet <ItemRule>());
                var    ruleSet      = RulesByIndex[index];
                JToken currentRules = retainerInfo["Rules"];
                if (currentRules == null)
                {
                    AutoRetainerSort.LogCritical("RetainerInfo didn't contain any rules array!");
                    return;
                }

                foreach (JToken rule in currentRules)
                {
                    ItemRule itemRule = rule.ToObject <ItemRule>();
                    if (itemRule == null)
                    {
                        JToken itemIdToken = rule["Item"];
                        AutoRetainerSort.LogCritical(itemIdToken == null ? "Couldn't parse rule! ID is null?" : $"Couldn't parse rule for ID {itemIdToken.ToObject<uint>().ToString()}");
                        continue;
                    }

                    ruleSet.Add(itemRule);
                }
            }
        }