Skip to content

Commit d1fcc58

Browse files
committed
fix: restore obstacle setup
before it was being added in game_socket_handler from the BotManager but that file was deleted
1 parent a64da99 commit d1fcc58

File tree

1 file changed

+57
-2
lines changed
  • apps/arena/lib/arena/bots

1 file changed

+57
-2
lines changed

apps/arena/lib/arena/bots/bot.ex

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,48 @@ defmodule Arena.Bots.Bot do
8080
state
8181
|> Map.put_new(:config, config)
8282
|> Map.put_new(:bot_player_id, get_in(game_state, [:client_to_player_map, state.bot_id]))
83+
|> maybe_set_obstacles(game_state)
84+
end
85+
86+
defp maybe_set_obstacles(%{bot_state_machine: %{obstacles: nil}} = state, %{obstacles: obstacles}) when not is_nil(obstacles) do
87+
obstacles =
88+
obstacles
89+
|> Enum.map(fn {obstacle_id, obstacle} ->
90+
obstacle =
91+
obstacle
92+
|> Map.take([
93+
:id,
94+
:shape,
95+
:position,
96+
:radius,
97+
:vertices,
98+
:speed,
99+
:category,
100+
:direction,
101+
:is_moving,
102+
:name
103+
])
104+
105+
obstacle =
106+
obstacle
107+
|> Map.put(:position, %{x: obstacle.position.x, y: obstacle.position.y})
108+
|> Map.put(
109+
:vertices,
110+
Enum.map(obstacle.vertices.positions, fn position -> %{x: position.x, y: position.y} end)
111+
)
112+
|> Map.put(:direction, %{x: obstacle.direction.x, y: obstacle.direction.y})
113+
|> Map.put(:shape, get_shape(obstacle.shape))
114+
|> Map.put(:category, get_category(obstacle.category))
115+
116+
{obstacle_id, obstacle}
117+
end)
118+
|> Map.new()
119+
120+
%{state | bot_state_machine: %{state.bot_state_machine | obstacles: obstacles}}
121+
end
122+
123+
defp maybe_set_obstacles(state, _game_state) do
124+
state
83125
end
84126

85127
defp generate_bot_name(bot_id), do: {:via, Registry, {BotRegistry, bot_id}}
@@ -151,6 +193,19 @@ defmodule Arena.Bots.Bot do
151193
Logger.error("Bot #{state.bot_id} terminating: #{inspect(reason)}")
152194
end
153195

154-
defp min_decision_delay_ms(), do: 40
155-
defp max_decision_delay_ms(), do: 60
196+
defp min_decision_delay_ms(), do: 100
197+
defp max_decision_delay_ms(), do: 150
198+
199+
defp get_shape("polygon"), do: :polygon
200+
defp get_shape("circle"), do: :circle
201+
defp get_shape("line"), do: :line
202+
defp get_shape("point"), do: :point
203+
defp get_shape(_), do: nil
204+
defp get_category("player"), do: :player
205+
defp get_category("projectile"), do: :projectile
206+
defp get_category("obstacle"), do: :obstacle
207+
defp get_category("power_up"), do: :power_up
208+
defp get_category("pool"), do: :pool
209+
defp get_category("item"), do: :item
210+
defp get_category("bush"), do: :bush
156211
end

0 commit comments

Comments
 (0)