def perform(self) -> None: """Pickup an item and add it to the actor's inventory, if there is a room for it.""" # Checking for inability if self.entity.check_for_immobility(): if self.entity == self.engine.player: self.engine.message_log.add_message(f"You can't do anything!", color.red) return None actor_location_x = self.entity.x actor_location_y = self.entity.y inventory = self.entity.inventory for item in self.engine.game_map.items: if actor_location_x == item.x and actor_location_y == item.y: if len(inventory.items) >= inventory.capacity: raise exceptions.Impossible("Your inventory is full.") # Remove the item from current gamemap self.engine.game_map.entities.remove(item) item.parent = self.entity.inventory inventory.add_item(item) if item.stack_count > 1: self.engine.message_log.add_message( f"You picked up the {item.name} (x{item.stack_count})!" ) else: self.engine.message_log.add_message( f"You picked up the {item.name}!") return #prevents picking up everything at once. # TODO : Add feature to pickup everything at once raise exceptions.Impossible("There is nothing here to pick up.")
def perform(self) -> None: # Checking for inability if self.entity.check_for_immobility(): if self.entity == self.engine.player: self.engine.message_log.add_message(f"You can't do anything!", color.red) return None # Set destination dest_x, dest_y = self.dest_xy ### Check map boundaries ### if not self.engine.game_map.in_bounds(dest_x, dest_y): # Destination is out of bounds. raise exceptions.Impossible("The way is blocked.") # If the actor is stuck in pit if self.entity.actor_state.is_in_deep_pit: # There are no "crawl out failure" when the actor is moving between different depth of pits. if self.engine.game_map.tiles[dest_x, dest_y][ "tile_id"] == "deep_pit" or self.engine.game_map.tiles[ dest_x, dest_y]["tile_id"] == "shallow_pit": crawl_out_chance = 1 else: # If the actor is big enough, it can crawl out freely if self.entity.actor_state.size >= 6: crawl_out_chance = 1 else: crawl_out_chance = 0.005 * self.entity.status.changed_status[ "dexterity"] * (self.entity.actor_state.size**2 ) # crawl-out chance calculation if random.random() > crawl_out_chance: if self.entity == self.engine.player: self.engine.message_log.add_message( f"You try to crawl out of the pit, but fail!", color.red, target=self.entity) else: self.engine.message_log.add_message( f"{self.entity.name} try to crawl out of the pit, but fail.", color.gray, target=self.entity) return None # Turn passes if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: # Destination is blocked by a tile. raise exceptions.Impossible("The way is blocked.") if self.engine.game_map.get_blocking_entity_at_location( dest_x, dest_y): # Destination is blocked by an entity. raise exceptions.Impossible("The way is blocked.") self.entity.move(self.dx, self.dy)
def perform(self) -> None: import semiactor_factories # Checking for inability if self.entity.check_for_immobility(): if self.entity == self.engine.player: self.engine.message_log.add_message(f"You can't do anything!", color.red) return None # Set coordinates dest_x, dest_y = self.dest_xy semiactor_on_dir = self.engine.game_map.get_semiactor_at_location( dest_x, dest_y) if not semiactor_on_dir: raise exceptions.Impossible("There is nothing to close.") elif semiactor_on_dir.entity_id == "opened_door": can_close_door = False dexterity = self.entity.status.changed_status["dexterity"] intelligence = self.entity.status.changed_status["intelligence"] # If the actor has arm, it can try to close the door regardless of its dexterity if self.entity.actor_state.has_left_arm or self.entity.actor_state.has_left_arm: can_close_door = True # If the actor has no arm, but has enough dexterity and intelligence, it still can try to close the door elif dexterity >= 10 and intelligence >= 10: can_close_door = True # If any entity (except for the door semiactor that the actor is trying to close) is on the same direction with the door, you can't close if self.engine.game_map.get_any_entity_at_location( dest_x, dest_y, exception=semiactor_on_dir): raise exceptions.Impossible("Something is blocking.") # Try to close the door close_fail = random.randint( 0, 10 ) # if dex > 10, actor will not fail closing the door by chance if not can_close_door or close_fail > dexterity: # check if the actor has no capabilities, or if the actor failed closing it by chance self.engine.message_log.add_message( f"{self.entity.name} has failed to close the door!", color.invalid, target=self.entity) return None semiactor_on_dir.remove_self() semiactor_factories.closed_door.spawn(self.engine.game_map, dest_x, dest_y, -1) return None elif self.engine.game_map.get_semiactor_at_location( dest_x, dest_y).entity_id == "closed_door": raise exceptions.Impossible("It is already closed.") else: raise exceptions.Impossible("There is nothing to close.")
def perform(self) -> None: dest_x, dest_y = self.dest_xy if not self.engine.game_map.in_bounds(dest_x, dest_y): raise exceptions.Impossible("That way is blocked.") if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: raise exceptions.Impossible("That way is blocked.") if self.engine.game_map.get_blocking_entity_at_location( dest_x, dest_y): raise exceptions.Impossible("That way is blocked.") self.entity.move(self.dx, self.dy)
def perform(self, depth: int = None) -> None: """ If the Player is the actor, and the game map is not yet generated, this method will generate a new gamemap object. """ # Checking for inability if self.entity.check_for_immobility(): if self.entity == self.engine.player: self.engine.message_log.add_message(f"You can't do anything!", color.red) return None if self.engine.game_map.tiles[ self.entity.x, self.entity.y]["tile_id"] == "descending_stair": ### Player Level Descending if self.entity == self.engine.player: if depth == None: goal_depth = self.engine.depth + 1 else: goal_depth = depth # Remove entity from previous gamemap self.engine.game_map.entities.remove(self.entity) if goal_depth in list( self.engine.world.keys()): # GameMap Already Exists. self.engine.game_map = self.engine.world[goal_depth] self.engine.depth = goal_depth else: # GameMap Does not Exists, Generate new dungeon. self.engine.world[ goal_depth] = self.engine.generate_new_dungeon( depth=goal_depth) self.engine.game_map = self.engine.world[goal_depth] self.engine.depth = goal_depth ### Monster Level Descending else: pass # TODO # Add the entity to current gamemap self.engine.game_map.entities.append(self.entity) self.engine.game_map.sort_entities() self.entity.place(self.engine.game_map.ascend_loc[0], self.engine.game_map.ascend_loc[1], self.engine.world[self.engine.depth]) # Set entity gamemap self.entity.gamemap = self.engine.game_map elif self.engine.game_map.tiles[ self.entity.x, self.entity.y]["tile_id"] == "ascending_stair": raise exceptions.Impossible("This stair only goes up.") else: raise exceptions.Impossible("There is no stair.")
def perform(self) -> None: dest_x,dest_y = self.dest_xy #this is what keeps the player from going out of bounds or walking on top of unwalkable tiles if not self.engine.game_map.in_bounds(dest_x, dest_y): #Destination is out of bounds raise exceptions.Impossible("That way is blocked.") if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: #Destination is blocked by a tile. raise exceptions.Impossible("That way is blocked.") if self.engine.game_map.get_blocking_entity_at_location(dest_x,dest_y): #Destination is blocked by another entity raise exceptions.Impossible("That way is blocked.") self.entity.move(self.dx, self.dy)
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("That way is out of bounds.") if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: # Destination blocked by tile. raise exceptions.Impossible("That way is blocked.") if self.engine.game_map.get_block_at_dest(dest_x, dest_y): # Destination blocked by an entity. raise exceptions.Impossible("Something is in your way.") self.entity.move(self.dx, self.dy)
def perform(self) -> None: dest_x, dest_y = self.dest_xy if not self.engine.game_map.in_bounds(dest_x, dest_y): # Desitination is out of bounds. raise exceptions.Impossible('That way is blocked.') if not self.engine.game_map.tiles['walkable'][dest_x, dest_y]: # Destination is blocked by a tile raise exceptions.Impossible('That way is blocked') if self.engine.game_map.get_blocking_entity_at_location( dest_x, dest_y): # Destination is blocked by an entity raise exceptions.Impossible('That way is blocked') self.entity.move(self.dx, self.dy)
def perform(self) -> None: dest_x, dest_y = self.dest_xy if not self.engine.game_map.in_bounds(dest_x, dest_y): raise exceptions.Impossible( "Your path is blocked") # destination is out of bounds if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: raise exceptions.Impossible( "Your path is blocked") # destination tile is impassible if self.engine.game_map.get_blocking_entity_at_location( dest_x, dest_y): raise exceptions.Impossible( "Your path is blocked") # destination blocked by entity self.entity.move(self.dx, self.dy)
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("That way is blocked.") if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: # Destination is blocked by a tile. raise exceptions.Impossible("That way is blocked.") if self.blocking_entity: # Destination is blocked by an entity raise exceptions.Impossible("That way is blocked.") self.entity.move(self.dx, self.dy)
def perform(self): dest_x, dest_y = self.dest_xy if not self.engine.game_map.in_bounds(dest_x, dest_y): raise exceptions.Impossible( "That way is blocked.") # Destination ikke indenfor mappet if not self.engine.game_map.tiles['walkable'][dest_x, dest_y]: raise exceptions.Impossible( "That way is blocked.") # Destination er blokeret. if self.engine.game_map.get_blocking_entity_at_location( dest_x, dest_y): raise exceptions.Impossible( "That way is blocked.") # Destination er blokeret af en entity self.entity.move(self.dir_x, self.dir_y)
def perform(self) -> None: dest_x, dest_y = self.dest_xy if not self.engine.game_map.in_bounds(dest_x, dest_y): # Место назначения находится за пределами поля. raise exceptions.Impossible("That way is blocked.") if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: # Место назначения загораживает стена. raise exceptions.Impossible("That way is blocked.") if self.engine.game_map.get_blocking_entity_at_location( dest_x, dest_y): # Место назначения блокируется объектом. raise exceptions.Impossible("That way is blocked.") self.entity.move(self.dx, self.dy)
def perform(self) -> None: target = self.target_actor if not target: raise exceptions.Impossible("Nothing to attack.") if target.faction == self.entity.faction: return damage = self.entity.fighter.power - target.fighter.defense attack_desc = f"{self.entity.name.capitalize()} attacks {target.name}" if self.entity.name == "Assassin": damage += self.entity.fighter.power attack_desc = f"{self.entity.name.capitalize()} stabs {target.name}, twice," if self.entity is self.engine.player: attack_color = color.player_atk else: attack_color = color.enemy_atk if target.name == "Player": print(target.fighter.base_defense) print(self.entity.fighter.base_power) if damage > 0: self.engine.message_log.add_message( f"{attack_desc} for {damage} hit points.", attack_color ) target.fighter.hp -= damage KillConfirm(self.entity).resolve(self.entity, target) else: self.engine.message_log.add_message( f"{attack_desc} but does no damage.", attack_color )
def perform(self) -> None: target = self.target_actor if not target: raise exceptions.Impossible("Nothing to attack.") else: if not target.encountered: playsound("sounds/" + str(target.name) + ".mp3", False) target.encountered = True damage = self.entity.fighter.power - target.fighter.defense attack_desc = f"{self.entity.name} 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 else: self.engine.message_log.add_message( f"{attack_desc} but does no damage.", attack_color )
def perform(self): target = self.target_actor if not target: raise exceptions.Impossible( "Nothing to attack.") # No entity 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 = CONFIG.get_colour("player_atk") else: attack_color = CONFIG.get_colour("enemy_atk") if damage > 0: self.engine.message_log.add_message( f"{attack_desc} for {damage} HP.", attack_color) target.fighter.hp -= damage else: self.engine.message_log.add_message( f"{attack_desc} but does no damage.", attack_color) # return true to trigger player turn return True
def perform(self) -> None: target = self.target_actor if not target: raise exceptions.Impossible("Nothing to attack.") to_hit = self.entity.roll_to_hit() target_ac = target.fighter.ac roll_desc = f"{to_hit} vs. {target_ac}" 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 to_hit >= target_ac: damage = self.entity.fighter.attack_dmg self.engine.message_log.add_message( f"{attack_desc} for {damage} hit points ({roll_desc}).", attack_color) target.fighter.hp -= damage else: self.engine.message_log.add_message( f"{attack_desc} but misses ({roll_desc}).", attack_color)
def equip_equipment(self, item: Item, forced: bool = False): """Equip item at region.""" # You tried to re-equip the item you are already equipping if item.item_state.is_equipped: if not forced: if self.parent == self.engine.player: raise exceptions.Impossible( f"You are already equipping {item.name}.") return None # TODO: check whether the equipper has the body part required for equipping # Remove item that was equipped on the region you are currently trying to equip if self.equipments[item.equipable.equip_region]: self.remove_equipment(item.equipable.equip_region) # Equip item, gain bonuses self.equipments[item.equipable.equip_region] = item item.equipable.upgrade_stat_change() self.add_equipable_bonuses(item) if not forced: if self.parent == self.engine.player: self.engine.message_log.add_message( f"You equipped the {item.name}.", fg=color.health_recovered) else: self.engine.message_log.add_message( f"{self.parent.name} equipped the {item.name}.", fg=color.gray, target=self.parent) item.item_state.is_equipped = item.equipable.equip_region
def perform(self) -> None: """Move in the given direction""" 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("That way is blocked.") if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: # Destination is blocked by a tile. raise exceptions.Impossible("That way is blocked.") if self.engine.game_map.get_blocking_entity_at_location( dest_x, dest_y): # Destination is blocked by an entity. raise exceptions.Impossible("That way is blocked.") self.entity.move(self.dx, self.dy)
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 perform(self) -> None: if (self.entity.x, self.entity.y) == self.engine.game_map.downstairs_location: self.engine.game_world.generate_floor() self.engine.message_log.add_message("You descend the staircase.", color.descend) else: raise exceptions.Impossible("There are no stairs here.")
def perform(self) -> None: actor_location_x = self.entity.x actor_location_y = self.entity.y inventory = self.entity.inventory for item in self.engine.game_map.items: if actor_location_x == item.x and actor_location_y == item.y: if len(inventory.items) >= inventory.capacity: raise exceptions.Impossible("Your inventory is full") self.engine.game_map.entities.remove(item) item.parent = self.entity.inventory inventory.items.append(item) self.engine.message_log.add_message( f"You picked up the {item.name}!") return raise exceptions.Impossible("There is nothing here to pick up.")
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() self.engine.message_log.add_message( "You descend deeper into the unknown...", color.descend) else: raise exceptions.Impossible("There are no stairs here")
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: inventory = self.entity.inventory for item in self.engine.GAMEMAP.items: if self.position == item.position: if len(inventory.items) >= inventory.capacity: raise exceptions.Impossible("Your inventory is full.") self.engine.GAMEMAP.entities.remove(item) item.parent = self.entity.inventory inventory.items.append(item) self.engine.message_log.add_message( f"You picked up the {item.name}.") return True # because it takes a turn # if we reach this point, we didn't pick up anything exceptions.Impossible("There is nothing here to pick up.")
def perform(self, depth: int = None) -> None: # Checking for inability if self.entity.check_for_immobility(): if self.entity == self.engine.player: self.engine.message_log.add_message(f"You can't do anything!", color.red) return None if self.engine.game_map.tiles[ self.entity.x, self.entity.y]["tile_id"] == "ascending_stair": ### Player Level Ascending if self.entity == self.engine.player: if depth == None: goal_depth = self.engine.depth - 1 else: goal_depth = depth # Remove entity from previous gamemap self.engine.game_map.entities.remove(self.entity) if goal_depth in list(self.engine.world.keys()): self.engine.game_map = self.engine.world[goal_depth] self.engine.depth = goal_depth else: print("ERROR : LEVEL DOES NOT EXIST") raise Exception # You cannot ascend to a level that does not exist. ### Monster Level Ascending else: pass # Add entity to current gamemap self.engine.game_map.entities.append(self.entity) self.engine.game_map.sort_entities() self.entity.place(self.engine.game_map.descend_loc[0], self.engine.game_map.descend_loc[1], self.engine.world[self.engine.depth]) # Set entity gamemap self.entity.gamemap = self.engine.game_map elif self.engine.game_map.tiles[ self.entity.x, self.entity.y]["tile_id"] == "descending_stair": raise exceptions.Impossible("This stair only goes down.") else: raise exceptions.Impossible("There is no stair.")
def perform(self): actor_location_x = self.entity.x actor_location_y = self.entity.y inventory = self.entity.inventory for item in self.engine.game_map.items: if actor_location_x == item.x and actor_location_y == item.y: if len(inventory.items) >= inventory.capacity: raise exceptions.Impossible('Shitter\'s full.') self.engine.game_map.entities.remove(item) item.parent = self.entity.inventory inventory.items.append(item) self.engine.message_log.add_message( f"You picked up the {item.name}!", ) return raise exceptions.Impossible( "You attempt to pick up the air, to no avail.")
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: raise exceptions.Impossible("There are no stairs here.") self.engine.game_world.generate_floor() self.engine.message_log.add_message("You descend the staircase.", color.descend)
def perform(self) -> None: dest_x, dest_y = self.dest_xy #dest_xy precalculates position of entity plus distance :) if not self.engine.game_map.in_bounds(dest_x, dest_y): # Destination is out of bounds. raise exceptions.Impossible("That way is blocked.") if not self.engine.game_map.tiles["walkable"][dest_x, dest_y]: raise exceptions.Impossible( "That way is blocked.") # Destination is blocked by a tile. if self.engine.game_map.get_blocking_entity_at_location( dest_x, dest_y): return #destination is blocked by entity #pick up item when you move onto it elif self.target_item and self.target_item.is_active: item = self.target_item self.entity.move(dx=self.dx, dy=self.dy) return ItemAction(self.entity, item).perform() self.entity.move(dx=self.dx, dy=self.dy)
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() self.engine.message_log.add_message( "You climb up the oral cavity.", color.climb ) else: raise exceptions.Impossible("You cannot climb up here.")
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() self.engine.message_log.add_message('You descend the staircase.', color.descend) else: raise exceptions.Impossible('There are no stairs here.')