Example #1
0
    def render_list(self):
        tcod.console_set_default_foreground(self.console, tcod.white)
        if self.mode == AbilityMode.DESCRIPTION:
            message = get_message('ability_menu.description')
        else:
            message = get_message('ability_menu.use')
        tcod.console_print_ex(self.console, 1, 1, tcod.BKGND_NONE, tcod.LEFT,
                              message)

        index = 0
        for ability in self.player.entity.get_abilities():
            if ability.hidden:
                continue
            letter_index = ord('a') + index
            if letter_index > ord('z'):
                letter_index = ord('A') + index - 26

            message = '{0}) {1}'

            tcod.console_set_default_foreground(self.console, tcod.white)
            tcod.console_print_ex(
                self.console, 2, 3 + index, tcod.BKGND_NONE, tcod.LEFT,
                message.format(chr(letter_index), ability.get_name()))
            index += 1

        if self.mode == AbilityMode.DESCRIPTION:
            message = get_message('ability_menu.switch_mode.use')
        else:
            message = get_message('ability_menu.switch_mode.description')

        tcod.console_set_default_foreground(self.console,
                                            tcod.desaturated_green)
        tcod.console_print_ex(self.console, 1, 55, tcod.BKGND_NONE, tcod.LEFT,
                              message.format('?'))
 def use_ability(cls, monster):
     if monster.target is None:
         return
     cls.reset_turn(monster)
     if monster == monster.target or monster.target.get_status(StatusEffectSoulbound) is not None:
         add_log_message(
             LogMessage(
                 get_message('soulsteal.fail'),
                 tcod.white
             )
         )
         return
     success_roll = randint(1, monster.get_soul_power() + monster.target.get_soul_power())
     success = success_roll <= monster.get_soul_power()
     if not success:
         add_log_message(
             LogMessage(
                 get_message('soulsteal.fail'),
                 tcod.white
             )
         )
         return
     monster.game_map.take_over_monster(monster.player, monster=monster.target)
     cls.reset_turn(monster.target)
     soulbound_turns = monster.get_soul_power() + monster.target.get_soul_power()
     monster.add_status(StatusEffectSoulbound, soulbound_turns * randint(27, 33))
     monster.target.add_status(StatusEffectSoulbound, soulbound_turns * randint(9, 11))
     monster.target.target = None
     monster.target = None
Example #3
0
 def use(cls, item):
     add_log_message(
         LogMessage(
             get_message(
                 get_monster_message_prefix(item.monster) +
                 'item.potion.use').format(
                     str.capitalize(item.monster.get_name()),
                     item.get_name())))
Example #4
0
def attack(attacker, target):
    message_key_prefix = get_monster_message_prefix(attacker)

    roll = make_attack_roll(attacker)
    evasion = target.get_evasion()
    roll -= evasion
    if roll <= 0:
        add_log_message(
            LogMessage(
                get_message(message_key_prefix + "miss_dodge").format(
                    str.capitalize(attacker.get_name()), target.get_name()),
                tcod.grey))
        return

    damage = make_damage_roll(attacker)
    if damage <= target.get_shield_block():
        shield = target.get_shield_rate()
        roll -= shield
        if roll <= 0:
            add_log_message(
                LogMessage(
                    get_message(message_key_prefix + "miss_block").format(
                        str.capitalize(attacker.get_name()),
                        target.get_name()), tcod.grey))
            return

    armor = target.get_armor_value()
    if armor >= 1:
        damage -= randint(0, armor)
    if damage <= 0:
        add_log_message(
            LogMessage(
                get_message(message_key_prefix + "miss_armor").format(
                    str.capitalize(attacker.get_name()), target.get_name()),
                tcod.grey))
        return

    add_log_message(
        LogMessage(
            get_message(message_key_prefix + "hit").format(
                str.capitalize(attacker.get_name()), target.get_name(),
                damage), tcod.white))
    target.take_damage(damage, attacker)
    attacker.apply_attack_effect(target)
Example #5
0
 def remove_effect(self):
     if tcod.map_is_in_fov(self.monster.game_map.fov_map, self.monster.x,
                           self.monster.y):
         add_log_message(
             LogMessage(
                 get_message(
                     get_monster_message_prefix(self.monster) +
                     "poison.end").format(
                         str.capitalize(self.monster.get_name())),
                 tcod.desaturated_orange))
Example #6
0
 def __init__(self, monster, turns):
     super().__init__(monster, turns)
     if tcod.map_is_in_fov(monster.game_map.fov_map, monster.x, monster.y):
         add_log_message(
             LogMessage(
                 get_message(
                     get_monster_message_prefix(self.monster) +
                     "poison.begin").format(
                         str.capitalize(self.monster.get_name())),
                 tcod.dark_orange))
