コード例 #1
0
    def close(self, player, args):
        if not player.container:
            return

        desc = ' '.join(args)
        container = player.find_best_match(desc)

        if not container:
            container = player.container.find_best_match(desc)

        if not container or not isinstance(container, Container):
            # Close what?
            player.text('Stäng vad?')
            return

        if not container.is_closeable:
            player.text(
                language.sentence('{} går inte att stänga!',
                                  container.get_description(indefinite=False)))
            return

        if not container.is_open:
            # {} is already closed.
            player.text(
                language.sentence('{} är redan stängd.',
                                  container.get_description(indefinite=False)))
            return

        if not player.close(container):
            player.emote('försöker stänga', container, 'men misslyckas')
コード例 #2
0
    def get_description(self, exclude_actor=None):
        """ Retrieves a description of the room.

            :returns: A description of the room, including its exits, any actors
                      in the room and any items in it.
        """

        room_desc = language.sentence(super(Room, self).get_description())
        exits_desc = language.list(
            self.exits.keys()) if len(self.exits) > 0 else 0

        # {}\nExits: {}
        desc = '{}\nUtgångar: {}'.format(room_desc, exits_desc)

        actors = self.get_entities(Actor)
        if exclude_actor in actors:
            actors.remove(exclude_actor)
        if len(actors) > 0:
            # {} are here.
            desc += '\n' + language.sentence('{} är här.',
                                             language.list(actors))

        items = self.get_entities(Item)
        if len(items) > 0:
            desc += '\n' + language.sentence('{}', language.list(items))

        return desc
コード例 #3
0
    def open(self, player, args):
        if not player.container:
            return

        desc = ' '.join(args)
        container = player.find_best_match(desc)

        if not container:
            container = player.container.find_best_match(desc)

        if not container or not isinstance(
                container, Container) or not container.is_closeable:
            # Open what?
            player.text('Öppna vad?')
            return

        unlockable_class = enigmus.get_entity_class(
            'special/unlockable.py:Unlockable')
        if isinstance(container, unlockable_class) and container.is_locked:
            # {} is locked.
            player.text(
                language.sentence('{} är låst.',
                                  container.get_description(indefinite=False)))
            return

        if container.is_open:
            # {} is already open.
            player.text(
                language.sentence('{} är redan öppen.',
                                  container.get_description(indefinite=False)))
            return

        if not player.open(container):
            player.emote('försöker öppna', container, 'men misslyckas')
コード例 #4
0
    def get_description(self, exclude_actor=None):
        """ Retrieves a description of the room.

            :returns: A description of the room, including its exits, any actors
                      in the room and any items in it.
        """

        room_desc  = language.sentence(super(Room, self).get_description())
        exits_desc = language.list(self.exits.keys()) if len(self.exits) > 0 else 0

        # {}\nExits: {}
        desc = '{}\nUtgångar: {}'.format(room_desc, exits_desc)

        actors = self.get_entities(Actor)
        if exclude_actor in actors:
            actors.remove(exclude_actor)
        if len(actors) > 0:
            # {} are here.
            desc += '\n' + language.sentence('{} är här.', language.list(actors))

        items = self.get_entities(Item)
        if len(items) > 0:
            desc += '\n' + language.sentence('{}', language.list(items))

        return desc
コード例 #5
0
ファイル: light.py プロジェクト: philiparvidsson/enigmus-mud
    def __player_command(self, player, command):
        args = command.split(' ')

        if args[0] == 'tänd':
            light = player.inventory.find_best_match(' '.join(args[1:]))
            if not isinstance(light, Light):
                player.text('Tänd vad?')
                return

            if light.is_on:
                light_desc = light.get_description(indefinite=False)
                player.text(language.sentence('{} är redan tänd.', light_desc))
                return

            light.switch_on()
            player.emote('tände', light)
        elif args[0] == 'släck':
            light = player.inventory.find_best_match(' '.join(args[1:]))
            if not isinstance(light, Light):
                player.text('Släck vad?')
                return

            if not light.is_on:
                light_desc = light.get_description(indefinite=False)
                player.text(language.sentence('{} är redan släckt.', light_desc))
                return

            light.switch_off()
            player.emote('släckte', light)
