示例#1
0
def cmd_list(ch, argument):
    argument, arg = game_utils.read_word(argument)

    buf = []
    if ch.in_room.room_flags.is_set(merc.ROOM_PET_SHOP):
        proomindexnext = None
        if ch.in_room.vnum + 1 in instance.room_templates:
            proomindexnext = handler_room.get_room_by_vnum(ch.in_room.vnum + 1)
        if not proomindexnext:
            comm.notify("cmd_list: bad pet shop at vnum {}".format(ch.in_room.vnum), merc.CONSOLE_ERROR)
            ch.send("You can't do that here.\n")
            return

        found = False
        for pet in proomindexnext.people[:]:
            if pet.act.is_set(merc.ACT_PET):
                if not found:
                    found = True
                    buf = "Pets for sale:\n"

                buf += "[{:2}] {:8} - {}\n".format(pet.level, 10 * pet.level * pet.level, pet.short_descr)

        if not found:
            buf += "Sorry, we're out of pets right now.\n"
        ch.send("".join(buf))
        return

    keeper = shop_utils.find_keeper(ch)
    if not keeper:
        return

    items = collections.OrderedDict()
    for item_id in keeper.inventory[:]:
        item = instance.items[item_id]
        cost = shop_utils.get_cost(keeper, item, True)

        if not item.equipped_to and ch.can_see_item(item) and cost > 0 and (not arg or not game_utils.str_prefix(arg, item.name)):
            if item.inventory:
                items[(item.vnum, item.short_descr)] = (item.vnum, -1)
            else:
                k = (item.vnum, item.short_descr)
                if k not in items:
                    items[k] = (item, 1)
                else:
                    items[k][1] += 1

    if not items:
        if not arg:
            buf += "You can't buy anything here.\n"
        else:
            buf += "You can't buy that here.\n"

    buf += "[Lv Price] Item\n"

    for k, p in items.items():
        item, count = p
        cost = shop_utils.get_cost(keeper, item, True)
        buf += "[{:2} {:5}] {}\n".format(item.level, cost, item.short_descr.capitalize())
    ch.send("".join(buf))
示例#2
0
def do_list(ch, argument):
    if state_checks.IS_SET(ch.in_room.room_flags, merc.ROOM_PET_SHOP):
        # hack to make new thalos pets work
        pRoomIndexNext = None
        if ch.in_room.vnum == 9621:
            if 9706 in instance.room_templates:
                pRoomIndexNext = handler_room.get_room_by_vnum(9706)
        else:
            if ch.in_room.vnum + 1 in instance.room_templates:
                pRoomIndexNext = handler_room.get_room_by_vnum(ch.in_room.vnum + 1)
        if not pRoomIndexNext:
            logger.warn("BUG: Do_list: bad pet shop at vnum %d.", ch.in_room.vnum)
            ch.send("You can't do that here.\n")
            return
        found = False
        for pet in pRoomIndexNext.people[:]:
            if pet.act.is_set(merc.ACT_PET):
                if not found:
                    found = True
                    ch.send("Pets for sale:\n")
                ch.send("[[%2d]] %8d - %s\n" % (pet.level, 10 * pet.level * pet.level, pet.short_descr))
        if not found:
            ch.send("Sorry, we're out of pets right now.\n")
        return
    else:
        keeper = shop_utils.find_keeper(ch)
        if not keeper:
            return
        argument, arg = game_utils.read_word(argument)
        items = collections.OrderedDict()
        for item_id in keeper.inventory[:]:
            item = instance.items[item_id]
            cost = shop_utils.get_cost(keeper, item, True)
            if not item.equipped_to and ch.can_see_item(item) and cost > 0 \
                    and (not arg or arg in item.name.lower()):
                if item.inventory:
                    items[(item.vnum, item.short_descr)] = (item.vnum, -1)
                else:
                    k = (item.vnum, item.short_descr)
                    if k not in items:
                        items[k] = (item, 1)
                    else:
                        items[k][1] += 1
        if not items:
            ch.send("You can't buy anything here.\n")
            return
        ch.send("[[Lv Price Qty]] Item\n")
        for k, p in items.items():
            item, count = p
            cost = shop_utils.get_cost(keeper, item, True)
            ch.send("[[%2d %5d %2s ]] %s" % (item.level, cost, ("--" if item.flags.shop_inventory else count), item.short_descr))
            if ch.act.is_set(merc.PLR_OMNI):
                ch.send("(%d)" % item.vnum)
            ch.send("\n")
