Skip to content

Commit

Permalink
fix: another wrong check and fix player positions
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillegas98 committed Nov 19, 2024
1 parent bd37988 commit 7112f16
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ defmodule Arena.GameUpdater do

send(self(), :natural_healing)

if state.game_config.game.game_mode != :deathmatch do
if state.game_config.game.game_mode != :DEATHMATCH do
send(self(), {:end_game_check, Map.keys(state.game_state.players)})
else
Process.send_after(self(), :deathmatch_end_game_check, state.game_config.game.match_duration)
Expand All @@ -334,12 +334,18 @@ defmodule Arena.GameUpdater do
end)
|> Enum.sort_by(fn {_player_id, _player, kills} -> kills end, :desc)


{winner_id, winner, _kills} = Enum.at(players, 0)

state =
state
|> put_in([:game_state, :status], :ENDED)
|> update_in([:game_state], fn game_state -> put_player_position(game_state, winner_id) end)
|> update_in([:game_state], fn game_state ->
players
|> Enum.reduce(game_state, fn {player_id, _player, _kills}, game_state_acc ->
put_player_position(game_state_acc, player_id)
end)
end)

PubSub.broadcast(Arena.PubSub, state.game_state.game_id, :end_game_state)
broadcast_game_ended(winner, state.game_state)
Expand Down

0 comments on commit 7112f16

Please sign in to comment.