Esempio n. 1
0
 def test_drinking_potion_empty_discards_it(self):
     """
     Test that empty potion is discarded from character inventory
     """
     assert_that(self.character.inventory, has_item(self.potion))
     drink(self.character, self.potion)
     assert_that(self.character.inventory, is_not(has_item(self.potion)))
Esempio n. 2
0
 def use_item(self, item):
     """
     Use item in different ways, depending on the item
     """
     if is_potion(item) and is_drinking_legal(self.character, item):
         drink(self.character,
               item)
     elif is_weapon(item):
         if self.character.inventory.weapon is not None:
             unequip(self.character,
                     self.character.inventory.weapon)
         equip(self.character,
               item)
     elif is_armour(item):
         if self.character.inventory.armour is not None:
             unequip(self.character,
                     self.character.inventory.armour)
         equip(self.character,
               item)
     elif is_boots(item):
         if self.character.inventory.boots is not None:
             unequip(self.character,
                     self.character.inventory.boots)
         equip(self.character,
               item)
     elif is_ammunition(item):
         equip(self.character,
               item)
     elif is_trap_bag(item):
         place_trap(self.character,
                    item)
Esempio n. 3
0
 def test_drinking_potion_empty_discards_it(self):
     """
     Test that empty potion is discarded from character inventory
     """
     assert_that(self.character.inventory, has_item(self.potion))
     drink(self.character,
           self.potion)
     assert_that(self.character.inventory, is_not(has_item(self.potion)))
Esempio n. 4
0
    def test_drinking_healing_potion(self):
        """
        Test that character drinking a healing potion gets healed
        """
        drink(self.character, self.potion)

        assert_that(self.character.hit_points, is_(greater_than(1)))
        assert_that(self.potion.maximum_charges_left, is_(equal_to(0)))
Esempio n. 5
0
    def test_drinking_empty_potion(self):
        """
        Test that empty potion has no effect
        """
        self.potion = (ItemBuilder().with_name('empty potion').build())
        drink(self.character, self.potion)

        assert_that(self.character.hit_points, is_(equal_to(1)))
Esempio n. 6
0
    def test_drinking_non_potion(self):
        """
        Test that drinking non-potion item will not crash the system
        """
        item = (ItemBuilder().with_name('club').build())

        self.character.inventory.append(self.potion)
        drink(self.character, item)
Esempio n. 7
0
    def test_drinking_potion_identifies_it(self):
        """
        Test that drinking a potion correctly identifies it
        """
        drink(self.character, self.potion)

        name = self.potion.get_name(self.character)
        assert_that(name, is_(equal_to('healing potion')))
Esempio n. 8
0
    def test_drinking_potion_identifies_it(self):
        """
        Test that drinking a potion correctly identifies it
        """
        drink(self.character,
              self.potion)

        name = self.potion.get_name(self.character)
        assert_that(name, is_(equal_to('healing potion')))
Esempio n. 9
0
    def test_drinking_healing_potion(self):
        """
        Test that character drinking a healing potion gets healed
        """
        drink(self.character,
              self.potion)

        assert_that(self.character.hit_points, is_(greater_than(1)))
        assert_that(self.potion.maximum_charges_left, is_(equal_to(0)))
Esempio n. 10
0
    def test_drinking_empty_potion(self):
        """
        Test that empty potion has no effect
        """
        self.potion = (ItemBuilder()
                            .with_name('empty potion')
                            .build())
        drink(self.character,
              self.potion)

        assert_that(self.character.hit_points, is_(equal_to(1)))
Esempio n. 11
0
    def test_drinking_non_potion(self):
        """
        Test that drinking non-potion item will not crash the system
        """
        item = (ItemBuilder()
                    .with_name('club')
                    .build())

        self.character.inventory.append(self.potion)
        drink(self.character,
              item)
Esempio n. 12
0
    def test_drinking_potion_does_not_discard_it(self):
        """
        Test that non-empty potions are not discarded after drinking
        """
        self.potion = (
            ItemBuilder().with_name('healing potion').with_effect_handle(
                EffectHandleBuilder().with_trigger('on drink').with_charges(
                    5)).build())

        self.character.inventory.append(self.potion)

        assert_that(self.character.inventory, has_item(self.potion))
        drink(self.character, self.potion)
        assert_that(self.character.inventory, has_item(self.potion))
Esempio n. 13
0
    def test_drinking_potion_does_not_discard_it(self):
        """
        Test that non-empty potions are not discarded after drinking
        """
        self.potion = (ItemBuilder()
                            .with_name('healing potion')
                            .with_effect_handle(
                                EffectHandleBuilder()
                                    .with_trigger('on drink')
                                    .with_charges(5))
                            .build())

        self.character.inventory.append(self.potion)

        assert_that(self.character.inventory, has_item(self.potion))
        drink(self.character,
              self.potion)
        assert_that(self.character.inventory, has_item(self.potion))
Esempio n. 14
0
    def test_drinking_triggers_effect(self):
        """
        Test that timed effect is triggered only after enough time
        has passed
        """
        effect_factory = get_effect_creator({'major heal':
                                                {'type': Heal,
                                                 'duration': 12,
                                                 'frequency': 3,
                                                 'tick': 3,
                                                 'healing': 10,
                                                 'icon': 100,
                                                 'title': 'healig',
                                                 'description': 'healing'}})

        pyherc.vtable['\ufdd0:create-effect'] = effect_factory
        
        potion = (ItemBuilder()
                  .with_effect_handle(EffectHandleBuilder()
                               .with_trigger('on drink')
                               .with_effect('major heal')
                               .with_charges(2))
                  .build())

        set_action_factory(ActionFactoryBuilder()
                           .with_drink_factory(DrinkFactoryBuilder()
                                               .with_effect_factory(effect_factory))  # noqa
                           .build())

        character = (CharacterBuilder()
                     .with_hit_points(1)
                     .with_max_hp(10)
                     .build())

        drink(character,
              potion)

        assert_that(character, has_effects(1))
Esempio n. 15
0
    def test_creating_effect(self):
        """
        Test that effect can be created and triggered immediately
        """
        effect_factory = get_effect_creator({'major heal':
                                                {'type': Heal,
                                                 'duration': 0,
                                                 'frequency': 0,
                                                 'tick': 0,
                                                 'healing': 10,
                                                 'icon': 100,
                                                 'title': 'healig',
                                                 'description': 'healing'}})

        pyherc.vtable['\ufdd0:create-effect'] = effect_factory
        
        potion = (ItemBuilder()
                  .with_effect_handle(EffectHandleBuilder()
                               .with_trigger('on drink')
                               .with_effect('major heal')
                               .with_charges(2))
                  .build())

        set_action_factory(ActionFactoryBuilder()
                           .with_drink_factory(DrinkFactoryBuilder()
                                               .with_effect_factory(effect_factory))  # noqa
                           .build())

        character = (CharacterBuilder()
                     .with_hit_points(1)
                     .with_max_hp(10)
                     .build())

        drink(character,
              potion)

        assert_that(character.hit_points, is_(equal_to(10)))
        assert_that(character, has_no_effects())