Skip to content

Commit

Permalink
Fixes for players visibility on bushes (#886)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
agustinesco authored Sep 4, 2024
1 parent bdca479 commit 9a89445
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion apps/arena/lib/arena/entities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
}
Expand Down
27 changes: 27 additions & 0 deletions apps/arena/lib/arena/game/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 #
####################
Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a89445

Please sign in to comment.