Example #7
0
 def heal(self, amount, with_message=True):
     self.hp += amount
     self.check_max_hp()
     if with_message:
         add_log_message(
             LogMessage(
                 get_message(get_monster_message_prefix(self) + 'healed')
                 .format(str.capitalize(self.get_name())),
                 tcod.desaturated_green if self.player is None else tcod.green
             )
         )
 def use_ability(cls, monster):
     items = monster.game_map.get_items_at(monster.x, monster.y)
     if not items:
         add_log_message(
             LogMessage(
                 get_message(get_monster_message_prefix(monster) + 'pickup_item.none'),
                 tcod.dark_grey
             )
         )
     else:
         item = items.pop()
         monster.inventory.add_item(item)
         add_log_message(
             LogMessage(
                 get_message(get_monster_message_prefix(monster) + 'pickup_item')
                 .format(monster.get_name(), item.get_name()),
                 tcod.white
             )
         )
     cls.reset_turn(monster)
Example #9
0
 def remove_effect(self):
     self.monster.remove_stat_bonus('dexterity', 'spider_web')
     self.monster.remove_stat_bonus('land_speed', 'spider_web')
     if tcod.map_is_in_fov(self.monster.game_map.fov_map, self.monster.x,
                           self.monster.y):
         add_log_message(
             LogMessage(
                 get_message(
                     get_monster_message_prefix(self.monster) +
                     "spider_web.end").format(
                         str.capitalize(self.monster.get_name())),
                 tcod.desaturated_orange))
Example #10
0
 def remove_effect(self):
     self.monster.remove_stat_bonus('strength', 'fatigue')
     self.monster.remove_stat_bonus('constitution', 'fatigue')
     self.monster.remove_stat_bonus('dexterity', 'fatigue')
     if tcod.map_is_in_fov(self.monster.game_map.fov_map, self.monster.x,
                           self.monster.y):
         add_log_message(
             LogMessage(
                 get_message(
                     get_monster_message_prefix(self.monster) +
                     "fatigue.end").format(
                         str.capitalize(self.monster.get_name())),
                 tcod.desaturated_orange))
Example #11
0
 def __init__(self, monster, turns):
     super().__init__(monster, turns)
     monster.add_stat_bonus('strength', 'fatigue', -2)
     monster.add_stat_bonus('constitution', 'fatigue', -2)
     monster.add_stat_bonus('dexterity', 'fatigue', -2)
     if tcod.map_is_in_fov(monster.game_map.fov_map, monster.x, monster.y):
         add_log_message(
             LogMessage(
                 get_message(
                     get_monster_message_prefix(self.monster) +
                     "fatigue.begin").format(
                         str.capitalize(self.monster.get_name())),
                 tcod.dark_orange))
Example #12
0
 def take_damage(self, damage, source = None):
     self.hp -= damage
     if self.hp <= 0:
         add_log_message(
             LogMessage(
                 get_message(get_monster_message_prefix(self) + "die")
                 .format(str.capitalize(self.get_name())),
                 tcod.orange if self.player is None else tcod.red
             )
         )
         self.dead = True
         if source is not None:
             source.gain_exp(self.get_defeat_experience())
         if self.player is not None:
             delete_game()
Example #13
0
 def remove_effect(self):
     self.monster.remove_stat_bonus('strength', 'rage')
     self.monster.remove_stat_bonus('constitution', 'rage')
     self.monster.remove_stat_bonus('dexterity', 'rage')
     self.monster.remove_stat_bonus('intelligence', 'rage')
     if tcod.map_is_in_fov(self.monster.game_map.fov_map, self.monster.x,
                           self.monster.y):
         add_log_message(
             LogMessage(
                 get_message(
                     get_monster_message_prefix(self.monster) +
                     "rage.end").format(
                         str.capitalize(self.monster.get_name())),
                 tcod.desaturated_blue))
     self.monster.add_status(StatusEffectFatigue, self.elapsed_turns * 2)
Example #14
0
 def __init__(self, monster, turns):
     self.elapsed_turns = 0
     super().__init__(monster, turns)
     monster.add_stat_bonus('strength', 'rage', 8)
     monster.add_stat_bonus('constitution', 'rage', 4)
     monster.add_stat_bonus('dexterity', 'rage', -4)
     monster.add_stat_bonus('intelligence', 'rage', -8)
     if tcod.map_is_in_fov(monster.game_map.fov_map, monster.x, monster.y):
         add_log_message(
             LogMessage(
                 get_message(
                     get_monster_message_prefix(self.monster) +
                     "rage.begin").format(
                         str.capitalize(self.monster.get_name())),
                 tcod.blue))
