Skip to content

Commit 4e7b897

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 278111f commit 4e7b897

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}}
@@ -146,6 +188,19 @@ defmodule Arena.Bots.Bot do
146188
Logger.error("Bot #{state.bot_id} terminating: #{inspect(reason)}")
147189
end
148190

149-
defp min_decision_delay_ms(), do: 40
150-
defp max_decision_delay_ms(), do: 60
191+
defp min_decision_delay_ms(), do: 100
192+
defp max_decision_delay_ms(), do: 150
193+
194+
defp get_shape("polygon"), do: :polygon
195+
defp get_shape("circle"), do: :circle
196+
defp get_shape("line"), do: :line
197+
defp get_shape("point"), do: :point
198+
defp get_shape(_), do: nil
199+
defp get_category("player"), do: :player
200+
defp get_category("projectile"), do: :projectile
201+
defp get_category("obstacle"), do: :obstacle
202+
defp get_category("power_up"), do: :power_up
203+
defp get_category("pool"), do: :pool
204+
defp get_category("item"), do: :item
205+
defp get_category("bush"), do: :bush
151206
end

0 commit comments

Comments
 (0)