Ejemplo n.º 1
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))
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def setTarget(self, target):
        self.target = target
        log.group('`%s` set melee target `%s`' % (self, self.target))

        if target and not target.getTarget():
            target.setTarget(self)
Ejemplo n.º 4
0
 def removeTarget(self):
     self.target = None
     log.group('`%s` remove target' % self.it)
Ejemplo n.º 5
0
    def importData(self, attacker, defender, location):
        """
        :type attacker: battle.structure.front.FrontCollection
        :type defender: battle.structure.front.FrontCollection
        :type location: battle.places.abstract.AbstractPlace
        """
        self.attacker = attacker
        self.defender = defender
        self.location = location

        self.attacker.setLocation(location)
        self.defender.setLocation(location)

        self.attacker.it = 'attacker'
        self.defender.it = 'defender'

        self.attacker.get(Front.TYPE_AVANGARD).it = 'attacker_avangard'
        self.attacker.get(Front.TYPE_LEFT_FLANG).it = 'attacker_left_flang'
        self.attacker.get(Front.TYPE_RIGHT_FLANG).it = 'attacker_right_flang'
        self.attacker.get(Front.TYPE_REAR).it = 'attacker_rear'

        self.defender.get(Front.TYPE_AVANGARD).it = 'defender_avangard'
        self.defender.get(Front.TYPE_LEFT_FLANG).it = 'defender_left_flang'
        self.defender.get(Front.TYPE_RIGHT_FLANG).it = 'defender_right_flang'
        self.defender.get(Front.TYPE_REAR).it = 'defender_rear'

        for direction in Front.TYPES:
            i = 1
            for group in self.attacker.get(direction).getGroups():
                group.it = self.attacker.get(direction).it + ('_group_%i' % i)

                y = 1
                for unit in group.getUnits():
                    unit.it = group.it + '_unit_%s' % y
                    y += 1

                i += 1

            i = 1
            for group in self.defender.get(direction).getGroups():
                group.it = self.defender.get(direction).it + ('_group_%i' % i)

                y = 1
                for unit in group.getUnits():
                    unit.it = group.it + '_unit_%s' % y
                    y += 1

                i += 1

        log.battle('INFORMATION ABOUT LOAD DATA')

        for direction in Front.TYPES:
            front = self.attacker.get(direction)
            log.front('%s front' % front.it)

            for group in front.getGroups():
                log.group('%s group' % group.it)

                if group.general:
                    log.unit('%s general with id %s' % (group.it, group.general.it))

                for unit in group.getUnits():
                    log.unit('%s unit with id %s' % (unit.it, unit._id))

        for direction in Front.TYPES:
            front = self.defender.get(direction)
            log.front('%s front' % front.it)

            for group in front.getGroups():
                log.group('%s group' % group.it)

                if group.general:
                    log.unit('%s general with id %s' % (group.it, group.general.it))

                for unit in group.getUnits():
                    log.unit('%s unit with id %s' % (unit.it, unit._id))