コード例 #6
0
    def __player_command(self, player, command):
        args = command.split(' ')

        if args[0] == 'tänd':
            light = player.inventory.find_best_match(' '.join(args[1:]))
            if not isinstance(light, Light):
                player.text('Tänd vad?')
                return

            if light.is_on:
                light_desc = light.get_description(indefinite=False)
                player.text(language.sentence('{} är redan tänd.', light_desc))
                return

            light.switch_on()
            player.emote('tände', light)
        elif args[0] == 'släck':
            light = player.inventory.find_best_match(' '.join(args[1:]))
            if not isinstance(light, Light):
                player.text('Släck vad?')
                return

            if not light.is_on:
                light_desc = light.get_description(indefinite=False)
                player.text(
                    language.sentence('{} är redan släckt.', light_desc))
                return

            light.switch_off()
            player.emote('släckte', light)
コード例 #7
0
    def open(self, player, args):
        if not player.container:
            return

        desc      = ' '.join(args)
        container = player.find_best_match(desc)

        if not container:
            container = player.container.find_best_match(desc)

        if not container or not isinstance(container, Container) or not container.is_closeable:
            # Open what?
            player.text('Öppna vad?')
            return

        unlockable_class = enigmus.get_entity_class('special/unlockable.py:Unlockable')
        if isinstance(container, unlockable_class) and container.is_locked:
            # {} is locked.
            player.text(language.sentence('{} är låst.',
                        container.get_description(indefinite=False)))
            return

        if container.is_open:
            # {} is already open.
            player.text(language.sentence('{} är redan öppen.',
                        container.get_description(indefinite=False)))
            return

        if not player.open(container):
            player.emote('försöker öppna', container, 'men misslyckas')
コード例 #8
0
    def close(self, player, args):
        if not player.container:
            return

        desc      = ' '.join(args)
        container = player.find_best_match(desc)

        if not container:
            container = player.container.find_best_match(desc)

        if not container or not isinstance(container, Container):
            # Close what?
            player.text('Stäng vad?')
            return

        if not container.is_closeable:
            player.text(language.sentence('{} går inte att stänga!', container.get_description(indefinite=False)))
            return

        if not container.is_open:
            # {} is already closed.
            player.text(language.sentence('{} är redan stängd.',
                        container.get_description(indefinite=False)))
            return

        if not player.close(container):
            player.emote('försöker stänga', container, 'men misslyckas')
コード例 #9
0
    def look(self, player, args):
        if not player.container:
            return

        if len(args) == 0:
            player.text(player.container.get_description(exclude_actor=player))
            return

        look_inside = False

        # at
        if len(args) > 1 and args[0] == 'på':
            args = args[1:]
        # in
        elif len(args) > 1 and args[0] == 'i':
            args = args[1:]
            look_inside = True

        text   = ' '.join(args)
        entity = player.find_best_match(text)

        if not entity:
            entity = player.container.find_best_match(text)

        if look_inside:
            if not isinstance(entity, Container):
                entity = None
            elif not entity.is_open:
                # {} is closed!
                player.text(language.sentence('{} är stängd!', entity.get_description(indefinite=False)))
                return

        if not entity:
            # Look at/in what?
            player.text('Titta {} vad?'.format('i' if look_inside else 'på'))
            return

        if look_inside:
            if len(entity.entities) == 0:
                # {} is empty.
                player.text(language.sentence('{} är tom.', entity.get_description(indefinite=False)))
                return

            s = language.list([x.get_description() for x in entity.entities])
            # {} contains: {}
            player.text(language.sentence('{} innehåller: {}', entity.get_description(indefinite=False), s))
            return

        if not isinstance(entity, Detail):
            player.text(language.sentence(entity.get_description()))

        if isinstance(entity, Actor):
            player.text(entity.get_long_description(observer=player))
        else:
            player.text(entity.get_long_description())
コード例 #10
0
ファイル: go.py プロジェクト: philiparvidsson/enigmus-mud
 def __actor_enter(self, actor, room, exit):
     actor_desc = actor.get_description()
     for player in room.get_entities(Player):
         if player == actor:
             player.text(room.get_description(exclude_actor=player))
         else:
             # {} comes in.
             player.text(language.sentence('{} kommer in.', actor_desc))
