From 9a89445dd96e13289d8cf037749fd595d45f1ea1 Mon Sep 17 00:00:00 2001 From: Agustin Escobar <106101218+agustinesco@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:57:56 -0300 Subject: [PATCH] Fixes for players visibility on bushes (#886) * Add new item effect duration to players * Always show players with item effect * Update item effect duration * Show player while executing skills * Credo complain * Changes requested --- apps/arena/lib/arena/entities.ex | 3 ++- apps/arena/lib/arena/game/player.ex | 27 +++++++++++++++++++++++++++ apps/arena/lib/arena/game_updater.ex | 7 ++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/apps/arena/lib/arena/entities.ex b/apps/arena/lib/arena/entities.ex index 673019e4c..a8d57e16a 100644 --- a/apps/arena/lib/arena/entities.ex +++ b/apps/arena/lib/arena/entities.ex @@ -65,7 +65,8 @@ defmodule Arena.Entities do bounties: [], selected_bounty: nil, bounty_completed: false, - current_basic_animation: 0 + current_basic_animation: 0, + item_effects_expires_at: now }, collides_with: [] } diff --git a/apps/arena/lib/arena/game/player.ex b/apps/arena/lib/arena/game/player.ex index 62c4edcc3..edb392e4a 100644 --- a/apps/arena/lib/arena/game/player.ex +++ b/apps/arena/lib/arena/game/player.ex @@ -363,7 +363,9 @@ defmodule Arena.Game.Player do game_state = Enum.reduce(item.effects, game_state, fn effect_name, game_state_acc -> effect = Enum.find(game_config.effects, fn %{name: name} -> name == effect_name end) + Effect.put_effect_to_entity(game_state_acc, player, player.id, effect) + |> maybe_update_player_item_effects_expires_at(player, effect) end) |> put_in([:players, player.id, :aditional_info, :inventory], nil) @@ -415,6 +417,16 @@ defmodule Arena.Game.Player do |> Effect.apply_stat_effects() end + def player_executing_skill?(player) do + Enum.any?(player.aditional_info.current_actions, fn current_action -> + Atom.to_string(current_action.action) + |> case do + "EXECUTING_SKILL" <> _number -> true + _ -> false + end + end) + end + #################### # Internal helpers # #################### @@ -575,4 +587,19 @@ defmodule Arena.Game.Player do defp get_skill_animation("kenzu_quickslash_third"), do: 3 defp get_skill_animation(_skill_name), do: 1 + + defp maybe_update_player_item_effects_expires_at(game_state, player, %{duration_ms: duration_ms} = _effect) + when not is_nil(duration_ms) do + duration = + System.monotonic_time(:millisecond) + duration_ms + + game_state + |> update_in([:players, player.id, :aditional_info, :item_effects_expires_at], fn item_duration -> + max(item_duration, duration) + end) + end + + defp maybe_update_player_item_effects_expires_at(game_state, _player, _effect) do + game_state + end end diff --git a/apps/arena/lib/arena/game_updater.ex b/apps/arena/lib/arena/game_updater.ex index e407ffc99..1c996ae33 100644 --- a/apps/arena/lib/arena/game_updater.ex +++ b/apps/arena/lib/arena/game_updater.ex @@ -1762,8 +1762,13 @@ defmodule Arena.GameUpdater do now - candidate_player.aditional_info.last_skill_triggered_inside_bush < game_config.game.time_visible_in_bush_after_skill + player_has_item_effect? = + candidate_player.aditional_info.item_effects_expires_at > now + + player_is_executing_skill? = Player.player_executing_skill?(candidate_player) + if Enum.empty?(candidate_bush_collisions) or (players_in_same_bush? and players_close_enough?) or - enough_time_since_last_skill? do + enough_time_since_last_skill? or player_has_item_effect? or player_is_executing_skill? do [candicandidate_player_id | acc] else acc