def test_add_weapons(self) -> None: player = make_player() shotgun = make_item('shotgun') player.inventory.attempt_pickup(shotgun) # nothing installed at arms location -> install shotgun backpack = player.inventory.backpack self.assertNotIn(shotgun.mod, backpack) active_mods = player.inventory.active_mods arm_mod = active_mods[mods.ModLocation.ARMS] self.assertIs(arm_mod, shotgun.mod) # adding a second arm mod goes into the backpack pistol = make_item('pistol') player.inventory.attempt_pickup(pistol) self.assertIn(pistol.mod, backpack) arm_mod = active_mods[mods.ModLocation.ARMS] self.assertIs(arm_mod, shotgun.mod) self.assertIn(pistol.mod, backpack) # make sure we can swap the pistol with the shotgun player.inventory.equip(pistol.mod) arm_mod = active_mods[mods.ModLocation.ARMS] self.assertEqual(arm_mod, pistol.mod) self.assertIn(shotgun.mod, backpack)
def _player_with_ready_healthpack(self) -> Tuple[items.ItemObject, Player]: player = make_player() hp = make_item('healthpack') player.inventory.attempt_pickup(hp) while hp.mod.ability.cooldown_fraction < 1: self.timer.current_time += 100 self.timer.current_time += 1 return hp, player
def _player_with_ready_laser(self) -> Tuple[items.ItemObject, Player]: player = make_player() laser_gun = make_item('laser') player.inventory.attempt_pickup(laser_gun) fire_ability = laser_gun.mod.ability while fire_ability.cooldown_fraction < 1: self.timer.current_time += 10 self.timer.current_time += 1 return laser_gun, player
def test_pickup_healthpacks(self) -> None: player = make_player() hp = make_item('healthpack') backpack = player.inventory.backpack player.inventory.attempt_pickup(hp) # healthpack goes straight to active mods. self.assertNotIn(hp.mod, backpack) # healthpack added to stack. active_mods = player.inventory.active_mods self.assertIn(hp.mod, active_mods.values()) self.assertEqual(active_mods[hp.mod.loc].ability.uses_left, 1) hp_2 = make_item('healthpack') player.inventory.attempt_pickup(hp_2) self.assertNotIn(hp_2.mod, backpack) self.assertEqual(active_mods[hp.mod.loc].ability.uses_left, 2)
def testmake_item_in_groups(self) -> None: groups = self.groups hp = make_item('healthpack') self.assertIn(hp, groups.all_sprites) self.assertIn(hp, groups.items) self.assertEqual(len(groups.all_sprites), 1) self.assertEqual(len(groups.items), 1) pistol = make_item('pistol') self.assertIn(pistol, groups.all_sprites) self.assertIn(pistol, groups.items) self.assertEqual(len(groups.all_sprites), 2) self.assertEqual(len(groups.items), 2) shotgun = make_item('shotgun') self.assertIn(shotgun, groups.all_sprites) self.assertIn(shotgun, groups.items) self.assertEqual(len(groups.all_sprites), 3) self.assertEqual(len(groups.items), 3)
def test_player_fire_laser_available_after_cooldown_time(self) -> None: player = make_player() laser_gun = make_item('laser') player.inventory.attempt_pickup(laser_gun) fire_ability = laser_gun.mod.ability self.assertFalse(fire_ability.can_use(player)) # Initially player can't fire the gun because the cooldown time has # not been waited. while fire_ability.cooldown_fraction < 1: self.timer.current_time += 1 self.assertFalse(fire_ability.can_use(player)) self.timer.current_time += 1 self.assertTrue(fire_ability.can_use(player))
def test_backpack_full(self) -> None: player = make_player() pistol = make_item('pistol') backpack = player.inventory.backpack self.assertEqual(len(backpack), backpack.size) # TODO (dvirk): You should not be able to add the same object to the # backpack more than once. for i in range(backpack.size + 1): self.assertFalse(backpack.is_full) player.inventory.attempt_pickup(pistol) self.assertTrue(backpack.is_full) # Item not gained since backpack full player.inventory.attempt_pickup(pistol) self.assertEqual(len(backpack), backpack.size)