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)
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)
def test_regenerate_player_energy_correct_amount(self) -> None: player = make_player() recharge_amount = 15 data = AbilityData(cool_down_time=300, finite_uses=True, uses_left=2, recharge_amount=recharge_amount) recharge = GenericAbility(data) source = player.energy_source starting_energy = source.max_energy energy_expended = 20 source.expend_energy(energy_expended) self.assertEqual(source.energy_available, starting_energy - energy_expended) recharge.use(player) self.assertEqual(source.energy_available, starting_energy - energy_expended + recharge_amount) self.assertEqual(recharge.uses_left, 1) recharge.use(player) self.assertEqual(source.energy_available, starting_energy) self.assertEqual(recharge.uses_left, 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)
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)
def test_heal_player_damaged_correct_amount(self) -> None: player = make_player() heal_amount = 10 data = AbilityData(cool_down_time=300, finite_uses=True, uses_left=3, heal_amount=heal_amount) heal = GenericAbility(data) max_health = player.status.max_health player.status.increment_health(-heal_amount - 2) heal.use(player) self.assertEqual(player.status.health, max_health - 2) self.assertEqual(heal.uses_left, 2)
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)
def test_heal_player_not_damaged(self) -> None: player = make_player() heal_amount = 10 data = AbilityData(cool_down_time=300, finite_uses=True, uses_left=3, heal_amount=heal_amount) heal = GenericAbility(data) max_health = player.status.max_health self.assertEqual(player.status.health, max_health) self.assertFalse(heal.can_use(player)) # use implements a heal anyway heal.use(player) self.assertEqual(player.status.health, max_health) self.assertEqual(heal.uses_left, 2)
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)
def setUpModule() -> None: initialize_pygame() model.initialize(ModTest.groups, ModTest.timer) ModTest.ability_data = AbilityData(10)
def test_ability_data_equality(self) -> None: base_data = AbilityData(cool_down_time=300, finite_uses=True, uses_left=3) base_data_2 = AbilityData(cool_down_time=300, finite_uses=True, uses_left=3) self.assertEqual(base_data, base_data_2) base_data = AbilityData(cool_down_time=300, finite_uses=True, uses_left=3) base_data_2 = AbilityData(cool_down_time=300, finite_uses=True, uses_left=2) self.assertEqual(base_data, base_data_2) base_data = AbilityData(cool_down_time=301, finite_uses=True, uses_left=3) base_data_2 = AbilityData(cool_down_time=300, finite_uses=True, uses_left=3) self.assertNotEqual(base_data, base_data_2) self.assertNotEqual(base_data, 1) self.assertNotEqual(1, base_data) reg_data = AbilityData(300, heal_amount=10, finite_uses=True, uses_left=1) reg_data_2 = AbilityData(300, heal_amount=10, finite_uses=True, uses_left=1) self.assertEqual(reg_data, reg_data_2) reg_data = AbilityData(301, heal_amount=10, finite_uses=True, uses_left=1) reg_data_2 = AbilityData(300, heal_amount=10, finite_uses=True, uses_left=1) self.assertNotEqual(reg_data, reg_data_2) reg_data = AbilityData(300, heal_amount=10, finite_uses=True, uses_left=1) reg_data_2 = AbilityData(300, heal_amount=11, finite_uses=True, uses_left=1) self.assertNotEqual(reg_data, reg_data_2) reg_data = AbilityData(300, heal_amount=10, finite_uses=True, uses_left=1) reg_data_2 = AbilityData(300, heal_amount=10, finite_uses=True, uses_left=2) self.assertEqual(reg_data, reg_data_2) reg_data = AbilityData(300, heal_amount=10, recharge_amount=1, finite_uses=True, uses_left=1) reg_data_2 = AbilityData(300, heal_amount=10, finite_uses=True, uses_left=1) self.assertNotEqual(reg_data, reg_data_2) proj_ability_data_0 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=5) proj_ability_data_1 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=5) self.assertEqual(proj_ability_data_0, proj_ability_data_1) proj_ability_data_0 = AbilityData(251, projectile_label='bullet', projectile_count=1, kickback=200, spread=5) proj_ability_data_1 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=5) self.assertNotEqual(proj_ability_data_0, proj_ability_data_1) proj_ability_data_0 = AbilityData(250, projectile_label='bullet', projectile_count=2, kickback=200, spread=5) proj_ability_data_1 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=5) self.assertNotEqual(proj_ability_data_0, proj_ability_data_1) proj_ability_data_0 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=201, spread=5) proj_ability_data_1 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=5) self.assertNotEqual(proj_ability_data_0, proj_ability_data_1) proj_ability_data_0 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=5) proj_ability_data_1 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=6) self.assertNotEqual(proj_ability_data_0, proj_ability_data_1) proj_ability_data_0 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=5, sound_on_use='a') proj_ability_data_1 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=5, sound_on_use='b') self.assertNotEqual(proj_ability_data_0, proj_ability_data_1) proj_ability_data_0 = AbilityData(250, projectile_label='bullet', projectile_count=1, kickback=200, spread=5) proj_ability_data_1 = AbilityData(250, projectile_label='little_bullet', projectile_count=1, kickback=200, spread=5) self.assertNotEqual(proj_ability_data_0, proj_ability_data_1)
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