Example #1
0
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))
Example #2
0
def npc_close(data):
    if autonext:
        global npc_id
        npc_id = -1
        mapserv.cmsg_npc_close(data.id)
    else:
        debuglog.info('[npc][close]')
Example #3
0
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)
Example #4
0
def npc_close(data):
    if autonext:
        global npc_id
        npc_id = -1
        mapserv.cmsg_npc_close(data.id)
    else:
        debuglog.info('[npc][close]')
Example #5
0
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)
Example #6
0
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')
Example #7
0
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')
Example #8
0
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)
Example #9
0
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)
Example #10
0
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)
Example #11
0
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()))
Example #12
0
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))
Example #13
0
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()))
Example #14
0
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)
Example #15
0
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
Example #16
0
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))
Example #17
0
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))
Example #18
0
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))
Example #19
0
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
Example #20
0
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)
Example #21
0
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)
Example #22
0
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
Example #23
0
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
Example #24
0
def npc_next(data):
    if autonext:
        mapserv.cmsg_npc_next_request(data.id)
    else:
        debuglog.info('[npc][next]')
Example #25
0
def npc_int_input(data):
    global input_type
    input_type = 'int'
    debuglog.info('[npc][input] Enter number:')
Example #26
0
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)
Example #27
0
def being_chat(data):
    message = pp(data.message, pp_actions)
    debuglog.info(message)
Example #28
0
def player_chat(data):
    message = pp(data.message, pp_actions)
    debuglog.info(message)
Example #29
0
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()
Example #30
0
def player_warp(data):
    mapserv.cmsg_map_loaded()
    m = "[warp] {} ({},{})".format(data.map, data.x, data.y)
    debuglog.info(m)
Example #31
0
def player_chat(data):
    message = pp(data.message)
    debuglog.info(message)
Example #32
0
def got_whisper(data):
    nick, message = data.nick, data.message
    message = pp(message)
    m = "[{} ->] {}".format(nick, message)
    debuglog.info(m)
Example #33
0
def got_whisper(data):
    nick, message = data.nick, data.message
    message = textutils.preprocess(message)
    m = "[{} ->] {}".format(nick, message)
    debuglog.info(m)
Example #34
0
def player_chat(data):
    message = textutils.preprocess(data.message)
    debuglog.info(message)
Example #35
0
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)
Example #36
0
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)
Example #37
0
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)
Example #38
0
def being_chat(data):
    message = pp(data.message)
    debuglog.info(message)
Example #39
0
def show_zeny(*unused):
    '''Show player money'''
    debuglog.info('You have {} GP'.format(mapserv.player_money))
Example #40
0
def player_warp(data):
    mapserv.cmsg_map_loaded()
    m = "[warp] {} ({},{})".format(data.map, data.x, data.y)
    debuglog.info(m)
Example #41
0
def player_position(*unused):
    '''Show player position'''
    debuglog.info(status.player_position())
Example #42
0
def npc_message(data):
    npc = mapserv.beings_cache.findName(data.id)
    m = '[npc] {} : {}'.format(npc, data.message)
    debuglog.info(m)
Example #43
0
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()
Example #44
0
def print_help(cmd, _):
    s = ' '.join(commands.keys())
    debuglog.info("[help] commands: %s", s)
Example #45
0
def npc_str_input(data):
    global input_type
    input_type = 'str'
    debuglog.info('[npc][input] Enter string:')
Example #46
0
def npc_next(data):
    if autonext:
        mapserv.cmsg_npc_next_request(data.id)
    else:
        debuglog.info('[npc][next]')
Example #47
0
def cmd_afk(_, arg):
    '''Become AFK'''
    if arg:
        chat.afk_message = '*AFK* ' + arg
    badge.is_afk = True
    debuglog.info(chat.afk_message)
Example #48
0
def npc_int_input(data):
    global input_type
    input_type = 'int'
    debuglog.info('[npc][input] Enter number:')
Example #49
0
def show_zeny(*unused):
    '''Show player money'''
    debuglog.info('You have {} GP'.format(mapserv.player_money))
Example #50
0
def npc_str_input(data):
    global input_type
    input_type = 'str'
    debuglog.info('[npc][input] Enter string:')
Example #51
0
def player_position(*unused):
    '''Show player position'''
    debuglog.info(status.player_position())
Example #52
0
def gm_chat(data):
    m = "[GM] {}".format(data.message)
    debuglog.info(m)
Example #53
0
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)
Example #54
0
def npc_message(data):
    npc = mapserv.beings_cache.findName(data.id)
    m = '[npc] {} : {}'.format(npc, data.message)
    debuglog.info(m)