Example #1
0
def trade_item_add_response(data):
    code = data.code
    amount = data.amount

    if code == 0:
        if amount > 0:
            item_id, _ = mapserv.trade_state['items_give'][-1]
            shoplog.info("I add to trade %d %s", amount, item_name(item_id))

    elif code == 1:
        shoplog.info("%s is overweight", s.player)
        whisper(s.player, "You are overweight")
        mapserv.cmsg_trade_cancel_request()
        cleanup()

    elif code == 2:
        shoplog.info("%s has no free slots", s.player)
        whisper(s.player, "You don't have free slots")
        mapserv.cmsg_trade_cancel_request()
        cleanup()

    else:
        shoplog.error("Unknown ITEM_ADD_RESPONSE code: ", code)
        mapserv.cmsg_trade_cancel_request()
        cleanup()
Example #2
0
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)
Example #3
0
def cmd_say(nick, message, is_whisper, match):
    if not is_whisper:
        return

    set_npc_owner(nick)
    msg = match.group(1)
    whisper(nick, msg)
Example #4
0
def cmd_invlist(nick, message, is_whisper, match):
    if not is_whisper:
        return

    ls = status.invlists(50)
    for l in ls:
        whisper(nick, l)
Example #5
0
def trade_item_add(data):
    item_id, amount = data.id, data.amount

    shoplog.info("%s adds %d %s", s.player, amount, item_name(item_id))

    if item_id == 0:
        return

    if s.mode == 'sell':
        whisper(s.player, "I accept only GP")
        mapserv.cmsg_trade_cancel_request()
        cleanup()

    elif s.mode == 'buy':
        if s.item_id != item_id or s.amount != amount:
            whisper(
                s.player,
                "You should give me {} {}".format(s.amount,
                                                  item_name(s.item_id)))
            mapserv.cmsg_trade_cancel_request()
            cleanup()

    elif s.mode == 'retrieve':
        pass

    else:
        shoplog.error("Unknown shop state: %s", s.mode)
        mapserv.cmsg_trade_cancel_request()
        cleanup()
Example #6
0
def trade_item_add_response(data):
    code = data.code
    amount = data.amount

    if code == 0:
        if amount > 0:
            item_id, _ = mapserv.trade_state['items_give'][-1]
            shoplog.info("I add to trade %d %s", amount, item_name(item_id))

    elif code == 1:
        shoplog.info("%s is overweight", s.player)
        whisper(s.player, "You are overweight")
        mapserv.cmsg_trade_cancel_request()
        cleanup()

    elif code == 2:
        shoplog.info("%s has no free slots", s.player)
        whisper(s.player, "You don't have free slots")
        mapserv.cmsg_trade_cancel_request()
        cleanup()

    else:
        shoplog.error("Unknown ITEM_ADD_RESPONSE code: ", code)
        mapserv.cmsg_trade_cancel_request()
        cleanup()
Example #7
0
def storage_status(data):
    global storage_is_open
    storage_is_open = True
    _times['storage'] = time.time()
    if npc_owner:
        whisper(npc_owner, '[storage][{}/{}]'.format(
            data.used, data.max_size))
Example #8
0
def cmd_inventory(nick, message, is_whisper, match):
    if not is_whisper:
        return

    ls = status.invlists2(255)
    for l in ls:
        whisper(nick, l)
Example #9
0
def trade_item_add(data):
    item_id, amount = data.id, data.amount

    shoplog.info("%s adds %d %s", s.player, amount, item_name(item_id))

    if item_id == 0:
        return

    if s.mode == 'sell':
        whisper(s.player, "I accept only GP")
        mapserv.cmsg_trade_cancel_request()
        cleanup()

    elif s.mode == 'buy':
        if s.item_id != item_id or s.amount != amount:
            whisper(s.player, "You should give me {} {}".format(
                s.amount, item_name(s.item_id)))
            mapserv.cmsg_trade_cancel_request()
            cleanup()

    elif s.mode == 'retrieve':
        pass

    else:
        shoplog.error("Unknown shop state: %s", s.mode)
        mapserv.cmsg_trade_cancel_request()
        cleanup()
Example #10
0
def storage_status(data):
    print 'storage_status'
    global storage_is_open
    storage_is_open = True
    _times['storage'] = time.time()
    if npc_owner:
        whisper(npc_owner, '[storage]')
