コード例 #1
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.")
コード例 #2
0
ファイル: interact.py プロジェクト: Mindcloud/texty
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.")
コード例 #3
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.")
コード例 #4
0
ファイル: character.py プロジェクト: Mindcloud/texty
    def load(self, weapon=None, ammo=None):

        if not weapon and not ammo:
            # no weapon or ammo, so grab one from the eq
            weapon = self.equipment.first(None, attribute='loadable')
            if not weapon:
                raise TextyException("What would you like to load?")

        if weapon and not ammo:
            # look for the first ammo in inventory that fits weapon
            condition = lambda y: weapon.__class__ in y.fits
            ammo = self.inventory.first(None, attribute='ammo', condition=condition)
            if not ammo:
                raise TextyException("You don't have any ammunition for {}.".format(weapon.name))

        elif ammo and not weapon:
            # look for the first weapon in equipment that fits ammo
            condition = lambda y: y.__class__ in ammo.fits
            weapon = self.equipment.first(None, attribute='loadable', condition=condition)
            if not weapon:
                raise TextyException("You aren't using a weapon that takes {}.".format(str(x)))

        weapon.load(ammo)
        self.inventory.remove(ammo)
        self.send(serialize.full_character(self))

        extra = {
            'weapon': weapon.name,
            'ammo': ammo.name
        }
        self.node.send(STR.T(STR.FIGHT.load, self, extra=extra), source=self)
        self.send(STR.T(STR.FIGHT.load, self, source=self, extra=extra))

        self.trigger('load', weapon=weapon, ammo=ammo)
コード例 #5
0
ファイル: interact.py プロジェクト: Mindcloud/texty
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.")
コード例 #6
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.")
コード例 #7
0
ファイル: interact.py プロジェクト: Mindcloud/texty
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.")
コード例 #8
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.")
コード例 #9
0
ファイル: interact.py プロジェクト: Mindcloud/texty
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.")
コード例 #10
0
ファイル: character.py プロジェクト: Mindcloud/texty
    def unload(self, weapon=None, ammo=None):

        if not weapon:
            weapon = self.equipment.first(None, attribute='loadable')
            if not weapon:
                raise TextyException("You aren't holding an unloadable weapon.")

        ammo = weapon.unload()

        self.inventory.append(ammo)
        self.send(serialize.full_character(self))
        extra = {
            'weapon': weapon.name,
            'ammo': ammo.name
        }
        self.node.send(STR.T(STR.FIGHT.unload, self, extra=extra), source=self)
        self.send(STR.T(STR.FIGHT.unload, self, source=self, extra=extra))
        self.trigger('unload', weapon=weapon)
コード例 #11
0
    def on_player_connect(self, player):
        """
        Start a player
        """
        # wakeup command, move player to Bertrams tent and introduce them
        player.gender = random.choice(['M', 'F'])
        player.name = construct_name(player.gender)
        player.occupation = construct_occupation()
        player.nouns.update(set(player.name.lower().split()))
        player.description = english.resolve_single(
            player, player.__class__.description)

        player.do('wakeup')

        player.equip(M1911())
        player.inventory += [Magazine45ACP(), Magazine45ACP(), Magazine45ACP()]

        player.send(serialize.full_character(player))

        return player
コード例 #12
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.")
コード例 #13
0
ファイル: interact.py プロジェクト: Mindcloud/texty
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.")
コード例 #14
0
ファイル: interact.py プロジェクト: Mindcloud/texty
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.")
コード例 #15
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.")
コード例 #16
0
ファイル: admin.py プロジェクト: sshyran/texty
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?")