Skip to content

Commit

Permalink
[HOTFIX] - Bug Fix Team Mode (#1052)
Browse files Browse the repository at this point in the history
* chore: modify if to check if the current amount of players is less than the max capacity

* Add team attribute to GameJoined proto

* chore: send the team id to the client

* feat: rename team_id to team

* chore: restore wrongly pushed file

* chore: increase arena version

---------

Co-authored-by: Nicolas Sanchez <sanchez.nicolas96@gmail.com>
  • Loading branch information
tvillegas98 and Nico-Sanchez authored Jan 24, 2025
1 parent afc5058 commit 209bdfa
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 4 deletions.
6 changes: 4 additions & 2 deletions apps/arena/lib/arena/game_socket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Arena.GameSocketHandler do
Logger.info("Websocket INIT called")
Phoenix.PubSub.subscribe(Arena.PubSub, state.game_id)

{:ok, %{player_id: player_id, game_config: config, game_status: game_status, bounties: bounties}} =
{:ok, %{player_id: player_id, team: team, game_config: config, game_status: game_status, bounties: bounties}} =
GameUpdater.join(state.game_pid, state.client_id)

state =
Expand All @@ -54,7 +54,9 @@ defmodule Arena.GameSocketHandler do

encoded_msg =
GameEvent.encode(%GameEvent{
event: {:joined, %GameJoined{player_id: player_id, config: to_broadcast_config(config), bounties: bounties}}
event:
{:joined,
%GameJoined{player_id: player_id, team: team, config: to_broadcast_config(config), bounties: bounties}}
})

:telemetry.execute([:arena, :clients], %{count: 1})
Expand Down
3 changes: 3 additions & 0 deletions apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ defmodule Arena.GameUpdater do
|> Enum.shuffle()
|> Enum.take(state.game_config.game.bounties_options_amount)

player = Map.get(state.game_state.players, player_id)

response = %{
player_id: player_id,
team: player.aditional_info.team,
game_config: state.game_config,
game_status: state.game_state.status,
bounties: bounties
Expand Down
2 changes: 1 addition & 1 deletion apps/arena/lib/arena/matchmaking/pair_mode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ defmodule Arena.Matchmaking.PairMode do
game_params = Map.put(game_params, :game_mode, :PAIR)

bot_clients =
if Application.get_env(:arena, :spawn_bots) do
if Enum.count(clients) < Application.get_env(:arena, :players_needed_in_match) do
get_bot_clients(Application.get_env(:arena, :players_needed_in_match) - Enum.count(clients))
else
[]
Expand Down
1 change: 1 addition & 0 deletions apps/arena/lib/arena/serialization/messages.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ defmodule Arena.Serialization.GameJoined do
field(:player_id, 1, type: :uint64, json_name: "playerId")
field(:config, 2, type: Arena.Serialization.Configuration)
field(:bounties, 3, repeated: true, type: Arena.Serialization.BountyInfo)
field(:team, 4, type: :uint32)
end

defmodule Arena.Serialization.Configuration do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ defmodule ArenaLoadTest.Serialization.GameJoined do
field(:player_id, 1, type: :uint64, json_name: "playerId")
field(:config, 2, type: ArenaLoadTest.Serialization.Configuration)
field(:bounties, 3, repeated: true, type: ArenaLoadTest.Serialization.BountyInfo)
field(:team, 4, type: :uint32)
end

defmodule ArenaLoadTest.Serialization.Configuration do
Expand Down
1 change: 1 addition & 0 deletions apps/bot_manager/lib/protobuf/messages.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ defmodule BotManager.Protobuf.GameJoined do
field(:player_id, 1, type: :uint64, json_name: "playerId")
field(:config, 2, type: BotManager.Protobuf.Configuration)
field(:bounties, 3, repeated: true, type: BotManager.Protobuf.BountyInfo)
field(:team, 4, type: :uint32)
end

defmodule BotManager.Protobuf.Configuration do
Expand Down
32 changes: 31 additions & 1 deletion apps/game_client/assets/js/protobuf/messages_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2934,7 +2934,8 @@ proto.GameJoined.toObject = function(includeInstance, msg) {
playerId: jspb.Message.getFieldWithDefault(msg, 1, 0),
config: (f = msg.getConfig()) && proto.Configuration.toObject(includeInstance, f),
bountiesList: jspb.Message.toObjectList(msg.getBountiesList(),
proto.BountyInfo.toObject, includeInstance)
proto.BountyInfo.toObject, includeInstance),
team: jspb.Message.getFieldWithDefault(msg, 4, 0)
};

if (includeInstance) {
Expand Down Expand Up @@ -2985,6 +2986,10 @@ proto.GameJoined.deserializeBinaryFromReader = function(msg, reader) {
reader.readMessage(value,proto.BountyInfo.deserializeBinaryFromReader);
msg.addBounties(value);
break;
case 4:
var value = /** @type {number} */ (reader.readUint32());
msg.setTeam(value);
break;
default:
reader.skipField();
break;
Expand Down Expand Up @@ -3037,6 +3042,13 @@ proto.GameJoined.serializeBinaryToWriter = function(message, writer) {
proto.BountyInfo.serializeBinaryToWriter
);
}
f = message.getTeam();
if (f !== 0) {
writer.writeUint32(
4,
f
);
}
};


Expand Down Expand Up @@ -3133,6 +3145,24 @@ proto.GameJoined.prototype.clearBountiesList = function() {
};


/**
* optional uint32 team = 4;
* @return {number}
*/
proto.GameJoined.prototype.getTeam = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 4, 0));
};


/**
* @param {number} value
* @return {!proto.GameJoined} returns this
*/
proto.GameJoined.prototype.setTeam = function(value) {
return jspb.Message.setProto3IntField(this, 4, value);
};



/**
* List of repeated fields within this message type.
Expand Down
1 change: 1 addition & 0 deletions apps/game_client/lib/game_client/protobuf/messages.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ defmodule GameClient.Protobuf.GameJoined do
field(:player_id, 1, type: :uint64, json_name: "playerId")
field(:config, 2, type: GameClient.Protobuf.Configuration)
field(:bounties, 3, repeated: true, type: GameClient.Protobuf.BountyInfo)
field(:team, 4, type: :uint32)
end

defmodule GameClient.Protobuf.Configuration do
Expand Down
1 change: 1 addition & 0 deletions apps/serialization/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ message GameJoined {
uint64 player_id = 1;
Configuration config = 2;
repeated BountyInfo bounties = 3;
uint32 team = 4;
}

message Configuration {
Expand Down

0 comments on commit 209bdfa

Please sign in to comment.