Beispiel #1
0
 def show_hit(self, char, target_x, target_y, attack_type, dam_type):
     if attack_type == 'melee':
         x = char.x + self.sign(target_x - char.x) * self.square_width
         y = char.y + self.sign(target_y - char.y) * self.square_height
     elif attack_type == 'ranged':
         x = target_x
         y = target_y
     if dam_type == 'dam_cut':
         particle_anim = self.resources.animations['hit_mark_slice']
         particle_anim.frame_index = 0
         part_x = x + (random.randrange(-3, 4) / 10 * self.square_width)
         part_y = y + (random.randrange(-3, 4) / 10 * self.square_height)
         new_particle = Particle(self, particle_anim, 'hit_slice', 12, 0, 0, part_x, part_y)
     elif dam_type == 'dam_pierce':
         particle_anim = self.resources.animations['hit_mark_pierce']
         particle_anim.frame_index = 0
         part_x = x + (random.randrange(-3, 4) / 10 * self.square_width)
         part_y = y + (random.randrange(-3, 4) / 10 * self.square_height)
         new_particle = Particle(self, particle_anim, 'tiny_metal_break', 12, 0, 0, part_x, part_y)
     elif dam_type == 'dam_bash':
         particle_anim = self.resources.animations['hit_mark_bash']
         particle_anim.frame_index = 0
         part_x = x + (random.randrange(-3, 4) / 10 * self.square_width)
         part_y = y + (random.randrange(-3, 4) / 10 * self.square_height)
         new_particle = Particle(self, particle_anim, 'tun', 12, 0, 0, part_x, part_y)
Beispiel #2
0
    def discharge(self, target):
        trap_attack = self.gameboard.tables.table_roll(self.rules['attack'],
                                                       'combat_table')
        damage = 0
        # trap strikes
        trap_attack = self.update_attack(trap_attack)

        inflict_status = {}
        if 'debuff' in trap_attack:
            status_list = trap_attack['debuff'].split(',')
            for i in status_list:
                status = self.gameboard.tables.table_roll(i, 'status_table')
                inflict_status[i] = status

        attack_list = self.get_discharges(trap_attack)
        for attack in attack_list:
            self.gameboard.woundme(self, target, attack['damage'],
                                   attack['attack_type'],
                                   attack['damage_type'], inflict_status)
        self.sound_set['discharge'].play()
        new_particle = Particle(self.gameboard, self.anim_set['discharge'],
                                None, 16, 0, 0, self.x, self.y)
        if self.rules['charges'] > 0:
            self.rules['charges'] -= 1
            if self.rules['charges'] == 0:
                self.gameboard.render_trap_list.remove(self)
