def __init__(self, world):
        super(ContainerSystem,
              self).__init__(world=world,
                             aspect=Aspect(all_of=set([Container])))

        for entity in self.world.entities_with_aspect(
                Aspect(all_of=set([Moveable]))):
            entity.location.inventory.add(entity)

        self.update()
Exemplo n.º 2
0
    def test_aspect_is_interested_in_exclude(self):
        aspect = Aspect(exclude=set([Container]))

        self.assertFalse(aspect.is_interested_in(self.cat))
        self.assertTrue(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertTrue(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities),
                         set([self.plant, self.brains]))
Exemplo n.º 3
0
    def test_make_aspect_from_assemblage(self):
        factory = Assemblage(components=[Portable])

        aspect = Aspect.make_from(factory)

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertTrue(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities), set([self.cat, self.brains]))
Exemplo n.º 4
0
    def test_aspect_is_interested_in_exclude(self):
        aspect = Aspect(exclude=set([Container]))

        self.assertFalse(aspect.is_interested_in(self.cat))
        self.assertTrue(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertTrue(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities), set([self.plant, self.brains]))
Exemplo n.º 5
0
    def test_aspect_is_interested_in_all_of(self):
        aspect = Aspect(all_of=set([Alive, Portable]))

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertFalse(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities),
                         set([self.cat]))
Exemplo n.º 6
0
    def test_make_aspect_from_assemblage(self):
        factory = Assemblage(components=[Portable])

        aspect = Aspect.make_from(factory)

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertTrue(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities),
                         set([self.cat, self.brains]))
Exemplo n.º 7
0
    def test_aspect_is_interested_in_some_of(self):
        aspect = Aspect(some_of=set([Location, Container]))

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertTrue(aspect.is_interested_in(self.bathtub))
        self.assertTrue(aspect.is_interested_in(self.brains))
        self.assertTrue(aspect.is_interested_in(self.zombie))

        self.assertEqual(
            aspect.select_entities(self.entities),
            set([self.cat, self.bathtub, self.brains, self.zombie]))
Exemplo n.º 8
0
    def test_aspect_is_interested_in_different_categories(self):
        aspect = Aspect(all_of=set([Container]),
                        exclude=set([Moveable]),
                        some_of=set([Location, Portable, Alive]))

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertFalse(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities),
                         set([self.cat]))
Exemplo n.º 9
0
    def test_aspect_is_interested_in_different_categories(self):
        aspect = Aspect(all_of=set([Container]), exclude=set([Moveable]), some_of=set([Location, Portable, Alive]))

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertFalse(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities), set([self.cat]))
Exemplo n.º 10
0
    def test_aspect_is_interested_in_all_of(self):
        aspect = Aspect(all_of=set([Alive, Portable]))

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertFalse(aspect.is_interested_in(self.bathtub))
        self.assertFalse(aspect.is_interested_in(self.brains))
        self.assertFalse(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities), set([self.cat]))
Exemplo n.º 11
0
    def test_aspect_is_interested_in_some_of(self):
        aspect = Aspect(some_of=set([Location, Container]))

        self.assertTrue(aspect.is_interested_in(self.cat))
        self.assertFalse(aspect.is_interested_in(self.plant))
        self.assertTrue(aspect.is_interested_in(self.bathtub))
        self.assertTrue(aspect.is_interested_in(self.brains))
        self.assertTrue(aspect.is_interested_in(self.zombie))

        self.assertEqual(aspect.select_entities(self.entities), set([self.cat, self.bathtub, self.brains, self.zombie]))
Exemplo n.º 12
0
 def __init__(self, world):
     super(NameSystem, self).__init__(world=world,
                                      aspect=Aspect(all_of=set([Name])))
     self.names = defaultdict(lambda: None)
     self.update()
Exemplo n.º 13
0
 def update(self):
     """Updates the `inventory` attribute on all Containers in the World"""
     for entity in self.world.entities_with_aspect(
             Aspect(all_of=set([Moveable]))):
         entity.location.inventory.add(entity)
Exemplo n.º 14
0
 def __init__(self, world):
     super(ViewSystem, self).__init__(world=world,
                                      aspect=Aspect(all_of=set([View])))
Exemplo n.º 15
0
 def __init__(self, world):
     super(DescriptionSystem,
           self).__init__(world=world,
                          aspect=Aspect(all_of=set([Description])))
     self.description_values = defaultdict(lambda: dict)
     self.update()
Exemplo n.º 16
0
import random
import re

from braga import Aspect
from braga.examples import duel

from hogwarts.engine.Command import Command, ChangefulCommand
from hogwarts.engine.exceptions import LogicError

player_aspect = Aspect.make_from(duel.player_factory)


# Command Responses
def _look(world, player):
    return player.location.description


def _inventory(world, player):
    return '/n'.join([thing.name for thing in player.inventory])


def _red_sparks(world, player):
    return "A stream of red sparks shoots out the end of your wand!\n\nJustin's wand spins out of his hand and flies to you.\nYour casting skill for the expelliarmus spell has increased."


def _get_skill(world, player):
    return "\n".join([
        str(player.skill), "Your chance of success is {}/20.".format(
            _get_expelliarmus_skill(player))
    ])
Exemplo n.º 17
0
 def __init__(self, world):
     super(ContextSystem, self).__init__(world=world, aspect=Aspect(all_of=set([components.Contexts])))