示例#3
0
def cmd_value(ch, argument):
    argument, arg = game_utils.read_word(argument)

    if not arg:
        ch.send("Value what?\n")
        return

    keeper = shop_utils.find_keeper(ch)
    if not keeper:
        return

    item = ch.get_item_carry(arg)
    if not item:
        handler_game.act("$n tells you 'You don't have that item'.", keeper,
                         None, ch, merc.TO_VICT)
        ch.reply = keeper
        return

    if not ch.can_drop_item(item):
        ch.send("You can't let go of it.\n")
        return

    cost = shop_utils.get_cost(keeper, item, False)
    if cost <= 0:
        handler_game.act("$n looks uninterested in $p.", keeper, item, ch,
                         merc.TO_VICT)
        return

    handler_game.act(
        "$n tells you 'I'll give you {:,} gold coins for $p'.".format(cost),
        keeper, item, ch, merc.TO_VICT)
    ch.reply = keeper
示例#4
0
def do_value(ch, argument):
    argument, arg = game_utils.read_word(argument)
    if not arg:
        ch.send("Value what?\n")
        return
    keeper = shop_utils.find_keeper(ch)
    if not keeper:
        return
    obj = ch.get_item_carry(arg, ch)
    if not obj:
        handler_game.act("$n tells you 'You don't have that item'.", keeper, None, ch, merc.TO_VICT)
        ch.reply = keeper
        return
    if not keeper.can_see_item(obj):
        handler_game.act("$n doesn't see what you are offering.",keeper,None,ch, merc.TO_VICT)
        return
    if not ch.can_drop_item(obj):
        ch.send("You can't let go of it.\n")
        return
    cost = shop_utils.get_cost(keeper, obj, False)
    if cost <= 0:
        handler_game.act( "$n looks uninterested in $p.", keeper, obj, ch, merc.TO_VICT)
        return
    handler_game.act("$n tells you 'I'll give you %d silver and %d gold coins for $p'." % (cost - (cost//100) * 100, cost//100),
      keeper, obj, ch, merc.TO_VICT)
    ch.reply = keeper
    return
示例#5
0
def do_value(ch, argument):
    argument, arg = game_utils.read_word(argument)
    if not arg:
        ch.send("Value what?\n")
        return
    keeper = shop_utils.find_keeper(ch)
    if not keeper:
        return
    obj = ch.get_item_carry(arg, ch)
    if not obj:
        handler_game.act("$n tells you 'You don't have that item'.", keeper,
                         None, ch, merc.TO_VICT)
        ch.reply = keeper
        return
    if not keeper.can_see_item(obj):
        handler_game.act("$n doesn't see what you are offering.", keeper, None,
                         ch, merc.TO_VICT)
        return
    if not ch.can_drop_item(obj):
        ch.send("You can't let go of it.\n")
        return
    cost = shop_utils.get_cost(keeper, obj, False)
    if cost <= 0:
        handler_game.act("$n looks uninterested in $p.", keeper, obj, ch,
                         merc.TO_VICT)
        return
    handler_game.act(
        "$n tells you 'I'll give you %d silver and %d gold coins for $p'." %
        (cost - (cost // 100) * 100, cost // 100), keeper, obj, ch,
        merc.TO_VICT)
    ch.reply = keeper
    return
示例#6
0
def cmd_sell(ch, argument):
    argument, arg = game_utils.read_word(argument)

    if not arg:
        ch.send("Sell what?\n")
        return

    keeper = shop_utils.find_keeper(ch)
    if not keeper:
        return

    item = ch.get_item_carry(arg)
    if not item:
        handler_game.act("$n tells you 'You don't have that item'.", keeper,
                         None, ch, merc.TO_VICT)
        ch.reply = keeper
        return

    if not ch.can_drop_item(item):
        ch.send("You can't let go of it.\n")
        return

    cost = shop_utils.get_cost(keeper, item, False)
    if cost <= 0:
        handler_game.act("$n looks uninterested in $p.", keeper, item, ch,
                         merc.TO_VICT)
        return

    handler_game.act("$n sells $p.", ch, item, None, merc.TO_ROOM)
    handler_game.act(
        "You sell $p for {:,} gold piece{}.".format(cost,
                                                    "" if cost == 1 else "s"),
        ch, item, None, merc.TO_CHAR)
    ch.gold += cost
    keeper.gold -= cost
    if keeper.gold < 0:
        keeper.gold = 0

    if item.item_type == merc.ITEM_TRASH:
        item.extract()
    else:
        ch.get(item)
        keeper.put(item)
示例#7
0
def cmd_buy(ch, argument):
    argument, arg = game_utils.read_word(argument)

    if not arg:
        ch.send("Buy what?\n")
        return

    if ch.in_room.room_flags.is_set(merc.ROOM_PET_SHOP):
        if ch.is_npc():
            return

        proomindexnext = None
        if ch.in_room.vnum + 1 in instance.room_templates:
            proomindexnext = handler_room.get_room_by_vnum(ch.in_room.vnum + 1)
        if not proomindexnext:
            comm.notify(
                "cmd_buy: bad pet shop at vnum {}".format(ch.in_room.vnum),
                merc.CONSOLE_ERROR)
            ch.send("Sorry, you can't buy that here.\n")
            return

        in_room = ch.in_room
        ch.in_room = proomindexnext
        pet = ch.get_char_room(arg)
        ch.in_room = in_room

        if not pet or not pet.act.is_set(merc.ACT_PET):
            ch.send("Sorry, you can't buy that here.\n")
            return

        if ch.gold < 10 * pet.level * pet.level:
            ch.send("You can't afford it.\n")
            return

        if ch.level < pet.level:
            ch.send("You're not ready for this pet.\n")
            return

        ch.gold -= 10 * pet.level * pet.level
        pet = object_creator.create_mobile(instance.npc_templates[pet.vnum])
        pet.act.set_bit(merc.ACT_PET)
        pet.affected_by.set_bit(merc.AFF_CHARM)

        argument, arg = game_utils.read_word(argument)
        if arg:
            pet.name = "{} {}".format(pet.name, arg)

        pet.description = "{}A neck tag says 'I belong to {}'.\n".format(
            pet.description, ch.name)
        ch.in_room.put(pet)
        pet.add_follower(ch)
        ch.send("Enjoy your pet.\n")
        handler_game.act("$n bought $N as a pet.", ch, None, pet, merc.TO_ROOM)
    else:
        keeper = shop_utils.find_keeper(ch)
        if not keeper:
            return

        item = keeper.get_item_carry(arg)
        cost = shop_utils.get_cost(keeper, item, True)
        if cost <= 0 or not ch.can_see_item(item):
            handler_game.act("$n tells you 'I don't sell that -- try 'list''.",
                             keeper, None, ch, merc.TO_VICT)
            ch.reply = keeper
            return

        if ch.gold < cost:
            handler_game.act("$n tells you 'You can't afford to buy $p'.",
                             keeper, item, ch, merc.TO_VICT)
            ch.reply = keeper
            return

        if item.level > ch.level and ch.level < 3:
            handler_game.act("$n tells you 'You can't use $p yet'.", keeper,
                             item, ch, merc.TO_VICT)
            ch.reply = keeper
            return

        if ch.carry_number + 1 > ch.can_carry_n():
            ch.send("You can't carry that many items.\n")
            return

        if ch.carry_weight + item.get_weight() > ch.can_carry_w():
            ch.send("You can't carry that much weight.\n")
            return

        handler_game.act("$n buys $p.", ch, item, None, merc.TO_ROOM)
        handler_game.act("You buy $p.", ch, item, None, merc.TO_CHAR)
        ch.gold -= cost
        keeper.gold += cost

        if item.flags.inventory:
            item = object_creator.create_item(
                instance.item_templates[item.vnum], item.level)
        else:
            item.in_living.get(item)
        ch.put(item)
示例#8
0
def do_sell(ch, argument):
    argument, arg = game_utils.read_word(argument)
    if not arg:
        ch.send("Sell what?\n")
        return
    keeper = shop_utils.find_keeper(ch)
    if not keeper:
        return
    item = ch.get_item_carry(arg, ch)
    if not item:
        handler_game.act("$n tells you 'You don't have that item'.", keeper,
                         None, ch, merc.TO_VICT)
        ch.reply = keeper
        return
    if not ch.can_drop_item(item):
        ch.send("You can't let go of it.\n")
        return
    if not keeper.can_see_item(item):
        handler_game.act("$n doesn't see what you are offering.", keeper, None,
                         ch, merc.TO_VICT)
        return
    cost = shop_utils.get_cost(keeper, item, False)
    if cost <= 0:
        handler_game.act("$n looks uninterested in $p.", keeper, item, ch,
                         merc.TO_VICT)
        return
    if cost > (keeper.silver + 100 * keeper.gold):
        handler_game.act(
            "$n tells you 'I'm afraid I don't have enough wealth to buy $p.",
            keeper, item, ch, merc.TO_VICT)
        return
    handler_game.act("$n sells $p.", ch, item, None, merc.TO_ROOM)
    # haggle
    roll = random.randint(1, 99)
    if not item.sell_extract and roll < ch.get_skill("haggle"):
        ch.send("You haggle with the shopkeeper.\n")
        cost += item.cost // 2 * roll // 100
        cost = min(cost, 95 * shop_utils.get_cost(keeper, item, True) // 100)
        cost = min(cost, (keeper.silver + 100 * keeper.gold))
        if ch.is_pc():
            ch.check_improve("haggle", True, 4)
    handler_game.act(
        "You sell $p for %d silver and %d gold piece%s." %
        (cost - (cost // 100) * 100, cost // 100, ("" if cost == 1 else "s")),
        ch, item, None, merc.TO_CHAR)
    ch.gold += cost // 100
    ch.silver += cost - (cost // 100) * 100

    keeper.deduct_cost(cost)
    if keeper.gold < 0:
        keeper.gold = 0
    if keeper.silver < 0:
        keeper.silver = 0
    if item.item_type == merc.ITEM_TRASH or item.sell_extract:
        item.extract()
    else:
        item.get()
        if item.timer:
            item.flags.had_timer = True
        else:
            item.timer = random.randint(50, 100)
        shop_utils.obj_to_keeper(item, keeper)
    return
示例#9
0
文件: do_list.py 项目: totalgit/PyRom
def do_list(ch, argument):
    if state_checks.IS_SET(ch.in_room.room_flags, merc.ROOM_PET_SHOP):
        # hack to make new thalos pets work
        pRoomIndexNext = None
        if ch.in_room.vnum == 9621:
            if 9706 in instance.room_templates:
                pRoomIndexNext = handler_room.get_room_by_vnum(9706)
        else:
            if ch.in_room.vnum + 1 in instance.room_templates:
                pRoomIndexNext = handler_room.get_room_by_vnum(
                    ch.in_room.vnum + 1)
        if not pRoomIndexNext:
            logger.warn("BUG: Do_list: bad pet shop at vnum %d.",
                        ch.in_room.vnum)
            ch.send("You can't do that here.\n")
            return
        found = False
        for pet in pRoomIndexNext.people[:]:
            if pet.act.is_set(merc.ACT_PET):
                if not found:
                    found = True
                    ch.send("Pets for sale:\n")
                ch.send(
                    "[[%2d]] %8d - %s\n" %
                    (pet.level, 10 * pet.level * pet.level, pet.short_descr))
        if not found:
            ch.send("Sorry, we're out of pets right now.\n")
        return
    else:
        keeper = shop_utils.find_keeper(ch)
        if not keeper:
            return
        argument, arg = game_utils.read_word(argument)
        items = collections.OrderedDict()
        for item_id in keeper.inventory[:]:
            item = instance.items[item_id]
            cost = shop_utils.get_cost(keeper, item, True)
            if not item.equipped_to and ch.can_see_item(item) and cost > 0 \
                    and (not arg or arg in item.name.lower()):
                if item.inventory:
                    items[(item.vnum, item.short_descr)] = (item.vnum, -1)
                else:
                    k = (item.vnum, item.short_descr)
                    if k not in items:
                        items[k] = (item, 1)
                    else:
                        items[k][1] += 1
        if not items:
            ch.send("You can't buy anything here.\n")
            return
        ch.send("[[Lv Price Qty]] Item\n")
        for k, p in items.items():
            item, count = p
            cost = shop_utils.get_cost(keeper, item, True)
            ch.send("[[%2d %5d %2s ]] %s" %
                    (item.level, cost,
                     ("--" if item.flags.shop_inventory else count),
                     item.short_descr))
            if ch.act.is_set(merc.PLR_OMNI):
                ch.send("(%d)" % item.vnum)
            ch.send("\n")