예제 #1
0
def cmd_drop(ch, argument):
    argument, arg = game_utils.read_word(argument)

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

    if arg.isdigit():
        # 'drop NNNN coins'
        amount = int(arg)
        argument, arg = game_utils.read_word(argument)

        if amount <= 0 or (not game_utils.str_cmp(arg, ["coins", "coin"])):
            ch.send("Sorry, you can't do that.\n")
            return

        # Otherwise causes complications if there's a pile on each plane
        if ch.is_affected(merc.AFF_SHADOWPLANE):
            ch.send("You cannot drop coins in the shadowplane.\n")
            return

        if ch.gold < amount:
            ch.send("You haven't got that many coins.\n")
            return

        ch.gold -= amount

        for item_id in ch.in_room.items:
            item = instance.items[item_id]

            if item.vnum == merc.OBJ_VNUM_MONEY_ONE:
                amount += 1
                item.extract()
            elif item.vnum == merc.OBJ_VNUM_MONEY_SOME:
                amount += item.value[0]
                item.extract()

        object_creator.create_money(amount).to_room(ch.in_room)
        handler_game.act("$n drops some gold.", ch, None, None, merc.TO_ROOM)
        ch.send("Ok.\n")
        ch.save(force=True)
        return

    if not game_utils.str_cmp(arg, "all") and not game_utils.str_prefix(
            "all.", arg):
        # 'drop obj'
        item = ch.get_item_carry(arg)
        if not item:
            ch.send("You do not have that item.\n")
            return

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

        ch.get(item)
        ch.in_room.put(item)

        # Objects should only have a shadowplane flag when on the floor
        if ch.is_affected(merc.AFF_SHADOWPLANE) and not item.flags.shadowplane:
            item.flags.shadowplane = True

        handler_game.act("$n drops $p.", ch, item, None, merc.TO_ROOM)
        handler_game.act("You drop $p.", ch, item, None, merc.TO_CHAR)
    else:
        # 'drop all' or 'drop all.obj'
        found = False
        for item_id in ch.inventory[:]:
            item = instance.items[item_id]

            if (len(arg) == 3 or game_utils.is_name(arg[4:], item.name)
                ) and ch.can_see_item(
                    item) and not item.equipped_to and ch.can_drop_item(item):
                found = True
                ch.get(item)
                ch.in_room.put(item)

                # Objects should only have a shadowplane flag when on the floor
                if ch.is_affected(
                        merc.AFF_SHADOWPLANE) and not item.flags.shadowplane:
                    item.flags.shadowplane = True

                handler_game.act("$n drops $p.", ch, item, None, merc.TO_ROOM)
                handler_game.act("You drop $p.", ch, item, None, merc.TO_CHAR)

        if not found:
            if len(arg) == 3:
                handler_game.act("You are not carrying anything.", ch, None,
                                 arg, merc.TO_CHAR)
            else:
                handler_game.act("You are not carrying any $T.", ch, None,
                                 arg[4:], merc.TO_CHAR)
