From bd37988d6fc7381f8fffa57164438ee59d7f85aa Mon Sep 17 00:00:00 2001 From: tvillegas98 Date: Fri, 15 Nov 2024 15:02:29 -0300 Subject: [PATCH] feat: centralize bot names --- .../lib/arena/matchmaking/deathmatch_mode.ex | 16 +------------ .../lib/arena/matchmaking/game_launcher.ex | 21 +--------------- apps/arena/lib/arena/matchmaking/pair_mode.ex | 21 +--------------- .../lib/arena/matchmaking/quick_game_mode.ex | 22 +---------------- apps/arena/lib/arena/utils.ex | 24 +++++++++++++++++++ 5 files changed, 28 insertions(+), 76 deletions(-) diff --git a/apps/arena/lib/arena/matchmaking/deathmatch_mode.ex b/apps/arena/lib/arena/matchmaking/deathmatch_mode.ex index 56ecf7366..91f7dd4ac 100644 --- a/apps/arena/lib/arena/matchmaking/deathmatch_mode.ex +++ b/apps/arena/lib/arena/matchmaking/deathmatch_mode.ex @@ -13,20 +13,6 @@ defmodule Arena.Matchmaking.DeathmatchMode do # Time to wait to start game with any amount of clients @start_timeout_ms 4_000 - @bot_names [ - "TheBlackSwordman", - "SlashJava", - "SteelBallRun", - "Jeff", - "Messi", - "Stone Ocean", - "Jeepers Creepers", - "Bob", - "El javo", - "Alberso", - "Thomas" - ] - # API def start_link(_) do GenServer.start_link(__MODULE__, [], name: __MODULE__) @@ -116,7 +102,7 @@ defmodule Arena.Matchmaking.DeathmatchMode do Enum.map(1..missing_clients//1, fn i -> client_id = UUID.generate() - {client_id, Enum.random(characters).name, Enum.at(@bot_names, i), nil} + {client_id, Enum.random(characters).name, Enum.at(Arena.Utils.bot_names(), i), nil} end) end diff --git a/apps/arena/lib/arena/matchmaking/game_launcher.ex b/apps/arena/lib/arena/matchmaking/game_launcher.ex index 3098a8e36..052b2c336 100644 --- a/apps/arena/lib/arena/matchmaking/game_launcher.ex +++ b/apps/arena/lib/arena/matchmaking/game_launcher.ex @@ -8,25 +8,6 @@ defmodule Arena.Matchmaking.GameLauncher do # Time to wait to start game with any amount of clients @start_timeout_ms 4_000 - @bot_names [ - "TheBlackSwordman", - "SlashJava", - "SteelBallRun", - "Jeff", - "Messi", - "Stone Ocean", - "Jeepers Creepers", - "Bob", - "El javo", - "Alberso", - "Thomas", - "Timmy", - "Pablito", - "Nicolino", - "Cangrejo", - "Mansito" - ] - # API def start_link(_) do GenServer.start_link(__MODULE__, [], name: __MODULE__) @@ -116,7 +97,7 @@ defmodule Arena.Matchmaking.GameLauncher do Enum.map(1..missing_clients//1, fn i -> client_id = UUID.generate() - {client_id, Enum.random(characters).name, Enum.at(@bot_names, i), nil} + {client_id, Enum.random(characters).name, Enum.at(Arena.Utils.bot_names(), i), nil} end) end diff --git a/apps/arena/lib/arena/matchmaking/pair_mode.ex b/apps/arena/lib/arena/matchmaking/pair_mode.ex index 7a96eb5b3..6d83da787 100644 --- a/apps/arena/lib/arena/matchmaking/pair_mode.ex +++ b/apps/arena/lib/arena/matchmaking/pair_mode.ex @@ -7,25 +7,6 @@ defmodule Arena.Matchmaking.PairMode do # Time to wait to start game with any amount of clients @start_timeout_ms 10_000 - # The available names for bots to enter a match, we should change this in the future - @bot_names [ - "TheBlackSwordman", - "SlashJava", - "SteelBallRun", - "Jeff", - "Messi", - "Stone Ocean", - "Jeepers Creepers", - "Bob", - "El javo", - "Alberso", - "Thomas", - "Timmy", - "Pablito", - "Nicolino", - "Cangrejo", - "Mansito" - ] # API def start_link(_) do @@ -110,7 +91,7 @@ defmodule Arena.Matchmaking.PairMode do Enum.map(1..missing_clients//1, fn i -> client_id = UUID.generate() - {client_id, Enum.random(characters).name, Enum.at(@bot_names, i), nil} + {client_id, Enum.random(characters).name, Enum.at(Arena.Utils.bot_names(), i), nil} end) end diff --git a/apps/arena/lib/arena/matchmaking/quick_game_mode.ex b/apps/arena/lib/arena/matchmaking/quick_game_mode.ex index df1106975..7ed4309a8 100644 --- a/apps/arena/lib/arena/matchmaking/quick_game_mode.ex +++ b/apps/arena/lib/arena/matchmaking/quick_game_mode.ex @@ -5,26 +5,6 @@ defmodule Arena.Matchmaking.QuickGameMode do use GenServer - # The available names for bots to enter a match, we should change this in the future - @bot_names [ - "TheBlackSwordman", - "SlashJava", - "SteelBallRun", - "Jeff", - "Messi", - "Stone Ocean", - "Jeepers Creepers", - "Bob", - "El javo", - "Alberso", - "Thomas", - "Timmy", - "Pablito", - "Nicolino", - "Cangrejo", - "Mansito" - ] - # API def start_link(_) do GenServer.start_link(__MODULE__, [], name: __MODULE__) @@ -80,7 +60,7 @@ defmodule Arena.Matchmaking.QuickGameMode do Enum.map(1..missing_clients//1, fn i -> client_id = UUID.generate() - {client_id, Enum.random(characters).name, Enum.at(@bot_names, i), nil} + {client_id, Enum.random(characters).name, Enum.at(Arena.Utils.bot_names(), i), nil} end) end diff --git a/apps/arena/lib/arena/utils.ex b/apps/arena/lib/arena/utils.ex index dc79d56f3..5a5bae17f 100644 --- a/apps/arena/lib/arena/utils.ex +++ b/apps/arena/lib/arena/utils.ex @@ -4,6 +4,26 @@ defmodule Arena.Utils do It contains utility functions like math functions. """ + # The available names for bots to enter a match, we should change this in the future + @bot_names [ + "TheBlackSwordman", + "SlashJava", + "SteelBallRun", + "Jeff", + "Messi", + "Stone Ocean", + "Jeepers Creepers", + "Bob", + "El javo", + "Alberso", + "Thomas", + "Timmy", + "Pablito", + "Nicolino", + "Cangrejo", + "Mansito" + ] + def normalize(%{x: 0, y: 0}) do %{x: 0, y: 0} end @@ -30,6 +50,10 @@ defmodule Arena.Utils do "#{protocol}#{bot_manager_host}/join/#{server_url}/#{game_id}/#{bot_client}" end + def bot_names() do + @bot_names + end + defp get_correct_protocol("localhost" <> _host), do: "http://" defp get_correct_protocol(_host), do: "https://" end