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

[GH-1059] - Send match's map to the client #1064

Merged
merged 10 commits into from
Feb 7, 2025
1 change: 1 addition & 0 deletions apps/arena/lib/arena/entities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ defmodule Arena.Entities do
defp get_team(%{category: :projectile} = entity), do: entity.aditional_info.owner_team
defp get_team(%{category: :pool} = entity), do: entity.aditional_info.owner_team
defp get_team(%{category: category} = _entity), do: category
defp get_team(%{aditional_info: %{team: :zone}}), do: :zone

def update_entity(%{category: :player} = entity, game_state) do
put_in(game_state, [:players, entity.id], entity)
Expand Down
11 changes: 9 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,8 @@ defmodule Arena.GameSocketHandler do
Logger.info("Websocket INIT called")
Phoenix.PubSub.subscribe(Arena.PubSub, state.game_id)

{:ok, %{player_id: player_id, team: team, 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, map: map}} =
GameUpdater.join(state.game_pid, state.client_id)

state =
Expand All @@ -56,7 +57,13 @@ defmodule Arena.GameSocketHandler do
GameEvent.encode(%GameEvent{
event:
{:joined,
%GameJoined{player_id: player_id, team: team, config: to_broadcast_config(config), bounties: bounties}}
%GameJoined{
player_id: player_id,
team: team,
config: to_broadcast_config(config),
bounties: bounties,
map: map
}}
})

:telemetry.execute([:arena, :clients], %{count: 1})
Expand Down
27 changes: 19 additions & 8 deletions apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ defmodule Arena.GameUpdater do
team: player.aditional_info.team,
game_config: state.game_config,
game_status: state.game_state.status,
bounties: []
bounties: [],
map: state.game_config.map_mode_params.map.name
}

state =
Expand Down Expand Up @@ -663,13 +664,23 @@ defmodule Arena.GameUpdater do
item_config = Enum.random(state.game_config.items)

position =
random_position_in_square(
item_config.radius,
state.game_state.external_wall,
state.game_state.obstacles,
state.game_state.external_wall.position,
state.game_state.square_wall
)
if is_nil(state.game_state.square_wall) do
random_position_in_map(
item_config.radius,
state.game_state.external_wall,
state.game_state.obstacles,
state.game_state.external_wall.position,
state.game_state.external_wall.radius
)
else
random_position_in_square(
item_config.radius,
state.game_state.external_wall,
state.game_state.obstacles,
state.game_state.external_wall.position,
state.game_state.square_wall
)
end

item = Entities.new_item(last_id, position, item_config)

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 @@ -225,6 +225,7 @@ defmodule Arena.Serialization.GameJoined do
field(:config, 2, type: Arena.Serialization.Configuration)
field(:bounties, 3, repeated: true, type: Arena.Serialization.BountyInfo)
field(:team, 4, type: :uint32)
field(:map, 5, type: :string)
end

defmodule Arena.Serialization.Configuration do
Expand Down
2 changes: 1 addition & 1 deletion apps/arena/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Arena.MixProject do
def project do
[
app: :arena,
version: "0.16.1",
version: "0.17.1",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ defmodule ArenaLoadTest.Serialization.GameJoined do
field(:config, 2, type: ArenaLoadTest.Serialization.Configuration)
field(:bounties, 3, repeated: true, type: ArenaLoadTest.Serialization.BountyInfo)
field(:team, 4, type: :uint32)
field(:map, 5, type: :string)
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 @@ -225,6 +225,7 @@ defmodule BotManager.Protobuf.GameJoined do
field(:config, 2, type: BotManager.Protobuf.Configuration)
field(:bounties, 3, repeated: true, type: BotManager.Protobuf.BountyInfo)
field(:team, 4, type: :uint32)
field(:map, 5, type: :string)
end

defmodule BotManager.Protobuf.Configuration do
Expand Down
3 changes: 3 additions & 0 deletions apps/game_backend/lib/game_backend/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ defmodule GameBackend.Configuration do
[basic_skill: [mechanics: [:on_arrival_mechanic, :on_explode_mechanics, :parent_mechanic]]],
[ultimate_skill: [mechanics: [:on_arrival_mechanic, :on_explode_mechanics, :parent_mechanic]]],
[dash_skill: [mechanics: [:on_arrival_mechanic, :on_explode_mechanics, :parent_mechanic]]]
],
game_mode_configurations: [
map_mode_params: :map
]
]
)
Expand Down
2 changes: 2 additions & 0 deletions apps/game_backend/lib/game_backend/configuration/version.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule GameBackend.Configuration.Version do
alias GameBackend.Units.Skills.Skill
alias GameBackend.CurseOfMirra.MapConfiguration
alias GameBackend.CurseOfMirra.GameConfiguration
alias GameBackend.CurseOfMirra.GameModeConfiguration

