コード例 #1
0
    async def test_multiple_invulnerability_boost_pickup_expiry(self, loop):
        """
        Ensure that each invulnerability 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 = InvulnerabilityPickup(cell_one)
        pickup_created_two = InvulnerabilityPickup(cell_two)

        cell_one.interactable = pickup_created_one
        cell_two.interactable = pickup_created_two

        assert self.avatar.resistance == 0

        # Avatar moves EAST to (1,0) where pickup one is located.
        await self.game.simulation_runner.run_single_turn(
            self.game.turn_collector.collected_turn_actions
        )

        assert isinstance(list(self.avatar.effects)[0], pickup_created_one.effects[0])
        assert len(self.avatar.effects) == 1
        assert list(self.avatar.effects)[0]._time_remaining == 10
        assert self.avatar.resistance == INVULNERABILITY_RESISTANCE

        # Move twice to the second pickup.
        for i in range(2):
            await self.game.simulation_runner.run_single_turn(
                self.game.turn_collector.collected_turn_actions
            )

        assert isinstance(list(self.avatar.effects)[1], pickup_created_two.effects[0])
        assert len(self.avatar.effects) == 2
        assert self.avatar.resistance == INVULNERABILITY_RESISTANCE * 2

        # Eight turns later, we expect the first effect to expire.
        for i in range(8):
            await self.game.simulation_runner.run_single_turn(
                self.game.turn_collector.collected_turn_actions
            )

        assert len(self.avatar.effects) == 1
        assert list(self.avatar.effects)[0]._time_remaining == 2
        assert self.avatar.resistance == INVULNERABILITY_RESISTANCE

        # Two turns later, the second pickup expires too.
        for i in range(2):
            await self.game.simulation_runner.run_single_turn(
                self.game.turn_collector.collected_turn_actions
            )

        assert len(self.avatar.effects) == 0
        assert self.avatar.resistance == 0
コード例 #2
0
    def test_invulnerability_pickups_increase_resistance_of_avatar(self):
        """
        Avatar spawns at the origin (0,0) and should have a resistance of 0. Moves
        EAST to (1,0) and should automatically pick up the pickup and get the
        effect.
        """
        self.cell.interactable = InvulnerabilityPickup(self.cell)
        self.assertEqual(self.game.avatar_manager.get_avatar(1).resistance, 0)
        self.assertEqual(
            self.cell.interactable.serialize(),
            {
                "type": "invulnerability",
                "location": {
                    "x": self.cell.location.x,
                    "y": self.cell.location.y
                },
            },
        )

        loop = asyncio.get_event_loop()
        loop.run_until_complete(
            self.game.simulation_runner.run_single_turn(
                self.game.avatar_manager.get_player_id_to_serialized_action()))

        self.assertEqual(self.cell.avatar,
                         self.game.avatar_manager.get_avatar(1))
        self.assertEqual(self.cell.avatar.resistance, 1000)
        self.assertEqual(len(self.cell.avatar.effects), 1)
コード例 #3
0
ファイル: test_effect_expiry.py プロジェクト: JackD03/aimmo
    def test_single_invulnerability_pickup_pickup_expiry(self):
        """
        Avatar spawns at ORIGIN. InvulnerabilityPickup 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 = InvulnerabilityPickup(self.cell)
        self.cell.interactable = pickup_created
        self.assertEqual(self.avatar.resistance, 0)

        # 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_serialized_action()))

        self.assertTrue(
            isinstance(
                list(self.avatar.effects)[0], pickup_created.effects[0]))
        self.assertEqual(list(self.avatar.effects)[0]._time_remaining, 5)
        self.assertEqual(self.avatar.resistance, INVULNERABILITY_RESISTANCE)

        # 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_serialized_action()))

        self.assertEqual(len(self.avatar.effects), 0)
        self.assertEqual(self.avatar.resistance, 0)
