コード例 #1
0
ファイル: CraftingEmbed.cs プロジェクト: DavidXLiu/Kamtro-Bot
        public override async Task PerformAction(SocketReaction option)
        {
            switch (option.Emote.ToString())
            {
            case ReactionHandler.UP_STR:
                await CursorUp();

                break;

            case ReactionHandler.DOWN_STR:
                await CursorDown();

                break;

            case ReactionHandler.SELECT_STR:
                if (Page == HOME_PAGE)
                {
                    Page = CRAFT_PAGE;
                    await UpdateEmbed();
                }
                else
                {
                    // item page
                    if (ItemCount == 0)
                    {
                        ZeroItemCountWarn = true;      // if the number to craft is 0, notify the user that they can only craft one or more of an item.
                        await UpdateEmbed();
                    }
                    else
                    {
                        if (Inventory.CanCraft(GetItemAtCursor().Id, ItemCount) && !ConfirmOut)
                        {
                            // User can craft X items
                            ConfirmOut = true;
                            ConfirmEmbed ce = new ConfirmEmbed(Context, $"Are you sure you want to craft {ItemCount} item{(ItemCount == 1 ? "" : "s")}?", DoCraft);
                            await ce.Display();
                        }
                        else
                        {
                            // user can't craft
                            CantCraftWarn = true;
                            await UpdateEmbed();
                        }
                    }
                }
                break;

            case ReactionHandler.BACK_STR:
                if (Page != HOME_PAGE)
                {
                    Page = HOME_PAGE;
                    await UpdateEmbed();
                }
                break;
            }
        }
コード例 #2
0
        public override async Task PerformAction(SocketReaction option)
        {
            switch (option.Emote.ToString())
            {
            case ReactionHandler.SELECT_STR:
                if (Page == HOME_PAGE)
                {
                    List <uint> Items = Inventory.Items.Keys.ToList();
                    Items.Sort();

                    Page = ITEM_PAGE;

                    SelectedItem = Items[Cursor];
                    await UpdateEmbed();
                }
                else if (Page == ITEM_PAGE)
                {
                    if (ItCursor == 0)
                    {
                        if (GetItemAtCursor() is IUsable)
                        {
                            // if the item can be used, the cursor is on the use option
                            // so use the item
                            ConfirmEmbed ce = new ConfirmEmbed(Context, "Are you sure you want to use the item?", UseItem);
                            await ce.Display();
                        }
                        else
                        {
                            await SwitchToSellPage();
                        }
                    }
                    else
                    {
                        await SwitchToSellPage();
                    }
                }
                else
                {
                    // on sell page, so process sell.
                    if (SellCount <= Inventory.ItemCount(GetItemAtCursor()) && SellCount > 0)
                    {
                        // if the user has enough items to sell
                        ConfirmEmbed ce = new ConfirmEmbed(Context, $"Are you sure you want to sell {SellCount} {GetItemAtCursor().Name}{(SellCount == 1 ? "":"s")} for {SellCount * GetItemAtCursor().GetSellPrice()} Kamtrokens?", SellItem);
                        await ce.Display();
                    }
                    else
                    {
                        // if the user has somehow selected more items than they have, correct the number and do nothing.
                        SellCount        = 0;
                        InvalidSellCount = true;
                        await UpdateEmbed();
                    }
                }
                break;

            case ReactionHandler.BACK_STR:
                if (Page > HOME_PAGE)
                {
                    Page--;
                    ItCursor = 0;

                    if (Cursor >= Inventory.Items.Count)
                    {
                        Cursor = Inventory.Items.Count;
                    }

                    if (Page == -1)
                    {
                        List <uint> Items = Inventory.Items.Keys.ToList();
                        Items.Sort();
                        SelectedItem = Items[Cursor];
                    }

                    await UpdateEmbed();
                }
                else
                {
                    Page = HOME_PAGE;
                    await UpdateEmbed();
                }
                break;

            case ReactionHandler.UP_STR:
                await CursorUp();

                break;

            case ReactionHandler.DOWN_STR:
                await CursorDown();

                break;
            }
        }