def item_action(cmd, name_or_id): '''/use <item> /equip <item> /unequip <item> item can be either item name or ID''' item_id = -10 item_db = itemdb.item_names try: item_id = int(name_or_id) except ValueError: for id_, name in item_db.iteritems(): if name == name_or_id: item_id = id_ if item_id < 0: debuglog.warning("Unknown item: %s", name_or_id) return index = get_item_index(item_id) if index > 0: if cmd == 'use': mapserv.cmsg_player_inventory_use(index, item_id) elif cmd == 'equip': mapserv.cmsg_player_equip(index) elif cmd == 'unequip': mapserv.cmsg_player_unequip(index) else: debuglog.error("You don't have %s", name_or_id)
def drop_item(_, arg): '''/drop <amount> <name or id>''' s = arg.split(None, 1) try: amount = int(s[0]) except ValueError: debuglog.warning('Usage: /drop <amount> <name or id>') return item_id = -10 item_db = itemdb.item_names try: item_id = int(s[1]) except ValueError: for id_, name in item_db.iteritems(): if name == s[1]: item_id = id_ if item_id < 0: debuglog.warning("Unknown item: %s", s[1]) return index = get_item_index(item_id) if index > 0: mapserv.cmsg_player_inventory_drop(index, amount) else: debuglog.error("You don't have %s", s[1])
def cmd_sell(nick, message, is_whisper, match): if not is_whisper: return try: amount = int(match.group(1)) item_id = int(match.group(2)) npc_s = match.group(3).strip() except ValueError: return if item_id not in allowed_sells: return index = get_item_index(item_id) if index < 0: return jobs = [] name = '' try: jobs = [int(npc_s)] except ValueError: name = npc_s b = find_nearest_being(name=name, type='npc', allowed_jobs=jobs) if b is None: return mapserv.cmsg_npc_buy_sell_request(b.id, 1) mapserv.cmsg_npc_sell_request(index, amount)
def buylist(nick, message, is_whisper, match): if not is_whisper: return # Support for 4144's shop (Sell list) data = "\302\202S1" for id_, (price, amount) in buying.iteritems(): index = get_item_index(id_) if index > 0: _, curr_amount = mapserv.player_inventory[index] amount -= curr_amount try: can_afford = mapserv.player_money / price except ZeroDivisionError: can_afford = 10000000 amount = min(can_afford, amount) if amount <= 0: continue data += encode_str(id_, 2) data += encode_str(price, 4) data += encode_str(amount, 3) whisper(nick, data)
def buylist(nick, message, is_whisper, match): if not is_whisper: return # Support for 4144's shop (Sell list) data = '\302\202S1' for id_, (price, amount) in buying.iteritems(): index = get_item_index(id_) if index > 0: _, curr_amount = mapserv.player_inventory[index] amount -= curr_amount try: can_afford = mapserv.player_money / price except ZeroDivisionError: can_afford = 10000000 amount = min(can_afford, amount) if amount <= 0: continue data += encode_str(id_, 2) data += encode_str(price, 4) data += encode_str(amount, 3) whisper(nick, data)
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 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)
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 player_stat_update(data): if not auto_heal_self: return global hp_prev_value, mp_prev_value if data.type == stats.HP: max_hp = mapserv.player_stats.get(stats.MAX_HP, 0) if data.stat_value < max_hp * hp_heal_at and not hp_is_healing: healing_found = False for item_id in hp_healing_ids: index = get_item_index(item_id) if index > 0: healing_found = True debuglog.info("Consuming %d", item_id) mapserv.cmsg_player_inventory_use(index, item_id) break if not healing_found: debuglog.info("Low health, but no HP healing item found") hp_prev_value = data.stat_value elif data.type == stats.MP: max_mp = mapserv.player_stats.get(stats.MAX_MP, 0) if data.stat_value < max_mp * mp_heal_at and not mp_is_healing: healing_found = False for item_id in mp_healing_ids: index = get_item_index(item_id) if index > 0: healing_found = True debuglog.info("Consuming %d", item_id) mapserv.cmsg_player_inventory_use(index, item_id) break if not healing_found: debuglog.info("Low mana, but no MP healing item found") mp_prev_value = data.stat_value
def cmd_store(nick, message, is_whisper, match): if not is_whisper: return if not storage_is_open: return try: amount = int(match.group(1)) item_id = int(match.group(2)) except ValueError: return index = get_item_index(item_id) if index > 0: mapserv.cmsg_move_to_storage(index, amount)
def cmd_drop(nick, message, is_whisper, match): if not is_whisper: return try: amount = int(match.group(1)) item_id = int(match.group(2)) except ValueError: return if nick not in admins: if item_id not in allowed_drops: return index = get_item_index(item_id) if index > 0: mapserv.cmsg_player_inventory_drop(index, amount)
def cmd_item_action(nick, message, is_whisper, match): if not is_whisper: return try: itemId = int(match.group(1)) except ValueError: return index = get_item_index(itemId) if index <= 0: return if message.startswith('!equip'): mapserv.cmsg_player_equip(index) elif message.startswith('!unequip'): mapserv.cmsg_player_unequip(index) elif message.startswith('!use'): mapserv.cmsg_player_inventory_use(index, itemId)
def item_use(_, name_or_id): item_id = -10 item_db = itemdb.item_names try: item_id = int(name_or_id) except ValueError: for id_, name in item_db.iteritems(): if name == name_or_id: item_id = id_ if item_id < 0: debuglog.warning("Unknown item: %s", name_or_id) return index = get_item_index(item_id) if index > 0: mapserv.cmsg_player_inventory_use(index, item_id) else: debuglog.error("You don't have %s", name_or_id)
def selllist(nick, message, is_whisper, match): if not is_whisper: return # Support for 4144's shop (Sell list) data = "\302\202B1" for id_, (price, amount) in selling.iteritems(): index = get_item_index(id_) if index < 0: continue _, curr_amount = mapserv.player_inventory[index] amount = min(curr_amount, amount) data += encode_str(id_, 2) data += encode_str(price, 4) data += encode_str(amount, 3) whisper(nick, data)
def selllist(nick, message, is_whisper, match): if not is_whisper: return # Support for 4144's shop (Sell list) data = '\302\202B1' for id_, (price, amount) in selling.iteritems(): index = get_item_index(id_) if index < 0: continue _, curr_amount = mapserv.player_inventory[index] amount = min(curr_amount, amount) data += encode_str(id_, 2) data += encode_str(price, 4) data += encode_str(amount, 3) whisper(nick, data)