def perform(self) -> None: target = self.target_actor if not target: raise exceptions.Impossible("Nothing to attack.") damage = self.entity.fighter.power - target.fighter.defense attack_desc = f"{self.entity.name.capitalize()} attacks {target.name}" if self.entity is self.engine.player: attack_color = color.player_atk else: attack_color = color.enemy_atk if damage > 0: self.engine.message_log.add_message( f"{attack_desc} for {damage} hit points.", attack_color ) target.fighter.hp -= damage clip = AudioClip('sfx/Socapex - new_hits_5.wav') SoundHandler.play(clip) else: self.engine.message_log.add_message( f"{attack_desc} but barely damages him.", attack_color ) target.fighter.hp -= 1 clip = AudioClip('sfx/swosh-20.flac') SoundHandler.play(clip)
def activate(self, action: actions.ItemAction) -> None: target_xy = action.target_xy consumer = action.entity if not self.engine.game_map.visible[target_xy]: raise Impossible("I can't target what I can't see.") targets_hit = False for actor in self.engine.game_map.actors: if actor.distance(*target_xy) <= self.radius: if not actor is consumer: self.engine.message_log.add_message( f"The {actor.name} is flashed", color.status_effect_applied, ) targets_hit = True actor.ai = components.ai.ConfusedEnemy( entity=actor, previous_ai=actor.ai, turns_remaining=self.number_of_turns, ) if not targets_hit: raise Impossible("No one is close to the effective range") self.consume() clip = AudioClip('sfx/rumble.flac') SoundHandler.play(clip)
def activate(self, action: actions.ItemAction) -> None: consumer = action.entity amount_recovered = consumer.fighter.heal(self.amount) if amount_recovered > 0: self.engine.message_log.add_message( f"You consume the {self.parent.name}, and recover {amount_recovered} HP!", color.health_recovered, ) self.consume() clip = AudioClip('sfx/heal.wav') SoundHandler.play(clip) else: raise Impossible(f"Can't heal what's not hurt")
def activate(self, action: actions.ItemAction) -> None: consumer = action.entity amount_recovered = consumer.fighter.eat(self.amount) if amount_recovered > 0: self.engine.message_log.add_message( f"You eat the {self.parent.name}, and fill your hunger by {amount_recovered}!", color.health_recovered, ) self.consume() clip = AudioClip('sfx/heal.wav') SoundHandler.play(clip) else: raise Impossible(f"I'm full")
def die(self) -> None: if self.engine.player is self.parent: death_message = "You died!" death_message_color = color.player_die clip = AudioClip("sfx/swosh-20.flac") SoundHandler.play(clip) else: death_message = f"{self.parent.name} is dead!" death_message_color = color.enemy_die self.parent.char = "%" self.parent.color = (191, 0, 0) self.parent.blocks_movement = False self.parent.ai = None self.parent.name = f"dead body of {self.parent.name}" self.parent.render_order = RenderOrder.CORPSE self.engine.message_log.add_message(death_message, death_message_color) self.engine.player.level.add_xp(self.parent.level.xp_given)
def perform(self) -> None: dest_x, dest_y = self.dest_xy if not self.engine.game_map.in_bounds(dest_x, dest_y): # Destination is out of bounds. raise exceptions.Impossible("I don't want to go there") if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: # Destination is blocked by a tile. raise exceptions.Impossible("There's a wall in there") if self.engine.game_map.get_blocking_entity_at_location(dest_x, dest_y): # Destination is blocked by an entity. raise exceptions.Impossible("Something blocks me") if self.entity is self.engine.player: self.engine.player.fighter.starve() self.entity.move(self.dx, self.dy) clip = AudioClip('sfx/stepdirt_1.wav') SoundHandler.play(clip)
def perform(self) -> None: """ Take the stairs, if any exist at the entity's location. """ if (self.entity.x, self.entity.y) == self.engine.game_map.downstairs_location: self.engine.game_world.generate_floor() if random.random() <0.5: self.engine.message_log.add_message( "You descend the staircase, you're filled with hope.", color.descend ) else: self.engine.message_log.add_message( "You descend the staircase, you feel a chill on your spine" ) clip = AudioClip('sfx/stepdirt_1.wav') SoundHandler.play(clip) else: raise exceptions.Impossible("There are no stairs here.")
def activate(self, action: actions.ItemAction) -> None: target_xy = action.target_xy if not self.engine.game_map.visible[target_xy]: raise Impossible("I can't target what I can't see.") targets_hit = False for actor in self.engine.game_map.actors: if actor.distance(*target_xy) <= self.radius: self.engine.message_log.add_message( f"The {actor.name} is engulfed in a fiery explosion, taking {self.damage} damage!" ) actor.fighter.take_damage(self.damage) targets_hit = True if not targets_hit: raise Impossible("No one is close to the effective range") self.consume() clip = AudioClip('sfx/rumble.flac') SoundHandler.play(clip)
def activate(self, action: actions.ItemAction) -> None: consumer = action.entity target = action.target_actor if not self.engine.game_map.visible[action.target_xy]: raise Impossible("I can't target what I can't see.") if not target: raise Impossible("No one is close to the effective range") if target is consumer: raise Impossible("I'm not this dumb.") self.engine.message_log.add_message( f"The {target.name} has been blinded", color.status_effect_applied, ) target.ai = components.ai.ConfusedEnemy( entity=target, previous_ai=target.ai, turns_remaining=self.number_of_turns, ) self.consume() clip = AudioClip('sfx/toggle.wav') SoundHandler.play(clip)
def activate(self, action: actions.ItemAction) -> None: consumer = action.entity target = None closest_distance = self.maximum_range + 1.0 for actor in self.engine.game_map.actors: if actor is not consumer and self.parent.gamemap.visible[actor.x, actor.y]: distance = consumer.distance(actor.x, actor.y) if distance < closest_distance: target = actor closest_distance = distance if target: self.engine.message_log.add_message( f"A brick was thrown at {target.name}, breaking on impact and dealing {self.damage} damage." ) target.fighter.take_damage(self.damage) self.consume() clip = AudioClip('sfx/impact.wav') SoundHandler.play(clip) else: raise Impossible("There's no one close enough to get bricked.")