def send_whisper_result(data): nick, msg = sent_whispers.popleft() if data.code == 0: m = "[-> {}] {}".format(nick, pp(msg)) debuglog.info(m) else: debuglog.warning("[error] {} is offline.".format(nick))
def npc_close(data): if autonext: global npc_id npc_id = -1 mapserv.cmsg_npc_close(data.id) else: debuglog.info('[npc][close]')
def debugbot(cmd, _): px = mapserv.player_pos['x'] py = mapserv.player_pos['y'] target_info = '<no_target>' if target is not None: target_info = '{} at ({},{})'.format(target.name, target.x, target.y) debuglog.info('target = %s | player at (%d, %d)', target_info, px, py)
def follow_cmd(_, player): '''Follow given player, or disable following (if no arg)''' global follow follow = player if player: debuglog.info('Following %s', player) else: debuglog.info('Not following anyone')
def print_beings(cmd, btype): '''Show nearby beings /beings -- show all beings /beings player|npc|portal --show only given being type''' for being in mapserv.beings_cache.itervalues(): if btype and being.type != btype: continue debuglog.info("id: %d | type: %s | pos: (%d, %d) | name: %s", being.id, being.type, being.x, being.y, being.name)
def npc_choice(data): global npc_id global input_type npc_id = data.id input_type = 'select' choices = filter(lambda s: len(s.strip()) > 0, data.select.split(':')) debuglog.info('[npc][select]') for i, s in enumerate(choices): debuglog.info(' %d) %s', i + 1, s)
def show_status(_, arg): '''Show various stats''' if arg: all_stats = arg.split() else: all_stats = ('stats', 'hpmp', 'weight', 'points', 'zeny', 'attack', 'skills') sr = status.stats_repr(*all_stats) debuglog.info(' | '.join(sr.values()))
def send_whisper_result(data): if data.code == 0: message = textutils.preprocess(commands.whisper_msg) m = "[-> {}] {}".format(commands.whisper_to, message) debuglog.info(m) cui.input_win.clear() cui.input_win.addstr('/w "{}" '.format(commands.whisper_to)) cui.input_win.refresh() else: debuglog.info("[error] {} is offline.".format(commands.whisper_to))
def load_itemdb(dbfile='itemdb.txt'): with open(dbfile, 'rt') as f: for l in f.readlines(): try: sn, sr = l.split(' ', 1) item_id = int(sn) item_name = sr[:-1] if sr.endswith('\n') else sr item_names[item_id] = item_name except ValueError: pass debuglog.info("Loaded itemdb from %s", dbfile) return item_names
def show_inventory(*unused): '''Show inventory''' inv = {} for itemId, amount in mapserv.player_inventory.values(): inv[itemId] = inv.setdefault(itemId, 0) + amount s = [] for itemId, amount in inv.items(): if amount > 1: s.append('{} [{}]'.format(amount, itemdb.item_name(itemId))) else: s.append('[{}]'.format(itemdb.item_name(itemId))) debuglog.info(', '.join(s))
def send_whisper_result(data): now = time.time() while True: try: nick, msg, ts = sent_whispers.popleft() except IndexError: return if now - ts < 1.0: break if data.code == 0: m = "[-> {}] {}".format(nick, pp(msg, pp_actions)) debuglog.info(m) else: debuglog.warning("[error] {} is offline.".format(nick))
def got_whisper(data): nick, message = data.nick, data.message message = pp(message, pp_actions) m = "[{} ->] {}".format(nick, message) debuglog.info(m) if badge.is_afk: if nick in chat_bots: return if message.startswith('!'): return now = time.time() global afk_ts if now > afk_ts + 20: afk_ts = now send_whisper(nick, afk_message) badge.is_afk = True
def print_help(_, hcmd): '''Show help /help -- show all commands /help CMD -- show help on CMD''' s = ' '.join(commands.keys()) if hcmd in commands: docstring = commands[hcmd].__doc__ if docstring: debuglog.info(docstring) else: debuglog.info('No help available for command /{}'.format(hcmd)) else: debuglog.info("[help] commands: %s", s)
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 npc_next(data): if autonext: mapserv.cmsg_npc_next_request(data.id) else: debuglog.info('[npc][next]')
def npc_int_input(data): global input_type input_type = 'int' debuglog.info('[npc][input] Enter number:')
def print_beings(cmd, btype): '''Show nearby beings /beings -- show all beings /beings player|npc|portal|monster --show only given being type''' for l in status.nearby(btype): debuglog.info(l)
def being_chat(data): message = pp(data.message, pp_actions) debuglog.info(message)
def player_chat(data): message = pp(data.message, pp_actions) debuglog.info(message)
def map_login_success(data): m = "[map] {} ({},{})".format(map_name, data.coor.x, data.coor.y) debuglog.info(m) mapserv.server.raw = True mapserv.cmsg_map_loaded()
def player_warp(data): mapserv.cmsg_map_loaded() m = "[warp] {} ({},{})".format(data.map, data.x, data.y) debuglog.info(m)
def player_chat(data): message = pp(data.message) debuglog.info(message)
def got_whisper(data): nick, message = data.nick, data.message message = pp(message) m = "[{} ->] {}".format(nick, message) debuglog.info(m)
def got_whisper(data): nick, message = data.nick, data.message message = textutils.preprocess(message) m = "[{} ->] {}".format(nick, message) debuglog.info(m)
def player_chat(data): message = textutils.preprocess(data.message) debuglog.info(message)
def being_chat(data): id_, message = data.id, data.message nick = mapserv.beings_cache[id_].name message = textutils.preprocess(message) m = "{} : {}".format(nick, message) debuglog.info(m)
def party_chat(data): nick = mapserv.party_members.get(data.id, str(data.id)) message = pp(data.message) m = "[Party] {} : {}".format(nick, message) debuglog.info(m)
def print_beings(cmd, _): for being in mapserv.beings_cache.itervalues(): debuglog.info("id: %d name: %s type: %s", being.id, being.name, being.type)
def being_chat(data): message = pp(data.message) debuglog.info(message)
def show_zeny(*unused): '''Show player money''' debuglog.info('You have {} GP'.format(mapserv.player_money))
def player_position(*unused): '''Show player position''' debuglog.info(status.player_position())
def npc_message(data): npc = mapserv.beings_cache.findName(data.id) m = '[npc] {} : {}'.format(npc, data.message) debuglog.info(m)
def print_help(cmd, _): s = ' '.join(commands.keys()) debuglog.info("[help] commands: %s", s)
def npc_str_input(data): global input_type input_type = 'str' debuglog.info('[npc][input] Enter string:')
def cmd_afk(_, arg): '''Become AFK''' if arg: chat.afk_message = '*AFK* ' + arg badge.is_afk = True debuglog.info(chat.afk_message)
def gm_chat(data): m = "[GM] {}".format(data.message) debuglog.info(m)
def party_chat(data): nick = mapserv.party_members.get(data.id, str(data.id)) message = textutils.preprocess(data.message) m = "[Party] {} : {}".format(nick, message) debuglog.info(m)