def use_ability(self, game_map, ability, target=None): results = [] targeting = False area = ability.target_area include_self = ability.target_self if include_self: target = self.owner results = self.owner.fighter.attack(target, ability) msgs = self.owner.status_effects.process_effects(game_map=game_map, self_targeting=True) if msgs: results.extend(msgs) elif not target: radius = ability.get_range() entities = get_neighbours(self.owner, game_map.tiles, radius, fighters=True, include_self=include_self, algorithm=area, mark_area=True) if not entities and not include_self: msg = Message("There are no available targets in range.") results.append(msg) elif len(entities) == 1 and not ability.requires_targeting: target = entities[0] results = self.owner.fighter.attack(target, ability) else: msg = Message(msg="Use '{0}' on which target? Range: {1}".format( ability.name, radius), style="question") results.append(msg) target = entities[0] targeting = True else: results = self.owner.fighter.attack(target, ability) return results, target, targeting
def translate(self): text = self.source_txt.toPlainText() message = Message() if text == "": message.level("warn") \ .title("Can't translate") \ .message("You need to write something!") \ .show() return if self._from == "": message.level("warn") \ .title("Can't translate") \ .message("Choose a source language") \ .show() return if self._to == "": message.level("warn") \ .title("Can't translate") \ .message("Choose a target language") \ .show() return try: translated = self.translator.translate(text, self._from, self._to) self.output_txt.setPlainText(translated) except Exception as e: message.level("error") \ .title("Something wrong happen") \ .message(str(e)) \ .show()
def add_item(self, game_map, item=None): results = [] if item: self.items.append(item) msg = Message("{0} was added to your inventory.".format(item.name)) results.append(msg) return results entities = game_map.tiles[self.owner.x][self.owner.y].items_on_tile if entities: for entity in entities: if entity.item and entity.item.pickable and not entity.hidden: if len(self.items) >= self.capacity: msg = Message("Your inventory is full.") results.append(msg) else: msg = Message("You pick up the {0}.".format( entity.name)) results.append(msg) self.items.append(entity) game_map.tiles[self.owner.x][ self.owner.y].remove_entity(entity) game_map.entities["items"].remove(entity) return results
def check_full_list(self): self.refresh_data() if len(self.config) >= self.options[4]: Message.information(Message(), 'Lista llena', u'Ya has llegado al máximo permitdo de configuraciones.\n' u'En caso de querer impedir este comportamiento puedes ' u'cambiarlo en opciones.', '') return True return False
def heal(self, entity, hp): if self.has_required_components(Components.HITPOINTS): health = entity.get_component(Components.HITPOINTS) if self.is_dead(entity): return Message("{0} cannot be healed.".format( entity.name.capitalize())) else: health.cur_hp += hp if health.cur_hp > health.max_hp: health.cur_hp = health.max_hp return Message("{0} regains {1} HP!".format( entity.name.capitalize(), str(hp)))
def init_translator(self): try: self.translator = Translator() self.translator.set_provider("yandex") self.langs = self.translator.get_langs() except Exception as e: message = Message() message.level("error") \ .title("Error on start") \ .message(str(e)) \ .show() quit()
def on_death(entity, char='%', color=tcod.red, src=None, visible=True): if entity.get_component(Components.ICON): chara = entity.get_component(Components.ICON) chara.char = char chara.color = color chara.render_order = Render_Order.CORPSE chara.visible = visible if entity.get_component(Components.POSITION): entity.get_component(Components.POSITION).solid = False entity.remove_component(Components.FIGHTER) entity.remove_component(Components.AI) entity.remove_component(Components.FOV) if src: return Message("{0} has killed {1}!".format(src.name.capitalize(), entity.name)) else: return Message("{0} has died!".format(entity.name.capitalize()))
def interaction(self, game_map): msg = None if self.name == "candle" and self.owner.light_source: msg = "You blow out the candle." self.owner.light_source = None elif self.name == "candle" and not self.owner.light_source: self.set_attributes(game_map) msg = "You light the candle." return Message(msg)
def interaction(self, levels): levels.change(self.destination[0]) results = [] if levels.current_map.name == "cavern" and levels.current_map.dungeon_level == 1: msg = Message( msg= "A sense of impending doom fills you as you delve into the cavern.", clear_buffer=True) results.append(msg) msg2 = Message("RIBBIT!") results.append(msg2) elif levels.current_map.name == "dream": msg = Message( msg="I'm dreaming... I feel my spirit power draining.", clear_buffer=True) results.append(msg) msg2 = Message("I'm hungry..") results.append(msg2) return results
def info_dialog(self): self.reload() interfaces_disconnected = '<h3>Interfaces desconectadas</h3>' interfaces_connected = '<h3>Interfaces conectadas</h3>' for config in self.IPCONFIG: if config[1] == 'disconnected': interfaces_disconnected += '<p>____________________</p>' # interfaces_disconnected += '<p>%s</p>' % config[2] interfaces_disconnected += '<p>%s</p>' % config[4] interfaces_disconnected += '<p>%s</p>' % config[5] else: interfaces_connected += '<p>%s</p>' % config[2] interfaces_connected += '<p>%s</p>' % config[4] interfaces_connected += '<p>%s</p>' % config[5] interfaces_connected += '<p>%s</p>' % config[6] interfaces_connected += '<p>%s</p>' % config[7] interfaces_connected += '<p>%s</p>' % config[8] interfaces_connected += '<p>____________________</p>' link_network_connexion = '<a href="ncpa.cpl">Presione aqui para ver las conexiones de red en Panel de Control.</a>' info = '<table><tr><td>%s</td><td>%s</td></tr></table><p>%s</p>' % ( interfaces_disconnected, interfaces_connected, link_network_connexion) Message.information(Message(background_color='white', size='8'), u'Información', info, '')
def heal(self, power): result = None amount = roll_dice(power) if self.hp >= self.max_hp: result = Message("{0} is already at max health.".format( self.owner.colored_name), extend_line=True) return result else: if self.hp + amount > self.max_hp: self.hp = self.max_hp else: self.hp += amount return result
def kill(self): if self.player: self.char = tilemap()["player_remains"] death_message = Message(msg="You died!", style="death") else: death_message = Message("The {0} is dead!".format(self.name), style="death") if self.boss: self.char = tilemap()["boss_remains"] self.color = "darkest red" else: self.char = tilemap()["monster_remains"] self.color = "dark gray" self.light_source = None self.blocks = False self.fighter = None self.ai = None self.name = "remains of " + get_article( self.name) + " " + self.name self.layer = 1 return death_message
def take_damage(self, attacker, target, damage): logs = [] if self.has_required_components(target): hp = target.get_component(Components.HITPOINTS) if hp.temp_hp > 0: hp.temp_hp -= damage if hp.temp_hp < 0: hp.cur_hp += hp.temp_hp hp.temp_hp = 0 else: hp.cur_hp -= damage logs.append( Message( "{0} attacks {1} for {2} HP!".format( attacker.name.capitalize(), target.name, str(damage)), tcod.red)) if hp.cur_hp <= 0: hp.cur_hp = 0 if hp.on_death: logs.append(hp.on_death(target, src=attacker)) else: logs.append(hp.on_death(target, src=attacker)) return logs
def handle_player_exp(self, killed_fighter): self.spirit_power += killed_fighter.max_hp self.char_exp["player"] += killed_fighter.max_hp self.owner.fighter.hp += killed_fighter.power levels_gained = int(self.char_exp["player"] / (self.exp_lvl_interval * self.char_level)) entity_name = killed_fighter.owner.name if entity_name in tilemap()["monsters"].keys(): self.char[entity_name] = tilemap()["monsters"][entity_name] elif entity_name in tilemap()["monsters_light"].keys(): self.char[entity_name] = tilemap()["monsters_light"][entity_name] elif entity_name in tilemap()["monsters_chaos"].keys(): self.char[entity_name] = tilemap()["monsters_chaos"][entity_name] if entity_name in self.char_exp.keys(): self.char_exp[entity_name] += 1 else: self.char_exp[entity_name] = 1 if levels_gained >= 1: self.level_up(levels_gained) return Message("You have gained a level!", style="level_up") return None
def draw_entities(self, entities): game_camera = self.owner.game_camera player = self.owner.player game_map = self.owner.levels.current_map cursor = self.owner.cursor results = [] self.light_sources = [] for entity in entities: x, y = game_camera.get_coordinates(entity.x, entity.y) if entity.x == player.x and entity.y == player.y and entity.stand_on_messages and not entity.hidden: results.append( Message( get_article(entity.name).capitalize() + " " + entity.colored_name + ".")) if entity.xtra_info: results.append( Message(msg=entity.xtra_info + ".", style="xtra")) if cursor: if entity.occupied_tiles is not None: if (game_map.tiles[entity.x][entity.y].explored and not entity.cursor and (cursor.x, cursor.y) in entity.occupied_tiles): results.append( Message( get_article(entity.name).capitalize() + " " + entity.name + ".")) results.append( Message( str("x: " + (str(cursor.x) + ", y: " + str(cursor.y))))) if entity.xtra_info: results.append( Message(msg=entity.xtra_info + ".", style="xtra")) if entity.fighter: self.draw_stats(entity) elif (entity.x == cursor.x and entity.y == cursor.y and not entity.cursor and game_map.tiles[entity.x][entity.y].explored and not entity.hidden): results.append( Message( get_article(entity.name).capitalize() + " " + entity.name + ".")) results.append( Message( msg=str("x: " + (str(cursor.x) + ", y: " + str(cursor.y))), extend_line=True)) if entity.xtra_info: results.append( Message(msg=entity.xtra_info + ".", style="xtra", extend_line=True)) if entity.fighter: self.draw_stats(entity) if entity.name == "cursor": self.clear(entity, entity.last_seen_x, entity.last_seen_y) self.draw(entity, x, y) if not entity.cursor and player.light_source.fov_map.fov[entity.y, entity.x]: # why is this here? causes rendering bugs!!! # clear(entity, entity.last_seen_x, entity.last_seen_y) if not entity.player and not entity.cursor: entity.last_seen_x = entity.x entity.last_seen_y = entity.y if entity.player or entity.fighter: self.draw(entity, x, y) elif not entity.light_source: self.draw(entity, x, y) else: self.light_sources.append(entity.light_source) continue elif (not player.light_source.fov_map.fov[entity.y, entity.x] and game_map.tiles[entity.last_seen_x][ entity.last_seen_y].explored and not player.light_source.fov_map.fov[entity.last_seen_y, entity.last_seen_x]): x, y = game_camera.get_coordinates(entity.last_seen_x, entity.last_seen_y) if entity.light_source and not entity.fighter: self.light_sources.append(entity.light_source) else: self.draw(entity, x, y) if player.light_source.fov_map.fov[ entity.y, entity. x] and entity.ai and self.owner.options.gfx != "ascii": self.draw_indicator(player.x, player.y, player.indicator_color) self.draw_indicator(entity.x, entity.y, entity.indicator_color, entity.occupied_tiles) self.draw_health_bar(entity) self.draw_health_bar(player) self.owner.message_log.send(results)
def process(self, game_map): msgs = [] if not self.summoning and self.summoned_entities: summons = [] for entity in self.summoned_entities: summons.append(entity.name) game_map.entities["allies"].remove(entity) game_map.tiles[entity.x][entity.y].remove_entity(entity) del entity self.summoned_entities = [] self.owner.fighter.summoning = False self.summoning = [""] if len(summons) > 1: msg = Message( "Your trusty companions {0} return back to the spirit plane!" .format(", ".join(summons))) else: msg = Message( "Your trusty companion {0} returns back to the spirit plane!" .format(summons[0])) msgs.append(msg) return msgs elif self.summoning and not self.summoned_entities: if len(self.summoning) <= self.rank: name = self.summoning[-1] else: name = self.summoning[self.rank] char = tilemap()["monsters"][name] color = get_monster_color(name) f_data = json_data.data.fighters[name] remarks = f_data["remarks"] fighter_component = Fighter(hp=f_data["hp"], ac=f_data["ac"], ev=f_data["ev"], power=f_data["power"], mv_spd=f_data["mv_spd"], atk_spd=f_data["atk_spd"], size=f_data["size"], fov=f_data["fov"]) ai_component = BasicMonster(ally=True) light_component = LightSource(radius=fighter_component.fov) abilities_component = Abilities(name) status_effects_component = StatusEffects(name) neighbours = get_neighbours(self.owner, game_map=game_map.tiles, radius=3, algorithm="square", empty_tiles=True) summon_tile = choice(neighbours) entity_name = name monster = Entity(summon_tile.x, summon_tile.y, 3, char, color, entity_name, blocks=True, fighter=fighter_component, ai=ai_component, light_source=light_component, abilities=abilities_component, status_effects=status_effects_component, remarks=remarks, indicator_color="light green") monster.light_source.initialize_fov(game_map) game_map.tiles[summon_tile.x][summon_tile.y].add_entity(monster) game_map.entities["allies"].append(monster) self.summoned_entities.append(monster) msg = Message("A friendly {0} appears!".format(entity_name)) msgs.append(msg) remark_str = "{0}: {1}".format(monster.colored_name, choice(monster.remarks)) remark_msg = Message(msg=remark_str, style="dialog") msgs.append(remark_msg) return msgs return msgs
def attack(self, target, skill): results = [] hit_chance = randint(1, 100) miss = (target.fighter.ev * 2) >= hit_chance - self.hit_penalty if (skill.skill_type == "attack" or skill.skill_type == "utility") and self.owner.player: miss = False if skill is not None: if skill.skill_type == "attack" or skill.skill_type == "weapon": if miss: if self.owner.player: msg = Message( msg="You attack the {0} with {1}, but miss.". format(target.name.lower(), skill.name), style="miss") results.append(msg) else: msg = Message( msg="The {0} attacks the {1} with {2}, but misses." .format(self.owner.name, target.colored_name.lower(), skill.name), style="miss") results.append(msg) else: damage = self.calculate_damage(skill, target) results = self.hit_messages(skill, target, damage) if skill.effect: for effect in skill.effect: json_efx = json_data.data.status_effects[effect] if skill.duration: duration = roll_dice( skill.duration[skill.rank]) else: duration = roll_dice( json_efx["duration"][skill.rank]) hit_penalty = json_efx[ "hit_penalty"] if "hit_penalty" in json_efx.keys( ) else [] if "delayed_damage" in json_efx.keys(): delayed_damage = roll_dice( json_efx["delayed_damage"][skill.rank]) else: delayed_damage = [] rank = skill.rank dps = json_efx["dps"] if "dps" in json_efx.keys( ) else [] slow = json_efx["slow"] if "slow" in json_efx.keys( ) else [] drain_stats = json_efx[ "drain_stats"] if "drain_stats" in json_efx.keys( ) else [] description = json_efx["description"] paralyze = json_efx[ "paralyze"] if "paralyze" in json_efx.keys( ) else False color = json_efx[ "color"] if "color" in json_efx.keys( ) else None chance = json_efx["chance"] power = json_efx[ "power"] if "power" in json_efx.keys( ) else None effect_component = StatusEffect( owner=target.fighter, source=self, name=effect, duration=duration, slow=slow, dps=dps, delayed_damage=delayed_damage, rank=rank, drain_stats=drain_stats, hit_penalty=hit_penalty, paralyze=paralyze, description=description, chance=chance, color=color, power=power) target.status_effects.add_item(effect_component) msg = Message( msg="The {0} is inflicted with {1}!".format( target.colored_name.lower(), effect), color=color) results.append(msg) if damage > 0: target.fighter.take_damage(damage) else: if self.owner.player: msg = Message( msg= "You attack the {0} with {1} but do no damage." .format(target.colored_name.lower(), skill.name), style="miss", extend_line=True) results.append(msg) else: msg = Message( msg= "The {0} attacks the {1} with {2} but does no damage." .format(self.owner.colored_name, target.colored_name.lower(), skill.name), style="miss", extend_line=True) results.append(msg) elif skill.skill_type == "utility": if skill.player_only and not self.owner.player: return results else: damage = self.calculate_damage(skill, target) if skill.effect: for effect in skill.effect: json_efx = json_data.data.status_effects[effect] description = json_efx["description"] if description in self.effects: results.append( Message("The {0} is already {1}!".format( self.owner.colored_name.lower(), description))) continue duration = roll_dice(skill.duration[skill.rank]) fly = skill if effect == "fly" else None sneak = skill if effect == "sneak" else None reveal = skill if effect == "reveal" else None heal = skill if effect == "heal" else None summoning = skill.summoned_entities if skill.summoned_entities else None invisibility = skill if skill.name == "invisibility" else None color = json_efx[ "color"] if "color" in json_efx.keys( ) else None if skill.power: power = skill.power else: power = json_efx[ "power"] if "power" in json_efx.keys( ) else None rank = skill.rank effect_component = StatusEffect( owner=target.fighter, source=self, name=effect, duration=duration, fly=fly, sneak=sneak, reveal=reveal, invisibility=invisibility, description=description, color=color, power=power, rank=rank, heal=heal, summoning=summoning) target.status_effects.add_item(effect_component) results.extend( self.hit_messages(skill, target, damage)) else: if damage > 0: target.fighter.take_damage(damage) results.extend( self.hit_messages(skill, target, damage)) return results
def hit_messages(self, skill, target, damage): results = [] if self.owner.player: if skill.skill_type != "weapon": if target == self.owner: msg = Message(msg="You use {0}!".format(skill.name), style="skill_use") else: msg = Message(msg="You use {0} on {1}!".format( skill.name, target.colored_name.lower()), style="skill_use") results.append(msg) if damage > 0: if skill.name == "heal" and target == self.owner: msg = Message( msg="You heal yourself for {0} hit points.".format( str(-1 * damage)), extend_line=True) elif skill.name == "heal": msg = Message( msg="You heal the {0} for {1} hit points.".format( target.colored_name.lower(), str(-1 * damage)), extend_line=True) else: msg = Message( msg="You attack the {0} for {1} damage.".format( target.colored_name.lower(), str(damage)), extend_line=True) results.append(msg) else: msg = Message( msg="You attack the {0} with {1} for {2} damage.".format( target.colored_name.lower(), skill.name, damage)) results.append(msg) else: if skill.skill_type != "weapon": if target == self.owner: msg = Message(msg="The {0} uses {1} on itself!".format( self.owner.colored_name.lower(), skill.name), style="skill_use") else: msg = Message(msg="The {0} uses {1} on {2}!".format( self.owner.colored_name.lower(), skill.name, target.colored_name.lower()), style="skill_use") results.append(msg) if damage > 0: if skill.name == "heal" and target == self.owner: msg = Message( msg="The {0} heals itself for {1} hit points.". format(self.owner.colored_name.lower(), str(-1 * damage)), extend_line=True) elif skill.name == "heal": msg = Message( msg="The {0} heals {1} for {2} hit points.".format( self.owner.colored_name.lower(), target.colored_name.lower(), str(-1 * damage)), extend_line=True) else: msg = Message( msg="The {0} attacks the {1} for {2} damage.". format(self.owner.colored_name.lower(), target.colored_name.lower(), str(damage)), extend_line=True) results.append(msg) else: msg = Message( msg="The {0} attacks the {1} with {2} for {3} damage.". format(self.owner.colored_name.lower(), target.colored_name.lower(), skill.name, damage)) results.append(msg) return results
def ally_actions(self): for entity in self.owner.levels.current_map.entities["allies"]: visible = self.owner.player.light_source.fov_map.fov[entity.y, entity.x] if visible: if entity.fighter: entity.status_effects.process_effects() self.owner.render_functions.draw_stats(entity) if self.owner.player.fighter.dead: kill_msg = self.owner.player.kill() self.owner.game_state = GameStates.PLAYER_DEAD self.owner.message_log.send(kill_msg) self.owner.render_functions.draw_stats() self.owner.fov_recompute = True break if entity.fighter and entity.fighter.dead: kill_msg = entity.kill() self.owner.levels.current_map.tiles[entity.x][ entity.y].blocking_entity = None self.owner.message_log.send(kill_msg) self.owner.fov_recompute = True elif entity.fighter and entity.fighter.paralyzed: self.owner.message_log.send( Message("Your {0} friend is paralyzed!".format( entity.name))) self.owner.game_state = GameStates.PLAYER_TURN elif entity.ai: target = self.owner.player prev_pos_x, prev_pos_y = entity.x, entity.y targets = get_neighbours( entity, self.owner.levels.current_map.tiles, radius=3, fighters=True, exclude_player=True) if targets: target = targets[0] combat_msg = entity.ai.take_turn( target, self.owner.levels.current_map, self.owner.levels.current_map.entities, self.owner.time_counter) self.owner.levels.current_map.tiles[prev_pos_x][ prev_pos_y].remove_entity(entity) self.owner.levels.current_map.tiles[entity.x][ entity.y].add_entity(entity) if entity.occupied_tiles is not None: self.owner.levels.current_map.tiles[prev_pos_x][ prev_pos_y + 1].remove_entity(entity) self.owner.levels.current_map.tiles[prev_pos_x + 1][ prev_pos_y + 1].remove_entity(entity) self.owner.levels.current_map.tiles[ prev_pos_x + 1][prev_pos_y].remove_entity(entity) self.owner.levels.current_map.tiles[entity.x][ entity.y + 1].add_entity(entity) self.owner.levels.current_map.tiles[entity.x + 1][ entity.y + 1].add_entity(entity) self.owner.levels.current_map.tiles[entity.x + 1][ entity.y].add_entity(entity) self.owner.fov_recompute = True if combat_msg: self.owner.message_log.send(combat_msg) self.owner.render_functions.draw_stats(entity) if self.owner.player.fighter.dead: kill_msg = self.owner.player.kill() self.owner.game_state = GameStates.PLAYER_DEAD self.owner.message_log.send(kill_msg) self.owner.render_functions.draw_stats() break # Functions on monster death if entity.fighter and entity.fighter.dead: level_up_msg = self.owner.player.player.handle_player_exp( entity.fighter) kill_msg = entity.kill() self.owner.levels.current_map.tiles[entity.x][ entity.y].blocking_entity = None self.owner.message_log.send(kill_msg) self.owner.message_log.send( Message("I feel my power returning!")) if level_up_msg: self.owner.message_log.send(level_up_msg) self.owner.fov_recompute = True
def enemy_actions(self): self.owner.render_functions.draw_messages() for entity in self.owner.levels.current_map.entities["monsters"]: visible = self.owner.player.light_source.fov_map.fov[entity.y, entity.x] if visible: if entity.fighter: entity.status_effects.process_effects() self.owner.render_functions.draw_stats(entity) if self.owner.player.fighter.dead: kill_msg = self.owner.player.kill() self.owner.game_state = GameStates.PLAYER_DEAD self.owner.message_log.send(kill_msg) self.owner.render_functions.draw_stats() self.owner.fov_recompute = True break if entity.fighter and entity.fighter.dead: level_up_msg = self.owner.player.player.handle_player_exp( entity.fighter) kill_msg = entity.kill() self.owner.levels.current_map.tiles[entity.x][ entity.y].blocking_entity = None self.owner.message_log.send(kill_msg) self.owner.message_log.send( Message("I feel my power returning!")) if level_up_msg: self.owner.message_log.send(level_up_msg) self.owner.fov_recompute = True elif entity.fighter and entity.fighter.paralyzed: self.owner.message_log.send( Message("The monster is paralyzed!")) self.owner.game_state = GameStates.PLAYER_TURN elif entity.ai: prev_pos_x, prev_pos_y = entity.x, entity.y combat_msg = entity.ai.take_turn( self.owner.player, self.owner.levels.current_map, self.owner.levels.current_map.entities, self.owner.time_counter) self.owner.levels.current_map.tiles[prev_pos_x][ prev_pos_y].remove_entity(entity) self.owner.levels.current_map.tiles[entity.x][ entity.y].add_entity(entity) if entity.occupied_tiles is not None: self.owner.levels.current_map.tiles[prev_pos_x][ prev_pos_y + 1].remove_entity(entity) self.owner.levels.current_map.tiles[prev_pos_x + 1][ prev_pos_y + 1].remove_entity(entity) self.owner.levels.current_map.tiles[ prev_pos_x + 1][prev_pos_y].remove_entity(entity) self.owner.levels.current_map.tiles[entity.x][ entity.y + 1].add_entity(entity) self.owner.levels.current_map.tiles[entity.x + 1][ entity.y + 1].add_entity(entity) self.owner.levels.current_map.tiles[entity.x + 1][ entity.y].add_entity(entity) self.owner.fov_recompute = True if combat_msg: self.owner.message_log.send(combat_msg) self.owner.render_functions.draw_stats(entity) if self.owner.player.fighter.dead: kill_msg = self.owner.player.kill() self.owner.game_state = GameStates.PLAYER_DEAD self.owner.message_log.send(kill_msg) self.owner.render_functions.draw_stats() break # Functions on monster death if entity.fighter and entity.fighter.dead: level_up_msg = self.owner.player.player.handle_player_exp( entity.fighter) kill_msg = entity.kill() self.owner.levels.current_map.tiles[entity.x][ entity.y].blocking_entity = None self.owner.message_log.send(kill_msg) self.owner.message_log.send( Message("I feel my power returning!")) if level_up_msg: self.owner.message_log.send(level_up_msg) self.owner.fov_recompute = True if not self.owner.game_state == GameStates.PLAYER_DEAD: self.owner.game_state = GameStates.PLAYER_TURN
def turn_taking_actions(self, wait=None, move=None, interact=None, pickup=None, stairs=None, examine=None, use_ability=None, key=None): if wait or move or interact or pickup or stairs or use_ability and not self.owner.player.fighter.dead: self.owner.player.status_effects.process_effects( game_map=self.owner.levels.current_map) if self.owner.player.fighter.paralyzed: msg = Message("You are paralyzed!") self.owner.message_log.send(msg) self.owner.time_counter.take_turn(1) if wait: self.owner.time_counter.take_turn(1) # player.player.spirit_power -= 1 msg = Message("You wait a turn.") self.owner.message_log.send(msg) self.owner.game_state = GameStates.ENEMY_TURN self.owner.fov_recompute = True elif move: dx, dy = move destination_x = self.owner.player.x + dx destination_y = self.owner.player.y + dy # Handle player attack if not self.owner.levels.current_map.is_blocked( destination_x, destination_y): target = self.owner.levels.current_map.tiles[destination_x][ destination_y].blocking_entity if target: results = self.owner.player.fighter.attack( target, self.owner.player.player.sel_weapon) self.owner.message_log.send(results) # player.player.spirit_power -= 0.5 self.owner.time_counter.take_turn(1) self.owner.render_functions.draw_stats(target) else: if self.owner.player.fighter.mv_spd <= 0: msg = Message("You are unable to move!") self.owner.message_log.send(msg) self.owner.time_counter.take_turn(1) else: prev_pos_x, prev_pos_y = self.owner.player.x, self.owner.player.y self.owner.player.move(dx, dy) self.owner.time_counter.take_turn( 1 / self.owner.player.fighter.mv_spd) self.owner.fov_recompute = True self.owner.levels.current_map.tiles[prev_pos_x][ prev_pos_y].remove_entity(self.owner.player) self.owner.levels.current_map.tiles[ self.owner.player.x][ self.owner.player.y].add_entity( self.owner.player) self.owner.game_state = GameStates.ENEMY_TURN elif self.owner.levels.current_map.tiles[destination_x][ destination_y].is_door: door = self.owner.levels.current_map.tiles[destination_x][ destination_y].door interact_msg = door.interaction(self.owner.levels.current_map) self.owner.message_log.send(interact_msg) self.owner.time_counter.take_turn(1) self.owner.game_state = GameStates.ENEMY_TURN self.owner.fov_recompute = True elif interact: entities = get_neighbours(self.owner.player, self.owner.levels.current_map.tiles) interact_msg = None for entity in entities: if entity.door: interact_msg = entity.door.interaction( self.owner.levels.current_map) self.owner.message_log.send(interact_msg) elif entity.item: interact_msg = entity.item.interaction( self.owner.levels.current_map) self.owner.message_log.send(interact_msg) if interact_msg: self.owner.time_counter.take_turn(1) self.owner.game_state = GameStates.ENEMY_TURN self.owner.fov_recompute = True elif pickup: pickup_msg = self.owner.player.inventory.add_item( self.owner.levels.current_map) if pickup_msg: self.owner.message_log.send(pickup_msg) self.owner.time_counter.take_turn(1) self.owner.game_state = GameStates.ENEMY_TURN self.owner.fov_recompute = True else: msg = Message("There is nothing here to pick up.") self.owner.message_log.send(msg) elif stairs: stairs_component = self.owner.levels.current_map.tiles[ self.owner.player.x][self.owner.player.y].stairs if stairs_component: results = stairs_component.interaction(self.owner.levels) self.owner.message_log.send(results) self.owner.time_counter.take_turn(1) self.owner.render_functions.draw_messages() self.owner.fov_recompute = True elif examine: self.owner.game_state = GameStates.TARGETING cursor_component = Cursor() cursor = Entity(self.owner.player.x, self.owner.player.y, 5, 0xE800 + 1746, "light yellow", "cursor", cursor=cursor_component, stand_on_messages=False) self.owner.cursor = cursor self.owner.levels.current_map.tiles[self.owner.cursor.x][ self.owner.cursor.y].add_entity(self.owner.cursor) self.owner.levels.current_map.entities["cursor"] = [ self.owner.cursor ] self.owner.fov_recompute = True elif use_ability: if key == blt.TK_Z: ability = self.owner.player.player.sel_utility else: ability = self.owner.player.player.sel_attack result, target, targeting = self.owner.player.player.use_ability( self.owner.levels.current_map, ability) if target: self.owner.render_functions.draw_stats(target) if targeting: self.owner.game_state = GameStates.TARGETING cursor_component = Cursor(targeting_ability=ability) cursor = Entity(target.x, target.y, 5, 0xE800 + 1746, "light yellow", "cursor", cursor=cursor_component, stand_on_messages=False) self.owner.cursor = cursor self.owner.levels.current_map.tiles[self.owner.cursor.x][ self.owner.cursor.y].add_entity(self.owner.cursor) self.owner.levels.current_map.entities["cursor"] = [ self.owner.cursor ] else: self.owner.time_counter.take_turn(1) self.owner.game_state = GameStates.ENEMY_TURN self.owner.message_log.send(result) self.owner.fov_recompute = True if self.owner.player.fighter.summoning: msg = self.owner.player.summoner.process( game_map=self.owner.levels.current_map) if msg: self.owner.message_log.send(msg) self.owner.fov_recompute = True
def take_turn(self, target, game_map, entities, time): monster = self.owner if not self.action_begin: self.last_action = time.get_last_turn() time_to_act = time.get_turn() - self.last_action action_cost = 0 combat_msgs = [] self.owner.light_source.recompute_fov(monster.x, monster.y) if self.ally and target.player: if monster.distance_to(target) > 1: monster.move_astar(target, entities, game_map) elif randint(0, 4) == 0: tiles = get_neighbours(self.owner, game_map.tiles, algorithm="square", empty_tiles=True) target_tile = choice(tiles) self.owner.move_to_tile(target_tile.x, target_tile.y) if self.owner.remarks: remark = choice(self.owner.remarks) combat_msgs.append( Message("{0}: {1}".format(self.owner.colored_name, remark), style="dialog")) elif self.owner.light_source.fov_map.fov[target.y, target.x]: self.target_seen = True self.target_last_seen_x = target.x self.target_last_seen_y = target.y self.action_begin = True while action_cost < time_to_act: if monster.distance_to( target ) == 1 and self.owner.fighter.atk_spd <= time_to_act - action_cost: if target.fighter.hp > 0: combat_msg, skill = self.choose_skill() if skill is None: combat_msgs.extend(combat_msg) return combat_msgs combat_msg = monster.fighter.attack(target, skill) combat_msgs.extend(combat_msg) action_cost += 1 #self.last_action += action_cost else: break elif 1 / self.owner.fighter.mv_spd <= time_to_act - action_cost and monster.distance_to( target) >= 2: if randint(0, 4) == 0: if self.owner.remarks: remark = choice(self.owner.remarks) combat_msgs.append( Message(msg="{0}: {1}".format( self.owner.colored_name, remark), style="dialog")) monster.move_astar(target, entities, game_map) action_cost += 1 / monster.fighter.mv_spd #self.last_action += action_cost else: break self.last_action += action_cost elif self.target_seen: self.action_begin = False if not monster.x == self.target_last_seen_x and not monster.y == self.target_last_seen_y: monster.move_astar(target, entities, game_map) else: self.action_begin = False return combat_msgs