def test_multiple_damage_boost_pickup_expiry(self): """ Ensure that each damage boost effect expires at the appropriate time, even if the user stacks up on them. One pickup will be at (1,0) and another at (3,0). """ cell_one = self.game.game_state.world_map.get_cell(Location(1, 0)) cell_two = self.game.game_state.world_map.get_cell(Location(3, 0)) pickup_created_one = DamageBoostPickup(cell_one, 10) pickup_created_two = DamageBoostPickup(cell_two, 15) cell_one.pickup = pickup_created_one cell_two.pickup = pickup_created_two self.assertEqual(self.avatar.attack_strength, 1) # Avatar moves EAST to (1,0) where pickup one is located. self.game.turn_manager._run_single_turn() self.assertTrue( isinstance( list(self.avatar.effects)[0], pickup_created_one.EFFECT)) self.assertEqual(len(self.avatar.effects), 1) self.assertEqual(list(self.avatar.effects)[0]._time_remaining, 10) self.assertEqual(self.avatar.attack_strength, 11) # Move twice to the second pickup. for i in range(2): self.game.turn_manager._run_single_turn() self.assertTrue( isinstance( list(self.avatar.effects)[1], pickup_created_two.EFFECT)) self.assertEqual(len(self.avatar.effects), 2) self.assertEqual(self.avatar.attack_strength, 26) # Eight turns later, we expect the first effect to expire. for i in range(8): self.game.turn_manager._run_single_turn() self.assertEqual(len(self.avatar.effects), 1) self.assertEqual(list(self.avatar.effects)[0]._time_remaining, 2) self.assertEqual(self.avatar.attack_strength, 16) # Two turns later, the second pickup expires too. for i in range(2): self.game.turn_manager._run_single_turn() self.assertEqual(len(self.avatar.effects), 0) self.assertEqual(self.avatar.attack_strength, 1)
def test_single_damage_boost_pickup_expiry(self): """ Avatar spawns at ORIGIN. DamageBoostPickup is at 1,0. Avatar moves to the pickup and picks it up next turn and then we wait for the effect to expire EFFECT_TIME turns later (value defined in the effects class). """ pickup_created = DamageBoostPickup(self.cell, 10) self.cell.pickup = pickup_created self.assertEqual(self.avatar.attack_strength, 1) # Avatar moves EAST to (1,0) where pickup is located, then repeats it 5 times. loop = asyncio.get_event_loop() for i in range(6): loop.run_until_complete( self.game.simulation_runner.run_single_turn( self.game.avatar_manager. get_player_id_to_serialised_action())) self.assertTrue( isinstance(list(self.avatar.effects)[0], pickup_created.EFFECT)) self.assertEqual(list(self.avatar.effects)[0]._time_remaining, 5) self.assertEqual(self.avatar.attack_strength, 11) # Run 5 more turns and expect the effect to expire. for i in range(5): loop.run_until_complete( self.game.simulation_runner.run_single_turn( self.game.avatar_manager. get_player_id_to_serialised_action())) self.assertEqual(len(self.avatar.effects), 0) self.assertEqual(self.avatar.attack_strength, 1)
def test_damage_boost_increases_attack_strength_with_default_integer(self): """ Damage boost with no value parameter provided (ie. default). """ pickup_created = DamageBoostPickup(self.cell) self.cell.pickup = pickup_created self.loop.run_until_complete(self.game.simulation_runner.run_single_turn(self.game.avatar_manager.get_player_id_to_serialised_action())) self.assertTrue(self.cell.avatar.attack_strength, self.initial_attack_strength + DAMAGE_BOOST_DEFAULT)
def test_damage_boost_pickup_can_be_picked_up_default(self): pickup_created = DamageBoostPickup(self.cell) self.cell.pickup = pickup_created self.loop.run_until_complete(self.game.simulation_runner.run_single_turn(self.game.avatar_manager.get_player_id_to_serialised_action())) self.assertEqual(self.cell.avatar, self.game.avatar_manager.get_avatar(1)) self.assertEqual(len(self.game.avatar_manager.get_avatar(1).effects), 1) damage_boost_effect = self.game.avatar_manager.get_avatar(1).effects.pop() self.assertTrue(isinstance(damage_boost_effect, pickup_created.EFFECT))
def test_damage_boost_increases_attack_strength_with_custom_integers(self, boost_value): """ Damage Boost with random integers provided as a parameter. """ self.setUp() pickup_created = DamageBoostPickup(self.cell, boost_value) self.cell.pickup = pickup_created self.loop.run_until_complete(self.game.simulation_runner.run_single_turn(self.game.avatar_manager.get_player_id_to_serialised_action())) self.assertTrue(self.cell.avatar.attack_strength, self.initial_attack_strength + boost_value)
def test_damage_boost_increases_attack_strength_with_default_integer(self): """ Damage boost with no value parameter provided (ie. default). """ pickup_created = DamageBoostPickup(self.cell) self.cell.pickup = pickup_created self.game.turn_manager._run_single_turn() self.assertTrue(self.cell.avatar.attack_strength, self.initial_attack_strength + DAMAGE_BOOST_DEFAULT)
def test_damage_boost_pickup_can_be_picked_up_custom_floats(self, boost_value): assume(not math.isinf(boost_value)) self.setUp() pickup_created = DamageBoostPickup(self.cell, boost_value) self.cell.pickup = pickup_created self.loop.run_until_complete(self.game.simulation_runner.run_single_turn(self.game.avatar_manager.get_player_id_to_serialised_action())) self.assertEqual(self.cell.avatar, self.game.avatar_manager.get_avatar(1)) self.assertEqual(len(self.game.avatar_manager.get_avatar(1).effects), 1) damage_boost_effect = self.game.avatar_manager.get_avatar(1).effects.pop() self.assertTrue(isinstance(damage_boost_effect, pickup_created.EFFECT))
def test_damage_boost_increases_attack_strength_with_custom_integers( self, boost_value): """ Damage Boost with random integers provided as a parameter. """ self.setUp() pickup_created = DamageBoostPickup(self.cell, boost_value) self.cell.pickup = pickup_created self.game.turn_manager._run_single_turn() self.assertTrue(self.cell.avatar.attack_strength, self.initial_attack_strength + boost_value)
def test_damage_boost_pickup_can_be_picked_up_default(self): pickup_created = DamageBoostPickup(self.cell) self.cell.pickup = pickup_created self.game.turn_manager._run_single_turn() self.assertEqual(self.cell.avatar, self.game.avatar_manager.get_avatar(1)) self.assertEqual(len(self.game.avatar_manager.get_avatar(1).effects), 1) damage_boost_effect = self.game.avatar_manager.get_avatar( 1).effects.pop() self.assertTrue(isinstance(damage_boost_effect, pickup_created.EFFECT))
def test_damage_boost_pickup_can_be_picked_up_custom_floats( self, boost_value): self.setUp() pickup_created = DamageBoostPickup(self.cell, boost_value) self.cell.pickup = pickup_created self.game.turn_manager._run_single_turn() self.assertEqual(self.cell.avatar, self.game.avatar_manager.get_avatar(1)) self.assertEqual(len(self.game.avatar_manager.get_avatar(1).effects), 1) damage_boost_effect = self.game.avatar_manager.get_avatar( 1).effects.pop() self.assertTrue(isinstance(damage_boost_effect, pickup_created.EFFECT))
def test_single_damage_boost_pickup_expiry(self): """ Avatar spawns at ORIGIN. DamageBoostPickup is at 1,0. Avatar moves to the pickup and picks it up next turn and then we wait for the effect to expire EFFECT_TIME turns later (value defined in the effects class). """ pickup_created = DamageBoostPickup(self.cell, 10) self.cell.pickup = pickup_created self.assertEqual(self.avatar.attack_strength, 1) # Avatar moves EAST to (1,0) where pickup is located, then repeats it 5 times. for i in range(6): self.game.turn_manager._run_single_turn() self.assertTrue( isinstance(list(self.avatar.effects)[0], pickup_created.EFFECT)) self.assertEqual(list(self.avatar.effects)[0]._time_remaining, 5) self.assertEqual(self.avatar.attack_strength, 11) # Run 5 more turns and expect the effect to expire. for i in range(5): self.game.turn_manager._run_single_turn() self.assertEqual(len(self.avatar.effects), 0) self.assertEqual(self.avatar.attack_strength, 1)