Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public async Task CustomizeAsync([Summary("Item ID (in hex)")] string itemHex, [Summary("Customization value sum")] int sum)
        {
            ushort itemID = ItemUtil.GetID(itemHex);

            if (itemID == Item.NONE)
            {
                await ReplyAsync("Invalid item requested.").ConfigureAwait(false);

                return;
            }
            if (sum <= 0)
            {
                await ReplyAsync("No customization data specified.").ConfigureAwait(false);

                return;
            }

            var remake = ItemRemakeUtil.GetRemakeIndex(itemID);

            if (remake < 0)
            {
                await ReplyAsync("No customization data available for the requested item.").ConfigureAwait(false);

                return;
            }

            int body   = sum & 7;
            int fabric = sum >> 5;

            if (fabric > 7 || ((fabric << 5) | body) != sum)
            {
                await ReplyAsync("Invalid customization data specified.").ConfigureAwait(false);

                return;
            }

            var  info      = ItemRemakeInfoData.List[remake];
            bool hasBody   = body == 0 || (body <= 7 && body <= info.ReBodyPatternNum);
            bool hasFabric = fabric == 0 || (fabric <= 7 && info.GetFabricDescription(fabric) != "Invalid");

            if (!hasBody || !hasFabric)
            {
                await ReplyAsync("Requested customization for item appears to be invalid.").ConfigureAwait(false);
            }

            var item = new Item(itemID)
            {
                BodyType = body, PatternChoice = fabric
            };
            var msg = ItemUtil.GetItemText(item);

            await ReplyAsync(msg).ConfigureAwait(false);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public async Task StackAsync([Summary("Item ID (in hex)")] string itemHex, [Summary("Count of items in the stack")] int count)
        {
            ushort itemID = ItemUtil.GetID(itemHex);

            if (itemID == Item.NONE || count < 1 || count > 99)
            {
                await ReplyAsync("Invalid item requested.").ConfigureAwait(false);

                return;
            }

            var ct   = count - 1; // value 0 => count of 1
            var item = new Item(itemID)
            {
                Count = (ushort)ct
            };
            var msg = ItemUtil.GetItemText(item);

            await ReplyAsync(msg).ConfigureAwait(false);
        }
Ejemplo n.º 5
0
        private static Item CreateItem(string name, int i, IConfigItem config, string lang = "en")
        {
            var item = ItemUtil.GetItem(name, lang);

            if (item.IsNone)
            {
                throw new Exception($"Failed to convert item {i}:{name} for Language {lang}.");
            }

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

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

            return(item);
        }
Ejemplo n.º 6
0
        public async Task GetItemInfoAsync([Summary("Item ID (in hex)")] string itemHex)
        {
            ushort itemID = ItemUtil.GetID(itemHex);

            if (itemID == Item.NONE)
            {
                await ReplyAsync("Invalid item requested.").ConfigureAwait(false);

                return;
            }

            var name   = GameInfo.Strings.GetItemName(itemID);
            var result = ItemUtil.GetItemInfo(itemID);

            if (result.Length == 0)
            {
                await ReplyAsync($"No customization data available for the requested item ({name}).").ConfigureAwait(false);
            }
            else
            {
                await ReplyAsync($"{name}:\r\n{result}").ConfigureAwait(false);
            }
        }
Ejemplo n.º 7
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;
            }

            foreach (var item in strings)
            {
                if (!string.Equals(item.Text, itemName, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (!DropUtil.InvertedRecipeDictionary.TryGetValue((ushort)item.Value, out var recipeID))
                {
                    await ReplyAsync("Requested item is not a DIY recipe.").ConfigureAwait(false);

                    return;
                }

                var msg = $"{item.Value:X4} {item.Text}: Recipe {recipeID:X3}";
                await ReplyAsync(Format.Code(msg)).ConfigureAwait(false);

                return;
            }

            var items   = ItemUtil.GetItemsMatching(itemName, strings).ToArray();
            var matches = new List <string>();

            foreach (var item in items)
            {
                if (!DropUtil.InvertedRecipeDictionary.TryGetValue((ushort)item.Value, out var recipeID))
                {
                    continue;
                }

                var msg = $"{item.Value:X4} {item.Text}: Recipe {recipeID:X3}";
                matches.Add(msg);
            }

            var result = string.Join(Environment.NewLine, matches);

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

                return;
            }

            const int maxLength = 500;

            if (result.Length > maxLength)
            {
                result = result.Substring(0, maxLength) + "...[truncated]";
            }

            await ReplyAsync(Format.Code(result)).ConfigureAwait(false);
        }