def real_weapon(my_sword_blueprint, bronze, usual): return Weapon("test axe1", Damage(50, DamageTypes.SLASH), 50, blueprint=my_sword_blueprint, material=bronze, quality=usual)
def test_can_take_damage(obstacle): health_before = obstacle.health dmg = Damage(50, DamageTypes.SONIC) DamageEvent(dmg, obstacle) health_after = obstacle.health assert health_after < health_before
def _lightning_bolt_callback(active, single_unit_targeting): source = active.owner target = single_unit_targeting.unit spell = active.spell n_damage = spell.amount dmg = Damage(n_damage, DamageTypes.LIGHTNING) DamageEvent(dmg, target=target, source=source)
def distance_between(self, n1, n2): assert self.unit is not None if n2 in self.battlefield.units_at: obstacle = self.battlefield.units_at[n2] damage_per_turn = Damage.calculate_damage(self.unit.get_melee_weapon().damage, obstacle)[0] if damage_per_turn == 0: return StarPathSearch.really_big_number n_turns = obstacle.health / damage_per_turn return n_turns + 1 else: return 1
def resolve(self): _, armor_dur_dmg, weapon_dur_dmg = Damage.calculate_damage( self.damage, self.target, self.impact_factor) body_armor = self.target.equipment["body"] if body_armor and body_armor.durability: body_armor.durability -= armor_dur_dmg if self.weapon and self.weapon.durability: self.weapon.durability -= weapon_dur_dmg self.target.lose_health(self.amount, self.source)
def test_immortality(game, hero): trig = immortality(hero) dmg = Damage(200, DamageTypes.ACID) while hero.health > 0: DamageEvent(dmg, hero) assert hero.alive trig.deactivate() DamageEvent(dmg, hero) assert not hero.alive
def test_refraction(game, hero, n): refraction(hero, n) dmg = Damage(200, DamageTypes.FROST) for _ in range(n): DamageEvent(dmg, hero) assert hero.health == hero.max_health DamageEvent(dmg, hero) assert hero.health < hero.max_health
def test_damage_to_attackers(game, hero, pirate_band): trig = damage_to_attackers(hero, hero, Damage(15, DamageTypes.FIRE)) for pirate in pirate_band: Attack.attack(pirate, hero) assert pirate.health < pirate.max_health trig.deactivate() health_before = [pirate.health for pirate in pirate_band] for pirate in pirate_band: Attack.attack(pirate, hero) assert [pirate.health for pirate in pirate_band] == health_before
def test_armor_reduces_damage(hero): hp_before_dmg = hero.health dmg = Damage(5, DamageTypes.FIRE) DamageEvent(dmg, hero) dealt_no_armor = hp_before_dmg - hero.health hp_before_dmg = hero.health armor = Armor(3) hero.natural_armor = armor DamageEvent(dmg, hero) dealt_armor = hp_before_dmg - hero.health assert dealt_no_armor > dealt_armor
def test_undead_n_hits(game, hero, n): trig = upgrade_hits(hero, n) damage_amount = 33 dmg = Damage(damage_amount, DamageTypes.ACID) for _ in range(n): hp_before = hero.health DamageEvent(dmg, hero, source=hero, impact_factor=ImpactFactor.HIT) hp_after = hero.health assert hp_before - hp_after > damage_amount hp_before = hero.health DamageEvent(dmg, hero, source=hero, impact_factor=ImpactFactor.HIT) hp_after = hero.health assert hp_before - hp_after <= damage_amount
def test_undead_n_hits(game, hero, n): undead_n_hits(hero, n) dmg = Damage(200, DamageTypes.ACID) while hero.health > 0: DamageEvent(dmg, hero) assert hero.alive n_left = n - 1 for _ in range(n_left): DamageEvent(dmg, hero) assert hero.alive DamageEvent(dmg, hero) assert not hero.alive
def test_interrupting_damage_to_attackers(game, hero, pirate_band, no_chances): trig = damage_to_attackers(hero, hero, Damage(1500, DamageTypes.LIGHTNING), interrupt=True) for pirate in pirate_band: Attack.attack(pirate, hero) assert not pirate.alive assert hero.health == hero.max_health break trig.deactivate() alive_band = [pirate for pirate in pirate_band if pirate.alive] health_before = [pirate.health for pirate in alive_band] for pirate in alive_band: hero_hp_before = hero.health Attack.attack(pirate, hero) assert hero.health < hero_hp_before assert [pirate.health for pirate in alive_band] == health_before
def amount(self): return Damage.calculate_damage(self.damage, self.target, self.impact_factor)[0]
def get_unarmed_weapon(self): dmg = Damage(amount=self.str * Unit.UNARMED_DAMAGE_PER_STR, type=self.unarmed_damage_type) return Weapon(name="Fists", damage=dmg, mastery=MasteriesEnum.UNARMED)
class FireDamage50: fixed_damage = Damage(50, DamageTypes.FIRE) @staticmethod def apply(source, target): DamageEvent(FireDamage50.fixed_damage, target, source=source)
def dmg(request): yield Damage(5, request.param)
def apply(source, target): damage = Damage(source.int * 5, DamageTypes.FIRE) DamageEvent(damage, target, source=source)
def weapon(): return Weapon("test axe1", Damage(50, DamageTypes.SLASH), 50)