def take_turn(self, target, fov_map, game_map, entities): results = [] monster = self.owner if libtcod.map_is_in_fov(fov_map, monster.x, monster.y): if randint(1, 100) < 5: message_log.add_message( Message( 'The shaman barks something, and a goblin materializes beside you!', libtcod.light_violet)) monster = Entity((randint(-3, 3) + target.x), (randint(-3, 3) + target.y), 'g', libtcod.green, 'Clanfear Goblin', blocks=True, render_order=RenderOrder.ACTOR, fighter=Fighter(hp=15, defense=1, power=2, xp=45), ai=BasicMonster(), inventory=Inventory(5)) entities.add_new_entity(monster) elif monster.distance_to(target) >= 2: monster.move_astar(target, entities, game_map) elif target.fighter.hp > 0: attack_results = monster.fighter.attack(target) results.extend(attack_results) return results
def cast_lightning(caster: Entity, *, entities: List[Entity], fov_map: tcod.map.Map, damage: int, maximum_range: float, **_: Any) -> ActionResults: results = [] target = None closest_distance = maximum_range + 1 for entity in entities: if (entity.fighter and entity != caster and fov_map.fov[entity.x, entity.y]): distance = caster.distance_to(entity) if distance < closest_distance: target = entity closest_distance = distance if target: results.append({ 'consumed': True, 'target': target, 'message': Message( f"A lighting bolt strikes the {target.name}" f" with a loud thunder! The damage is {damage}", tcod.orange, ), }) results.extend(target.fighter.take_damage(damage)) else: results.append({ 'consumed': False, 'target': None, 'message': Message( "No enemy is close enough to strike.", tcod.red, ), }) return results