Ejemplo n.º 1
0
def use(cmd, verb, object, prep, complement):
    """
    """
    if complement:
        valid, msg, x, y = cmd.rules(
            (lambda _, y: y.resolve(SCOPE.ANY), "You don't see {y} here."),
            (lambda x, _: x.resolve(SCOPE.ANY), "You don't see {x} here."),
            (lambda x, y: x.allows('use'), "You can't use {x} with {y}. {R}"),
            (lambda x, y: y.allows('use'), "You can't use {y} with {x}. {R}"),
            (lambda x, y: True, "You use {x} with {y}."))

        if x.is_a('usable'):
            x.obj.use(y.obj)
            return

        elif x.is_a('equipable') and x.is_a('bodypart'):
            return equip(cmd, verb, object, prep, complement)

        elif x.is_any('loadable ammo') and y.is_any('loadable ammo'):
            return load(cmd, verb, object, prep, complement)

        else:
            return cmd.response(
                "You aren't sure how to use {x} {prep} {y}.".format(x=str(x),
                                                                    y=str(y),
                                                                    prep=prep))

    # command form C. VERB PREP OBJECT.
    elif prep:
        raise TextyException("That doesn't make sense.")

    # command form B. VERB OBJECT.
    if object:
        valid, msg, x, _ = cmd.rules(
            (lambda x, _: x.resolve(SCOPE.ANY), "You don't see {x} here."),
            (lambda x, _: x.allows('use'), "You can't use {x}. {R}"),
            (lambda x, _: True, "You use {x}."))

        if x.is_a('usable'):
            x.obj.use()
            return

        elif x.is_a('equipable'):
            return equip(cmd, verb, object, None, None)

        elif x.is_any('ammo'):
            return load(cmd, verb, object, None, None)

        elif x.is_a('food'):
            return eat(cmd, verb, object, None, None)

        else:
            return cmd.response(
                "You aren't sure how to use {x}.".format(x=str(x)))

    # command form A. VERB.
    elif verb:
        raise TextyException("What would you like to {}?".format(verb))

    raise TextyException("That doesn't make ANY sense.")
Ejemplo n.º 2
0
def eat(cmd, verb, object, prep, complement):
    """
    """
    # command form D. VERB OBJECT PREP COMPLEMENT.
    if verb and object and complement:
        raise TextyException("That doesn't make sense.")

    # command form C. VERB PREP OBJECT.
    elif verb and object and prep:
        raise TextyException("That doesn't make sense.")

    # command form B. VERB OBJECT.
    elif verb and object:
        valid, msg, x, _ = cmd.rules(
            (lambda x, _: x.resolve(SCOPE.INV), "You don't have {x}."),
            (lambda x, _: x.is_a('food'), "{x} is not edible."),
            (lambda x, _: x.allows('eats'), "You can't eat {x}. {R}"),
            (lambda x, _: True, "You eat {x}."))
        # drop an object in the room
        x.obj.eat()
        cmd.source.inventory.remove(x.obj)
        cmd.source.send(serialize.full_character(cmd.source))
        cmd.to_node('A:{} eats {}.'.format(cmd.source.name, str(x)))
        return cmd.response(msg)

    # command form A. VERB.
    elif verb:
        raise TextyException("What would you like to eat?")

    raise TextyException("That doesn't make ANY sense.")
