Пример #1
0
    def tick(self, tick):
        # Wait for our current plan to finish
        if self.brain.actions:
            return

        # Collect spear if we don't have one
        if not self.owner.weapon.isinstance('Spear'):
            s = [
                e for e in self.owner.visible_entities if e.isinstance('Spear')
            ]
            if s:
                s = sorted(s,
                           key=lambda t: utils.math.distance(
                               self.owner.position, t.position))[0]
                act = movetoaction.MoveToAction(self.owner, s.position)
                self.brain.add_action(act)
                self.brain.add_action(action.IdleAction(self.owner))
                return

        # Wander
        if self.owner.visible_tiles:
            dest = random.choice(list(self.owner.visible_tiles))
            act = movetoaction.MoveToAction(self.owner, dest)
            self.brain.add_action(act)
            self.brain.add_action(action.IdleAction(self.owner))
Пример #2
0
 def on_state_exit(self, next_state):
     if isinstance(next_state, KoboldHurtState):
         ani = animation.Flash('?',
                               fg=palette.BRIGHT_YELLOW,
                               bg=palette.BLACK)
         self.owner.append(ani)
         self.brain.add_action(action.IdleAction(self.owner))
Пример #3
0
    def tick(self, tick):
        if not self.brain.actions:
            # Lay babies...
            if random.random() < 1 / 32:
                corpses = [e for e in self.owner.visible_entities if e.isinstance('Corpse') and e.position != self.owner.position]
                corpses = sorted(corpses, key=lambda c: utils.math.distance(self.owner.position, c.position))

                target = corpses[0] if corpses else None

                if target:
                    act = movetoaction.MoveToAction(self.owner, target.position)
                    self.brain.add_action(act)

            # ...or wander.
            else:
                batched_action = action.BatchedAction(self.owner)

                for _ in range(random.randint(1, 3)):
                    idle_action = action.IdleAction(self.owner)
                    idle_action.parent = batched_action
                    self.brain.add_action(idle_action)

                wander_action = wanderaction.WanderAction(self.owner)
                wander_action.parent = batched_action
                self.brain.add_action(wander_action)

                self.brain.add_action(batched_action)
Пример #4
0
    def tick(self, tick):
        if not self.brain.actions:
            # Attempt to heal
            # TODO: Have a more generic way of finding healing items
            corpses = [
                e for e in self.owner.visible_entities
                if e.isinstance('Corpse')
            ]
            corpses = sorted(corpses,
                             key=lambda c: utils.math.distance(
                                 self.owner.position, c.position))

            target = corpses[0] if corpses else None

            if target:
                act = movetoaction.MoveToAction(self.owner, target.position)
                self.brain.add_action(act)

            # Wander otherwise
            else:
                batched_action = action.BatchedAction(self.owner)

                for _ in range(random.randint(1, 3)):
                    idle_action = action.IdleAction(self.owner)
                    idle_action.parent = batched_action
                    self.brain.add_action(idle_action)

                wander_action = wanderaction.WanderAction(self.owner)
                wander_action.parent = batched_action
                self.brain.add_action(wander_action)

                self.brain.add_action(batched_action)
Пример #5
0
    def tick(self, tick):
        if not self.brain.actions:
            # Attempt to heal
            corpses = [e for e in self.owner.visible_entities if e.isinstance('Corpse') and e.position != self.owner.position]
            corpses = sorted(corpses, key=lambda c: utils.math.distance(self.owner.position, c.position))

            target = corpses[0] if corpses else None

            if not target:
                weaker = [e for e in self.owner.visible_entities if e.isinstance('Creature') and e.current_health == 1]
                sorted(weaker, key=lambda w: utils.math.distance(self.owner.position, w.position))
                target = weaker[0] if weaker else None

            if target:
                act = movetoaction.MoveToAction(self.owner, target.position)
                self.brain.add_action(act)

            # Wander otherwise
            else:
                batched_action = action.BatchedAction(self.owner)

                for _ in range(random.randint(1, 3)):
                    idle_action = action.IdleAction(self.owner)
                    idle_action.parent = batched_action
                    self.brain.add_action(idle_action)

                wander_action = wanderaction.WanderAction(self.owner)
                wander_action.parent = batched_action
                self.brain.add_action(wander_action)

                self.brain.add_action(batched_action)
