Esempio n. 1
0
    def tryAttacking(self):
        if self.canAttackTimer.timeIsUp():
            logger.debug("{}: Check if i can attack player".format(self.name))
            if self.canAttackPlayer():
                if (EntityFinder.numEnemiesInState(self.brain.owner.world,
                                                   'attack') <
                        Config.maxEnemiesInStateAttacking):
                    self.brain.pop()
                    self.brain.push("attackwindup")

            self.canAttackTimer.reset()
Esempio n. 2
0
    def drawStats(self):
        x = 2
        y = 1
        color, attr = ColorPalette.getColorByColorType(ColorType.menu)

        o = []

        enemiesAlive = EntityFinder.numEnemies(world=self.world)
        enemiesAttacking = EntityFinder.numEnemiesInState(world=self.world,
                                                          state='attack')
        enemiesChasing = EntityFinder.numEnemiesInState(world=self.world,
                                                        state='chase')
        enemiesWandering = EntityFinder.numEnemiesInState(world=self.world,
                                                          state='wander')

        o.append("Enemies:")
        o.append("  Alive     : {}".format(enemiesAlive))
        o.append("  Attacking : {}".format(enemiesAttacking))
        o.append("  Chasing   : {}".format(enemiesChasing))
        o.append("  Wandering: {}".format(enemiesWandering))

        playerEntity = EntityFinder.findPlayer(self.world)
        playerRenderable = self.world.component_for_entity(
            playerEntity, Renderable)

        o.append('Player:')
        o.append('  Location:' + str(playerRenderable.getLocation()))

        o.append('Scene:')
        o.append('  Name:' + self.sceneManager.currentScene.name)
        o.append('  Scne State:' + str(self.sceneProcessor.state))
        o.append('  Enemies Alive:' +
                 str(self.sceneProcessor.numEnemiesAlive()))
        o.append('  Enemies Visible:' +
                 str(self.sceneProcessor.numEnemiesVisible()))

        n = 0
        while n < len(o):
            self.viewport.addstr(y + n, x, o[n], color=color, attr=attr)
            n += 1
Esempio n. 3
0
    def process(self, dt):
        meRenderable = self.brain.owner.world.component_for_entity(
            self.brain.owner.entity, system.graphics.renderable.Renderable)
        meAttackable = self.brain.owner.world.component_for_entity(
            self.brain.owner.entity, system.gamelogic.attackable.Attackable)
        meEnemy = self.brain.owner.world.component_for_entity(
            self.brain.owner.entity, system.gamelogic.enemy.Enemy)

        if meAttackable.isStunned:
            return

        self.lastInputTimer.advance(dt)

        if self.lastInputTimer.timeIsUp():
            self.getInputWander()
            self.lastInputTimer.reset()

        if self.timeIsUp():
            if (EntityFinder.numEnemiesInState(self.brain.owner.world, 'chase')
                    < Config.maxEnemiesInStateChase):
                logger.info("{}: Too long wandering, chase again a bit".format(
                    self.owner))
                self.brain.pop()
                self.brain.push("chase")

        elif Utility.isIdentical(meRenderable.getLocation(), self.destCoord):
            # No reset of wander state atm, just a new location
            self.chooseDestination()

        else:
            # check if player is close
            for message in messaging.getByType(MessageType.PlayerLocation):
                distance = Utility.distance(
                    message.data,
                    meRenderable.getLocation())

                if distance['sum'] < meEnemy.enemyInfo.wanderAttackDistance:
                    logger.info("{}: Player is close, chasing".format(self.owner))
                    self.brain.pop()
                    self.brain.push("chase")