Beispiel #3
0
 def test_arrow(self, from_x, from_y, to_x, to_y):
     dist_x = to_x - from_x
     dist_y = to_y - from_y
     if abs(dist_x) >= abs(dist_y):
         if dist_x != 0:
             step_y = round(abs(dist_y / dist_x) * self.sign(dist_y) * self.square_height)
         else:
             step_y = 0
         step_x = round(self.sign(dist_x) * self.square_width)
     else:
         step_y = round(self.sign(dist_y) * self.square_height)
         if dist_y != 0:
             step_x = round(abs(dist_x / dist_y) * self.sign(dist_x) * self.square_width)
         else:
             step_x = 0
     temp_x = from_x
     temp_y = from_y
     hit = False
     while (abs(temp_x - to_x) >= self.square_width or abs(temp_y - to_y) >= self.square_height) and not hit:
         print(temp_x, temp_y, to_x, to_y)
         obj = self.collidelist(None, temp_x, temp_y, self.solid_list, self.square_width // 2)
         door = self.collidelist(None, temp_x, temp_y, self.labyrinth.door_list, self.square_width // 2)
         if obj or (door and door.rules['closed'] == 1):
             hit = True
         # test ray calculation
         new_particle = Particle(self, self.resources.animations['damage_mark_blood'],
                                 None, 60, 0, 0, temp_x, temp_y)
         temp_x += step_x
         temp_y += step_y
     if hit:
         return False
     else:
         return True
Beispiel #4
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)
Beispiel #5
0
 def ranged_attack_check(self, x, y):
     if self.inventory.equipped[
             'main_hand'] is not None and 'ranged' in self.inventory.equipped[
                 'main_hand'].rules:
         if 'ammo_type' not in self.inventory.equipped[
                 'main_hand'].rules or (
                     self.inventory.equipped['ammo_slot'] is not None
                     and 'ammo_type'
                     in self.inventory.equipped['ammo_slot'].rules and
                     self.inventory.equipped['main_hand'].rules['ammo_type']
                     == self.inventory.equipped['ammo_slot'].
                     rules['ammo_type']):
             obj_target = self.gameboard.mouse_on_object(
                 x, y, self.gameboard.render_mobs_list)
             if obj_target is not False and self.gameboard.test_arrow(
                     self.x + self.width // 2, self.y + self.height // 2,
                     obj_target.x + obj_target.width // 2,
                     obj_target.y + obj_target.height // 2):
                 if 'ammo_type' in self.inventory.equipped[
                         'main_hand'].rules:
                     if self.inventory.equipped['ammo_slot'].rules[
                             'amount_cur'] != 0:
                         speed_x = (obj_target.x - self.x) / 8
                         speed_y = (obj_target.y - self.y) / 8
                         new_particle = Particle(
                             self.gameboard, self.inventory.
                             equipped['ammo_slot'].anim_set['tile'], None,
                             8, speed_x, speed_y, self.x + self.width // 2,
                             self.y + self.height // 2)
                         if self.inventory.equipped['ammo_slot'].rules[
                                 'amount_cur'] > 1:
                             self.inventory.equipped['ammo_slot'].rules[
                                 'amount_cur'] -= 1
                         elif self.inventory.equipped['ammo_slot'].rules[
                                 'amount_cur'] == 1:
                             self.inventory.equipped['ammo_slot'] = None
                         self.attack(obj_target)
                     self.gameboard.ui.ragdoll_refresh(
                         self.gameboard.ui.container_crumps[-1])
                 return True
     return False
Beispiel #6
0
    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)
Beispiel #7
0
    def attack(self, target):
        distance = self.gameboard.get_distance(target.x, target.y, self.x,
                                               self.y)
        mob_attack = self.gameboard.tables.table_roll(self.rules['attack'],
                                                      'combat_table')

        # Mob strikes
        if distance == 1 or ('ranged' in mob_attack
                             and 1 < distance < self.rules['aggr_distance']
                             and self.gameboard.test_arrow(
                                 self.x + self.width // 2,
                                 self.y + self.height // 2,
                                 target.dest_x + target.width // 2,
                                 target.dest_y + target.height // 2)):

            self.stats.stats_recalc()
            mob_attack = self.attack_update(mob_attack)

            modifiers_dict = self.stats.get_modifiers_dict(self.inventory)
            self.stats.update_modifiers_dict(modifiers_dict, mob_attack, 3)

            inflict_status = {}
            if 'debuff' in mob_attack:
                status_list = mob_attack['debuff'].split(',')
                for i in status_list:
                    status = self.gameboard.tables.table_roll(
                        i, 'status_table')
                    inflict_status[i] = status
            attack_list = self.stats.get_attacks(self.stats, modifiers_dict)
            for attack in attack_list:
                self.gameboard.woundme(self, target, attack['damage'],
                                       attack['attack_type'],
                                       attack['damage_type'], inflict_status)

            self.sound_set['attack'].play()

            if target.x > self.x:
                self.mirrored = True
            elif target.x < self.x:
                self.mirrored = False
            self.gameboard.set_temp_anim(self, 'attack', 16, True)

            if 'ranged' in mob_attack:
                speed_x = (target.dest_x - self.x) / 16
                speed_y = (target.dest_y - self.y) / 16
                new_particle = Particle(self.gameboard,
                                        self.anim_set['missile'], None, 16,
                                        speed_x, speed_y,
                                        self.x + self.width // 2,
                                        self.y + self.height // 2)

        # Mob move towards target
        elif 1 < distance <= self.rules['aggr_distance']:
            self.gameboard.set_anim(self, 'walk', False)
            dir_x, dir_y = self.gameboard.get_direction(
                target.dest_x, target.dest_y, self.x, self.y)
            if abs(dir_y) > abs(dir_x) or (abs(dir_y) == abs(dir_x)
                                           and random.randrange(0, 2) == 0):
                self.gameboard.move_object(
                    self, self.x,
                    self.y + self.gameboard.square_height * dir_y)
            else:
                self.gameboard.move_object(
                    self, self.x + self.gameboard.square_width * dir_x, self.y)
        # Mob stays idle
        else:
            pass