Example #15
0
 def __init__(self, monster, turns):
     super().__init__(monster, turns)
     self.total_turns = turns
     self.total_dex_malus = -1
     self.total_speed_malus = 25
     monster.add_stat_bonus('dexterity', 'spider_web', self.total_dex_malus)
     monster.add_stat_bonus('land_speed', 'spider_web',
                            self.total_speed_malus)
     if tcod.map_is_in_fov(monster.game_map.fov_map, monster.x, monster.y):
         add_log_message(
             LogMessage(
                 get_message(
                     get_monster_message_prefix(self.monster) +
                     "spider_web.begin").format(
                         str.capitalize(self.monster.get_name())),
                 tcod.dark_orange))
Example #16
0
 def gain_level(self, level, log=False):
     if level < 1:
         return
     for _ in range(level - 1):
         self.monster_race.gain_level(self)
         if self.monster_class:
             self.monster_class.gain_level(self)
     self.level += level
     if log:
         add_log_message(
             LogMessage(
                 get_message(get_monster_message_prefix(self) + "level_up")
                 .format(str.capitalize(self.get_name())),
                 tcod.orange if self.player is None else tcod.green
             )
         )
Example #17
0
    def stack(self, monster, turns):
        add_turns = min(300, self.turns + turns) - self.turns
        self.turns += add_turns
        self.total_turns += add_turns
        self.total_dex_malus = max(-5, self.total_dex_malus - 1)
        self.total_speed_malus = min(250, self.total_speed_malus + 25)

        multiplier = self.turns / self.total_turns
        monster.add_stat_bonus('dexterity', 'spider_web',
                               floor(self.total_dex_malus * multiplier))
        monster.add_stat_bonus('land_speed', 'spider_web',
                               ceil(self.total_speed_malus * multiplier))

        if tcod.map_is_in_fov(monster.game_map.fov_map, monster.x, monster.y):
            add_log_message(
                LogMessage(
                    get_message(
                        get_monster_message_prefix(self.monster) +
                        "spider_web.stack").format(
                            str.capitalize(self.monster.get_name())),
                    tcod.dark_orange))
Example #18
0
    def run(self):
        while not tcod.console_is_window_closed():
            self.render_engine.render_scene(self.current_scene)
            if self.current_scene.data is not None:
                input_return = self.current_scene.manage_input(None)
            else:
                game_input = self.input_manager.get_input()
                input_return = self.current_scene.manage_input(game_input)
            if input_return is None:
                continue
            if input_return['action']:
                if input_return['action'] == 'confirm':
                    input_return = self.current_scene.need_confirm
                if input_return['action'] == 'cancel' or input_return['action'] == 'cancel_with_action':
                    if self.current_scene.previous_scene is not None:
                        current = self.current_scene
                        self.current_scene = self.current_scene.previous_scene
                        current.previous_scene = None
                        if input_return['action'] == 'cancel_with_action' and isinstance(self.current_scene, MapScene):
                            self.current_scene.player_took_action = True
                        self.current_scene.render_next = True
                        del current
                    else:
                        if self.current_scene.need_confirm is not None:
                            return True
                        self.current_scene.need_confirm = input_return
                        add_log_message(
                            LogMessage(
                                get_message("quit_game.confirm"),
                                tcod.light_cyan
                            )
                        )
                        self.current_scene.render_next = True
                elif input_return['action'] == 'change_scene':
                    self.current_scene = input_return['scene']
                    self.current_scene.render_next = True

        if not self.player.entity.dead:
            save_game(self.player)
Example #19
0
    def render_list(self):
        tcod.console_set_default_foreground(self.console, tcod.white)
        if self.mode == InventoryMode.DESCRIPTION:
            message = get_message('inventory.description')
        elif self.mode == InventoryMode.DROP:
            message = get_message('inventory.drop')
        else:
            message = get_message('inventory.use')
        tcod.console_print_ex(self.console, 1, 1, tcod.BKGND_NONE, tcod.LEFT,
                              message)

        index = 0
        for item in self.player.entity.inventory.items:
            letter_index = ord('a') + index
            if letter_index > ord('z'):
                letter_index = ord('A') + index - 26

            if item.usable or self.mode != InventoryMode.USE:
                color = item.get_color()
                message = '{0}) {1}'
            else:
                color = tcod.dark_grey
                message = '   {1}'

            tcod.console_set_default_foreground(self.console, color)
            tcod.console_print_ex(
                self.console, 2, 3 + index, tcod.BKGND_NONE, tcod.LEFT,
                message.format(chr(letter_index), item.get_name()))
            index += 1

        if self.mode == InventoryMode.DESCRIPTION:
            message = get_message('inventory.switch_mode.drop')
        elif self.mode == InventoryMode.DROP:
            message = get_message('inventory.switch_mode.use')
        else:
            message = get_message('inventory.switch_mode.description')

        tcod.console_set_default_foreground(self.console,
                                            tcod.desaturated_green)
        tcod.console_print_ex(self.console, 1, 55, tcod.BKGND_NONE, tcod.LEFT,
                              message.format('?'))