Example #11
0
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)
Example #12
0
def npc_message(data):
    if not npc_owner:
        return

    npc = mapserv.beings_cache.findName(data.id)
    m = '[npc] {} : {}'.format(npc, data.message)
    whisper(npc_owner, m)
Example #13
0
def storage_status(data):
    print 'storage_status'
    global storage_is_open
    storage_is_open = True
    _times['storage'] = time.time()
    if npc_owner:
        whisper(npc_owner, '[storage]')
Example #14
0
def cmd_invlist(nick, message, is_whisper, match):
    if not is_whisper:
        return

    ls = status.invlists(50)
    for l in ls:
        whisper(nick, l)
Example #15
0
def cmd_inventory(nick, message, is_whisper, match):
    if not is_whisper:
        return

    ls = status.invlists2(255)
    for l in ls:
        whisper(nick, l)
Example #16
0
def cmd_report_bug(nick, message, is_whisper, match):
    if not is_whisper:
        return

    bug_s = match.group(1)
    bugs.append((nick, bug_s))
    whisper(nick, 'Thank you for your bug report')
Example #17
0
def trade_response(data):
    code = data.code

    if code == 0:
        shoplog.info("%s is too far", s.player)
        whisper(s.player, "You are too far, please come closer")
        mapserv.cmsg_trade_cancel_request()  # NOTE: do I need it?
        cleanup()

    elif code == 3:
        shoplog.info("%s accepts trade", s.player)
        if s.mode == 'sell':
            mapserv.cmsg_trade_item_add_request(s.index, s.amount)
            mapserv.cmsg_trade_add_complete()
        elif s.mode == 'buy':
            mapserv.cmsg_trade_item_add_request(0, s.price)
            mapserv.cmsg_trade_add_complete()
        elif s.mode == 'retrieve':
            mapserv.cmsg_trade_item_add_request(s.index, s.amount)
            mapserv.cmsg_trade_add_complete()
        else:
            shoplog.error("Unknown shop state: %s", s.mode)
            mapserv.cmsg_trade_cancel_request()
            cleanup()

    elif code == 4:
        shoplog.info("%s cancels trade", s.player)
        cleanup()

    else:
        shoplog.info("Unknown TRADE_RESPONSE code %d", code)
        cleanup()
Example #18
0
def npc_message(data):
    if not npc_owner:
        return

    npc = mapserv.beings_cache.findName(data.id)
    m = '[npc] {} : {}'.format(npc, data.message)
    whisper(npc_owner, m)
Example #19
0
def trade_response(data):
    code = data.code

    if code == 0:
        shoplog.info("%s is too far", s.player)
        whisper(s.player, "You are too far, please come closer")
        mapserv.cmsg_trade_cancel_request()  # NOTE: do I need it?
        cleanup()

    elif code == 3:
        shoplog.info("%s accepts trade", s.player)
        if s.mode == 'sell':
            mapserv.cmsg_trade_item_add_request(s.index, s.amount)
            mapserv.cmsg_trade_add_complete()
        elif s.mode == 'buy':
            mapserv.cmsg_trade_item_add_request(0, s.price)
            mapserv.cmsg_trade_add_complete()
        elif s.mode == 'retrieve':
            mapserv.cmsg_trade_item_add_request(s.index, s.amount)
            mapserv.cmsg_trade_add_complete()
        else:
            shoplog.error("Unknown shop state: %s", s.mode)
            mapserv.cmsg_trade_cancel_request()
            cleanup()

    elif code == 4:
        shoplog.info("%s cancels trade", s.player)
        cleanup()

    else:
        shoplog.info("Unknown TRADE_RESPONSE code %d", code)
        cleanup()
Example #20
0
def cmd_help(nick, message, is_whisper, match):
    if not is_whisper:
        return

    m = ('[@@https://forums.themanaworld.org/viewtopic.php?f=12&t=19673|Forum@@]'
         '[@@https://bitbucket.org/rumly111/manachat|Sources@@] '
         'Try !commands for list of commands')
    whisper(nick, m)
Example #21
0
def storage_items(data):
    if not npc_owner:
        return

    ls = status.invlists2(max_length=255, source='storage')

    for l in ls:
        whisper(npc_owner, l)
Example #22
0
def storage_items(data):
    if not npc_owner:
        return

    ls = status.invlists2(max_length=255, source='storage')

    for l in ls:
        whisper(npc_owner, l)
