Esempio 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)
Esempio 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])
Esempio n. 3
0
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)
Esempio 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])
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
0
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)
Esempio n. 9
0
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)
Esempio n. 10
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))
    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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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
Esempio n. 14
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
Esempio n. 15
0
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)
Esempio n. 16
0
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)
Esempio n. 17
0
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)
Esempio n. 18
0
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)
Esempio n. 19
0
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)
Esempio n. 20
0
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)
Esempio n. 21
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)
Esempio n. 22
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)
Esempio n. 23
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)