예제 #2
0
    def interpret(self, argument):
        # Strip leading spaces.
        argument = argument.lstrip()
        if not argument:
            return

        # Implement freeze command.
        if not self.is_npc() and self.sentances.is_set(merc.SENT_FREEZE):
            self.send("You're totally frozen!\n")
            return

        # Grab the command word.
        # Special parsing so ' can be a command,
        #   also no spaces needed after punctuation.
        logline = argument
        if not argument[0].isalpha() and not argument[0].isdigit():
            command = argument[0]
            argument = argument[:1].lstrip()
        else:
            argument, command = game_utils.read_word(argument)

        # Look for command in command table.
        trust = self.trust
        cmd = state_checks.prefix_lookup(interp.cmd_table, command)
        if cmd:
            if command[0] == cmd.name[0] and game_utils.str_prefix(
                    command, cmd.name) and cmd.level <= trust:
                if self.head.is_set(merc.LOST_HEAD) or self.extra.is_set(
                        merc.EXTRA_OSWITCH):
                    cmd_list = [
                        "say", "'", "immtalk", ":", "chat"
                        ".", "look", "save", "exits", "emote", "tell", "order",
                        "who", "weather", "where", "relevel", "safe", "scan",
                        "say", "spy", "score", "save", "inventory", "oreturn",
                        "roll", "leap", "lifespan", "nightsight", "truesight",
                        "horns", "fangs", "cast"
                    ]
                    if game_utils.str_cmp(cmd.name, cmd_list) or (
                            game_utils.str_cmp(cmd.name, ["quit", "humanform"])
                            and not self.is_npc() and self.obj_vnum != 0):
                        pass
                    else:
                        self.send("Not without a body!\n")
                        return
                elif self.extra.is_set(merc.EXTRA_TIED_UP):
                    cmd_list = [
                        "say", "'", "chat", ".", "yell", "shout", "look",
                        "save", "exits", "inventory", "tell", "order", "who",
                        "weather", "where", "introduce", "relevel", "safe",
                        "scan", "spy", "wake", "fangs", "claws", "nightsight",
                        "shadowsight", "shadowplane", "regenerate", "shield",
                        "vclan", "upkeep", "score", "immune", "report", "goto",
                        "flex", "change", "drink"
                    ]
                    if game_utils.str_cmp(cmd.name, cmd_list):
                        pass
                    else:
                        self.send("Not while tied up.\n")

                        if self.position > merc.POS_STUNNED:
                            handler_game.act("$n strains against $s bonds.",
                                             self, None, None, merc.TO_ROOM)
                        return
            else:
                cmd = None

        # Log and snoop.
        if cmd and cmd.log == merc.LOG_NEVER:
            logline = "XXXXXXXX XXXXXXXX XXXXXXXX"

        if (not self.is_npc() and self.sentances.is_set(merc.SENT_LOG)
            ) or settings.LOGALL or (cmd and cmd.log == merc.LOG_ALWAYS):
            comm.notify("{}: {}".format(self.name, logline), merc.CONSOLE_INFO)

        if self.desc and self.desc.snoop_by:
            self.desc.snoop_by.send("% " + logline + "\n")

        if not cmd:
            # Look for command in socials table.
            if not Pc.check_social(self, command, argument):
                self.huh()
            return

        # Pc not in position for command?
        if self.position < cmd.position:
            if self.position == merc.POS_DEAD:
                self.send("Lie still; you are DEAD.\n")
            elif self.position in [merc.POS_MORTAL, merc.POS_INCAP]:
                self.send("You are hurt far too bad for that.\n")
            elif self.position == merc.POS_STUNNED:
                self.send("You are too stunned to do that.\n")
            elif self.position == merc.POS_SLEEPING:
                self.send("In your dreams, or what?\n")
            elif self.position in [
                    merc.POS_MEDITATING, merc.POS_SITTING, merc.POS_RESTING
            ]:
                self.send("Nah... You feel too relaxed...\n")
            elif self.position == merc.POS_FIGHTING:
                self.send("No way!  You are still fighting!\n")
            return

        # Dispatch the command.
        cmd.cmd_fun(self,
                    cmd.default_arg if cmd.default_arg else argument.lstrip())