Example #20
0
    def render_stats(self):
        tcod.console_set_default_background(self.stat_console, tcod.black)
        tcod.console_clear(self.stat_console)
        bar_width = int(
            float(self.player.entity.get_hp()) /
            self.player.entity.get_max_hp() * (stat_console_width - 6))
        tcod.console_set_default_background(self.stat_console, tcod.red)
        tcod.console_rect(self.stat_console, 5, 5, (stat_console_width - 6), 1,
                          False, tcod.BKGND_SCREEN)
        tcod.console_set_default_background(self.stat_console, tcod.green)
        if bar_width > 0:
            tcod.console_rect(self.stat_console, 5, 5, bar_width, 1, False,
                              tcod.BKGND_SCREEN)

        tcod.console_print_ex(self.stat_console, 1, 5, tcod.BKGND_NONE,
                              tcod.LEFT, 'HP:')
        tcod.console_set_default_foreground(self.stat_console, tcod.black)
        tcod.console_print_ex(
            self.stat_console, 5, 5, tcod.BKGND_NONE, tcod.LEFT,
            '{0: 3}/{1: 3}'.format(
                self.player.entity.get_hp(),
                self.player.entity.get_max_hp(),
            ))
        tcod.console_set_default_foreground(self.stat_console, tcod.white)

        tcod.console_print_ex(
            self.stat_console, 1, 1, tcod.BKGND_NONE,
            tcod.LEFT, 'Race:  {0}'.format(
                str.upper(self.player.entity.monster_race.name)))
        class_name = 'None'
        if self.player.entity.monster_class is not None:
            class_name = str.upper(self.player.entity.monster_class.name)
        level = self.player.entity.get_level()
        tcod.console_print_ex(self.stat_console, 1, 2, tcod.BKGND_NONE,
                              tcod.LEFT, 'Class: {0}'.format(class_name))
        tcod.console_print_ex(self.stat_console, 1, 3, tcod.BKGND_NONE,
                              tcod.LEFT, 'Level: {0}'.format(str(level)))
        tcod.console_print_ex(
            self.stat_console, 1, 4, tcod.BKGND_NONE,
            tcod.LEFT, 'Exp: {0} / {1}'.format(
                self.player.entity.current_exp,
                self.player.entity.get_exp_to_next_level()))
        tcod.console_print_ex(
            self.stat_console, 1, 7, tcod.BKGND_NONE, tcod.LEFT,
            'STR {0:02} DEX {1:02} CON {2:02} INT {3:02}'.format(
                self.player.entity.get_strength(),
                self.player.entity.get_dexterity(),
                self.player.entity.get_constitution(),
                self.player.entity.get_intelligence(),
            ))
        tcod.console_print_ex(self.stat_console, 1, 9, tcod.BKGND_NONE,
                              tcod.LEFT, 'Equipment:')
        console_y = 10
        if self.player.entity.equip_slots:
            for slot in self.player.entity.equip_slots:
                slot_name = get_message('equip.slot.' + str(slot.value) +
                                        '.truncate')
                equip = self.player.entity.inventory.get_equip(slot)
                if equip:
                    equip_name = equip.get_name()
                else:
                    equip_name = get_message('equip.no_equipment')
                tcod.console_print_ex(
                    self.stat_console, 1, console_y, tcod.BKGND_NONE,
                    tcod.LEFT, ' {0}: {1}'.format(slot_name, equip_name))
                console_y += 1
        else:
            slot_name = get_message('equip.slot.none')
            tcod.console_print_ex(self.stat_console, 1, console_y,
                                  tcod.BKGND_NONE, tcod.LEFT,
                                  ' {0}'.format(slot_name))
            console_y += 1

        console_y += 1

        tcod.console_print_ex(self.stat_console, 1, console_y, tcod.BKGND_NONE,
                              tcod.LEFT, 'Traits:')
        console_y += 1
        for trait in self.player.entity.traits:
            tcod.console_print_ex(self.stat_console, 1, console_y,
                                  tcod.BKGND_NONE, tcod.LEFT,
                                  ' {0}'.format(trait.name))
            console_y += 1

        under_mouse_lines = textwrap.wrap(self.under_mouse, stat_console_width)

        i_line = 0
        for line in under_mouse_lines:
            tcod.console_print_ex(self.stat_console, 1,
                                  field_console_height + i_line,
                                  tcod.BKGND_NONE, tcod.LEFT, line)
            i_line += 1

        tcod.console_blit(self.stat_console, 0, 0, stat_console_width,
                          stat_console_height, 0, field_console_width, 0)