コード例 #4
0
    async def test_single_invulnerability_pickup_pickup_expiry(self, loop):
        """
        Avatar spawns at ORIGIN. InvulnerabilityPickup 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 = InvulnerabilityPickup(self.cell)
        self.cell.interactable = pickup_created
        assert self.avatar.resistance == 0

        # Avatar moves EAST to (1,0) where pickup is located, then repeats it 5 times.
        for i in range(6):
            await self.game.simulation_runner.run_single_turn(
                self.game.turn_collector.collected_turn_actions
            )

        assert isinstance(list(self.avatar.effects)[0], pickup_created.effects[0])
        assert list(self.avatar.effects)[0]._time_remaining == 5
        assert self.avatar.resistance == INVULNERABILITY_RESISTANCE

        # Run 5 more turns and expect the effect to expire.
        for i in range(5):
            await self.game.simulation_runner.run_single_turn(
                self.game.turn_collector.collected_turn_actions
            )

        assert len(self.avatar.effects) == 0
        assert self.avatar.resistance == 0
コード例 #5
0
    async def test_invulnerability_pickups_can_increase_resistance_to_2000(
            self, loop):
        """
        Checks if the pickup can be applied twice. First moved from ORIGIN to 1,0 ->
        then picks up the pickup, and moves to 2,0 to do the same.
        """
        self.cell.interactable = InvulnerabilityPickup(self.cell)
        await self.game.simulation_runner.run_single_turn(
            self.game.turn_collector.collected_turn_actions)
        assert self.cell.avatar == self.game.avatar_manager.get_avatar(1)
        assert self.cell.avatar.resistance == 1000

        self.cell = self.game.game_state.world_map.get_cell(Location(2, 0))
        self.cell.interactable = InvulnerabilityPickup(self.cell)
        await self.game.simulation_runner.run_single_turn(
            self.game.turn_collector.collected_turn_actions)

        assert self.cell.avatar.resistance == 2000
        assert self.cell.avatar == self.game.avatar_manager.get_avatar(1)
コード例 #6
0
    def test_invulnerability_pickups_can_increase_resistance_to_2000(self):
        """
        Checks if the pickup can be applied twice. First moved from ORIGIN to 1,0 ->
        then picks up the pickup, and moves to 2,0 to do the same.
        """
        loop = asyncio.get_event_loop()
        self.cell.interactable = InvulnerabilityPickup(self.cell)
        loop.run_until_complete(
            self.game.simulation_runner.run_single_turn(
                self.game.avatar_manager.get_player_id_to_serialized_action()))
        self.assertEqual(self.cell.avatar,
                         self.game.avatar_manager.get_avatar(1))
        self.assertEqual(self.cell.avatar.resistance, 1000)

        self.cell = self.game.game_state.world_map.get_cell(Location(2, 0))
        self.cell.interactable = InvulnerabilityPickup(self.cell)
        loop.run_until_complete(
            self.game.simulation_runner.run_single_turn(
                self.game.avatar_manager.get_player_id_to_serialized_action()))

        self.assertEqual(self.cell.avatar.resistance, 2000)
        self.assertEqual(self.cell.avatar,
                         self.game.avatar_manager.get_avatar(1))
コード例 #7
0
    async def test_invulnerability_pickups_increase_resistance_of_avatar(
            self, loop):
        """
        Avatar spawns at the origin (0,0) and should have a resistance of 0. Moves
        EAST to (1,0) and should automatically pick up the pickup and get the
        effect.
        """
        self.cell.interactable = InvulnerabilityPickup(self.cell)
        assert self.game.avatar_manager.get_avatar(1).resistance == 0
        assert self.cell.interactable.serialize() == {
            "type": "invulnerability",
            "location": {
                "x": self.cell.location.x,
                "y": self.cell.location.y
            },
        }

        await self.game.simulation_runner.run_single_turn(
            self.game.turn_collector.collected_turn_actions)

        assert self.cell.avatar == self.game.avatar_manager.get_avatar(1)
        assert self.cell.avatar.resistance == 1000
        assert len(self.cell.avatar.effects) == 1
コード例 #8
0
ファイル: test_effect_expiry.py プロジェクト: JackD03/aimmo
    def test_multiple_invulnerability_boost_pickup_expiry(self):
        """
        Ensure that each invulnerability 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 = InvulnerabilityPickup(cell_one)
        pickup_created_two = InvulnerabilityPickup(cell_two)

        cell_one.interactable = pickup_created_one
        cell_two.interactable = pickup_created_two

        self.assertEqual(self.avatar.resistance, 0)

        # Avatar moves EAST to (1,0) where pickup one is located.
        loop = asyncio.get_event_loop()
        loop.run_until_complete(
            self.game.simulation_runner.run_single_turn(
                self.game.avatar_manager.get_player_id_to_serialized_action()))

        self.assertTrue(
            isinstance(
                list(self.avatar.effects)[0], pickup_created_one.effects[0]))
        self.assertEqual(len(self.avatar.effects), 1)
        self.assertEqual(list(self.avatar.effects)[0]._time_remaining, 10)
        self.assertEqual(self.avatar.resistance, INVULNERABILITY_RESISTANCE)

        # Move twice to the second pickup.
        for i in range(2):
            loop.run_until_complete(
                self.game.simulation_runner.run_single_turn(
                    self.game.avatar_manager.
                    get_player_id_to_serialized_action()))

        self.assertTrue(
            isinstance(
                list(self.avatar.effects)[1], pickup_created_two.effects[0]))
        self.assertEqual(len(self.avatar.effects), 2)
        self.assertEqual(self.avatar.resistance,
                         INVULNERABILITY_RESISTANCE * 2)

        # Eight turns later, we expect the first effect to expire.
        for i in range(8):
            loop.run_until_complete(
                self.game.simulation_runner.run_single_turn(
                    self.game.avatar_manager.
                    get_player_id_to_serialized_action()))

        self.assertEqual(len(self.avatar.effects), 1)
        self.assertEqual(list(self.avatar.effects)[0]._time_remaining, 2)
        self.assertEqual(self.avatar.resistance, INVULNERABILITY_RESISTANCE)

        # Two turns later, the second pickup expires too.
        for i in range(2):
            loop.run_until_complete(
                self.game.simulation_runner.run_single_turn(
                    self.game.avatar_manager.
                    get_player_id_to_serialized_action()))

        self.assertEqual(len(self.avatar.effects), 0)
        self.assertEqual(self.avatar.resistance, 0)