예제 #3
0
    def check_social(self, command, argument):
        cmd = None
        for key, social in const.social_table.items():
            if command[0] == social.name[0] and game_utils.str_prefix(
                    command, social.name):
                cmd = social
                break

        if not cmd:
            return False

        if not self.is_npc() and self.sentances.is_set(merc.SENT_NO_EMOTE):
            self.send("You are anti-social!\n")
            return True

        if self.position == merc.POS_DEAD:
            self.send("Lie still; you are DEAD.\n")
            return True
        if self.position in [merc.POS_INCAP, merc.POS_MORTAL]:
            self.send("You are hurt far too bad for that.\n")
            return True
        if self.position == merc.POS_STUNNED:
            self.send("You are too stunned to do that.\n")
            return True
        if self.position == merc.POS_SLEEPING:
            # I just know this is the path to a 12" 'if' statement.  :(
            # But two players asked for it already!  -- Furey
            if not game_utils.str_cmp(cmd.name, "snore"):
                self.send("In your dreams, or what?\n")
                return True

        holder, arg = game_utils.read_word(argument)
        victim = self.get_char_room(arg)
        if not arg:
            handler_game.act(cmd.others_no_arg, self, None, victim,
                             merc.TO_ROOM)
            handler_game.act(cmd.char_no_arg, self, None, victim, merc.TO_CHAR)
        elif not victim:
            self.not_here(arg)
        elif victim == self:
            handler_game.act(cmd.others_auto, self, None, victim, merc.TO_ROOM)
            handler_game.act(cmd.char_auto, self, None, victim, merc.TO_CHAR)
        else:
            handler_game.act(cmd.others_found, self, None, victim,
                             merc.TO_NOTVICT)
            handler_game.act(cmd.char_found, self, None, victim, merc.TO_CHAR)
            handler_game.act(cmd.vict_found, self, None, victim, merc.TO_VICT)

            if not self.is_npc() and victim.is_npc(
            ) and not victim.is_affected(merc.AFF_CHARM) and victim.is_awake():
                chance = game_utils.number_bits(4)
                if chance == 0:
                    fight.multi_hit(victim, self, merc.TYPE_UNDEFINED)
                elif chance in [1, 2, 3, 4, 5, 6, 7, 8]:
                    handler_game.act(cmd.others_found, victim, None, self,
                                     merc.TO_NOTVICT)
                    handler_game.act(cmd.char_found, victim, None, self,
                                     merc.TO_CHAR)
                    handler_game.act(cmd.vict_found, victim, None, self,
                                     merc.TO_VICT)
                elif chance in [9, 10, 11, 12]:
                    handler_game.act("$n slaps $N.", victim, None, self,
                                     merc.TO_NOTVICT)
                    handler_game.act("You slap $N.", victim, None, self,
                                     merc.TO_CHAR)
                    handler_game.act("$n slaps you.", victim, None, self,
                                     merc.TO_VICT)
        return True
예제 #4
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))
예제 #5
0
def cmd_get(ch, argument):
    argument, arg1 = game_utils.read_word(argument)
    argument, arg2 = game_utils.read_word(argument)

    if ch.is_affected(merc.AFF_ETHEREAL):
        ch.send("You cannot pick things up while ethereal.\n")
        return

    # Get type.
    if not arg1:
        ch.send("Get what?\n")
        return

    if not arg2:
        if not game_utils.str_cmp(arg1, "all") and not game_utils.str_prefix(
                "all.", arg1):
            # 'get obj'
            item = ch.get_item_list(arg1, ch.in_room.items)
            if not item:
                handler_game.act("I see no $T here.", ch, None, arg1,
                                 merc.TO_CHAR)
                return

            handler_item.get_item(ch, item, None)
        else:
            # 'get all' or 'get all.obj'
            found = False
            for item_id in ch.in_room.items:
                item = instance.items[item_id]

                if (len(arg1) == 3 or game_utils.is_name(
                        arg1[4:], item.name)) and ch.can_see_item(item):
                    found = True
                    handler_item.get_item(ch, item, None)

            if not found:
                if len(arg1) == 3:
                    ch.send("I see nothing here.\n")
                else:
                    handler_game.act("I see no $T here.", ch, None, arg1[4:],
                                     merc.TO_CHAR)
    else:
        # 'get ... container'
        if game_utils.str_cmp(arg2, "all") or game_utils.str_prefix(
                "all.", arg2):
            ch.send("You can't do that.\n")
            return

        container = ch.get_item_here(arg2)
        if not container:
            handler_game.act("I see no $T here.", ch, None, arg2, merc.TO_CHAR)
            return

        itype = container.item_type
        if itype == merc.ITEM_CORPSE_PC:
            if ch.is_npc():
                ch.send("You can't do that.\n")
                return
        elif itype not in [merc.ITEM_CONTAINER, merc.ITEM_CORPSE_NPC]:
            ch.send("That's not a container.\n")
            return

        if state_checks.is_set(container.value[1], merc.CONT_CLOSED):
            handler_game.act("The $d is closed.", ch, None, container.name,
                             merc.TO_CHAR)
            return

        if not game_utils.str_cmp(arg1, "all") and not game_utils.str_prefix(
                "all.", arg1):
            # 'get obj container'
            item = ch.get_item_list(arg1, container.inventory)
            if not item:
                handler_game.act("I see nothing like that in the $T.", ch,
                                 None, arg2, merc.TO_CHAR)
                return

            handler_item.get_item(ch, item, container)
        else:
            # 'get all container' or 'get all.obj container'
            found = False
            for item_id in container.inventory[:]:
                item = instance.items[item_id]

                if (len(arg1) == 3 or game_utils.is_name(
                        arg1[4:], item.name)) and ch.can_see_item(item):
                    found = True
                    handler_item.get_item(ch, item, container)

            if not found:
                if len(arg1) == 3:
                    handler_game.act("I see nothing in the $T.", ch, None,
                                     arg2, merc.TO_CHAR)
                else:
                    handler_game.act("I see nothing like that in the $T.", ch,
                                     None, arg2, merc.TO_CHAR)
    ch.save(force=True)
