def test_buyShopitem_failed_noProduct(self):
     MemberUtil.add_member(member_id=123)
     MemberUtil.add_token(member_id=123, amount=100)
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     ItemUtil.createItem(guild_id=1,
                         item_name="hey",
                         item_type=ItemType.STATUS,
                         buff_type=BuffType.DEFENCE,
                         buff_value=10,
                         buff_round=3,
                         level_required=0,
                         price=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     InventoryUtil.addItemToShop(guild_id=1,
                                 item_name="hey",
                                 amount=10,
                                 hidden=True)
     result = InventoryUtil.buyShopitem(guild_id=1,
                                        user_id=123,
                                        item_name="he",
                                        count=2)
     assert result == ErrorCode.CannotFindProduct
     result == InventoryUtil.buyShopitem(guild_id=1,
                                         user_id=123,
                                         item_name="hey",
                                         count=2)
     assert result == ErrorCode.CannotFindProduct
 def test_buyShopitem_success_shopItemchangeHidden(self):
     MemberUtil.add_member(member_id=123)
     MemberUtil.add_token(member_id=123, amount=500)
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=1)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     InventoryUtil.buyShopitem(guild_id=1,
                               user_id=123,
                               item_name="hello",
                               count=10)
     InventoryUtil.checkZeroAmount(guild_id=1)
     result = InventoryUtil.ShopMenu(guild_id=1)
     assert len(result) == 0 and result == []
 def test_buyShopitem_success(self):
     MemberUtil.add_member(member_id=123)
     MemberUtil.add_token(member_id=123, amount=100)
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     shopItem1 = InventoryUtil.addItemToShop(guild_id=1,
                                             item_name="hello",
                                             amount=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hey", amount=10)
     InventoryUtil.buyShopitem(guild_id=1,
                               user_id=123,
                               item_name="hello",
                               count=2)
     itemList = InventoryUtil.getAllItemsBelongToUser(guild_id=1,
                                                      user_id=123)
     assert itemList[0].user_id == 123 and itemList[0].item == shopItem1.item
Beispiel #4
0
 async def buy_item(self, ctx: commands.Command, count: int,
                    item_name: str):
     result = InventoryUtil.buyShopitem(ctx.guild.id, ctx.author.id,
                                        item_name, count)
     if result == ErrorCode.CannotFindProduct:
         await ctx.send("沒有該項商品,請確認!")
     elif result == ErrorCode.LevelDoesNotReach:
         await ctx.send("等級不夠,無法購買!")
     elif result == ErrorCode.TokenDoesNotEnough:
         await ctx.send("雞腿不夠,無法購買!")
     elif result == ErrorCode.SupplyDoesNotEnough:
         await ctx.send("商品數量不足,無法購買!")
     else:
         await ctx.send(f"{count}個{result.item.name} 購買成功!")
     InventoryUtil.checkZeroAmount(ctx.guild.id)
 def test_buyShopitem_failed_notEnoughSupply(self):
     MemberUtil.add_member(member_id=123)
     MemberUtil.add_token(member_id=123, amount=100)
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=1)
     result = InventoryUtil.buyShopitem(guild_id=1,
                                        user_id=123,
                                        item_name="hello",
                                        count=2)
     assert result == ErrorCode.SupplyDoesNotEnough