def meleeAttack(self): targetGroup = self.getTarget() infinityGenerator = itertools.cycle(targetGroup.getUnits()) for unit in self.getUnits(): if not unit.steps >= 10: log.unit('`%s` skip step, he is weak') continue blows = int(unit.steps / 10) unit.steps %= 10 log.unit('`%s` has blows %i' % (unit.it, blows)) for blow in range(blows): target = None for i in range(targetGroup.getCount()): tmp = next(infinityGenerator) if targetGroup.hasUnit(tmp): target = tmp break if target is None: log.group('`%s` killed enemy group `%s`' % (self.it, targetGroup.it)) self.removeTarget() return log.unit('`%s` blow enemy `%s`' % (unit.it, target.it)) if Actions.meleeFire(unit, target) and target.health <= 0: targetGroup.removeUnit(target) log.unit('`%s` infantry killed enemy `%s`' % (unit.it, target.it))
def meleeFire(self): self.disableRandomChoice(True) shooter = self.createUnit(weaponType=self.TYPE_WEAPON_BOW, damage=100, agility=60) target = self.createUnit(armorType=self.TYPE_ARMOR_LEATHER, agility=30, health=500) self.assertTrue(Actions.meleeFire(shooter, target)) self.assertEqual(target.health, 395)