Esempio n. 1
0
class TestStatues(object):
    """
    Test handling of statues (mainly mimicing items)
    """

    def __init__(self):
        """
        Default constructor
        """
        super(TestStatues, self).__init__()

    def test_deactivating_creature(self):
        """
        Test that activated character can deactivate
        """
        self.model = Model()

        creature = (CharacterBuilder()
                        .with_model(self.model)
                        .with_name('Mimic')
                        .build())

        item = (ItemBuilder()
                    .with_name('Chest')
                    .build())

        creature.set_mimic_item(item)

        self.model.dungeon = Dungeon()

        self.level1 = LevelBuilder().build()
        self.model.dungeon.levels = self.level1

        self.level1.add_creature(creature, self.level1.find_free_space())

        location = creature.location

        creatures = self.level1.get_creature_at(location)
        items = self.level1.get_items_at(location)
        assert_that(creatures, is_(same_instance(creature)))
        assert_that(len(items), is_(equal_to(0)))

        deactivate(self.model, creature)

        creatures = self.level1.get_creature_at(location)
        items = self.level1.get_items_at(location)
        assert_that(creatures, is_(none()))
        assert_that(len(items), is_(equal_to(1)))
Esempio n. 2
0
class TestMeleeCombat(object):
    """
    Class for testing melee combat related rules
    """
    def __init__(self):
        """
        Default constructor
        """
        super(TestMeleeCombat, self).__init__()
        self.level = None
        self.modle = None
        self.character1 = None
        self.character2 = None
        self.action_factory = None

    def setup(self):
        """
        Setup for testcases
        """

        self.model = Model()

        self.action_factory = (ActionFactoryBuilder()
                                    .with_attack_factory()
                                    .build())

        self.character1 = (CharacterBuilder()
                                .with_model(self.model)
                                .with_action_factory(self.action_factory)
                                .with_speed(1)
                                .with_tick(1)
                                .with_hit_points(10)
                                .with_attack(3)
                                .with_body(5)
                                .build())

        self.character2 = (CharacterBuilder()
                                .with_model(self.model)
                                .with_action_factory(self.action_factory)
                                .with_speed(1)
                                .with_tick(1)
                                .with_hit_points(10)
                                .with_attack(3)
                                .with_body(5)
                                .build())

        self.model.dungeon = Dungeon()
        self.level = LevelBuilder().build()

        self.model.dungeon.levels = self.level

        self.level.add_creature(self.character1, (5, 5))
        self.level.add_creature(self.character2, (6, 5))

    def test_get_unarmed_action(self):
        """
        Test that unarmed combat action can be generated
        """
        rng = mock()

        action = self.action_factory.get_action(AttackParameters(
                                                      self.character1,
                                                      3,
                                                      'unarmed',
                                                      rng))

        assert_that(action, is_(instance_of(AttackAction)))
        assert_that(action.attack_type, is_(equal_to('unarmed')))

    def test_events_in_unarmed_combat(self):
        """
        Test that attacking raises events
        """
        character1 = (CharacterBuilder()
                        .with_model(self.model)
                        .with_action_factory(self.action_factory)
                        .with_attack(12)
                        .with_speed(1)
                        .with_tick(0)
                        .build())

        self.level.add_creature(character1, (2, 2))

        character2 = mock(Character)
        character2.hit_points = 20
        self.level.add_creature(character2, (2, 3))

        character1.perform_attack(5)

        verify(character2).receive_event(any())