Skip to content

Commit

Permalink
Set all winners as 1st position (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-Sanchez authored Feb 18, 2025
1 parent db69982 commit 0ce0faf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
19 changes: 19 additions & 0 deletions apps/arena/docs/player-match-positions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Player Match Positions

Every time a player dies, we assign them a position.
When the game ends, we set the winners to position **1**.

## Positioning Rules

- **Solo Mode:**
Player positions range from **N to 1**, where **1** is the winner and **N** is the first player to die.

- **Team Modes:**
Player positions range from **N to 1**, where **1** is assigned to **all players on the winning team**.
The remaining players are ranked from **N to 2**, based on the order in which they died.

## Potential Issue

A possible bug occurs when a player initially receives a position (e.g., **6**) upon dying.
If their team later wins, their position is overridden to **1**, leaving the **6th position empty**.

13 changes: 12 additions & 1 deletion apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ defmodule Arena.GameUpdater do

state =
put_in(state, [:game_state, :status], :ENDED)
|> update_in([:game_state], fn game_state -> put_player_position(game_state, winner_team_ids) end)
|> update_in([:game_state], fn game_state -> put_winner_positions(game_state, winner_team_ids) end)

PubSub.broadcast(Arena.PubSub, state.game_state.game_id, :end_game_state)
broadcast_game_ended(winner_team, state.game_state)
Expand Down Expand Up @@ -1874,6 +1874,17 @@ defmodule Arena.GameUpdater do
defp get_entity_path(%{category: :trap}), do: :traps
defp get_entity_path(%{category: :crate}), do: :crates

defp put_winner_positions(game_state, player_ids) when is_list(player_ids) do
Enum.reduce(player_ids, game_state, fn player_id, game_state_acc ->
{client_id, _player_id} =
Enum.find(game_state.client_to_player_map, fn {_, map_player_id} -> map_player_id == player_id end)

game_state_acc
|> update_in([:players, player_id, :aditional_info, :match_position], fn _ -> 1 end)
|> update_in([:positions], fn positions -> Map.put(positions, client_id, "#{1}") end)
end)
end

defp put_player_position(game_state, player_ids) when is_list(player_ids) do
Enum.reduce(player_ids, game_state, fn player_id, game_state_acc ->
put_player_position(game_state_acc, player_id)
Expand Down

0 comments on commit 0ce0faf

Please sign in to comment.