Ejemplo n.º 1
0
 def test_load_regeneration_ability_data(self) -> None:
     data = AbilityData(**load_ability_data_kwargs('basic_heal'))
     expected_data = AbilityData(cool_down_time=300,
                                 heal_amount=20,
                                 finite_uses=True,
                                 uses_left=1,
                                 sound_on_use='health_pack.wav')
     self.assertEqual(data, expected_data)
Ejemplo n.º 2
0
    def test_load_projectile_ability(self) -> None:
        data = AbilityData(**load_ability_data_kwargs('pistol'))

        expected_data = AbilityData(250,
                                    projectile_label='bullet',
                                    kickback=200,
                                    spread=5,
                                    muzzle_flash=True,
                                    sound_on_use='pistol.wav')
        self.assertEqual(data, expected_data)
Ejemplo n.º 3
0
    def __new__(cls, location: str, ability_label: str,
                equipped_image_file: str, backpack_image_file: str,
                description: str, stackable: bool = False,
                buffs: Set[Buffs] = None,
                proficiencies: Set[Proficiencies] = None) -> BaseModData:
        ability_data = AbilityData(**load_ability_data_kwargs(ability_label))

        return super().__new__(cls, ModLocation(location),  # type: ignore
                               ability_data, equipped_image_file,
                               backpack_image_file, description, stackable,
                               buffs, proficiencies)
Ejemplo n.º 4
0
    def test_player_fires_laser_expends_energy(self) -> None:
        laser_gun, player = self._player_with_ready_laser()

        starting_energy = player.energy_source.energy_available

        fire_laser = player.ability_caller(laser_gun.mod.loc)
        fire_laser()
        final_energy = player.energy_source.energy_available

        expected = load_ability_data_kwargs('laser')['energy_required']
        actual = starting_energy - final_energy
        self.assertEqual(actual, expected)
Ejemplo n.º 5
0
    def test_creation_of_usable_items_from_data(self) -> None:
        player = make_player()
        item_data = items.ItemData(**load_item_data_kwargs('pistol'))
        pistol_ability = AbilityData(**load_ability_data_kwargs('pistol'))

        pistol = items.ItemFromData(item_data, Vector2(0, 0))
        player.inventory.attempt_pickup(pistol)

        self.assertIs(pistol.mod, player.inventory.active_mods[pistol.mod.loc])

        use_pistol = player.ability_caller(mods.ModLocation.ARMS)
        self.timer.current_time += pistol_ability.cool_down_time + 1

        use_pistol()
        self.assertEqual(len(self.groups.bullets), 1)
Ejemplo n.º 6
0
    def test_fire_projectile_distance_independent_of_count(self) -> None:
        player = make_player()
        num_updates = 100

        data_dict = load_ability_data_kwargs('shotgun')
        data_dict['projectile_count'] = 1
        ability_data = AbilityData(**data_dict)

        fire_little_bullet = GenericAbility(ability_data)

        fire_little_bullet.use(player)

        self.assertEqual(len(self.groups.bullets), 1)
        bullet = self.groups.bullets.sprites()[0]
        first_pos = Vector2(bullet.pos.x, bullet.pos.y)

        for _ in range(num_updates):
            self.groups.bullets.update()

        one_disp = (bullet.pos - first_pos).length()

        many = 10
        ability_data = ability_data._replace(projectile_count=many)
        fire_little_bullet = GenericAbility(ability_data)

        self.groups.bullets.empty()
        fire_little_bullet.use(player)
        self.assertEqual(len(self.groups.bullets), many)

        bullet = self.groups.bullets.sprites()[0]
        first_pos = Vector2(bullet.pos.x, bullet.pos.y)

        for _ in range(num_updates):
            self.groups.bullets.update()

        many_disp = (bullet.pos - first_pos).length()

        self.assertLess(0.5 * many_disp, one_disp)
Ejemplo n.º 7
0
def setUpModule() -> None:
    initialize_pygame()
    model.initialize(LaserTest.groups, LaserTest.timer)

    ability_data = AbilityData(**load_ability_data_kwargs('laser'))
    LaserTest.laser_ability = GenericAbility(ability_data)
Ejemplo n.º 8
0
def setUpModule() -> None:
    initialize_pygame()
    model.initialize(AbilitiesTest.groups, AbilitiesTest.timer)
    ability_data = AbilityData(**load_ability_data_kwargs('pistol'))

    AbilitiesTest.projectile_ability_data = ability_data
Ejemplo n.º 9
0
    def test_load_ability_data_bad_name(self) -> None:
        bad_name = 'seoifjosiejf'

        with self.assertRaisesRegex(KeyError, 'not recognized'):
            load_ability_data_kwargs(bad_name)