Пример #1
0
        public static IReadOnlyCollection <Item> GetDIYItems(IReadOnlyList <string> split, string lang)
        {
            if (split.Count > 1 && split[0].Length < 3)
            {
                var langIndex = GameLanguage.GetLanguageIndex(split[0]);
                lang  = GameLanguage.Language2Char(langIndex);
                split = split.Skip(1).ToArray();
            }

            var result = new Item[split.Count];

            for (int i = 0; i < result.Length; i++)
            {
                var text = split[i].Trim();
                var item = ItemUtil.GetItem(text, lang);
                if (!InvertedRecipeDictionary.TryGetValue(item.ItemId, out var diy))
                {
                    throw new Exception($"DIY recipe appears to be invalid ({text}).");
                }

                result[i] = new Item(Item.DIYRecipe)
                {
                    Count = diy
                };
            }
            return(result);
        }
Пример #2
0
        private async Task PrintItemsAsync(string itemName, IReadOnlyList <ComboItem> strings)
        {
            const int minLength = 2;

            if (itemName.Length <= minLength)
            {
                await ReplyAsync($"Please enter a search term longer than {minLength} characters.").ConfigureAwait(false);

                return;
            }

            var exact = ItemUtil.GetItem(itemName, strings);

            if (!exact.IsNone)
            {
                var msg = $"{exact.ItemId:X4} {itemName}";
                await ReplyAsync(Format.Code(msg)).ConfigureAwait(false);

                return;
            }

            var matches = ItemUtil.GetItemsMatching(itemName, strings).ToArray();
            var result  = string.Join(Environment.NewLine, matches.Select(z => $"{z.Value:X4} {z.Text}"));

            if (result.Length == 0)
            {
                await ReplyAsync("No matches found.").ConfigureAwait(false);

                return;
            }

            const int maxLength = 500;

            if (result.Length > maxLength)
            {
                var ordered = matches.OrderBy(z => LevenshteinDistance.Compute(z.Text, itemName));
                result = string.Join(Environment.NewLine, ordered.Select(z => $"{z.Value:X4} {z.Text}"));
                result = result.Substring(0, maxLength) + "...[truncated]";
            }

            await ReplyAsync(Format.Code(result)).ConfigureAwait(false);
        }
Пример #3
0
        private static Item CreateItem(string name, int i, IConfigItem config, bool placeFloor, string lang = "en")
        {
            var item = ItemUtil.GetItem(name, lang);

            if (item.IsNone)
            {
                throw new Exception($"Failed to convert item {i}:{name} for Language {lang}. Ensure all your items are valid.");
            }

            if (!placeFloor)
            {
                if (!IsSaneItemForDrop(item))
                {
                    throw new Exception($"Unsupported item: {i}:{name}");
                }
            }

            if (config.WrapAllItems && item.ShouldWrapItem() && !placeFloor)
            {
                item.SetWrapping(ItemWrapping.WrappingPaper, config.WrappingPaper, true);
            }

            return(item);
        }