Ejemplo n.º 3
0
def get(cmd, verb, object, prep, complement):
    """
    Get an object from the room or other container.
    """
    # command form D. VERB OBJECT PREP COMPLEMENT.
    if verb and object and complement and prep in ('from', 'in', 'inside'):
        valid, msg, x, y = cmd.rules(
            (lambda _, y: y.resolve(), "You don't see {y} here."),
            (lambda _, y: y.is_any('container node'),
             "{y} is not a container."),
            (lambda x, y: x.resolve(SCOPE.IN, y), "You don't see {x} in {y}."),
            (lambda x, y: x.is_a('portable'),
             "You can't remove {x} from {y}."),
            (lambda x, y: x.allows('get'),
             "You can't remove {x} from {y}. {R}"),
            (lambda x, y: y.allows('get'),
             "You can't remove {x} from {y}. {R}"),
            (lambda x, y: True, "You get {x} from {y}."))

        # get an object from within another object
        if isinstance(y, Node):
            y.obj.objects.remove(x.obj)
        else:
            y.obj.contents.remove(x.obj)

        cmd.source.inventory.append(x.obj)

        cmd.source.send(serialize.full_character(cmd.source))
        cmd.to_node('A:{} takes {} from {}.'.format(cmd.source.name, str(x),
                                                    str(y)))
        return cmd.response(msg)

    # command form C. VERB PREP OBJECT.
    elif verb and object and prep:
        raise TextyException("That doesn't make sense.")

    # command form B. VERB OBJECT.
    elif verb and object:
        valid, msg, x, _ = cmd.rules(
            (lambda x, _: x.resolve(SCOPE.ROOM), "You don't see {x} here."),
            (lambda x, _: x.is_a('portable'), "{x} is far too heavy to move."),
            (lambda x, _: x.allows('get'), "You can't take {x}. {R}"),
            (lambda x, _: True, "You take {x}."),
        )
        # get an object from the room
        cmd.node.objects.remove(x.obj)
        cmd.source.inventory.append(x.obj)
        cmd.source.send(serialize.full_character(cmd.source))
        cmd.to_node('A:{} takes {}.'.format(cmd.source.name, str(x)))
        return cmd.response(msg)

    # command form A. VERB.
    elif verb:
        raise TextyException("What would you like to get?")

    raise TextyException("That doesn't make ANY sense.")
Ejemplo n.º 4
0
def load(cmd, verb, object, prep, complement):
    """
    Load a weapon with ammunition.
    raise TextyException('Quit breaking things kaptin.')
    "You don't have one of those."
    "What do you want to load?"
    "What do you want to load it in?"
    "You need to load {} into a <b>{x}</b>."
    "{y} doesn't seem to fit in {x}."
    """

    # command form D. VERB OBJECT PREP COMPLEMENT.
    if (verb and object and complement and prep in ('on', 'in', 'into', 'inside', 'with', 'using')):
        valid, msg, x, y = cmd.rules(
            (lambda x,_: x.resolve(SCOPE.HAS),                      "You don't have {x}."),
            (lambda x,_: x.is_any('ammo loadable'),                 "You can't load {x}."),
            (lambda _,y: y.resolve(SCOPE.HAS),                      "You don't have {y}."),
            (lambda _,y: y.is_any('ammo loadable'),                 "You can't load {y}."),
            (lambda x,y: (y.is_a('ammo') and not x.is_a('ammo')) or \
                (y.is_a('loadable') and not x.is_a('loadable')),    "You can't load {x} and {y} together."),
            (lambda x,y: x.allows('load'),                          "You can't load {x} with {y}. {R}"),
            (lambda x,y: y.allows('load'),                          "You can't load {y} with {x}. {R}"),
            (lambda x,y: True,                                      "")
        )
        if x.is_a('loadable'):
            weapon, ammo = x.obj, y.obj
        else:
            weapon, ammo = y.obj, x.obj

    # command form C. VERB PREP OBJECT.
    elif verb and object and prep:
        raise TextyException("That doesn't make sense.")

    # command form B. VERB OBJECT.
    elif (verb and object):
        valid, msg, x, y = cmd.rules(
            (lambda x,_: x.resolve(SCOPE.HAS),                      "You don't have {x}."),
            (lambda x,_: x.is_any('loadable ammo'),                 "You can't load {x}."),
            (lambda x,_: x.allows('load'),                          "You can't load {x}. {R}"),
            (lambda x,_: True,                                      "")
        )
        if x.is_a('loadable'):
            weapon, ammo = x.obj, None
        else:
            weapon, ammo = None, x.obj

    # command form A. VERB.
    elif verb:
        weapon, ammo = None, None

    else:
        raise TextyException("That doesn't make ANY sense.")

    cmd.source.load(weapon, ammo)
Ejemplo n.º 5
0
def warp(cmd, verb, object, prep, complement, string=None):


    if not string:
        raise TextyException("Warp where?")

    m = Story.get().map
    node = m.nodes.get(string.upper())
    if not node:
        raise TextyException("Node ID {} not found.".format(string))

    cmd.source.move_to(node)
    cmd.enqueue('look')
    return cmd.response('You warp to {}.'.format(node))
