Esempio n. 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))
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
    def tick(self, tick):
        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
Esempio n. 6
0
    def tick(self, tick):
        if self.aggro_counter <= 0 and self.threat_lost_counter == 0:
            self.brain.add_action(movetoaction.MoveToAction(self.owner, self.threat.position, self.brain.owner.sight_radius))
            self.aggro_counter = self.aggro_cooldown

        self.aggro_counter -= 1

        if not self.threat_visible:
            self.threat_lost_counter += 1

            if self.threat_lost_counter >= 5:
                self.threat = None
                self.brain.set_state(RatIdleState)
Esempio n. 7
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))
Esempio n. 8
0
    def tick(self, tick):
        if self.aggro_counter <= 0 and self.threat_lost_counter == 0:
            self.brain.add_action(movetoaction.MoveToAction(self.owner, self.threat.position, self.brain.owner.sight_radius))
            self.aggro_counter = self.aggro_cooldown

        self.aggro_counter -= 1

        if not self.threat_visible:
            self.threat_lost_counter += 1

            if self.threat_lost_counter >= 5:
                self.threat = None
                self.brain.set_state(RatIdleState)

        allies = self.brain.allies[:]
        allies.append(self.owner)
        health = sum([a.current_health for a in allies])
Esempio n. 9
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