def get_priority(cls, actor): """ Priority is based on health but adjusted when corpses are close """ if actor.hp >= actor.max_hp: return Priority.Never corpses = actor.level.get_actors_by_team(Team.Corpse) if not corpses: return Priority.Never if not actor.level.get_actors_by_team(Team.Goblin): return Priority.High closest_corpse = utils.get_closest_actor(actor, corpses) dist = utils.get_distance(actor, closest_corpse) hp = actor.hp quarter_hp = actor.max_hp / 4 if hp >= quarter_hp * 3: if dist <= 1: return Priority.High else: return Priority.VeryLow elif hp >= quarter_hp * 2: if dist <= 1: return Priority.High elif dist <= 3: return Priority.Medium else: return Priority.Low else: return Priority.High
def _get_target(cls, actor): goblins = actor.level.get_actors_by_team(Team.Goblin) if not goblins: return None goblin = utils.get_closest_actor(actor, goblins) return goblin
def _get_target(cls, actor): corpses = actor.level.get_actors_by_team(Team.Corpse) if not corpses: return None target = utils.get_closest_actor(actor, corpses) return target
def test_get_closest_actor_returns_closest_actor(): actor = actors.Egg(None, 0, 0) closest = actors.Cocoon(None, 1, 0) all_objects = [ closest, actors.Goblin(None, 2, 2), actors.Goblin(None, 1, 1) ] result = utils.get_closest_actor(actor, all_objects) assert result is closest
def act(self): if self.stunned > 0: self.stunned -= 1 return if not self.dead: spiders = self.level.get_actors_by_team(Team.SpiderQueen) if spiders: closest_spider = utils.get_closest_actor(self, spiders) return movement.step_to_target(self, closest_spider)
def _get_target(cls, actor): spiders = actor.level.get_actors_by_team(Team.SpiderQueen) cocoons = [ c for c in spiders if c.actor_type == ActorTypes.Cocoon and c.burrowed is False ] if not cocoons: return None cocoon = utils.get_closest_actor(actor, cocoons) return cocoon
def get_priority(cls, actor): goblins = actor.level.get_actors_by_team(Team.Goblin) if not goblins: return Priority.Never goblin = utils.get_closest_actor(actor, goblins) dist = utils.get_distance(actor, goblin) if dist <= 1: return Priority.Extreme elif dist == 2: return Priority.Medium else: return Priority.Low
def get_priority(cls, actor): if actor.cooldowns.get("lay_egg"): return Priority.Never enemies = actor.level.get_actors_by_team(Team.Goblin) if enemies: closest_enemy = utils.get_closest_actor(actor, enemies) dist = utils.get_distance(actor, closest_enemy) if dist >= 10: return Priority.High elif dist >= 5: return Priority.Medium else: return Priority.Never return Priority.High