Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-607] Only spawn bots if player is alive #608

Merged
merged 2 commits into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/arena/lib/arena/game_socket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ defmodule Arena.GameSocketHandler do
|> Map.put(:enable, game_status == :RUNNING)
|> Map.put(:block_actions, false)
|> Map.put(:game_finished, game_status == :ENDED)
|> Map.put(:player_alive, true)

encoded_msg =
GameEvent.encode(%GameEvent{
Expand Down Expand Up @@ -131,7 +132,12 @@ defmodule Arena.GameSocketHandler do
@impl true
def websocket_info({:player_dead, player_id}, state) do
if state.player_id == player_id do
{:ok, Map.put(state, :enable, false)}
state =
state
|> Map.put(:enable, false)
|> Map.put(:player_alive, false)

{:ok, state}
else
{:ok, state}
end
Expand All @@ -153,7 +159,7 @@ defmodule Arena.GameSocketHandler do
end

@impl true
def terminate(_reason, _req, %{game_finished: false} = state) do
def terminate(_reason, _req, %{game_finished: false, player_alive: true} = state) do
spawn(fn ->
Finch.build(:get, Utils.get_bot_connection_url(state.game_id, state.client_id))
|> Finch.request(Arena.Finch)
Expand Down
Loading