Ejemplo n.º 6
0
    def load(self, ammo):
        """
        Put ammo in this thing.
        """
        if not ammo.is_a('ammo'):
            raise TextyException('{} is not ammunition.'.format(ammo.name))
        if not hasattr(ammo, 'fits') or self.__class__ not in ammo.fits:
            raise TextyException('{} doesn\'t fit in {}.'.format(
                ammo.name, self.name))
        if self.ammo:
            raise TextyException('{} is already loaded.'.format(self.name))

        self.ammo = ammo

        return True
Ejemplo n.º 7
0
def kill(cmd, verb, object, prep, complement):
    """
    """

    if complement:
        pass

    elif prep:
        pass

    elif object:
        valid, msg, x, y = cmd.rules(
            (lambda x,_: x.resolve(SCOPE.CHAR),                     "You don't see {x}."),
            (lambda x,_: x.is_a('character'),                       "You can't attack {x}."),
            (lambda x,_: x.allows('attack'),                        "You can't attack {x}. {R}"),
            (lambda x,_: True,                                      "")
        )

        if cmd.source.target(x.obj):
            extra = {
                'weapon': cmd.source.weapon,
                'target': x.obj
            }
            return cmd.response(STR.T(STR.FIGHT.aim, cmd.source, source=cmd.source, extra=extra))

    elif verb:
        raise TextyException('Whom or what would you like to attack?')

    else:
        pass
Ejemplo n.º 8
0
def equip(cmd, verb, object, prep, complement):
    """
    Equip things like a boss.
    """
    # command form D. VERB OBJECT PREP COMPLEMENT.

    if (complement and prep in ('on', 'in')):
        valid, msg, x, y = cmd.rules(
            (lambda x, _: x.resolve(SCOPE.INV), "You don't have {x}."),
            (lambda x, _: x.is_a('equipable'), "You can't equip {x}."),
            (lambda _, y: y.resolve(SCOPE.BODY), "You don't have {y}."),
            (lambda _, y: y.is_a('bodypart'), "{y} is not a body part."),
            (lambda x, y: x.allows('equip'),
             "You can't equip {x} on your {y}. {R}"),
            (lambda x, y: y.allows('equip'),
             "You can't equip {x} on your {y}. {R}"),
            (lambda x, y: True, "You equip {x} on your {y}."))
        cmd.source.equip(x.obj, parts=[y.obj.typ])
        cmd.source.inventory.remove(x.obj)
        cmd.source.send(serialize.full_character(cmd.source))
        cmd.to_node('A:{} equips {} on {}.'.format(cmd.source.name, str(x),
                                                   str(y)))
        return cmd.response(msg)

    # command form C. VERB PREP OBJECT.
    elif prep:
        raise TextyException("That doesn't make sense.")

    # command form B. VERB OBJECT.
    elif (object):
        valid, msg, x, _ = cmd.rules(
            (lambda x, _: x.resolve(SCOPE.INV), "You don't have {x}."),
            (lambda x, _: x.is_a('equipable'), "You can't equip {x}."),
            (lambda x, _: x.allows('equip'), "You can't equip {x}. {R}"),
            (lambda x, _: True, "You equip {x}."))
        cmd.source.equip(x.obj)
        cmd.source.inventory.remove(x.obj)
        cmd.source.send(serialize.full_character(cmd.source))
        cmd.to_node('A:{} equips {}.'.format(cmd.source.name, str(x)))
        return cmd.response(msg)

    # command form A. VERB.
    elif verb:
        raise TextyException("What would you like to {}?".format(verb))

    raise TextyException("That doesn't make ANY sense.")
Ejemplo n.º 9
0
 def unload(self):
     """
     Remove ammo from this thing.
     """
     if not self.ammo:
         raise TextyException('{} is empty.'.format(self.name))
     ammo, self.ammo = self.ammo, None
     return ammo