schema "versions" do
field(:name, :string)
Expand All @@ -20,6 +21,7 @@ defmodule GameBackend.Configuration.Version do
has_many(:skills, Skill)
has_many(:map_configurations, MapConfiguration)
has_one(:game_configuration, GameConfiguration)
has_many(:game_mode_configurations, GameModeConfiguration)

timestamps(type: :utc_datetime)
end
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 @@ -2935,7 +2935,8 @@ 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),
team: jspb.Message.getFieldWithDefault(msg, 4, 0)
team: jspb.Message.getFieldWithDefault(msg, 4, 0),
map: jspb.Message.getFieldWithDefault(msg, 5, "")
};

if (includeInstance) {
Expand Down Expand Up @@ -2990,6 +2991,10 @@ proto.GameJoined.deserializeBinaryFromReader = function(msg, reader) {
var value = /** @type {number} */ (reader.readUint32());
msg.setTeam(value);
break;
case 5:
var value = /** @type {string} */ (reader.readString());
msg.setMap(value);
break;
default:
reader.skipField();
break;
Expand Down Expand Up @@ -3049,6 +3054,13 @@ proto.GameJoined.serializeBinaryToWriter = function(message, writer) {
f
);
}
f = message.getMap();
if (f.length > 0) {
writer.writeString(
5,
f
);
}
};


Expand Down Expand Up @@ -3163,6 +3175,24 @@ proto.GameJoined.prototype.setTeam = function(value) {
};


/**
* optional string map = 5;
* @return {string}
*/
proto.GameJoined.prototype.getMap = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 5, ""));
};


/**
* @param {string} value
* @return {!proto.GameJoined} returns this
*/
proto.GameJoined.prototype.setMap = function(value) {
return jspb.Message.setProto3StringField(this, 5, 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 @@ -225,6 +225,7 @@ defmodule GameClient.Protobuf.GameJoined do
field(:config, 2, type: GameClient.Protobuf.Configuration)
field(:bounties, 3, repeated: true, type: GameClient.Protobuf.BountyInfo)
field(:team, 4, type: :uint32)
field(:map, 5, type: :string)
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 @@ -61,6 +61,7 @@ message GameJoined {
Configuration config = 2;
repeated BountyInfo bounties = 3;
uint32 team = 4;
string map = 5;
}

message Configuration {
Expand Down
18 changes: 16 additions & 2 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ _slow_field_effect = %{
araban_map_config = %{
name: "Araban",
radius: 5520.0,
active: false,
active: true,
initial_positions: [
%{
x: 5400,
Expand Down Expand Up @@ -4348,7 +4348,7 @@ merliot_map_config = %{
}
}

{:ok, _araban_map_configuration} =
{:ok, araban_map_configuration} =
GameBackend.Configuration.create_map_configuration(araban_map_config)

{:ok, merliot_map_configuration} =
Expand Down Expand Up @@ -4450,6 +4450,20 @@ deathmatch_mode_params = %{
%{x: -5047, y: 853}
],
map_id: merliot_map_configuration.id
},
%{
amount_of_players: 7,
initial_positions: [
%{x: 5400, y: -400.0},
%{x: -5300, y: 400.0},
%{x: 1100, y: 5100},
%{x: 3200, y: -4300},
%{x: -3400, y: 3600},
%{x: -1900, y: -5100},
%{x: 4200, y: 3200}
],
team_team_initial_positions: [],
map_id: araban_map_configuration.id
}
]
}
Expand Down
Loading