def sellitem(nick, message, is_whisper, match): if not is_whisper: return item_id = amount = 0 # FIXME: check if amount=0 or id=0 try: item_id = int(match.group(1)) # price = int(match.group(2)) amount = int(match.group(3)) if item_id < 1 or amount < 1: raise ValueError except ValueError: whisper(nick, "usage: !sellitem ID PRICE AMOUNT") return if s.player: whisper(nick, "I am currently trading with someone") return player_id = mapserv.beings_cache.findId(nick) if player_id < 0: whisper(nick, "I don't see you nearby") return if item_id not in buying: whisper(nick, "I don't buy that") return real_price, max_amount = buying[item_id] index = get_item_index(item_id) if index > 0: _, curr_amount = mapserv.player_inventory[index] max_amount -= curr_amount if amount > max_amount: whisper(nick, "I don't need that many") return total_price = real_price * amount if total_price > mapserv.player_money: whisper(nick, "I can't afford it") return s.player = nick s.mode = 'buy' s.item_id = item_id s.amount = amount s.price = total_price s.index = index s.start_time = time.time() mapserv.cmsg_trade_request(player_id)
def retrieve(nick, message, is_whisper, match): if not is_whisper: return if shop_admins is None: return if not shop_admins.check_player(nick): return item_id = amount = 0 try: item_id = int(match.group(1)) amount = int(match.group(2)) if amount < 1: raise ValueError except ValueError: whisper(nick, "usage: !retrieve ID AMOUNT (ID=0 for money)") return if s.player: whisper(nick, "I am currently trading with someone") return player_id = mapserv.beings_cache.findId(nick) if player_id < 0: whisper(nick, "I don't see you nearby") return index = max_amount = 0 if item_id == 0: max_amount = mapserv.player_money else: index = get_item_index(item_id) if index > 0: max_amount = mapserv.player_inventory[index][1] if amount > max_amount: whisper(nick, "I don't have that many") return s.player = nick s.mode = 'retrieve' s.item_id = item_id s.amount = amount s.index = index s.start_time = time.time() mapserv.cmsg_trade_request(player_id)
def buyitem(nick, message, is_whisper, match): if not is_whisper: return item_id = amount = 0 # FIXME: check if amount=0 or id=0 try: item_id = int(match.group(1)) # price = int(match.group(2)) amount = int(match.group(3)) except ValueError: mapserv.cmsg_chat_whisper(nick, "usage: !buyitem ID PRICE AMOUNT") return if s.player: whisper(nick, "I am currently trading with someone") return player_id = mapserv.beings_cache.findId(nick) if player_id < 0: whisper(nick, "I don't see you nearby") return if item_id not in selling: whisper(nick, "I don't sell that") return real_price, max_amount = selling[item_id] index = get_item_index(item_id) if index > 0: _, curr_amount = mapserv.player_inventory[index] max_amount = min(max_amount, curr_amount) else: max_amount = 0 if amount > max_amount: whisper(nick, "I don't have that many") return total_price = real_price * amount s.player = nick s.mode = "sell" s.item_id = item_id s.amount = amount s.price = total_price s.index = index mapserv.cmsg_trade_request(player_id)