Пример #6
0
    def tick(self, tick):
        if self.brain.actions:
            return

        # Attempt to heal
        potions = [
            e for e in self.owner.visible_entities
            if e.isinstance('Potion') and e.position != self.owner.position
        ]
        potions = sorted(
            potions,
            key=lambda c: utils.math.distance(self.owner.position, c.position))

        if potions:
            act = movetoaction.MoveToAction(self.owner, potions[0].position)
            self.brain.add_action(act)
            return

        # Collect spear if we don't have one
        if not self.owner.weapon.isinstance('Spear'):
            s = [
                e for e in self.owner.visible_entities if e.isinstance('Spear')
            ]
            if s:
                s = sorted(s,
                           key=lambda t: utils.math.distance(
                               self.owner.position, t.position))[0]
                act = movetoaction.MoveToAction(self.owner, s.position)
                self.brain.add_action(act)
                self.brain.add_action(action.IdleAction(self.owner))
                return

        # Wander
        if self.owner.visible_tiles:
            dest = random.choice(list(self.owner.visible_tiles))
            act = movetoaction.MoveToAction(self.owner, dest)
            self.brain.add_action(act)
            self.brain.add_action(action.IdleAction(self.owner))
Пример #7
0
    def tick(self, tick):
        # Idle behavior. Wait and wander.
        if not self.brain.actions:
            batched_action = action.BatchedAction(self.owner)

            for _ in range(random.randint(1, 3)):
                idle_action = action.IdleAction(self.owner)
                idle_action.parent = batched_action
                self.brain.add_action(idle_action)

            wander_action = wanderaction.WanderAction(self.owner)
            wander_action.parent = batched_action
            self.brain.add_action(wander_action)

            self.brain.add_action(batched_action)
Пример #8
0
    def tick(self, tick):
        # Idle behavior. Wait and wander.
        if not self.brain.actions:
            batched_action = action.BatchedAction(self.owner)

            for _ in range(random.randint(1, 3)):
                idle_action = action.IdleAction(self.owner)
                idle_action.parent = batched_action
                self.brain.add_action(idle_action)

            wander_action = wanderaction.WanderAction(self.owner)
            wander_action.parent = batched_action
            self.brain.add_action(wander_action)

            self.brain.add_action(batched_action)

        self.turns_util_sleep -= 1
        if self.turns_util_sleep <= 0 and random.random() < 1 / 32:
            self.brain.set_state(creature.CreatureSleepState)
Пример #9
0
 def on_state_enter(self, prev_state):
     ani = animation.Flash('!', fg=palette.BRIGHT_BLUE, bg=palette.BLACK)
     self.owner.append(ani)
     self.brain.add_action(action.IdleAction(self.owner))
Пример #10
0
    def get_action(self, requester=None):
        if requester.weapon.isinstance('PickAxe'):
            direction = utils.math.sub(self.position, requester.position)
            return attackaction.AttackAction(requester, self, direction)

        return action.IdleAction(requester)
Пример #11
0
    def tick(self, tick):
        if self.owner.weapon.isinstance('Spear'):
            # Are we lined up for a throw?
            if self.current_target.x == self.owner.x or self.current_target.y == self.owner.y:

                # Are we in range?
                dist = utils.math.distance(self.owner.position,
                                           self.current_target.position)
                if dist <= self.owner.weapon.throw_distance and dist > 1:
                    dir = utils.math.sub(self.current_target.position,
                                         self.owner.position)
                    dir = utils.math.normalize(dir)
                    dir = tuple(map(lambda i: int(i), dir))

                    s = self.owner.weapon
                    s.remove()
                    s.position = utils.math.add(self.owner.position, dir)
                    instances.scene_root.append(s)
                    self.owner.equip_weapon(fist.Fist())

                    act = throwaction.ThrowAction(self.owner, s)
                    self.brain.add_action(act)
                    self.brain.add_action(action.IdleAction(self.owner))
                    return

            # Attempt to line up a throw
            elif not self.brain.actions:
                dir = utils.math.sub(self.current_target.position,
                                     self.owner.position)

                if abs(dir[0]) < abs(dir[1]):
                    dir = dir[0], 0

                else:
                    dir = 0, dir[1]

                dir = utils.math.normalize(dir)
                dir = tuple(map(lambda i: int(i), dir))
                act = moveaction.MoveAction(self.owner, dir)
                self.brain.add_action(act)
                return

            # Attack enemy
            if self.aggro_counter <= 0:
                self.brain.add_action(
                    movetoaction.MoveToAction(self.owner,
                                              self.current_target.position,
                                              self.brain.owner.sight_radius))
                self.aggro_counter = self.aggro_cooldown

            self.aggro_counter -= 1
            return

        # Go get our spear
        elif not self.brain.actions:
            s = [
                e for e in self.owner.visible_entities if e.isinstance('Spear')
            ]
            if s:
                s = sorted(s,
                           key=lambda t: utils.math.distance(
                               self.owner.position, t.position))[0]
                act = movetoaction.MoveToAction(self.owner, s.position)
                self.brain.add_action(act)
                self.brain.add_action(action.IdleAction(self.owner))
                return

        # Attack enemy
        if self.aggro_counter <= 0:
            self.brain.add_action(
                movetoaction.MoveToAction(self.owner,
                                          self.current_target.position,
                                          self.brain.owner.sight_radius))
            self.aggro_counter = self.aggro_cooldown

        self.aggro_counter -= 1