コード例 #11
0
ファイル: go.py プロジェクト: philiparvidsson/Enigmus-MUD
 def __actor_enter(self, actor, room, exit):
     actor_desc = actor.get_description()
     for player in room.get_entities(Player):
         if player == actor:
             player.text(room.get_description(exclude_actor=player))
         else:
             # {} comes in.
             player.text(language.sentence('{} kommer in.', actor_desc))
コード例 #12
0
    def get_long_description(self, observer=None):
        if not observer:
            observer = self

        desc = super(Actor, self).get_long_description()

        if len(self.wearables) > 0:
            wearable_descs = [x.get_description() for x in self.wearables]
            # {} is wearing {}.
            desc += '\n' + language.sentence(language.pronouns(observer, self, self, 'har', language.list(wearable_descs), 'på', self))

        return desc
コード例 #13
0
    def take(self, player, args):
        if not player.container:
            return

        # To prevent conflict with wear/remove.
        if len(args) > 0 and (args[0] == 'på' or args[0] == 'av'):
            return

        container = player.container

        # from
        i = args.index('från') if 'från' in args else -1

        # in
        if i == -1:
            i = args.index('i') if 'i' in args else -1

        if i > 0:
            s = ' '.join(args[i + 1:])
            container = player.find_best_match(s)

            if not container:
                container = player.container.find_best_match(s)

            if not container or not isinstance(container, Container):
                # Take from what?
                player.text('Ta från vad?')
                return

            if not container.is_open:
                # {} is closed!
                item_desc = container.get_description(indefinite=False)
                player.text(language.sentence('{} är stängd!', item_desc))
                return

            args = args[:i]

        items = container.find_matches(' '.join(args))

        if len(items) == 0:
            # Take what?
            player.text('Ta vad?')
            return

        for item in items:
            if isinstance(item, Detail):
                continue

            if not player.take(item):
                # tries to take {} but fails.
                item_desc = item.get_description(indefinite=False)
                player.emote(
                    'försöker ta {} men misslyckas.'.format(item_desc))
コード例 #14
0
    def take(self, player, args):
        if not player.container:
            return

        # To prevent conflict with wear/remove.
        if len(args) > 0 and (args[0] == 'på' or args[0] == 'av'):
            return

        container = player.container

        # from
        i = args.index('från') if 'från' in args else -1

        # in
        if i == -1:
            i = args.index('i') if 'i' in args else -1

        if i > 0:
            s = ' '.join(args[i+1:])
            container = player.find_best_match(s)

            if not container:
                container = player.container.find_best_match(s)

            if not container or not isinstance(container, Container):
                # Take from what?
                player.text('Ta från vad?')
                return

            if not container.is_open:
                # {} is closed!
                item_desc = container.get_description(indefinite=False)
                player.text(language.sentence('{} är stängd!', item_desc))
                return

            args = args[:i]

        items = container.find_matches(' '.join(args))

        if len(items) == 0:
            # Take what?
            player.text('Ta vad?')
            return

        for item in items:
            if isinstance(item, Detail):
                continue

            if not player.take(item):
                # tries to take {} but fails.
                item_desc = item.get_description(indefinite=False)
                player.emote('försöker ta {} men misslyckas.'.format(item_desc))
コード例 #15
0
    def get_long_description(self, observer=None):
        if not observer:
            observer = self

        desc = super(Actor, self).get_long_description()

        if len(self.wearables) > 0:
            wearable_descs = [x.get_description() for x in self.wearables]
            # {} is wearing {}.
            desc += '\n' + language.sentence(
                language.pronouns(observer, self, self, 'har',
                                  language.list(wearable_descs), 'på', self))

        return desc
コード例 #16
0
    def drop(self, player, args):
        if not player.container:
            return

        container = None

        # in
        i = args.index('i') if 'i' in args else -1
        if i > 0:
            desc = ' '.join(args[i + 1:])
            container = player.find_best_match(desc)

            if not container:
                container = player.container.find_best_match(desc)

            if not container or not isinstance(container, Container):
                player.text('Släng i vad?')
                return

            if not container.is_open:
                # {} is closed!
                player.text(
                    language.sentence(
                        '{} är stängd!',
                        container.get_description(indefinite=False)))
                return

            args = args[:i]

        items = player.find_matches(' '.join(args))

        if len(items) == 0 or (len(items) == 1 and items[0] == container):
            # Drop what?
            player.text('Släng vadå?')
            return

        for item in items:
            if item in player.wearables:
                # Remove {} first.
                item_desc = item.get_description(indefinite=False)
                player.text('Ta av dig {} först.'.format(item_desc))
                continue

            if item != container:
                player.drop(item, container)
