Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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])
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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])
Ejemplo n.º 5
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))
Ejemplo n.º 6
0
def attack(_, arg):
    '''Attack being (ID or Name)'''
    try:
        target = mapserv.beings_cache[int(arg)]
    except (ValueError, KeyError):
        target = find_nearest_being(name=arg,
                                    ignored_ids=walkto.unreachable_ids)

    if target is not None:
        walkto.walkto_and_action(target, 'attack')
    else:
        debuglog.warning("Being %s not found", arg)
Ejemplo n.º 7
0
def attack(_, arg):
    '''Attack being (ID or Name)'''
    try:
        target = mapserv.beings_cache[int(arg)]
    except (ValueError, KeyError):
        target = find_nearest_being(name=arg,
                                    ignored_ids=walkto.unreachable_ids)

    if target is not None:
        walkto.walkto_and_action(target, 'attack')
    else:
        debuglog.warning("Being %s not found", arg)
Ejemplo n.º 8
0
def cmd_autospell(_, arg):
    '''Cast a spell multiple times automatically
/autospell TIMES DELAY SPELL'''
    global times, delay, spell, next_ts
    m = as_re.match(arg)
    if m:
        times = int(m.group(1))
        delay = int(m.group(2))
        spell = m.group(3)
    else:
        debuglog.warning("Usage: /autospell TIMES DELAY SPELL")
        return

    next_ts = time.time() + delay
Ejemplo n.º 9
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))
Ejemplo n.º 10
0
def cmd_npctalk(_, arg):
    global npc_id
    jobs = []
    name = ''
    try:
        jobs = [int(arg)]
    except ValueError:
        name = arg

    b = find_nearest_being(name=name, type='npc', allowed_jobs=jobs)

    if b is not None:
        npc_id = b.id
        mapserv.cmsg_npc_talk(npc_id)
    else:
        debuglog.warning("NPC %s not found", arg)
Ejemplo n.º 11
0
def cmd_npctalk(_, arg):
    global npc_id
    jobs = []
    name = ''
    try:
        jobs = [int(arg)]
    except ValueError:
        name = arg

    b = find_nearest_being(name=name, type='npc', allowed_jobs=jobs)

    if b is not None:
        npc_id = b.id
        mapserv.cmsg_npc_talk(npc_id)
    else:
        debuglog.warning("NPC %s not found", arg)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
def attack(_, name_or_id):
    target_id = -10
    mob_db = monsterdb.monster_db

    try:
        target_id = int(name_or_id)
        if target_id not in mapserv.beings_cache:
            raise ValueError
    except ValueError:
        for b in mapserv.beings_cache:
            if b.name == name_or_id:
                target_id = b.id
                break
            if b.job in mob_db:
                if mob_db[b.job] == name_or_id:
                    target_id = b.id
                    break

    if target_id > 0:
        mapserv.cmsg_player_change_act(target_id, 7)
    else:
        debuglog.warning("Being %s not found", name_or_id)
Ejemplo n.º 14
0
def command_not_found(cmd):
    debuglog.warning("[warning] command not found: %s. Try /help.", cmd)
Ejemplo n.º 15
0
def command_not_found(cmd):
    debuglog.warning("[warning] command not found: %s. Try /help.", cmd)