예제 #6
0
def cmd_put(ch, argument):
    argument, arg1 = game_utils.read_word(argument)
    argument, arg2 = game_utils.read_word(argument)

    if not arg1 or not arg2:
        ch.send("Put what in what?\n")
        return

    if game_utils.str_cmp(arg2, "all") or game_utils.str_prefix("all.", arg2):
        ch.send("You can't do that.\n")
        return

    container = ch.get_item_here(arg2)
    if not container:
        handler_game.act("I see no $T here.", ch, None, arg2, merc.TO_CHAR)
        return

    if container.item_type != merc.ITEM_CONTAINER:
        ch.send("That's not a container.\n")
        return

    if state_checks.is_set(container.value[1], merc.CONT_CLOSED):
        handler_game.act("The $d is closed.", ch, None, container.name,
                         merc.TO_CHAR)
        return

    if not game_utils.str_cmp(arg1, "all") and not game_utils.str_prefix(
            "all.", arg1):
        # 'put obj container'
        item = ch.get_item_carry(arg1)
        if not item:
            ch.send("You do not have that item.\n")
            return

        if item == container:
            ch.send("You can't fold it into itself.\n")
            return

        if item.flags.artifact:
            ch.send("You cannot put artifacts in a container.\n")
            return

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

        if item.get_weight() + container.get_weight() > container.value[0]:
            ch.send("It won't fit.\n")
            return

        for item2_id in container.inventory[:]:
            item2 = instance.items[item2_id]

            if item2.chobj and item != item2:
                handler_game.act("A hand reaches inside $P and drops $p.",
                                 item2.chobj, item, container, merc.TO_CHAR)

        ch.get(item)
        container.put(item)
        handler_game.act("$n puts $p in $P.", ch, item, container,
                         merc.TO_ROOM)
        handler_game.act("You put $p in $P.", ch, item, container,
                         merc.TO_CHAR)
    else:
        objroom = instance.rooms[merc.ROOM_VNUM_IN_OBJECT]

        # 'put all container' or 'put all.obj container'
        for item in ch.inventory[:]:
            if (len(arg1) == 3 or game_utils.is_name(arg1[4:], item.name)) and ch.can_see_item(item) and not item.equipped_to and \
                    item != container and not item.flags.artifact and ch.can_drop_item(item) and \
                    item.get_weight() + container.true_weight() <= container.value[0]:
                for item2 in container.inventory[:]:
                    if item2.chobj and item2.chobj.in_room:
                        if objroom != instance.rooms[item2.chobj.in_room.vnum]:
                            item2.chobj.in_room.get(item2.chobj)
                            objroom.put(item2.chobj)
                            item2.chobj.cmd_look("auto")

                        if item != item2:
                            handler_game.act(
                                "A hand reaches inside $P and drops $p.",
                                item2.chobj, item, container, merc.TO_CHAR)

                ch.get(item)
                container.put(item)
                handler_game.act("$n puts $p in $P.", ch, item, container,
                                 merc.TO_ROOM)
                handler_game.act("You put $p in $P.", ch, item, container,
                                 merc.TO_CHAR)

    ch.save(force=True)