示例#1
0
        public async Task CraftAsync([Name("recipe_id")] Recipe recipe)
        {
            /*
             * if (!ItemHelper.RecipeExists(recipeId))
             * {
             *  await Context.Channel.WarnAsync("Could not find the specified recipe.");
             *  return;
             * }*/

            if (!CraftHelper.CanCraft(Context.Account, recipe))
            {
                var notice = new StringBuilder();

                notice.AppendLine(Format.Warning("You are unable to craft this recipe."));
                notice.AppendLine("\n> **Missing Components**");

                foreach ((string itemId, int amount) in CraftHelper.GetMissingFromRecipe(Context.Account, recipe))
                {
                    notice.AppendLine(RecipeViewer.WriteRecipeComponent(itemId, amount));
                }

                await Context.Channel.SendMessageAsync(notice.ToString());

                return;
            }


            if (CraftHelper.Craft(Context.Account, recipe))
            {
                var result = new StringBuilder();

                result.AppendLine($"> 📑 **{ItemHelper.NameOf(recipe.Result.ItemId)}**{(recipe.Result.Amount > 1 ? $" (x**{recipe.Result.Amount:##,0}**)" : "")}");
                result.AppendLine("> Successfully crafted an item!");

                result.AppendLine("\n> **Losses**");

                foreach ((string itemId, int amount) in recipe.Components)
                {
                    string icon = ItemHelper.IconOf(itemId);

                    if (!Check.NotNull(icon))
                    {
                        icon = "•";
                    }

                    result.AppendLine($"{icon} **{ItemHelper.NameOf(itemId)}**{(amount > 1 ? $" (x**{amount:##,0}**)" : "")}");
                }

                await Context.Channel.SendMessageAsync(result.ToString());

                return;
            }

            await Context.Channel.SendMessageAsync(Format.Warning("An unknown error has occured when crafting this recipe."));
        }
示例#2
0
        private static string WriteRecipeText(ArcadeUser user, Recipe recipe)
        {
            var text = new StringBuilder();

            string recipeName = ItemHelper.GetItem(recipe.Result.ItemId)?.Name;

            if (!Check.NotNull(recipeName))
            {
                recipeName = "Unknown Item";
            }

            text.AppendLine($"\n> `{CraftHelper.GetBaseRecipeId(recipe)}`")
            .Append($"> {(CraftHelper.CanCraft(user, recipe) ? "📑" : "📄")} **Recipe: {recipeName}**");

            return(text.ToString());
        }
示例#3
0
        // Group all recipes with the same result ID
        // Paginate all variations
        public static string ViewRecipeInfo(ArcadeUser user, Recipe recipe)
        {
            var info = new StringBuilder();

            string resultName = ItemHelper.GetItem(recipe.Result.ItemId)?.Name ?? "Unknown Item";
            bool   craft      = CraftHelper.CanCraft(user, recipe);

            if (craft)
            {
                CraftHelper.SetRecipeStatus(user, recipe, RecipeStatus.Known);
            }
            else if (CraftHelper.GetRecipeStatus(user, recipe) == RecipeStatus.Unknown)
            {
                return(Format.Warning("Unknown recipe specified."));
            }


            info.AppendLine($"> {(craft ? "📑" : "📄")} **Recipe: {resultName}**");

            if (craft)
            {
                info.AppendLine("> You can craft this recipe.");
            }

            info.AppendLine($"\n> **Components**");

            foreach ((string itemId, int amount) in recipe.Components)
            {
                info.AppendLine(WriteRecipeComponent(itemId, amount));
            }

            info.AppendLine($"\n> **Result**");
            info.AppendLine(WriteRecipeComponent(recipe.Result.ItemId, recipe.Result.Amount));

            return(info.ToString());
        }