public async Task GetItemInfoAsync([Summary("Item ID (in hex)")] string itemHex)
        {
            if (!Globals.Bot.Config.AllowLookup)
            {
                return;
            }
            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);
            }
        }
        public async Task CustomizeAsync([Summary("Item ID (in hex)")] string itemHex, [Summary("Customization value sum")] int sum)
        {
            if (!Globals.Bot.Config.AllowLookup)
            {
                return;
            }
            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];
            // already checked out-of-range body/fabric values above
            bool hasBody   = body == 0 || body <= info.ReBodyPatternNum;
            bool hasFabric = fabric == 0 || 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);
        }
Exemple #3
0
        private static bool IsSaneItemForDrop(Item item)
        {
            if (!ItemUtil.IsDroppable(item))
            {
                return(false);
            }

            // Sanitize Values
            if (item.ItemId == Item.MessageBottle || item.ItemId == Item.MessageBottleEgg)
            {
                item.ItemId    = Item.DIYRecipe;
                item.FreeParam = 0;
            }

            return(true);
        }
        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);
        }
Exemple #5
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);
        }
        public async Task StackAsync([Summary("Item ID (in hex)")] string itemHex, [Summary("Count of items in the stack")] int count)
        {
            if (!Globals.Bot.Config.AllowLookup)
            {
                return;
            }
            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);
        }
Exemple #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 order code: 0{recipeID:X3}000016A2";
                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 order code: 0{recipeID:X3}000016A2";
                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);
        }