Пример #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);
        }
Пример #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));
            }
        }
Пример #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();
        }
Пример #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);
                }
            }
        }
        private void AddNewItem_Click(object sender, EventArgs e)
        {
            var toAddIds = new HashSet <uint>();

            using (AddNewItemForm newItemForm = new AddNewItemForm())
            {
                DialogResult dr = newItemForm.ShowDialog(this);
                if (dr != DialogResult.OK)
                {
                    return;
                }

                SearchResult selectedItem = newItemForm.SelectedSearchResult;
                if (selectedItem == null || selectedItem.RawItemId == 0)
                {
                    return;
                }

                if (newItemForm.ModifierNone)
                {
                    toAddIds.Add(selectedItem.RawItemId);
                }
                else if (newItemForm.ModifierHQ)
                {
                    toAddIds.Add(selectedItem.RawItemId + QualityOffset);
                }
                else if (newItemForm.ModifierCollectable)
                {
                    toAddIds.Add(selectedItem.RawItemId + CollectableOffset);
                }
                else
                {
                    return;
                }

                if (newItemForm.IncludeHQ)
                {
                    toAddIds.Add(selectedItem.RawItemId + QualityOffset);
                }
                if (newItemForm.IncludeCollectable)
                {
                    toAddIds.Add(selectedItem.RawItemId + CollectableOffset);
                }
            }

            foreach (uint toAddId in toAddIds)
            {
                ItemSortInfo sortInfo  = ItemSortStatus.GetSortInfo(toAddId);
                var          shouldAdd = true;
                foreach (var indexInfoPair in AutoRetainerSortSettings.Instance.InventoryOptions)
                {
                    if (indexInfoPair.Key == _index)
                    {
                        continue;
                    }
                    if (!indexInfoPair.Value.ContainsItem(sortInfo))
                    {
                        continue;
                    }
                    if (sortInfo.ItemInfo.Unique)
                    {
                        continue;
                    }

                    DialogResult dr = MessageBox.Show(
                        string.Format(Strings.AddNewItem_AlreadyExists_Warning, indexInfoPair.Value.Name, sortInfo.Name, indexInfoPair.Value.Name, _sortInfo.Name),
                        Strings.WarningCaption,
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Warning);

                    if (dr == DialogResult.Yes)
                    {
                        indexInfoPair.Value.SpecificItems.Remove(sortInfo);
                    }
                    else
                    {
                        shouldAdd = false;
                        break;
                    }
                }

                if (!shouldAdd)
                {
                    continue;
                }
                AutoRetainerSort.LogSuccess($"Added {sortInfo.Name} to {_sortInfo.Name}!");
                _bsItems.Add(sortInfo);
            }

            AutoRetainerSortSettings.Instance.Save();
        }
Пример #6
0
        private void AutoSetup_Click(object sender, EventArgs e)
        {
            if (!AutoRetainerSortSettings.Instance.InventoryOptions.ContainsKey(ItemSortStatus.PlayerInventoryIndex))
            {
                DialogResult dr = MessageBox.Show(
                    "It looks like you don't have the player inventory added to the indexes... somehow. Do you want me to re-add that for you?",
                    "Um.",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning
                    );

                if (dr == DialogResult.Yes)
                {
                    AutoRetainerSortSettings.Instance.InventoryOptions.Add(ItemSortStatus.PlayerInventoryIndex, new InventorySortInfo("Player Inventory"));
                }
            }

            if (!AutoRetainerSortSettings.Instance.InventoryOptions.ContainsKey(ItemSortStatus.SaddlebagInventoryIndex))
            {
                DialogResult dr = MessageBox.Show(
                    "It looks like you don't have the chocobo saddlebag added to the indexes. Do you want me to re-add that for you?",
                    "Hey Listen!",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Information
                    );

                if (dr == DialogResult.Yes)
                {
                    AutoRetainerSortSettings.Instance.InventoryOptions.Add(ItemSortStatus.SaddlebagInventoryIndex, new InventorySortInfo("Chocobo Saddlebag"));
                }
            }

            MessageBox.Show(
                Strings.AutoSetup_CacheAdvice,
                "Careful!",
                MessageBoxButtons.OK,
                MessageBoxIcon.Information);

            DialogResult warningResult = MessageBox.Show(
                Strings.AutoSetup_OverwriteWarning,
                "Warning!",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning);

            if (warningResult == DialogResult.No)
            {
                return;
            }

            bool conflictUnsorted = MessageBox.Show(
                Strings.AutoSetup_ConflictQuestion,
                "Conflict?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question) == DialogResult.Yes;

            var newInventorySetup = AutoRetainerSortSettings.Instance.InventoryOptions;

            foreach (InventorySortInfo inventorySortInfo in newInventorySetup.Values)
            {
                inventorySortInfo.SortTypes.Clear();
            }

            var orderedRetainerList = RetainerList.Instance.OrderedRetainerList;

            for (var i = 0; i < orderedRetainerList.Length; i++)
            {
                if (newInventorySetup.ContainsKey(i))
                {
                    continue;
                }
                RetainerInfo retInfo = orderedRetainerList[i];
                if (!retInfo.Active)
                {
                    continue;
                }

                newInventorySetup.Add(i, new InventorySortInfo(retInfo.Name));
            }

            AutoRetainerSortSettings.Instance.InventoryOptions = newInventorySetup;

            ItemSortStatus.UpdateFromCache(orderedRetainerList);

            var sortTypeCounts = new Dictionary <SortType, Dictionary <int, int> >();

            foreach (SortType sortType in Enum.GetValues(typeof(SortType)).Cast <SortType>())
            {
                sortTypeCounts[sortType] = new Dictionary <int, int>();
            }

            foreach (CachedInventory cachedInventory in ItemSortStatus.GetAllInventories())
            {
                foreach (SortType sortType in cachedInventory.ItemCounts.Select(x => ItemSortStatus.GetSortInfo(x.Key).SortType))
                {
                    var indexCountDic = sortTypeCounts[sortType];
                    if (indexCountDic.ContainsKey(cachedInventory.Index))
                    {
                        indexCountDic[cachedInventory.Index]++;
                    }
                    else
                    {
                        indexCountDic.Add(cachedInventory.Index, 1);
                    }
                }
            }

            foreach (var typeDicPair in sortTypeCounts)
            {
                SortType sortType   = typeDicPair.Key;
                int      indexCount = typeDicPair.Value.Keys.Count;
                if (indexCount == 0)
                {
                    continue;
                }
                if (indexCount > 1 && conflictUnsorted)
                {
                    continue;
                }

                int desiredIndex = typeDicPair.Value.OrderByDescending(x => x.Value).First().Key;
                AutoRetainerSortSettings.Instance.InventoryOptions[desiredIndex].SortTypes.Add(new SortTypeWithCount(sortType));
            }

            ResetBindingSource();
            AutoRetainerSortSettings.Instance.Save();
            AutoRetainerSort.LogSuccess("Auto-Setup done!");
        }