Skip to content

Commit

Permalink
Fix attack block behavior killing bots processes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-Sanchez committed Sep 13, 2024
1 parent ba051f7 commit 2a57eb4
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions apps/bot_manager/lib/game_socket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,17 @@ defmodule BotManager.GameSocketHandler do

def handle_info(:perform_action, state) do
Process.send_after(self(), :perform_action, @action_delay_ms)

send_current_action(state)
{:ok, update_block_attack_state(state)}
end

state =
case state.current_action do
{:attack, _} ->
Map.put(state, :attack_blocked, true)
Process.send_after(self(), :unblock_attack, Enum.random(2000..4000))

_ ->
state
end

{:ok, state}
defp update_block_attack_state(%{current_action: {:attack, _}} = state) do
Process.send_after(self(), :unblock_attack, Enum.random(2000..4000))
Map.put(state, :attack_blocked, true)
end

defp update_block_attack_state(state), do: state

def handle_cast({:send, {_type, _msg} = frame}, state) do
{:reply, frame, state}
end
Expand Down

0 comments on commit 2a57eb4

Please sign in to comment.