コード例 #17
0
    def drop(self, player, args):
        if not player.container:
            return

        container = None

        # in
        i = args.index('i') if 'i' in args else -1
        if i > 0:
            desc      = ' '.join(args[i+1:])
            container = player.find_best_match(desc)

            if not container:
                container = player.container.find_best_match(desc)

            if not container or not isinstance(container, Container):
                player.text('Släng i vad?')
                return

            if not container.is_open:
                # {} is closed!
                player.text(language.sentence('{} är stängd!',
                            container.get_description(indefinite=False)))
                return

            args = args[:i]

        items = player.find_matches(' '.join(args))

        if len(items) == 0 or (len(items) == 1 and items[0] == container):
            # Drop what?
            player.text('Släng vadå?')
            return

        for item in items:
            if item in player.wearables:
                # Remove {} first.
                item_desc = item.get_description(indefinite=False)
                player.text('Ta av dig {} först.'.format(item_desc))
                continue

            if item != container:
                player.drop(item, container)
コード例 #18
0
    def __actor_emote(self, actor, args):
        room = actor.container

        if not room or not isinstance(room, Room):
            return

        #args = [actor] + list(args)
        for player in room.get_entities(Player):
            s = 'Du' if player == actor else actor.get_description()
            s2 = ' dig' if s == 'Du' else ' sig'

            for arg in args:
                if isinstance(arg, basestring):
                    s += ' ' + arg
                    continue

                if player == actor:
                    s += s2 if arg == player else ' ' + arg.get_description(indefinite=False)
                else:
                    s += ' dig' if arg == player else ' ' + arg.get_description(indefinite=False)

            #s = language.pronouns(player, actor, *args)
            player.send(language.sentence(s))
コード例 #19
0
ファイル: emotes.py プロジェクト: philiparvidsson/enigmus-mud
    def __actor_emote(self, actor, args):
        room = actor.container

        if not room or not isinstance(room, Room):
            return

        # args = [actor] + list(args)
        for player in room.get_entities(Player):
            s = "Du" if player == actor else actor.get_description()
            s2 = " dig" if s == "Du" else " sig"

            for arg in args:
                if isinstance(arg, basestring):
                    s += " " + arg
                    continue

                if player == actor:
                    s += s2 if arg == player else " " + arg.get_description(indefinite=False)
                else:
                    s += " dig" if arg == player else " " + arg.get_description(indefinite=False)

            # s = language.pronouns(player, actor, *args)
            player.send(language.sentence(s))
コード例 #20
0
    def __player_command(self, player, command):
        args = command.split(' ')
        command = args[0]
        args = args[1:]

        if command != 'lås':
            return

        unlock = False

        if len(args) > 0 and args[0] == 'upp':
            unlock = True
            args = args[1:]

        i = args.index('med') if 'med' in args else -1
        if i == -1:
            if unlock:
                player.text('Lås upp med vad?')
            else:
                player.text('Lås med vad?')
            return

        key_desc = ' '.join(args[i + 1:])
        unlockable_desc = ' '.join(args[:i])

        key = player.find_best_match(key_desc)
        if not key or not isinstance(key, Key):
            if unlock:
                player.text('Lås upp med vad?')
            else:
                player.text('Lås med vad?')
            return

        unlockable = player.find_best_match(unlockable_desc)
        if not unlockable and player.container:
            unlockable = player.container.find_best_match(unlockable_desc)

        if not unlockable or not isinstance(unlockable, Unlockable):
            if unlock:
                player.text('Lås upp vad?')
            else:
                player.text('Lås vad?')
            return

        if isinstance(unlockable, Container) and unlockable.is_open:
            player.text(
                language.sentence(
                    'Stäng {} först.',
                    unlockable.get_description(indefinite=False)))
            return

        if unlock:
            if not unlockable.is_locked:
                player.text(
                    language.sentence(
                        '{} är inte låst.',
                        unlockable.get_description(indefinite=False)))
                return

            if not player.unlock(unlockable, key):
                player.emote('försöker låsa upp', unlockable, 'men misslyckas')
        else:
            if unlockable.is_locked:
                player.text(
                    language.sentence(
                        '{} är redan låst.',
                        unlockable.get_description(indefinite=False)))
                return

            if not player.lock(unlockable, key):
                player.emote('försöker låsa', unlockable, 'men misslyckas')
