Skip to content

Commit

Permalink
Allow decapitation as a rated victory condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Feb 1, 2025
1 parent 630dfc6 commit ae13331
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 6 deletions.
10 changes: 6 additions & 4 deletions server/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,12 @@ async def validate_game_mode_settings(self):
await self.mark_invalid(ValidityState.UNEVEN_TEAMS_NOT_RANKED)
return

valid_options = {
"Victory": (Victory.DEMORALIZATION, ValidityState.WRONG_VICTORY_CONDITION)
}
await self._validate_game_options(valid_options)
if self.game_options.get("Victory") not in (
Victory.DEMORALIZATION,
Victory.DECAPITATION,
):
await self.mark_invalid(ValidityState.WRONG_VICTORY_CONDITION)
return

async def _validate_game_options(
self,
Expand Down
84 changes: 82 additions & 2 deletions tests/integration_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def host_game(
*,
mod: str = "faf",
visibility: str = "public",
game_options: dict = {},
**kwargs
) -> int:
await proto.send_message({
Expand All @@ -42,6 +43,13 @@ async def host_game(
await open_fa(proto)
await read_until_command(proto, "HostGame", target="game")

for option, value in game_options.items():
await proto.send_message({
"target": "game",
"command": "GameOption",
"args": [option, value],
})

return game_id


Expand All @@ -62,10 +70,16 @@ async def setup_game_1v1(
guest_proto: Protocol,
guest_id: int,
mod: str = "faf",
game_options: dict = {},
**kwargs,
):
# Set up the game
game_id = await host_game(host_proto, mod=mod, **kwargs)
game_id = await host_game(
host_proto,
mod=mod,
game_options=game_options,
**kwargs,
)
await join_game(guest_proto, game_id)
# Set player options
await send_player_options(
Expand Down Expand Up @@ -552,7 +566,7 @@ async def test_game_ended_broadcasts_rating_update(lobby_server, channel):


@fast_forward(60)
async def test_neroxis_map_generator_rates_game(lobby_server):
async def test_neroxis_map_generator_game_rated(lobby_server):
host_id, _, host_proto = await connect_and_sign_in(
("test", "test_password"), lobby_server
)
Expand Down Expand Up @@ -615,6 +629,72 @@ async def test_neroxis_map_generator_rates_game(lobby_server):
await read_until_command(host_proto, "player_info", timeout=10)


@fast_forward(60)
async def test_decapitation_game_rated(lobby_server):
host_id, _, host_proto = await connect_and_sign_in(
("test", "test_password"), lobby_server
)
guest_id, _, guest_proto = await connect_and_sign_in(
("Rhiza", "puff_the_magic_dragon"), lobby_server
)
await read_until_command(guest_proto, "game_info")
ratings = await get_player_ratings(host_proto, "test", "Rhiza")

await setup_game_1v1(
host_proto,
host_id,
guest_proto,
guest_id,
game_options={
"Victory": "decapitation",
}
)
await host_proto.send_message({
"target": "game",
"command": "EnforceRating",
"args": []
})

# End the game
# Reports results
for proto in (host_proto, guest_proto):
await proto.send_message({
"target": "game",
"command": "GameResult",
"args": [1, "victory 10"]
})
await proto.send_message({
"target": "game",
"command": "GameResult",
"args": [2, "defeat -10"]
})
# Report GameEnded
for proto in (host_proto, guest_proto):
await proto.send_message({
"target": "game",
"command": "GameEnded",
"args": []
})

# Check that the ratings were updated
new_ratings = await get_player_ratings(host_proto, "test", "Rhiza")

assert ratings["test"][0] < new_ratings["test"][0]
assert ratings["Rhiza"][0] > new_ratings["Rhiza"][0]

# Now disconnect both players
for proto in (host_proto, guest_proto):
await proto.send_message({
"target": "game",
"command": "GameState",
"args": ["Ended"]
})

# The game should only be rated once
with pytest.raises(asyncio.TimeoutError):
await read_until_command(host_proto, "player_info", timeout=10)


@fast_forward(30)
async def test_double_host_message(lobby_server):
_, _, proto = await connect_and_sign_in(
Expand Down

0 comments on commit ae13331

Please sign in to comment.