def gain_exp(self, exp): self.char_pools['experience'] += exp new_level = self.level_calculate(self.char_pools['experience']) if new_level > self.char_stats['level']: self.char_stats['level'] = new_level self.levelup_bonus(self.levelup_hp_bonus, self.levelup_mp_bonus, self.levelup_sp_bonus) self.stats_recalc() self.char_pools_maximize() new_text = Text(self.gameboard, 'LEVEL UP!', self.character.x + self.character.width // 2, self.character.y, 'default', 18, (255, 255, 255), 'center', 'top', 1, 0, -0.5) self.gameboard.audio.sound_bank['tiny_needle'].play() elif new_level < self.char_stats['level']: self.char_stats['level'] = new_level self.levelup_bonus(self.levelup_hp_bonus * -1, self.levelup_mp_bonus * -1, self.levelup_sp_bonus * -1) self.stats_recalc() self.char_pools_check() new_text = Text(self.gameboard, 'LEVEL DOWN!', self.character.x + self.character.width // 2, self.character.y, 'default', 18, (255, 0, 0), 'center', 'top', 1, 0, -0.5) self.gameboard.audio.sound_bank['deep_vortex'].play() else: exp_caption = self.gameboard.resources.text_bank[ 'exp_gain'].replace('%1', str(exp)) new_text = Text(self.gameboard, exp_caption, self.character.x + self.character.width // 2, self.character.y, 'default', 18, (255, 255, 255), 'center', 'top', 1, 0, -0.5) self.gameboard.ui.stats_refresh()
def disarm(self, char): if self.rules['m_trap'] == 1: # magic traps cannot be disarmed with tools return False else: tool = self.gameboard.inventory_find_item(char.inventory.backpack, item_id='tool') if tool is not False: char.stats.stats_recalc() print('Attempting to disarm the trap. Difficulty', self.rules['difficulty'], ', skill', char.stats.char_stats_modified['disarm_traps'], '.') result = self.gameboard.pick_random([ char.stats.char_stats_modified['disarm_traps'], self.rules['difficulty'] ], [1, 0]) if result: self.gameboard.render_trap_list.remove(self) self.sound_set['disarm_success'].play() new_text = Text(self.gameboard, self.text_set['disarm_success'], self.x + self.width // 2, self.y, 'default', 18, (255, 255, 255), 'center', 'top', 1, 0, 0) print('Success!') char.stats.gain_exp(self.rules['difficulty'] // 2) return True else: if tool[0].rules['amount_cur'] > 1: tool[0].rules['amount_cur'] -= 1 else: tool[1].remove(tool[0]) self.gameboard.ui.ragdoll_refresh( self.gameboard.ui.container_crumps[-1]) # self.sound_set['unlock_fail'].play() new_text = Text(self.gameboard, self.text_set['disarm_fail'], self.x + self.width // 2, self.y, 'default', 18, (255, 0, 0), 'center', 'top', 1, 0, 0) print('Failed. Tool is lost.') return False else: new_text = Text(self.gameboard, self.text_set['no_tool'], self.x + self.width // 2, self.y, 'default', 18, (255, 255, 0), 'center', 'top', 1, 0, 0) # self.sound_set['no_tool'].play() return False
def lootme(self, loot_item, looter): loot_item.sound_set['pickup'].play() cap_text = loot_item.text_set['pickup'] if 'amount_cur' in loot_item.rules: amount = int(loot_item.rules['amount_cur']) cap_text = cap_text.replace('%1', str(amount)) if amount > 1: cap_text = cap_text.replace('%2', 's') else: cap_text = cap_text.replace('%2', '') else: cap_text = cap_text.replace('%1', loot_item.compose_full_title()) cap_x, cap_y = loot_item.x + loot_item.width // 2, loot_item.y cap_color = (255, 255, 255) self.set_anim(loot_item, 'tile', False) if looter is not self.player_char or self.player_char.autoequip(loot_item) is False: left_item = self.container_item_not_fit(loot_item, looter.inventory.backpack, looter.inventory.bp_max) if left_item: looter.inventory.backpack.append(left_item) else: self.ui.ragdoll_refresh(self.ui.container_crumps[-1]) self.render_items_list.remove(loot_item) if self.inventory_check(looter) > 0: cap_text = 'Inventory full!' cap_color = (255, 255, 0) new_caption = Text(self, cap_text, cap_x, cap_y, 'default', 20, cap_color, 'center', 'top', 1, 0, 0)
def show_damage(self, char, actual_damage, damage_type): rand_x = char.x + random.randrange(0, char.width + 1) rand_y = char.y + random.randrange(0, round(char.height * 0.6)) cap_text = '' + str(actual_damage) if damage_type in ['dam_cut', 'dam_pierce', 'dam_bash']: particle_anim = self.resources.animations['damage_mark_blood'] new_particle = Particle(self, particle_anim, None, 15, 0, 4, rand_x, rand_y) new_caption = Text(self, cap_text, rand_x, rand_y, 'default', 22, (255, 0, 0), 'center', 'middle', 0.75, 0, -0.2) elif damage_type == 'dam_poison': particle_anim = self.resources.animations['damage_mark_poison'] new_particle = Particle(self, particle_anim, None, 15, 0, 1, rand_x, rand_y) new_caption = Text(self, cap_text, rand_x, rand_y, 'default', 22, (0, 255, 0), 'center', 'middle', 0.75, 0, -0.2) elif damage_type == 'dam_fire': particle_anim = self.resources.animations['damage_mark_fire'] new_particle = Particle(self, particle_anim, None, 15, 0, -1, rand_x, rand_y) new_caption = Text(self, cap_text, rand_x, rand_y, 'default', 22, (255, 255, 0), 'center', 'middle', 0.75, 0, -0.2) elif damage_type == 'dam_ice': particle_anim = self.resources.animations['damage_mark_ice'] new_particle = Particle(self, particle_anim, None, 15, 0, -1, rand_x, rand_y) new_caption = Text(self, cap_text, rand_x, rand_y, 'default', 22, (0, 0, 255), 'center', 'middle', 0.75, 0, -0.2) elif damage_type == 'dam_lightning': particle_anim = self.resources.animations['damage_mark_lightning'] new_particle = Particle(self, particle_anim, None, 15, 0, 0, rand_x, rand_y) new_caption = Text(self, cap_text, rand_x, rand_y, 'default', 22, (0, 255, 255), 'center', 'middle', 0.75, 0, -0.2) elif damage_type == 'dam_arcane': particle_anim = self.resources.animations['damage_mark_arcane'] new_particle = Particle(self, particle_anim, None, 15, 0, 0, rand_x, rand_y) new_caption = Text(self, cap_text, rand_x, rand_y, 'default', 22, (255, 0, 255), 'center', 'middle', 0.75, 0, -0.2)
def picklock(self, char): if self.rules['m_lock'] == 1: new_text = Text(self.gameboard, self.text_set['m_lock'], self.x + self.width // 2, self.y, 'default', 18, (255,0,255), 'center', 'top', 1, 0,0) self.sound_set['m_lock'].play() return False else: lockpick = self.gameboard.inventory_find_item(char.inventory.backpack, item_id='lockpick') if lockpick is not False: char.stats.stats_recalc() print('Attempting to pick the lock. Difficulty', self.rules['lock'], ', skill', char.stats.char_stats_modified['pick_locks'], '.') result = self.gameboard.pick_random([char.stats.char_stats_modified['pick_locks'], self.rules['lock']], [1, 0]) if result: char.stats.gain_exp(self.rules['lock']) self.rules['lock'] = 0 self.checkme() self.sound_set['unlock_success'].play() new_text = Text(self.gameboard, self.text_set['unlock_success'], self.x + self.width // 2, self.y, 'default', 18, (255, 255, 255), 'center', 'top', 1, 0, 0) print('Success!') return True else: if lockpick[0].rules['amount_cur'] > 1: lockpick[0].rules['amount_cur'] -= 1 else: lockpick[1].remove(lockpick[0]) self.gameboard.ui.ragdoll_refresh(self.gameboard.ui.container_crumps[-1]) self.sound_set['unlock_fail'].play() new_text = Text(self.gameboard, self.text_set['unlock_fail'], self.x + self.width // 2, self.y, 'default', 18, (255, 0, 0), 'center', 'top', 1, 0, 0) print('Failed. Lockpick has broken.') return False else: new_text = Text(self.gameboard, self.text_set['no_lockpick'], self.x + self.width // 2, self.y, 'default', 18, (255, 255, 0), 'center', 'top', 1, 0, 0) self.sound_set['no_lockpick'].play() return False
def reveal(self, char): char.stats.stats_recalc() print('Attempting to reveal the trap. Difficulty', self.rules['hidden'], ', skill', char.stats.char_stats_modified['find_traps'], '.') result = self.gameboard.pick_random([ char.stats.char_stats_modified['find_traps'], self.rules['hidden'] ], [1, 0]) if result: self.rules['hidden'] = 0 self.visible = True self.sound_set['reveal'].play() new_text = Text(self.gameboard, self.text_set['reveal'], self.x + self.width // 2, self.y, 'default', 18, (255, 255, 255), 'center', 'top', 1, 0, 0) print('Success!') char.stats.gain_exp(self.rules['hidden'] // 2) return True else: return False
def spell_cast(self, spell_dict, char, target): if char.stats.char_pools[ 'mp_cur'] < spell_dict['cost_mp'] * spell_dict['level']: # message about low mp return cast = False spell_particle_cast = self.gameboard.resources.animations[ spell_dict['spell_media']['anim_set']['cast']] spell_particle_effect = self.gameboard.resources.animations[ spell_dict['spell_media']['anim_set']['effect']] if spell_dict['spell_media']['sound_set']['cast'] is not None: spell_sound = self.gameboard.audio.sound_bank[ spell_dict['spell_media']['sound_set']['cast']] else: spell_sound = False spell_text = spell_dict['spell_media']['text_set']['cast'] spell_particle_time = spell_dict['particle_time'] if spell_dict['id'] == 'spl_healing_food': cast = True if target is not None: try: target.stats.char_pools[ 'hp_cur'] += self.gameboard.exponential( self.magic_exponential_ratio, spell_dict['level'], 5) except AttributeError: pass if spell_dict['id'] == 'spl_heal': cast = True if target is not None: try: target.stats.char_pools[ 'hp_cur'] += self.gameboard.exponential( self.magic_exponential_ratio, spell_dict['level'], 50) except AttributeError: pass if spell_dict['id'] == 'spl_dispel': if target is not None: try: if 'm_lock' in target.rules and target.rules['m_lock'] == 1: char.stats.stats_recalc() result = self.gameboard.pick_random([ spell_dict['level'] + char.stats.char_stats_modified['intelligence'], target.rules['lock'] ], [1, 0]) if result: char.stats.gain_exp(target.rules['lock'] * 10) target.rules['lock'] = target.rules['m_lock'] = 0 target.checkme() target.sound_set['unlock_success'].play() new_text = Text(self.gameboard, target.text_set['unlock_success'], target.x + target.width // 2, target.y, 'default', 18, (255, 255, 255), 'center', 'top', 1, 0, 0) except AttributeError: pass cast = True if cast: if target is not None: target_x = target.x target_y = target.y else: target_x = ( self.gameboard.mouse_x + self.gameboard.view_x ) // self.gameboard.square_width * self.gameboard.square_width target_y = ( self.gameboard.mouse_y + self.gameboard.view_y ) // self.gameboard.square_height * self.gameboard.square_height char.stats.char_pools[ 'mp_cur'] -= spell_dict['cost_mp'] * spell_dict['level'] if spell_dict['cost_mp'] > 0: char.stats.char_pools['ap_cur'] -= 1 char.stats.char_pools_check() if char == self.gameboard.player_char: char.checkme() if spell_sound is not False: spell_sound.play() new_particle = Particle(self.gameboard, spell_particle_cast, None, spell_particle_time, 0, 0, char.x, char.y) new_particle = Particle(self.gameboard, spell_particle_effect, None, spell_particle_time, 0, 0, target_x, target_y) new_text = Text(self.gameboard, spell_text, char.x + char.width // 2, char.y, 'default', 22, (255, 255, 255), 'center', 'top', 1, 0, 0)
def _check_events(self): for event in pygame.event.get(): if event.type == pygame.VIDEORESIZE: self.sight_width, self.sight_height = event.w, event.h pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE) # Window1.blit(Window1copy, (0, 0)) pygame.display.update() if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: if self.ui.active_ui_flags['ui_characters']: self.ui.hero_name_input(event) else: if event.key == pygame.K_q: sys.exit() if event.key == pygame.K_w: wpn_item = self.tables.table_roll('wpn_shortsword_base', 'treasure_table') new_wpn = Item(self, wpn_item, 1, self.player_char.x, self.player_char.y) self.player_char.inventory.backpack.append(new_wpn) if event.key == pygame.K_l: self.player_char.stats.stat_points += 10 if event.key == pygame.K_d and len(self.player_char.inventory.backpack) > 0: chest_item = self.tables.table_roll('cnt_chest_common', 'treasure_table') new_chest = Item(self, chest_item, 1, self.player_char.x, self.player_char.y) new_chest.rules['container'] = [itm for itm in self.player_char.inventory.backpack] self.player_char.inventory.backpack.clear() self.player_char.inventory.backpack.append(new_chest) self.labyrinth.drop_loot(self.player_char.inventory.backpack, self.player_char.x, self.player_char.y, True) self.player_char.inventory.backpack.clear() self.ui.ragdoll_refresh(self.ui.container_crumps[-1]) if event.key == pygame.K_b: chest_item = self.tables.table_roll('cnt_chest_common', 'treasure_table') new_chest = Item(self, chest_item, 1, self.player_char.x, self.player_char.y) self.player_char.inventory.backpack.append(new_chest) if self.player_char and self.players_turn and not self.player_char.stop: if event.key == pygame.K_DOWN: self.player_char.move_key = 'down' self.move_player = True elif event.key == pygame.K_UP: self.player_char.move_key = 'up' self.move_player = True elif event.key == pygame.K_LEFT: self.player_char.move_key = 'left' self.move_player = True elif event.key == pygame.K_RIGHT: self.player_char.move_key = 'right' self.move_player = True if event.key == pygame.KMOD_SHIFT: self.controls_shift = True elif self.player_char is not None and event.type == pygame.KEYUP: if event.key == pygame.K_DOWN and self.player_char.move_key == 'down': self.player_char.move_key = None self.move_player = False elif event.key == pygame.K_UP and self.player_char.move_key == 'up': self.player_char.move_key = None self.move_player = False elif event.key == pygame.K_LEFT and self.player_char.move_key == 'left': self.player_char.move_key = None self.move_player = False elif event.key == pygame.K_RIGHT and self.player_char.move_key == 'right': self.player_char.move_key = None self.move_player = False if event.key == pygame.KMOD_SHIFT: self.controls_shift = False self.mouse_x, self.mouse_y = pygame.mouse.get_pos() if event.type == pygame.MOUSEBUTTONDOWN: mouse_button = event.button if not self.ui.control_capture_mouse('mouse_down', mouse_button, self.mouse_x, self.mouse_y): if self.player_char is not None and self.mouse_hand is None and not self.player_char.stop and \ not self.ui.active_ui_flags['ui_pause'] and not self.ui.active_ui_flags[ 'ui_message'] and not self.ui.active_ui_flags['ui_dialogue']: if mouse_button == 1 and ( self.player_char.inventory.equipped['main_hand'] is None or 'ranged' not in self.player_char.inventory.equipped['main_hand'].rules or self.mouse_on_object( self.mouse_x + self.view_x, self.mouse_y + self.view_y, self.render_mobs_list) is False): self.move_player = True elif event.type == pygame.MOUSEBUTTONUP: mouse_button = event.button if mouse_button == 1: self.move_player = False if not self.ui.control_capture_mouse('mouse_up', mouse_button, self.mouse_x, self.mouse_y) and \ not self.ui.active_ui_flags['ui_pause'] and not self.ui.active_ui_flags[ 'ui_message'] and not self.ui.active_ui_flags['ui_dialogue']: if self.mouse_hand is None: if mouse_button == 3: if self.player_char is not None and not self.player_char.stop and self.magic.player_spell is not None: self.magic.spell_mouse() if self.player_char and self.mouse_hand is not None and mouse_button == 1 and not self.player_char.stop: if 'curse' in self.mouse_hand.rules: new_text = Text(self, self.resources.text_bank['cant_drop_cursed'], self.player_char.x + self.player_char.width // 2, self.player_char.y, 'default', 22, (255,255,255), 'center', 'top', 1, 0, 0) self.mouse_hand.sound_set['pickup'].play() else: if 'container' in self.mouse_hand.rules: self.player_char.inventory.backpack.extend(self.pick_cursed_items(self.mouse_hand.rules['container'])) self.ui.ragdoll_refresh(self.ui.container_crumps[-1]) self.labyrinth.drop_loot([self.mouse_hand], self.player_char.x, self.player_char.y, True) self.mouse_hand.sound_set['pickup'].play() self.mouse_hand = None if mouse_button == 1 and self.player_char is not None and not self.player_char.stop: self.player_char.ranged_attack_check(self.mouse_x + self.view_x, self.mouse_y + self.view_y) if pygame.mouse.get_rel() != (0, 0): self.mouse_idle_ticks = 0