From 8e9eef63aa7b5411462d2e6da5ce879633ee345f Mon Sep 17 00:00:00 2001 From: agustinesco Date: Wed, 8 May 2024 20:27:00 -0300 Subject: [PATCH 01/10] Split block movement from block actions --- apps/arena/lib/arena/game/player.ex | 20 +++++++++-- apps/arena/lib/arena/game_socket_handler.ex | 39 +++++++++++++-------- apps/arena/lib/arena/game_updater.ex | 9 +++++ apps/arena/priv/config.json | 13 +++++++ 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/apps/arena/lib/arena/game/player.ex b/apps/arena/lib/arena/game/player.ex index 677ed19fb..f63fddb29 100644 --- a/apps/arena/lib/arena/game/player.ex +++ b/apps/arena/lib/arena/game/player.ex @@ -3,6 +3,7 @@ defmodule Arena.Game.Player do Module for interacting with Player entity """ + alias Arena.GameUpdater alias Arena.Utils alias Arena.Game.Effect alias Arena.Game.Skill @@ -172,6 +173,14 @@ defmodule Arena.Game.Player do skill.execution_duration_ms ) + GameUpdater.broadcast_player_block_movement(game_state.game_id, player.id, skill.block_movement) + + Process.send_after( + self(), + {:block_movement, player.id, false}, + skill.execution_duration_ms + ) + {auto_aim?, skill_direction} = skill_params.target |> Skill.maybe_auto_aim(skill, player, targetable_players(game_state.players)) @@ -205,10 +214,17 @@ defmodule Arena.Game.Player do player = add_action(player, action) |> apply_skill_cooldown(skill_key, skill) - |> put_in([:direction], skill_direction |> Utils.normalize()) - |> put_in([:is_moving], false) |> put_in([:aditional_info, :last_skill_triggered], System.monotonic_time(:millisecond)) + player = + if skill.block_movement do + player + |> put_in([:direction], skill_direction |> Utils.normalize()) + |> put_in([:is_moving], false) + else + player + end + put_in(game_state, [:players, player.id], player) |> maybe_make_player_invincible(player.id, skill) end diff --git a/apps/arena/lib/arena/game_socket_handler.ex b/apps/arena/lib/arena/game_socket_handler.ex index 506dfdfe0..36e2aa46c 100644 --- a/apps/arena/lib/arena/game_socket_handler.ex +++ b/apps/arena/lib/arena/game_socket_handler.ex @@ -33,6 +33,7 @@ defmodule Arena.GameSocketHandler do Map.put(state, :player_id, player_id) |> Map.put(:enable, game_status == :RUNNING) |> Map.put(:block_actions, false) + |> Map.put(:block_movement, false) |> Map.put(:game_finished, game_status == :ENDED) encoded_msg = @@ -50,11 +51,6 @@ defmodule Arena.GameSocketHandler do {:ok, state} end - @impl true - def websocket_handle(_, %{block_actions: true} = state) do - {:ok, state} - end - @impl true def websocket_handle(:pong, state) do last_ping_time = state.last_ping_time @@ -74,21 +70,27 @@ defmodule Arena.GameSocketHandler do {:reply, {:pong, ""}, state} end - def websocket_handle({:binary, message}, state) do + def websocket_handle({:binary, message}, %{block_actions: block_actions, block_movement: block_movement} = state) do case Serialization.GameAction.decode(message) do %{action_type: {:attack, %{skill: skill, parameters: params}}, timestamp: timestamp} -> - GameUpdater.attack(state.game_pid, state.player_id, skill, params, timestamp) + unless block_actions do + GameUpdater.attack(state.game_pid, state.player_id, skill, params, timestamp) + end %{action_type: {:use_item, _}, timestamp: timestamp} -> - GameUpdater.use_item(state.game_pid, state.player_id, timestamp) + unless block_actions do + GameUpdater.use_item(state.game_pid, state.player_id, timestamp) + end %{action_type: {:move, %{direction: direction}}, timestamp: timestamp} -> - GameUpdater.move( - state.game_pid, - state.player_id, - {direction.x, direction.y}, - timestamp - ) + unless block_movement do + GameUpdater.move( + state.game_pid, + state.player_id, + {direction.x, direction.y}, + timestamp + ) + end _ -> {} @@ -146,6 +148,15 @@ defmodule Arena.GameSocketHandler do end end + @impl true + def websocket_info({:block_movement, player_id, value}, state) do + if state.player_id == player_id do + {:ok, Map.put(state, :block_movement, value)} + else + {:ok, state} + end + end + @impl true def websocket_info(message, state) do Logger.info("You should not be here: #{inspect(message)}") diff --git a/apps/arena/lib/arena/game_updater.ex b/apps/arena/lib/arena/game_updater.ex index cb96d29aa..59eab89bf 100644 --- a/apps/arena/lib/arena/game_updater.ex +++ b/apps/arena/lib/arena/game_updater.ex @@ -415,6 +415,11 @@ defmodule Arena.GameUpdater do {:noreply, state} end + def handle_info({:block_movement, player_id, value}, state) do + broadcast_player_block_movement(state.game_state.game_id, player_id, value) + {:noreply, state} + end + ########################## # End callbacks ########################## @@ -427,6 +432,10 @@ defmodule Arena.GameUpdater do PubSub.broadcast(Arena.PubSub, game_id, {:block_actions, player_id, value}) end + def broadcast_player_block_movement(game_id, player_id, value) do + PubSub.broadcast(Arena.PubSub, game_id, {:block_movement, player_id, value}) + end + # Broadcast game update to all players defp broadcast_player_dead(game_id, player_id) do PubSub.broadcast(Arena.PubSub, game_id, {:player_dead, player_id}) diff --git a/apps/arena/priv/config.json b/apps/arena/priv/config.json index 37b8cdf55..f9e319f7c 100644 --- a/apps/arena/priv/config.json +++ b/apps/arena/priv/config.json @@ -899,6 +899,7 @@ "max_autoaim_range": 800, "stamina_cost": 1, "can_pick_destination": false, + "block_movement": true, "mechanics": [ { "circle_hit": { @@ -920,6 +921,7 @@ "autoaim": true, "max_autoaim_range": 1500, "can_pick_destination": true, + "block_movement": true, "mechanics": [ { "spawn_pool": { @@ -945,6 +947,7 @@ "autoaim": true, "max_autoaim_range": 1500, "can_pick_destination": true, + "block_movement": true, "mechanics": [ { "leap": { @@ -972,6 +975,7 @@ "autoaim": true, "max_autoaim_range": 1500, "can_pick_destination": true, + "block_movement": true, "mechanics": [ { "spawn_pool": { @@ -997,6 +1001,7 @@ "max_autoaim_range": 1600, "stamina_cost": 1, "can_pick_destination": false, + "block_movement": false, "mechanics": [ { "multi_shoot": { @@ -1023,6 +1028,7 @@ "autoaim": false, "max_autoaim_range": 0, "can_pick_destination": false, + "block_movement": true, "mechanics": [ { "dash": { @@ -1042,6 +1048,7 @@ "autoaim": false, "max_autoaim_range": 0, "can_pick_destination": false, + "block_movement": true, "mechanics": [ { "dash": { @@ -1061,6 +1068,7 @@ "max_autoaim_range": 800, "stamina_cost": 1, "can_pick_destination": false, + "block_movement": true, "mechanics": [ { "multi_circle_hit": { @@ -1085,6 +1093,7 @@ "autoaim": true, "max_autoaim_range": 0, "can_pick_destination": false, + "block_movement": true, "mechanics": [ { "circle_hit": { @@ -1108,6 +1117,7 @@ "autoaim": false, "max_autoaim_range": 0, "can_pick_destination": false, + "block_movement": true, "mechanics": [ { "dash": { @@ -1129,6 +1139,7 @@ "autoaim": false, "max_autoaim_range": 0, "can_pick_destination": true, + "block_movement": true, "stamina_cost": 1, "mechanics": [ { @@ -1150,6 +1161,7 @@ "autoaim": false, "max_autoaim_range": 0, "can_pick_destination": false, + "block_movement": true, "mechanics": [ { "dash": { @@ -1170,6 +1182,7 @@ "max_autoaim_range": 1600, "stamina_cost": 1, "can_pick_destination": false, + "block_movement": true, "mechanics": [ { "simple_shoot": { From 6a4a958ac0d81e2981edf2ff45ecfffda9574646 Mon Sep 17 00:00:00 2001 From: agustinesco Date: Wed, 8 May 2024 20:27:17 -0300 Subject: [PATCH 02/10] use skill direction instead of player direction for mechanics --- apps/arena/lib/arena/game/skill.ex | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/apps/arena/lib/arena/game/skill.ex b/apps/arena/lib/arena/game/skill.ex index dc26091d6..419b3a07f 100644 --- a/apps/arena/lib/arena/game/skill.ex +++ b/apps/arena/lib/arena/game/skill.ex @@ -13,8 +13,8 @@ defmodule Arena.Game.Skill do end) end - def do_mechanic(game_state, entity, {:circle_hit, circle_hit}, _skill_params) do - circle_center_position = get_position_with_offset(entity.position, entity.direction, circle_hit.offset) + def do_mechanic(game_state, entity, {:circle_hit, circle_hit}, %{skill_direction: skill_direction} = _skill_params) do + circle_center_position = get_position_with_offset(entity.position, skill_direction, circle_hit.offset) circular_damage_area = Entities.make_circular_area(entity.id, circle_center_position, circle_hit.range) entity_player_owner = get_entity_player_owner(game_state, entity) @@ -63,11 +63,11 @@ defmodule Arena.Game.Skill do |> maybe_move_player(entity, circle_hit[:move_by]) end - def do_mechanic(game_state, entity, {:cone_hit, cone_hit}, _skill_params) do + def do_mechanic(game_state, entity, {:cone_hit, cone_hit}, %{skill_direction: skill_direction} = _skill_params) do triangle_points = Physics.calculate_triangle_vertices( entity.position, - entity.direction, + skill_direction, cone_hit.range, cone_hit.angle ) @@ -145,7 +145,12 @@ defmodule Arena.Game.Skill do do_mechanic(game_state, entity, {:circle_hit, multi_circle_hit}, skill_params) end - def do_mechanic(game_state, entity, {:dash, %{speed: speed, duration: duration}}, _skill_params) do + def do_mechanic( + game_state, + entity, + {:dash, %{speed: speed, duration: duration}}, + %{skill_direction: skill_direction} = _skill_params + ) do Process.send_after(self(), {:stop_dash, entity.id, entity.aditional_info.base_speed}, duration) ## Modifying base_speed rather than speed because effects will reset the speed on game tick @@ -154,6 +159,7 @@ defmodule Arena.Game.Skill do entity |> Map.put(:is_moving, true) |> put_in([:aditional_info, :base_speed], speed) + |> put_in([:aditional_info, :direction], skill_direction) |> put_in([:aditional_info, :forced_movement], true) players = Map.put(game_state.players, entity.id, entity) @@ -199,10 +205,10 @@ defmodule Arena.Game.Skill do |> put_in([:projectiles, projectile.id], projectile) end - def do_mechanic(game_state, entity, {:multi_shoot, multishot}, skill_params) do + def do_mechanic(game_state, entity, {:multi_shoot, multishot}, %{skill_direction: skill_direction} = skill_params) do entity_player_owner = get_entity_player_owner(game_state, entity) - calculate_angle_directions(multishot.amount, multishot.angle_between, entity.direction) + calculate_angle_directions(multishot.amount, multishot.angle_between, skill_direction) |> Enum.reduce(game_state, fn direction, game_state_acc -> last_id = game_state_acc.last_id + 1 @@ -211,7 +217,7 @@ defmodule Arena.Game.Skill do last_id, get_position_with_offset( entity_player_owner.position, - entity_player_owner.direction, + skill_direction, multishot.projectile_offset ), direction, @@ -228,7 +234,7 @@ defmodule Arena.Game.Skill do end) end - def do_mechanic(game_state, entity, {:simple_shoot, simple_shoot}, skill_params) do + def do_mechanic(game_state, entity, {:simple_shoot, simple_shoot}, %{skill_direction: skill_direction} = skill_params) do last_id = game_state.last_id + 1 entity_player_owner = get_entity_player_owner(game_state, entity) @@ -240,7 +246,7 @@ defmodule Arena.Game.Skill do entity_player_owner.direction, simple_shoot.projectile_offset ), - entity.direction, + skill_direction, entity_player_owner.id, skill_params.skill_key, simple_shoot From 7a83829595cba34f34cb9919b193a1a657aaa8ee Mon Sep 17 00:00:00 2001 From: agustinesco Date: Fri, 10 May 2024 12:36:27 -0300 Subject: [PATCH 03/10] Add direction to player action message --- apps/arena/lib/arena/game/player.ex | 3 +- .../lib/arena/serialization/messages.pb.ex | 1 + .../serialization/messages.pb.ex | 1 + apps/bot_manager/lib/protobuf/messages.pb.ex | 1 + .../assets/js/protobuf/messages_pb.js | 53 ++++++++++++++++++- .../lib/game_client/protobuf/messages.pb.ex | 1 + apps/serialization/messages.proto | 1 + 7 files changed, 59 insertions(+), 2 deletions(-) diff --git a/apps/arena/lib/arena/game/player.ex b/apps/arena/lib/arena/game/player.ex index f63fddb29..c7da626f9 100644 --- a/apps/arena/lib/arena/game/player.ex +++ b/apps/arena/lib/arena/game/player.ex @@ -188,7 +188,8 @@ defmodule Arena.Game.Player do action = %{ action: skill_key_execution_action(skill_key), - duration: skill.execution_duration_ms + duration: skill.execution_duration_ms, + direction: skill_direction } |> maybe_add_destination(game_state, player, skill_direction, skill) diff --git a/apps/arena/lib/arena/serialization/messages.pb.ex b/apps/arena/lib/arena/serialization/messages.pb.ex index 35523c3d4..05ef6c2bb 100644 --- a/apps/arena/lib/arena/serialization/messages.pb.ex +++ b/apps/arena/lib/arena/serialization/messages.pb.ex @@ -520,6 +520,7 @@ defmodule Arena.Serialization.PlayerAction do field(:action, 1, type: Arena.Serialization.PlayerActionType, enum: true) field(:duration, 2, type: :uint64) field(:destination, 3, type: Arena.Serialization.Position) + field(:direction, 4, type: Arena.Serialization.Position) end defmodule Arena.Serialization.Move do diff --git a/apps/arena_load_test/lib/arena_load_test/serialization/messages.pb.ex b/apps/arena_load_test/lib/arena_load_test/serialization/messages.pb.ex index 2088aef96..1310de3e6 100644 --- a/apps/arena_load_test/lib/arena_load_test/serialization/messages.pb.ex +++ b/apps/arena_load_test/lib/arena_load_test/serialization/messages.pb.ex @@ -550,6 +550,7 @@ defmodule ArenaLoadTest.Serialization.PlayerAction do field(:action, 1, type: ArenaLoadTest.Serialization.PlayerActionType, enum: true) field(:duration, 2, type: :uint64) field(:destination, 3, type: ArenaLoadTest.Serialization.Position) + field(:direction, 4, type: ArenaLoadTest.Serialization.Position) end defmodule ArenaLoadTest.Serialization.Move do diff --git a/apps/bot_manager/lib/protobuf/messages.pb.ex b/apps/bot_manager/lib/protobuf/messages.pb.ex index bb19954bf..e8f14b5bb 100644 --- a/apps/bot_manager/lib/protobuf/messages.pb.ex +++ b/apps/bot_manager/lib/protobuf/messages.pb.ex @@ -520,6 +520,7 @@ defmodule BotManager.Protobuf.PlayerAction do field(:action, 1, type: BotManager.Protobuf.PlayerActionType, enum: true) field(:duration, 2, type: :uint64) field(:destination, 3, type: BotManager.Protobuf.Position) + field(:direction, 4, type: BotManager.Protobuf.Position) end defmodule BotManager.Protobuf.Move do diff --git a/apps/game_client/assets/js/protobuf/messages_pb.js b/apps/game_client/assets/js/protobuf/messages_pb.js index 87781ce17..514617bfd 100644 --- a/apps/game_client/assets/js/protobuf/messages_pb.js +++ b/apps/game_client/assets/js/protobuf/messages_pb.js @@ -7249,7 +7249,8 @@ proto.PlayerAction.toObject = function(includeInstance, msg) { var f, obj = { action: jspb.Message.getFieldWithDefault(msg, 1, 0), duration: jspb.Message.getFieldWithDefault(msg, 2, 0), - destination: (f = msg.getDestination()) && proto.Position.toObject(includeInstance, f) + destination: (f = msg.getDestination()) && proto.Position.toObject(includeInstance, f), + direction: (f = msg.getDirection()) && proto.Position.toObject(includeInstance, f) }; if (includeInstance) { @@ -7299,6 +7300,11 @@ proto.PlayerAction.deserializeBinaryFromReader = function(msg, reader) { reader.readMessage(value,proto.Position.deserializeBinaryFromReader); msg.setDestination(value); break; + case 4: + var value = new proto.Position; + reader.readMessage(value,proto.Position.deserializeBinaryFromReader); + msg.setDirection(value); + break; default: reader.skipField(); break; @@ -7350,6 +7356,14 @@ proto.PlayerAction.serializeBinaryToWriter = function(message, writer) { proto.Position.serializeBinaryToWriter ); } + f = message.getDirection(); + if (f != null) { + writer.writeMessage( + 4, + f, + proto.Position.serializeBinaryToWriter + ); + } }; @@ -7426,6 +7440,43 @@ proto.PlayerAction.prototype.hasDestination = function() { }; +/** + * optional Position direction = 4; + * @return {?proto.Position} + */ +proto.PlayerAction.prototype.getDirection = function() { + return /** @type{?proto.Position} */ ( + jspb.Message.getWrapperField(this, proto.Position, 4)); +}; + + +/** + * @param {?proto.Position|undefined} value + * @return {!proto.PlayerAction} returns this +*/ +proto.PlayerAction.prototype.setDirection = function(value) { + return jspb.Message.setWrapperField(this, 4, value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.PlayerAction} returns this + */ +proto.PlayerAction.prototype.clearDirection = function() { + return this.setDirection(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.PlayerAction.prototype.hasDirection = function() { + return jspb.Message.getField(this, 4) != null; +}; + + diff --git a/apps/game_client/lib/game_client/protobuf/messages.pb.ex b/apps/game_client/lib/game_client/protobuf/messages.pb.ex index 9e393b196..4213abf52 100644 --- a/apps/game_client/lib/game_client/protobuf/messages.pb.ex +++ b/apps/game_client/lib/game_client/protobuf/messages.pb.ex @@ -520,6 +520,7 @@ defmodule GameClient.Protobuf.PlayerAction do field(:action, 1, type: GameClient.Protobuf.PlayerActionType, enum: true) field(:duration, 2, type: :uint64) field(:destination, 3, type: GameClient.Protobuf.Position) + field(:direction, 4, type: GameClient.Protobuf.Position) end defmodule GameClient.Protobuf.Move do diff --git a/apps/serialization/messages.proto b/apps/serialization/messages.proto index d070c1c9a..79867bbdb 100644 --- a/apps/serialization/messages.proto +++ b/apps/serialization/messages.proto @@ -233,6 +233,7 @@ message PlayerAction { PlayerActionType action = 1; uint64 duration = 2; Position destination = 3; + Position direction = 4; } enum PlayerActionType { From 1aff622c4f299e9ed172413025fce29093c67cbf Mon Sep 17 00:00:00 2001 From: agustinesco Date: Mon, 20 May 2024 12:01:58 -0300 Subject: [PATCH 04/10] Revert h4ck slingshot while moving --- apps/arena/priv/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/arena/priv/config.json b/apps/arena/priv/config.json index 17eb34bad..d154d2750 100644 --- a/apps/arena/priv/config.json +++ b/apps/arena/priv/config.json @@ -970,7 +970,7 @@ "max_autoaim_range": 1600, "stamina_cost": 1, "can_pick_destination": false, - "block_movement": false, + "block_movement": true, "mechanics": [ { "multi_shoot": { From da4a0f144c174e81b51487defd45de08af604440 Mon Sep 17 00:00:00 2001 From: agustinesco Date: Mon, 20 May 2024 13:18:26 -0300 Subject: [PATCH 05/10] Add missing param to do_mechanic call --- apps/arena/lib/arena/game_updater.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/arena/lib/arena/game_updater.ex b/apps/arena/lib/arena/game_updater.ex index 6bdb2a48c..1756122ff 100644 --- a/apps/arena/lib/arena/game_updater.ex +++ b/apps/arena/lib/arena/game_updater.ex @@ -233,7 +233,7 @@ defmodule Arena.GameUpdater do game_state = put_in(state.game_state, [:players, player_id], player) - |> Skill.do_mechanic(player, on_arrival_mechanic, %{}) + |> Skill.do_mechanic(player, on_arrival_mechanic, %{skill_direction: player.direction}) {:noreply, %{state | game_state: game_state}} end @@ -936,7 +936,7 @@ defmodule Arena.GameUpdater do game_state, projectile, projectile.aditional_info.on_explode_mechanics, - %{} + %{skill_direction: projectile.direction} ) else game_state From b1dbae14f50ba28977568c19ea467752dcd78a65 Mon Sep 17 00:00:00 2001 From: agustinesco Date: Mon, 20 May 2024 13:30:19 -0300 Subject: [PATCH 06/10] Fix skill direction on simple shoot and restore maybe_normalize --- apps/arena/lib/arena/game/skill.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/arena/lib/arena/game/skill.ex b/apps/arena/lib/arena/game/skill.ex index 4f2f20a1d..6c42bdcca 100644 --- a/apps/arena/lib/arena/game/skill.ex +++ b/apps/arena/lib/arena/game/skill.ex @@ -243,7 +243,7 @@ defmodule Arena.Game.Skill do last_id, get_position_with_offset( entity_player_owner.position, - entity_player_owner.direction, + skill_direction, simple_shoot.projectile_offset ), skill_direction, @@ -377,6 +377,7 @@ defmodule Arena.Game.Skill do true -> nearest_entity_position_in_range = Physics.nearest_entity_position_in_range(player, entities, skill.max_autoaim_range) + |> maybe_normalize(not skill.can_pick_destination) {nearest_entity_position_in_range != player.direction, nearest_entity_position_in_range} From f742c59473409443552d0ce309644688b4813874 Mon Sep 17 00:00:00 2001 From: agustinesco Date: Mon, 20 May 2024 16:19:01 -0300 Subject: [PATCH 07/10] Fix doc typos --- apps/arena/lib/arena/game/player.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/arena/lib/arena/game/player.ex b/apps/arena/lib/arena/game/player.ex index ff3a6cef9..ab4b89e12 100644 --- a/apps/arena/lib/arena/game/player.ex +++ b/apps/arena/lib/arena/game/player.ex @@ -238,8 +238,8 @@ defmodule Arena.Game.Player do end # This is a messy solution to get a mechanic result before actually running the mechanic since the client needed the - # position in wich the player will spawn when the skill start and not when we actually execute the teleport - # this is also optimistic since we asume the destination will be always available + # position in which the player will spawn when the skill start and not when we actually execute the teleport + # this is also optimistic since we assume the destination will be always available defp maybe_add_destination(action, game_state, player, skill_direction, %{mechanics: [{:teleport, teleport}]}) do target_position = %{ x: player.position.x + skill_direction.x * teleport.range, @@ -258,7 +258,7 @@ defmodule Arena.Game.Player do Receives a player that owns the damage and the damage number - to calculate the real damage we'll use the config "power_up_damage_modifier" multipling that with base damage of the + to calculate the real damage we'll use the config "power_up_damage_modifier" multiplying that with base damage of the ability and multiply that with the amount of power ups that a player has then adding that to the base damage resulting in the real damage From 4413d28eee571d04a94c3ce3dd5ec8be4c8d4f8f Mon Sep 17 00:00:00 2001 From: agustinesco Date: Mon, 20 May 2024 16:23:31 -0300 Subject: [PATCH 08/10] keep player pipe line --- apps/arena/lib/arena/game/player.ex | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/arena/lib/arena/game/player.ex b/apps/arena/lib/arena/game/player.ex index ab4b89e12..3973af231 100644 --- a/apps/arena/lib/arena/game/player.ex +++ b/apps/arena/lib/arena/game/player.ex @@ -221,17 +221,9 @@ defmodule Arena.Game.Player do player = add_action(player, action) |> apply_skill_cooldown(skill_key, skill) + |> maybe_face_player_towards_direction(skill_direction, skill.block_movement) |> put_in([:aditional_info, :last_skill_triggered], System.monotonic_time(:millisecond)) - player = - if skill.block_movement do - player - |> put_in([:direction], skill_direction |> Utils.normalize()) - |> put_in([:is_moving], false) - else - player - end - put_in(game_state, [:players, player.id], player) |> maybe_make_player_invincible(player.id, skill) end @@ -254,6 +246,14 @@ defmodule Arena.Game.Player do defp maybe_add_destination(action, _, _, _, _), do: action + defp maybe_face_player_towards_direction(player, skill_direction, true) do + player + |> put_in([:direction], skill_direction |> Utils.normalize()) + |> put_in([:is_moving], false) + end + + defp maybe_face_player_towards_direction(player, _skill_direction, _), do: player + @doc """ Receives a player that owns the damage and the damage number From 533bdaf14e8a3d69200d51885f406f51168798e3 Mon Sep 17 00:00:00 2001 From: agustinesco Date: Mon, 20 May 2024 16:27:25 -0300 Subject: [PATCH 09/10] Refactor block movement callback --- apps/arena/lib/arena/game/player.ex | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/apps/arena/lib/arena/game/player.ex b/apps/arena/lib/arena/game/player.ex index 3973af231..f28e0c6fa 100644 --- a/apps/arena/lib/arena/game/player.ex +++ b/apps/arena/lib/arena/game/player.ex @@ -169,26 +169,15 @@ defmodule Arena.Game.Player do game_state skill -> - Process.send_after( - self(), - {:block_actions, player.id}, - skill.execution_duration_ms - ) - GameUpdater.broadcast_player_block_movement(game_state.game_id, player.id, skill.block_movement) - Process.send_after( - self(), - {:block_movement, player.id, false}, - skill.execution_duration_ms - ) - {auto_aim?, skill_direction} = skill_params.target |> Skill.maybe_auto_aim(skill, player, targetable_players(game_state.players)) execution_duration = calculate_duration(skill, player.position, skill_direction, auto_aim?) Process.send_after(self(), {:block_actions, player.id}, execution_duration) + Process.send_after(self(), {:block_movement, player.id, false}, execution_duration) action = %{ From f8530bd7a2d86bc27402b28ecb39c4d48c1509f2 Mon Sep 17 00:00:00 2001 From: agustinesco Date: Mon, 20 May 2024 19:42:18 -0300 Subject: [PATCH 10/10] Send messages instead of broadcasting --- apps/arena/lib/arena/game/player.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/arena/lib/arena/game/player.ex b/apps/arena/lib/arena/game/player.ex index f28e0c6fa..94de8af60 100644 --- a/apps/arena/lib/arena/game/player.ex +++ b/apps/arena/lib/arena/game/player.ex @@ -177,7 +177,11 @@ defmodule Arena.Game.Player do execution_duration = calculate_duration(skill, player.position, skill_direction, auto_aim?) Process.send_after(self(), {:block_actions, player.id}, execution_duration) - Process.send_after(self(), {:block_movement, player.id, false}, execution_duration) + + if skill.block_movement do + send(self(), {:block_movement, player.id, true}) + Process.send_after(self(), {:block_movement, player.id, false}, execution_duration) + end action = %{