def test_merging_ammunition_in_pickup(self): """ Same kind of ammunition should be merged when picked up """ ammo_1 = (ItemBuilder() .with_name('arrow') .with_count(10) .build()) ammo_2 = (ItemBuilder() .with_name('arrow') .with_count(20) .build()) add_item(self.level, self.character.location, ammo_1) add_item(self.level, self.character.location, ammo_2) pick_up(self.character, ammo_1) pick_up(self.character, ammo_2) assert_that(len(self.character.inventory), is_(equal_to(1))) item = self.character.inventory[0] assert_that(item.ammunition_data.count, is_(equal_to(30)))
def test_armour_is_used(self): """ Test that armoud used by target is used """ character = CharacterBuilder().build() armour = ItemBuilder().build() armour.armour_data = mock() armour.armour_data.damage_reduction = 1 character.inventory.armour = armour damage = new_damage([(5, "crushing")]) damage_inflicted = damage(target=character) assert_that(damage_inflicted[0], is_(equal_to(4)))
def Club(): """ Creates a club """ item = (ItemBuilder().with_name('club').with_damage(3, 'crushing').build()) return item
def test_armour_is_used(self): """ Test that armoud used by target is used """ character = CharacterBuilder().build() armour = ItemBuilder().build() armour.armour_data = mock() armour.armour_data.damage_reduction = 1 character.inventory.armour = armour damage = new_damage([(5, 'crushing')]) damage_inflicted = damage(target=character) assert_that(damage_inflicted[0], is_(equal_to(4)))
def setup(self): """ Setup the test case """ self.rng = Random() self.model = mock() self.effect_factory = get_effect_creator({ 'heal': { 'type': Heal, 'duration': 0, 'frequency': 0, 'tick': 0, 'healing': 10, 'icon': 101, 'title': 'title', 'description': 'major heal' } }) drink_factory = DrinkFactory(self.effect_factory) set_action_factory(ActionFactory(self.model, drink_factory)) self.character = ( CharacterBuilder().with_hit_points(1).with_max_hp(5).build()) effect = (HealBuilder().with_duration(0).with_frequency(0).with_tick( 0).with_healing(5).with_target(self.character).build()) self.potion = ( ItemBuilder().with_name('healing potion').with_effect_handle( EffectHandleBuilder().with_trigger('on drink').with_effect( 'heal')).build()) self.character.inventory.append(self.potion)
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)))
def test_less_than_double_protection_is_not_negated(self): """ Damage that is less than protection, but higher than half of the protection should deal 1 point of damage """ character = CharacterBuilder().build() armour = ItemBuilder().build() armour.armour_data = mock() armour.armour_data.damage_reduction = 3 character.inventory.armour = armour damage = new_damage([(2, 'crushing')]) damage_inflicted = damage(target=character) assert_that(damage_inflicted[0], is_(equal_to(1)))
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)
def Warhammer(): """ Creates a warhammer """ item = (ItemBuilder().with_name('warhammer').with_damage( 7, 'crushing').with_speed(0.7).build()) return item
def Sword(): """ Creates a sword """ item = (ItemBuilder().with_name('sword').with_damage( 2, 'piercing').with_damage(2, 'slashing').build()) return item
def Dagger(): """ Creates a dagger """ item = (ItemBuilder().with_name('dagger').with_damage(2, 'piercing').build()) return item
def Arrows(): """ Creates a bundle of arrows """ item = (ItemBuilder().with_name('arrow').with_range_damage( 2, 'piercing').with_ammunition_type('arrow').with_count(10).build()) return item
def Bow(): """ Creates a bow """ item = (ItemBuilder().with_name('bow').with_damage( 1, 'crushing').with_required_ammunition_type('arrow').build()) return item
def test_less_than_double_protection_is_not_negated(self): """ Damage that is less than protection, but higher than half of the protection should deal 1 point of damage """ character = CharacterBuilder().build() armour = ItemBuilder().build() armour.armour_data = mock() armour.armour_data.damage_reduction = 3 character.inventory.armour = armour damage = new_damage([(2, "crushing")]) damage_inflicted = damage(target=character) assert_that(damage_inflicted[0], is_(equal_to(1)))
def Rune(): """ Creates a rune """ item = (ItemBuilder() .with_name('rune') .build()) item.old_values = {} return item
def test_melee_combat_is_handled(self): """ Damage modifiers should be handled in melee combat too """ weapon = (ItemBuilder().with_name('hammer').with_damage( 2, 'crushing').build()) self.character1.inventory.weapon = weapon pyherc.vtable['\ufdd0:attack'](self.character1, 3) assert_that(self.character2.hit_points, is_(equal_to(7)))
def test_wear_boots(self): """ Test that boots can be worn """ character = CharacterBuilder().build() boots = (ItemBuilder().with_name('boots').with_boots_speed_modifier( 1).build()) equip(character, boots) assert_that(character, is_wearing_boots(boots))
def test_wear_armour(self): """ Test that armour can be worn """ character = CharacterBuilder().build() armour = (ItemBuilder().with_damage_reduction(2).with_speed_modifier( 1).with_name('leather armour').build()) equip(character, armour) assert_that(character, is_wearing_armour(armour))
def test_taking_off_boots(self): """ Boots can be removed """ character = CharacterBuilder().build() boots = (ItemBuilder().with_name('boots').with_boots_speed_modifier( 1).build()) character.inventory.boots = boots unequip(character, boots) assert_that(character, is_not(is_wearing_boots(boots)))
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))
def test_worn_boots_effects(self): """ Boots' effects are reported as user's effects """ effect = (EffectBuilder() .build()) item = (ItemBuilder() .with_effect(effect) .build()) self.character.inventory.boots = item assert_that(self.character, has_effect(effect))
def setup(self): """ Setup test cases """ self.character = (CharacterBuilder().with_hit_points(10).build()) self.target = (CharacterBuilder().with_hit_points(10).build()) self.level = (LevelBuilder().build()) add_character(self.level, (2, 2), self.character) add_character(self.level, (5, 2), self.target) bow = (ItemBuilder().with_name('bow').with_required_ammunition_type( 'arrow').with_damage(1, 'crushing').build()) self.arrows = (ItemBuilder().with_name('arrows').with_ammunition_type( 'arrow').with_range_damage(3, 'piercing').with_count(10).build()) self.character.inventory.append(bow) self.character.inventory.append(self.arrows) self.character.inventory.weapon = bow self.character.inventory.projectiles = self.arrows set_action_factory(ActionFactoryBuilder().build())
def test_is_proficient(self): """ Test that weapon proficiency of character can be checked """ creature = CharacterBuilder().build() weapon = (ItemBuilder().with_name('club').with_tag('weapon').with_tag( 'one-handed weapon').with_tag('melee').with_tag( 'simple weapon').with_damage( 2, 'bashing').with_weapon_type('simple').build()) proficiency = creature.is_proficient(weapon) assert_that(proficiency, is_(equal_to(False))) creature.feats.append(WeaponProficiency('simple')) proficiency = creature.is_proficient(weapon) assert_that(proficiency, is_(equal_to(True)))
def setup(self): """ Setup test cases """ self.item = (ItemBuilder() .build()) self.model = Model() self.level = LevelBuilder().build() self.character = (CharacterBuilder() .with_location((5, 5)) .with_level(self.level) .with_model(self.model) .build()) add_item(self.level, (5, 5), self.item) set_action_factory(ActionFactoryBuilder() .with_inventory_factory() .build())
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())
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))