Example #23
0
def cmd_help(nick, message, is_whisper, match):
    if not is_whisper:
        return

    m = ('[@@https://forums.themanaworld.org/viewtopic.php?f=12&t=19673|Forum@@]'
         '[@@https://bitbucket.org/rumly111/manachat|Sources@@] '
         'Try !commands for list of commands')
    whisper(nick, m)
Example #24
0
def cmd_status(nick, message, is_whisper, match):
    if not is_whisper:
        return

    all_stats = ('stats', 'hpmp', 'weight', 'points',
                 'zeny', 'attack', 'skills')

    sr = status.stats_repr(*all_stats)
    whisper(nick, ' | '.join(sr.values()))
Example #25
0
def npc_choice(data):
    if not npc_owner:
        return

    choices = filter(lambda s: len(s.strip()) > 0, data.select.split(':'))

    whisper(npc_owner, '[npc][select] (use !input <number> to select)')
    for i, s in enumerate(choices):
        whisper(npc_owner, '    {}) {}'.format(i + 1, s))
Example #26
0
def cmd_status(nick, message, is_whisper, match):
    if not is_whisper:
        return

    all_stats = ('stats', 'hpmp', 'weight', 'points',
                 'zeny', 'attack', 'skills')

    sr = status.stats_repr(*all_stats)
    whisper(nick, ' | '.join(sr.values()))
Example #27
0
def npc_input(data):
    if not npc_owner:
        return

    t = 'number'
    if plugins.npc.input_type == 'str':
        t = 'string'

    whisper(npc_owner, '[npc][input] (use !input <{}>)'.format(t))
Example #28
0
def npc_input(data):
    if not npc_owner:
        return

    t = 'number'
    if plugins.npc.input_type == 'str':
        t = 'string'

    whisper(npc_owner, '[npc][input] (use !input <{}>)'.format(t))
Example #29
0
def npc_choice(data):
    if not npc_owner:
        return

    choices = filter(lambda s: len(s.strip()) > 0,
        data.select.split(':'))

    whisper(npc_owner, '[npc][select] (use !input <number> to select)')
    for i, s in enumerate(choices):
        whisper(npc_owner, '    {}) {}'.format(i + 1, s))
Example #30
0
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))
        if item_id < 1 or amount < 1:
            raise ValueError
    except ValueError:
        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
    s.start_time = time.time()

    mapserv.cmsg_trade_request(player_id)
Example #31
0
def cmd_check_bugs(nick, message, is_whisper, match):
    if not is_whisper:
        return

    if nick not in admins:
        return

    for user, bug in bugs:
        whisper(nick, '{} : {}'.format(user, bug))

    bugs.clear()
Example #32
0
def cmd_nearby(nick, message, is_whisper, match):
    if not is_whisper:
        return

    btype = message[8:]
    if btype.endswith('s'):
        btype = btype[:-1]

    ls = status.nearby(btype)
    for l in ls:
        whisper(nick, l)
Example #33
0
def zeny(nick, message, is_whisper, match):
    if not is_whisper:
        return

    if shop_admins is None:
        return

    if not shop_admins.check_player(nick):
        return

    whisper(nick, 'I have {} GP'.format(mapserv.player_stats[20]))
Example #34
0
def storage_equipment(data):
    if not npc_owner:
        return

    items_s = []
    for item in data.equipment:
        s = itemdb.item_name(item.id, True)
        items_s.append(s)

    for l in status.split_names(items_s):
        whisper(npc_owner, l)
Example #35
0
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))
        if item_id < 1 or amount < 1:
            raise ValueError
    except ValueError:
        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
    s.start_time = time.time()

    mapserv.cmsg_trade_request(player_id)
Example #36
0
def storage_items(data):
    if not npc_owner:
        return

    items_s = []
    for item in data.storage:
        s = itemdb.item_name(item.id, True)
        if item.amount > 1:
            s = str(item.amount) + ' ' + s
        items_s.append(s)

    for l in status.split_names(items_s):
        whisper(npc_owner, l)
Example #37
0
def invlist(nick, message, is_whisper, match):
    if not is_whisper:
        return

    if shop_admins is None:
        return

    if not shop_admins.check_player(nick):
        return

    ls = status.invlists(50)
    for l in ls:
        whisper(nick, l)
Example #38
0
def cmd_commands(nick, message, is_whisper, match):
    if not is_whisper:
        return

    c = []
    for cmd in manaboy_commands:
        if cmd.startswith('!('):
            br = cmd.index(')')
            c.extend(cmd[2:br].split('|'))
        elif cmd.startswith('!'):
            c.append(cmd[1:].split()[0])

    c.sort()
    whisper(nick, ', '.join(c))
