Skip to content
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

Merged
merged 39 commits into from
Feb 5, 2025

Conversation

tvillegas98
Copy link
Contributor

@tvillegas98 tvillegas98 commented Jan 29, 2025

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:

  • Team Size: Specifies the size of each team.

You most be able to tweak those parameters and also these as well:

  • match_duration_ms
  • team_size
  • respawn_time_ms

And you'll have to wait until the changes impact into the game (the params are refreshed every 5 seconds)

Checklist

  • Tested the changes locally.
  • Reviewed the changes on GitHub, line by line.
  • This change requires new documentation.
    • Documentation has been added/updated.

@tvillegas98 tvillegas98 marked this pull request as ready for review February 3, 2025 13:20

{:noreply, %{state | clients: remaining_clients}}
end

def handle_info(:update_params, state) do
Copy link
Contributor Author

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

Copy link
Collaborator

@Nico-Sanchez Nico-Sanchez left a 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.

Copy link
Contributor Author

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

Copy link
Collaborator

@Nico-Sanchez Nico-Sanchez left a 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.

Comment on lines 904 to 908
if config.game.team_enabled do
config.map_mode_params.team_initial_positions
else
config.map_mode_params.solo_initial_positions
end
Copy link
Collaborator

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.

Comment on lines 17 to 19
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})
Copy link
Collaborator

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).

Comment on lines 69 to 71
{: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)
Copy link
Collaborator

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.

Comment on lines 93 to 95
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)
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 57 to 74
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
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvillegas98
Copy link
Contributor Author

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.

As we talked, we will:

  • Remove the :team_enabled field
  • Merge team_initial_positions and solo_initial_positions into one field called initial_positions
  • Query the game modes by type and team size

- templates not working due to an unexistent field
- battle mode not working
Copy link
Collaborator

@Nico-Sanchez Nico-Sanchez left a 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.

@tvillegas98
Copy link
Contributor Author

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

Nico-Sanchez
Nico-Sanchez previously approved these changes Feb 5, 2025
Copy link
Collaborator

@manucamejo manucamejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing the branch, but I couldn't see Araban, are you filtering the INACTIVE maps?
image

@tvillegas98
Copy link
Contributor Author

tvillegas98 commented Feb 5, 2025

I was testing the branch, but I couldn't see Araban, are you filtering the INACTIVE maps? image

whoops. Fixed in
feat: filter maps only in the game mode form

@Nico-Sanchez Nico-Sanchez merged commit 774fe84 into main Feb 5, 2025
1 check passed
@Nico-Sanchez Nico-Sanchez deleted the link-game-modes-table-with-matchmaking branch February 5, 2025 22:30
tvillegas98 added a commit that referenced this pull request Feb 6, 2025
* 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>
tvillegas98 added a commit that referenced this pull request Feb 6, 2025
* 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>
Nico-Sanchez added a commit that referenced this pull request Feb 7, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants