def sell_item(item_name: str, player_id: int, amount: int): """sells amount of the specified item with the resell price""" player = PlayerLogic.get_player_by_id(player_id) item = ItemLogic.get_item_by_name(item_name) if amount <= 0: raise InputError("The amount has to be bigger than 0!") p_item = ItemLogic.get_player_item(player.player_id, item.item_name) if p_item.amount < amount: raise NotEnoughItemsException(item.item_name, amount) else: PlayerLogic.add_money(player.player_id, item.resell_price * amount) p_item.amount = p_item.amount - amount try: p_item.save() except Exception as e: raise DatabaseException(e.message)
def player_lose_penalty(player: Player): level = PlayerLogic.get_highest_teammember(player) return PlayerLogic.add_money(player, (120*level)*-1)
def gain_money(player) -> int: return PlayerLogic.add_money(player, random.randint(100, 500))