Example #1
0
    def testShieldDefenceArcherFire(self):
        self.disableRandomChoice(True)
        shooter = self.createUnit(weaponType=self.TYPE_WEAPON_BOW,
                                  damage=100,
                                  agility=60)
        target = self.createUnit(armorType=self.TYPE_ARMOR_LEATHER,
                                 shieldType=self.TYPE_SHIELD_WOOD,
                                 shieldDurability=1000,
                                 shieldBlocking=50,
                                 agility=30,
                                 health=500)

        Actions.archerFire(shooter, target, 1)

        self.assertEqual(target.shieldDurability, 900)
Example #2
0
    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))
Example #3
0
    def archersFire(self, targetFront, bonus):
        """
        :type targetFront: battle.structure.front.Front
        :return:
        """
        log.group('`%s` %i archers fire for enemy `%s`' %
                  (self.it, len(self.range), targetFront.it))

        for archer in self.range:
            if not archer.steps >= 10:
                continue

            shoots = int(archer.steps / 10)
            archer.steps %= 10

            log.unit('`%s` create archery shoots %i' % (archer.it, shoots))
            for i in range(shoots):
                group = targetFront.getRandomGroup()
                if group.getCount() == 0:
                    break

                target = group.getRandomUnit()

                log.unit('`%s` shoot to enemy `%s`' % (archer.it, target.it))
                if Actions.archerFire(archer, target,
                                      bonus) and target.health <= 0:
                    log.unit('`%s` archer killed enemy `%s`' %
                             (archer.it, target.it))
                    group.removeUnit(target)
Example #4
0
    def testMinimalArcherChange(self):
        shooter = self.createUnit(weaponType=self.TYPE_WEAPON_BOW,
                                  damage=100,
                                  agility=0)
        target = self.createUnit(armorType=self.TYPE_ARMOR_LEATHER, agility=30)

        self.assertEqual(Actions._getArcherChance(shooter, target, 1), 5)
Example #5
0
    def testMeleeDamageZeroSword(self):
        attacker = self.createUnit(weaponType=self.TYPE_WEAPON_SWORD,
                                   damage=100,
                                   agility=60)
        target = self.createUnit(armorType=self.TYPE_ARMOR_MAIL)

        self.assertEqual(Actions._getMeleeDamage(attacker, target), 100)
Example #6
0
    def testMeleeDamageBlunt(self):
        attacker = self.createUnit(weaponType=self.TYPE_WEAPON_BLUNT,
                                   damage=100,
                                   agility=60)
        target = self.createUnit(armorType=self.TYPE_ARMOR_MAIL)

        self.assertEqual(Actions._getMeleeDamage(attacker, target), 150)
Example #7
0
    def testArcherDamage(self):
        shooter = self.createUnit(weaponType=self.TYPE_WEAPON_BOW,
                                  damage=100,
                                  strength=100)
        target = self.createUnit(armorType=self.TYPE_ARMOR_LEATHER,
                                 absorption=60)

        self.assertEqual(Actions._getArcheryDamage(shooter, target), 105)
Example #8
0
    def testArcherCriticalDamageNotChose(self):
        shooter = self.createUnit(weaponType=self.TYPE_WEAPON_BOW,
                                  damage=100,
                                  criticalChance=100,
                                  criticalDamage=5)
        self.disableRandomChoice(False)

        self.assertEqual(Actions._getCriticalDamage(shooter, shooter.damage),
                         100)
Example #9
0
    def testArcherFire(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.archerFire(shooter, target, 1))
        self.assertEqual(target.health, 395)
Example #10
0
 def move(self):
     for unit in self.units:
         Actions.move(unit)
Example #11
0
    def testMeleeChanceMaximal(self):
        attacker = self.createUnit(agility=100)
        defender = self.createUnit(agility=0)

        self.assertEqual(Actions._getMeleeChance(attacker, defender), 90)