Ejemplo n.º 10
0
def put(cmd, verb, object, prep, complement):
    """
    put PORTABLE in CONTAINER
    """
    # command form D. VERB OBJECT PREP COMPLEMENT.
    # command form B. VERB OBJECT.
    if (verb and object and complement
            and prep in ('in', 'into', 'inside')) or (verb and object
                                                      and not prep):
        valid, msg, x, y = cmd.rules(
            (lambda x, _: x.resolve(SCOPE.INV), "You don't have {x}."),
            # (lambda x,_: x.is_any('portable'),           "You can't move {x}."),
            (lambda x, y: y.provided(), "What do you want to put {x} in?"),
            (lambda _, y: y.resolve(), "You don't see {y}."),
            (lambda _, y: y.is_any('container loadable'),
             "{y} is not a container."),
            (lambda x, y: x.allows('put'), "You can't put {x} into {y}. {R}"),
            (lambda x, y: y.allows('put'), "You can't put {x} into {y}. {R}"),
            (lambda x, y: True, "You put {x} into {y}."))

        if x.is_a('ammo') and y.is_a('loadable'):
            from .combat import load
            return load(cmd, 'load', object, 'in', complement)
            # cmd.enqueue('load {} in {}'.format())

        cmd.source.inventory.remove(x.obj)
        y.obj.contents.append(x.obj)
        cmd.source.send(serialize.full_character(cmd.source))
        cmd.to_node('A:{} puts {} into {}.'.format(cmd.source.name, str(x),
                                                   str(y)))
        return cmd.response(msg)

    # command form C. VERB PREP OBJECT.
    elif verb and object and prep:
        raise TextyException("That doesn't make sense.")

    # command form A. VERB.
    elif verb:
        raise TextyException("What would you like to put?")

    raise TextyException("That doesn't make ANY sense.")
Ejemplo n.º 11
0
def unload(cmd, verb, object, prep, complement):
    """
    Remove ammunition from a weapon.
    """
        # command form D. VERB OBJECT PREP COMPLEMENT.
    if verb and object and complement and prep in ('from'):
        valid, msg, x, y = cmd.rules(
            (lambda _,y: y.resolve(SCOPE.HAS),                      "You don't have {y}."),
            (lambda _,y: y.is_a('loadable'),                        "You can't unload {y}."),
            (lambda x,y: x.resolve(SCOPE.IN, y),                    "{y} isn't loaded with {x}."),
            (lambda x,y: x.allows('unload'),                        "You can't unload {y} from {x}. {R}"),
            (lambda x,y: y.allows('unload'),                        "You can't unload {y} from {x}. {R}"),
            (lambda x,y: True,                                      "")
        )
        weapon, ammo = y.obj, x.obj

    # command form C. VERB PREP OBJECT.
    elif verb and object and prep:
        raise TextyException("That doesn't make sense.")

    # command form B. VERB OBJECT.
    elif verb and object:
        valid, msg, x, y = cmd.rules(
            (lambda x,_: x.resolve(SCOPE.HAS),                      "You don't have {x}."),
            (lambda x,_: x.is_a('loadable'),                        "You can't unload {x}."),
            (lambda x,_: x.allows('unload'),                        "You can't unload {x}. {R}"),
            (lambda x,_: True,                                      "")
        )
        weapon, ammo = x.obj, None

    # command form A. VERB.
    elif verb:
        weapon, ammo = None, None

    else:
        raise TextyException("That doesn't make ANY sense.")

    cmd.source.unload(weapon, ammo)
Ejemplo n.º 12
0
def drop(cmd, verb, object, prep, complement):
    """
    Put an object in the room.
    """
    # command form D. VERB OBJECT PREP COMPLEMENT.
    if verb and object and complement:
        raise TextyException("That doesn't make sense.")

    # command form C. VERB PREP OBJECT.
    elif verb and object and prep:
        raise TextyException("That doesn't make sense.")

    # command form B. VERB OBJECT.
    elif verb and object:
        valid, msg, x, _ = cmd.rules(
            (lambda x, _: x.resolve(SCOPE.INV), "You don't have {x}."),
            # (lambda x,_: x.is_a('portable'),            "You can't drop {x}."),
            (lambda x, _: x.allows('drop'), "You can't drop {x}. {R}"),
            (lambda x, _: True, "You drop {x}."))
        # drop an object in the room
        cmd.source.inventory.remove(x.obj)

        if x.obj.is_a('character'):
            cmd.node.characters.append(x.obj)
        else:
            cmd.node.objects.append(x.obj)
            cmd.node.sort()

        cmd.source.send(serialize.full_character(cmd.source))
        cmd.to_node('A:{} drops {}.'.format(cmd.source.name, str(x)))
        return cmd.response(msg)

    # command form A. VERB.
    elif verb:
        raise TextyException("What would you like to drop?")

    raise TextyException("That doesn't make ANY sense.")