Example #39
0
def cmd_commands(nick, message, is_whisper, match):
    if not is_whisper:
        return

    c = []
    for cmd in manaboy_commands:
        if cmd.startswith('!('):
            br = cmd.index(')')
            c.extend(cmd[2:br].split('|'))
        elif cmd.startswith('!'):
            c.append(cmd[1:].split()[0])

    c.sort()
    whisper(nick, ', '.join(c))
Example #40
0
def trade_ok(data):
    who = data.who

    if who == 0:
        return

    shoplog.info("Trade OK: %s", s.player)

    if s.mode == 'sell':
        zeny_get = mapserv.trade_state['zeny_get']
        if zeny_get >= s.price:
            mapserv.cmsg_trade_ok()
        else:
            whisper(s.player, "Your offer makes me sad")
            mapserv.cmsg_trade_cancel_request()
            cleanup()

    elif s.mode == 'buy':
        items_get = {}
        for item_id, amount in mapserv.trade_state['items_get']:
            try:
                items_get[item_id] += amount
            except KeyError:
                items_get[item_id] = amount

        if s.item_id in items_get and s.amount == items_get[s.item_id]:
            mapserv.cmsg_trade_ok()
        else:
            whisper(
                s.player,
                "You should give me {} {}".format(s.amount,
                                                  item_name(s.item_id)))
            mapserv.cmsg_trade_cancel_request()
            cleanup()

    elif s.mode == 'retrieve':
        mapserv.cmsg_trade_ok()

    else:
        shoplog.error("Unknown shop state: %s", s.mode)
        mapserv.cmsg_trade_cancel_request()
        cleanup()
Example #41
0
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)
Example #42
0
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)
Example #43
0
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)
Example #44
0
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)
Example #45
0
def cmd_talk2npc(nick, message, is_whisper, match):
    if not is_whisper:
        return

    npc_s = match.group(1).strip()
    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:
        whisper(nick, '[error] NPC not found: {}'.format(npc_s))
        return

    set_npc_owner(nick)
    plugins.autofollow.follow = ''
    plugins.npc.npc_id = b.id
    mapserv.cmsg_npc_talk(b.id)
Example #46
0
def trade_ok(data):
    who = data.who

    if who == 0:
        return

    shoplog.info("Trade OK: %s", s.player)

    if s.mode == 'sell':
        zeny_get = mapserv.trade_state['zeny_get']
        if zeny_get >= s.price:
            mapserv.cmsg_trade_ok()
        else:
            whisper(s.player, "Your offer makes me sad")
            mapserv.cmsg_trade_cancel_request()
            cleanup()

    elif s.mode == 'buy':
        items_get = {}
        for item_id, amount in mapserv.trade_state['items_get']:
            try:
                items_get[item_id] += amount
            except KeyError:
                items_get[item_id] = amount

        if s.item_id in items_get and s.amount == items_get[s.item_id]:
            mapserv.cmsg_trade_ok()
        else:
            whisper(s.player, "You should give me {} {}".format(
                s.amount, item_name(s.item_id)))
            mapserv.cmsg_trade_cancel_request()
            cleanup()

    elif s.mode == 'retrieve':
        mapserv.cmsg_trade_ok()

    else:
        shoplog.error("Unknown shop state: %s", s.mode)
        mapserv.cmsg_trade_cancel_request()
        cleanup()
Example #47
0
def cmd_history(nick, message, is_whisper, match):
    if not is_whisper:
        return

    for user, cmd in history:
        whisper(nick, '{} : {}'.format(user, cmd))
Example #48
0
def player_chat(data):
    if not npc_owner:
        return

    whisper(npc_owner, data.message)
Example #49
0
def cmd_where(nick, message, is_whisper, match):
    if not is_whisper:
        return

    msg = status.player_position()
    whisper(nick, msg)
Example #50
0
def cmd_say(nick, message, is_whisper, match):
    if not is_whisper:
        return

    msg = match.group(1)
    whisper(nick, msg)
Example #51
0
def cmd_zeny(nick, message, is_whisper, match):
    if not is_whisper:
        return

    whisper(nick, 'I have {} GP'.format(mapserv.player_money))
Example #52
0
def cmd_history(nick, message, is_whisper, match):
    if not is_whisper:
        return

    for user, cmd in history:
        whisper(nick, '{} : {}'.format(user, cmd))