-
Notifications
You must be signed in to change notification settings - Fork 4
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
Link game modes table with matchmaking #1061
Conversation
- renamed name to type - add team size parameter when the game mode is teams - add team type to game modes
this is done because in the matchmaking we must always specify the amount of players to create a match
- select the initial positions based on if its teams or solo - select a random map amongst all the availables in a game mode
|
||
{:noreply, %{state | clients: remaining_clients}} | ||
end | ||
|
||
def handle_info(:update_params, state) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to update the params every certain amount of time. That way we will avoid to query the backend every millisecond
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed at the office. The field :amount_of_players in map_mode_params table was intended and discussed to be that way.
Let's re-arrange this PR to add the feature without that change.
This will lead to different matchmakings per map and mode (many to many), and that's what we should aim for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this because I've already deployed this branch in testing, so changing the migration file would cause a trouble
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR works good in its scope.
However, I think we are being redundant or error-prone in the game mode table columns and its queries.
Let's refactor those to avoid redundancy and potential errors by defining the specific and minimum params to retrieve whatever mode and map (we're randomizing the maps for now) the client asks for.
apps/arena/lib/arena/game_updater.ex
Outdated
if config.game.team_enabled do | ||
config.map_mode_params.team_initial_positions | ||
else | ||
config.map_mode_params.solo_initial_positions | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
team_enabled
is misleading. It tells that you can play as teams, but it doesn't tell this restriction.
If we want a boolean that makes the game mode for teams only, it should be "is_team?" or something like that.
Furthermore and more important, we have a separate field for team and not team positions, but with this boolean we only use one of them, leaving the other one blank.
We should either use one of those positions checking if the client asked to join :team, :solo OR just use one position field and check the new boolean. But not both behavior because is redundant.
def get_game_mode_configuration(name, type) do | ||
gateway_url = Application.get_env(:arena, :gateway_url) | ||
query_params = URI.encode_query(%{"name" => name, "type" => type}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of query is very error-prone. Type should be enough.
If we need something to differentiate between teams and solo, maybe we could create another field in the game mode schema as an enum for team mode types (:solo, :duo, :trio, etc).
{:ok, game_mode_configuration} -> | ||
# This is needed because we might not want to send a request every 300 seconds to the game backend | ||
Process.send_after(self(), :update_params, 5000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is called every 300 milliseconds.
If we fall here every 300 ms, we are queueing a message for 5 seconds from here, but every 300 ms, so we're just delaying the problem.
If we want to just update the params every 5 seconds, we should take this out of this function.
create_game_for_clients(game_clients, state.game_mode_configuration, state.current_map) | ||
|
||
{:noreply, %{state | clients: remaining_clients}} | ||
map = Enum.random(state.game_mode_configuration.map_mode_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing this? Couldn't we fall in an error where we use a different current_map to create_game_for_clients and then override a different one in the state.current_map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state = | ||
if Map.has_key?(state, :game_mode_configuration) do | ||
state | ||
else | ||
case Arena.Configuration.get_game_mode_configuration("pair", "battle_royale") do | ||
{:error, _} -> | ||
state | ||
|
||
{:ok, game_mode_configuration} -> | ||
# This is needed because we might not want to send a request every 300 seconds to the game backend | ||
map = Enum.random(game_mode_configuration.map_mode_params) | ||
|
||
Process.send_after(self(), :update_params, 5000) | ||
|
||
Map.put(state, :game_mode_configuration, game_mode_configuration) | ||
|> Map.put(:current_map, map) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create a function for this block of code that we use in every matchmaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…by team size and type
As we talked, we will:
|
- templates not working due to an unexistent field - battle mode not working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more thing and we're ready to go.
Can we only select "active" maps in the configurator for the game modes?
Otherwise, we could link an inactive map to them which could lead to an error.
Doing so we can merge this and not link Araban by mistake until it's ready to play.
Makes a lot of sense, done in feat: only display active maps for map mode params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops. Fixed in |
* feat: add team size to game mode configurations * feat: changes on the game mode configurations table and views - renamed name to type - add team size parameter when the game mode is teams - add team type to game modes * feat: create an endpoint to retrieve the game mode configuration * chore: move every migration into one file * chore: add seeds for game modes * feat: add new fields and logic for game mode form * chore: remove the amount of params from the map mode params this is done because in the matchmaking we must always specify the amount of players to create a match * feat: use the game modes in the matchmaking * code: handle the failed requests when the application starts * chore: remove not used require * feat: restore the has many in the game mode configurations * feat: fix pair and battle not using the game mode configuration * fix: correctly parse the map mode params * feat: changes on the initial positions and map - select the initial positions based on if its teams or solo - select a random map amongst all the availables in a game mode * chore: format * chore: credo * chore: fix seeds * chore: mix format again * feat: use the team size parameter * chore: remove not used field in migration * fix: deathmatch and battle were not working * feat: restore the amount of players to the map mode params * feat: use the map amount params in the matchmakings * chore: add quickgame to seeds * feat: use the map selected from the matchmaking * chore: restore changes in game modes form * chore: fix typo in game mode's form * chore: remove not needed map configurations from seeds * refactor: merge team and solo positions into one * feat: remove the name and filter and get the game mode configuration by team size and type * chore: send the update params event in the init of each matchmaking * refactor: modularize function in matchmaking module * code: rename variable * fix: errors - templates not working due to an unexistent field - battle mode not working * feat: only display active maps for map mode params * chore: mix format * feat: filter maps only in the game mode form --------- Co-authored-by: Nicolas Sanchez <sanchez.nicolas96@gmail.com>
* feat: add team size to game mode configurations * feat: changes on the game mode configurations table and views - renamed name to type - add team size parameter when the game mode is teams - add team type to game modes * feat: create an endpoint to retrieve the game mode configuration * chore: move every migration into one file * chore: add seeds for game modes * feat: add new fields and logic for game mode form * chore: remove the amount of params from the map mode params this is done because in the matchmaking we must always specify the amount of players to create a match * feat: use the game modes in the matchmaking * code: handle the failed requests when the application starts * chore: remove not used require * feat: restore the has many in the game mode configurations * feat: fix pair and battle not using the game mode configuration * fix: correctly parse the map mode params * feat: changes on the initial positions and map - select the initial positions based on if its teams or solo - select a random map amongst all the availables in a game mode * chore: format * chore: credo * chore: fix seeds * chore: mix format again * feat: use the team size parameter * chore: remove not used field in migration * fix: deathmatch and battle were not working * feat: restore the amount of players to the map mode params * feat: use the map amount params in the matchmakings * chore: add quickgame to seeds * feat: use the map selected from the matchmaking * chore: restore changes in game modes form * chore: fix typo in game mode's form * chore: remove not needed map configurations from seeds * refactor: merge team and solo positions into one * feat: remove the name and filter and get the game mode configuration by team size and type * chore: send the update params event in the init of each matchmaking * refactor: modularize function in matchmaking module * code: rename variable * fix: errors - templates not working due to an unexistent field - battle mode not working * feat: only display active maps for map mode params * chore: mix format * feat: filter maps only in the game mode form --------- Co-authored-by: Nicolas Sanchez <sanchez.nicolas96@gmail.com>
* feat: add new map params * chore: add the has many relationship with game modes to versions * feat: send the game modes with the version * feat: send the map to the client and add araban to deathmatch * feat: remove no longer used team merliot map * fix: errors that haven arisen when enabling araban - spikes were not working - random position in map needs to be within a circle * chore: change owner team for team * chore: remove not needed parameter * chore: increase arena version * Link game modes table with matchmaking (#1061) * feat: add team size to game mode configurations * feat: changes on the game mode configurations table and views - renamed name to type - add team size parameter when the game mode is teams - add team type to game modes * feat: create an endpoint to retrieve the game mode configuration * chore: move every migration into one file * chore: add seeds for game modes * feat: add new fields and logic for game mode form * chore: remove the amount of params from the map mode params this is done because in the matchmaking we must always specify the amount of players to create a match * feat: use the game modes in the matchmaking * code: handle the failed requests when the application starts * chore: remove not used require * feat: restore the has many in the game mode configurations * feat: fix pair and battle not using the game mode configuration * fix: correctly parse the map mode params * feat: changes on the initial positions and map - select the initial positions based on if its teams or solo - select a random map amongst all the availables in a game mode * chore: format * chore: credo * chore: fix seeds * chore: mix format again * feat: use the team size parameter * chore: remove not used field in migration * fix: deathmatch and battle were not working * feat: restore the amount of players to the map mode params * feat: use the map amount params in the matchmakings * chore: add quickgame to seeds * feat: use the map selected from the matchmaking * chore: restore changes in game modes form * chore: fix typo in game mode's form * chore: remove not needed map configurations from seeds * refactor: merge team and solo positions into one * feat: remove the name and filter and get the game mode configuration by team size and type * chore: send the update params event in the init of each matchmaking * refactor: modularize function in matchmaking module * code: rename variable * fix: errors - templates not working due to an unexistent field - battle mode not working * feat: only display active maps for map mode params * chore: mix format * feat: filter maps only in the game mode form --------- Co-authored-by: Nicolas Sanchez <sanchez.nicolas96@gmail.com> --------- Co-authored-by: Nicolas Sanchez <sanchez.nicolas96@gmail.com>
Motivation
In #1032 we have added a new table to store parameters that configures game modes and settings for the matchmaking, in this PR we're linking that table to our current matchmakings
Summary of changes
How to test it?
I’ve added a name and a type for each game mode. This will allow us to create different game modes with unique configurations and, in the future, render them on the front end.
Additionally, if you’d like, you can adjust the parameters in the configurator under the Game Modes section.
I’ve also introduced some new parameters:
You most be able to tweak those parameters and also these as well:
And you'll have to wait until the changes impact into the game (the params are refreshed every 5 seconds)
Checklist