def test_changeSupplyAmount_failed(self): 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) # item cannot find result1 = InventoryUtil.changeSupplyAmount(guild_id=1, item_name="he", newAmount=-1) assert result1 == -1 # shopitem cannot find result2 = InventoryUtil.changeSupplyAmount(guild_id=1, item_name="hey", newAmount=-1) assert result2 == -2
async def change_shopitem_amount(self, ctx: commands.Command, amount: int, item_name: str): if amount < -1: await ctx.send("商品供應數量不能為負數!") else: result = InventoryUtil.changeSupplyAmount(ctx.guild.id, item_name, amount) if result == -1: await ctx.send("查無此項目,請確認商品名稱是否輸入錯誤!") elif result == -2: await ctx.send("該商品存在但尚未上架!") else: if amount == 0: await ctx.send("數量為0,建議下架商品實在點") else: await ctx.send(f"修改成功! 目前{item_name}供給數量已改成{result.amount}" )
def test_changeSupplyAmount_success_limitedToUnlimited(self): 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) assert shopItem1.amount == 10 shopItem2 = InventoryUtil.changeSupplyAmount(guild_id=1, item_name="hello", newAmount=-1) assert shopItem2.amount == -1