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)
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)
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)
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)
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)