コード例 #21
0
    def __player_command(self, player, command):
        args    = command.split(' ')
        command = args[0]
        args    = args[1:]

        if command != 'lås':
            return

        unlock = False

        if len(args) > 0 and args[0] == 'upp':
            unlock = True
            args = args[1:]

        i = args.index('med') if 'med' in args else -1
        if i == -1:
            if unlock:
                player.text('Lås upp med vad?')
            else:
                player.text('Lås med vad?')
            return

        key_desc        = ' '.join(args[i+1:])
        unlockable_desc = ' '.join(args[:i])

        key = player.find_best_match(key_desc)
        if not key or not isinstance(key, Key):
            if unlock:
                player.text('Lås upp med vad?')
            else:
                player.text('Lås med vad?')
            return

        unlockable = player.find_best_match(unlockable_desc)
        if not unlockable and player.container:
            unlockable = player.container.find_best_match(unlockable_desc)

        if not unlockable or not isinstance(unlockable, Unlockable):
            if unlock:
                player.text('Lås upp vad?')
            else:
                player.text('Lås vad?')
            return

        if isinstance(unlockable, Container) and unlockable.is_open:
            player.text(language.sentence('Stäng {} först.', unlockable.get_description(indefinite=False)))
            return

        if unlock:
            if not unlockable.is_locked:
                player.text(language.sentence('{} är inte låst.', unlockable.get_description(indefinite=False)))
                return

            if not player.unlock(unlockable, key):
                player.emote('försöker låsa upp', unlockable, 'men misslyckas')
        else:
            if unlockable.is_locked:
                player.text(language.sentence('{} är redan låst.', unlockable.get_description(indefinite=False)))
                return

            if not player.lock(unlockable, key):
                player.emote('försöker låsa', unlockable, 'men misslyckas')
コード例 #22
0
ファイル: go.py プロジェクト: philiparvidsson/Enigmus-MUD
 def __actor_leave(self, actor, room, exit):
     actor_desc = actor.get_description(indefinite=False)
     for player in room.get_entities(Player):
         # {} left {}.
         player.text(language.sentence('{} gick {}.', actor_desc, exit))
コード例 #23
0
    def look(self, player, args):
        if not player.container:
            return

        if len(args) == 0:
            player.text(player.container.get_description(exclude_actor=player))
            return

        look_inside = False

        # at
        if len(args) > 1 and args[0] == 'på':
            args = args[1:]
        # in
        elif len(args) > 1 and args[0] == 'i':
            args = args[1:]
            look_inside = True

        text = ' '.join(args)
        entity = player.find_best_match(text)

        if not entity:
            entity = player.container.find_best_match(text)

        if look_inside:
            if not isinstance(entity, Container):
                entity = None
            elif not entity.is_open:
                # {} is closed!
                player.text(
                    language.sentence(
                        '{} är stängd!',
                        entity.get_description(indefinite=False)))
                return

        if not entity:
            # Look at/in what?
            player.text('Titta {} vad?'.format('i' if look_inside else 'på'))
            return

        if look_inside:
            if len(entity.entities) == 0:
                # {} is empty.
                player.text(
                    language.sentence(
                        '{} är tom.',
                        entity.get_description(indefinite=False)))
                return

            s = language.list([x.get_description() for x in entity.entities])
            # {} contains: {}
            player.text(
                language.sentence('{} innehåller: {}',
                                  entity.get_description(indefinite=False), s))
            return

        if not isinstance(entity, Detail):
            player.text(language.sentence(entity.get_description()))

        if isinstance(entity, Actor):
            player.text(entity.get_long_description(observer=player))
        else:
            player.text(entity.get_long_description())
コード例 #24
0
ファイル: go.py プロジェクト: philiparvidsson/enigmus-mud
 def __actor_leave(self, actor, room, exit):
     actor_desc = actor.get_description(indefinite=False)
     for player in room.get_entities(Player):
         # {} left {}.
         player.text(language.sentence('{} gick {}.', actor_desc, exit))