Ejemplo n.º 13
0
def give(cmd, verb, object, prep, complement):
    """
    give PORTABLE to CHARACTER
    """
    # command form D. VERB OBJECT PREP COMPLEMENT.
    # command form B. VERB OBJECT.
    if (verb and object and complement and prep in ('to')) or (verb and object
                                                               and not prep):
        valid, msg, x, y = cmd.rules(
            (lambda x, _: x.resolve(SCOPE.INV), "You don't have {x}."),
            # (lambda x,_: x.is_a('portable'),             "You can't move {x}."),
            (lambda x, y: y.provided(), "Who do you want to give {x} to?"),
            (lambda _, y: y.resolve(SCOPE.ROOM), "You don't see {y} around."),
            (lambda _, y: y.is_a('character'), "{y} is not a person."),
            (lambda x, y: x.allows('give'), "You can't give {x} to {y}. {R}"),
            (lambda x, y: y.allows('give'), "You can't give {x} to {y}. {R}"),
            (lambda x, y: True, "You give {x} to {y}."))
        cmd.source.inventory.remove(x.obj)
        y.obj.inventory.append(x.obj)
        cmd.source.send(serialize.full_character(cmd.source))

        if y.obj.is_a('player'):
            y.obj.send(serialize.full_character(y.obj))

        cmd.to_node('A:{} gives {} to {}.'.format(cmd.source.name, str(x),
                                                  str(y)))
        return cmd.response(msg)

    # command form C. VERB PREP OBJECT.
    elif verb and object and prep:
        raise TextyException("That doesn't make sense.")

    # command form A. VERB.
    elif verb:
        raise TextyException("What would you like to give?")

    raise TextyException("That doesn't make ANY sense.")
Ejemplo n.º 14
0
def create(cmd, verb, object, prep, complement, string=None):
    """
    """

    if complement:
        raise TextyException("That doesn't make sense.")

    elif prep:
        raise TextyException("That doesn't make sense.")

    elif object:

        obj_class = parser.object_table.first(object['noun'], terms=object['terms'])

        if obj_class:
            obj = obj_class()
            cmd.source.inventory.append(obj)
            cmd.source.send(serialize.full_character(cmd.source))
            return cmd.response('You create {}.'.format(obj.name))
        else:
            return cmd.response('Not found.')

    elif verb:
        raise TextyException("Create what?")
Ejemplo n.º 15
0
    def resolve(self, scope=SCOPE.ANY, target=None):
        if not self.ast_node:
            raise TextyException('No AST node provided for ObjectASTProxy.',
                                 str(self))
        if target:
            target = target.obj

        result = self.command.resolve(self.ast_node,
                                      scope=scope,
                                      target=target)

        self.obj = result[0]
        self.scope = result[1]
        self.container = result[2]

        return self.obj != None
Ejemplo n.º 16
0
    def rules(self, *rules):
        """
        Apply dem rules.
        """
        # make proxy objects to pass back and forth
        x = ObjectASTProxy(self.ast.get('object'), command=self)
        y = ObjectASTProxy(self.ast.get('complement'), command=self)

        # iterate rules
        message = None
        for rule, m in rules:
            # rule failed
            out = rule(x, y)
            message = m.format(x=str(x), y=str(y), R=out)
            if not out:
                raise TextyException(message)

        # send out final message as a response,
        # then yield control back to command function with resolved objects
        return True, message, x, y
Ejemplo n.º 17
0
 def use(self, other=None):
     raise TextyException('The radio emits a steady stream of static...')
Ejemplo n.º 18
0
 def decorator(cmd, *args, **kwargs):
     if not cmd.source.is_a('admin'):
         raise TextyException(STR.ERROR.unknown.format(**kwargs))
     return fn(cmd, *args, **kwargs)
Ejemplo n.º 19
0
 def is_resolved(self):
     if not self.obj:
         raise TextyException('AST node {} has not been resolved.',
                              str(self))
     return True
Ejemplo n.º 20
0
def hit(cmd, verb, object, prep, complement):
    """
    Use a melee weapon
    """
    raise TextyException('Unfortunately, you appear to be a pacifist.')
    pass
Ejemplo n.º 21
0
 def use(self, other=None):
     raise TextyException('You learn a new power move.')