Skip to content

Commit

Permalink
Show effects properly in configurator (#1035)
Browse files Browse the repository at this point in the history
* Rename Skill.effect_to_apply and Mechanic.on_collide_effect fields

* Add missing forms for DB associations used in game

* Add missing params for Mechanics forms

* Use assigns properly in effect_show template
  • Loading branch information
Nico-Sanchez authored Jan 9, 2025
1 parent de0a5a7 commit 66967d3
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 46 deletions.
16 changes: 8 additions & 8 deletions apps/arena/lib/arena/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ defmodule Arena.Configuration do
defp parse_skill_config(%{cooldown_mechanism: "stamina", stamina_cost: cost} = skill_config) when cost >= 0 do
skill_config = parse_combo_config(skill_config)
mechanics = parse_mechanics_config(skill_config.mechanics)
%{skill_config | mechanics: mechanics, effect_to_apply: parse_effect(skill_config.effect_to_apply)}
%{skill_config | mechanics: mechanics, on_owner_effect: parse_effect(skill_config.on_owner_effect)}
end

defp parse_skill_config(%{cooldown_mechanism: "time", cooldown_ms: cooldown} = skill_config) when cooldown >= 0 do
skill_config = parse_combo_config(skill_config)
mechanics = parse_mechanics_config(skill_config.mechanics)
%{skill_config | mechanics: mechanics, effect_to_apply: parse_effect(skill_config.effect_to_apply)}
%{skill_config | mechanics: mechanics, on_owner_effect: parse_effect(skill_config.on_owner_effect)}
end

defp parse_skill_config(%{cooldown_mechanism: "mana", mana_cost: cost} = skill_config) when cost >= 0 do
mechanics = parse_mechanics_config(skill_config.mechanics)
%{skill_config | mechanics: mechanics, effect_to_apply: parse_effect(skill_config.effect_to_apply)}
%{skill_config | mechanics: mechanics, on_owner_effect: parse_effect(skill_config.on_owner_effect)}
end

defp parse_skill_config(skill_config) do
Expand Down Expand Up @@ -163,7 +163,7 @@ defmodule Arena.Configuration do
on_explode_mechanics: parse_mechanics_config(mechanic.on_explode_mechanics),
parent_mechanic: parse_mechanic_config(mechanic.parent_mechanic),
effect: parse_effect(mechanic.effect),
on_collide_effects: parse_on_collide_effects(mechanic.on_collide_effects)
on_collide_effect: parse_on_collide_effect(mechanic.on_collide_effect)
}
end

Expand Down Expand Up @@ -218,14 +218,14 @@ defmodule Arena.Configuration do
%{mechanics | polygon_hit: %{polygon_hit | vertices: Enum.map(polygon_hit.vertices, &parse_position/1)}}
end

defp parse_on_collide_effects(nil) do
defp parse_on_collide_effect(nil) do
nil
end

defp parse_on_collide_effects(on_collide_effects) do
defp parse_on_collide_effect(on_collide_effect) do
%{
on_collide_effects
| effect: parse_effect(on_collide_effects.effect)
on_collide_effect
| effect: parse_effect(on_collide_effect.effect)
}
end

Expand Down
4 changes: 2 additions & 2 deletions apps/arena/lib/arena/entities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ defmodule Arena.Entities do
remove_on_collision: config_params.remove_on_collision,
on_explode_mechanics: Map.get(config_params, :on_explode_mechanics),
pull_immunity: true,
on_collide_effect: Map.get(config_params, :on_collide_effects)
on_collide_effect: Map.get(config_params, :on_collide_effect)
},
collides_with: []
}
Expand Down Expand Up @@ -215,7 +215,7 @@ defmodule Arena.Entities do
},
is_moving: false,
aditional_info: %{
effect_to_apply: pool_params.effect,
effect: pool_params.effect,
owner_id: pool_params.owner.id,
owner_team: pool_params.owner.aditional_info.team,
effects: [],
Expand Down
6 changes: 1 addition & 5 deletions apps/arena/lib/arena/game/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,7 @@ defmodule Arena.Game.Player do
skill.activation_delay_ms
)

Process.send_after(
self(),
{:delayed_effect_application, player.id, Map.get(skill, :effect_to_apply), skill.execution_duration_ms},
skill.activation_delay_ms
)
Process.send_after(self(), {:delayed_effect_application, player.id, skill}, skill.activation_delay_ms)

player =
add_action(player, action)
Expand Down
4 changes: 2 additions & 2 deletions apps/arena/lib/arena/game/skill.ex
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ defmodule Arena.Game.Skill do
apply_damage_and_effects_to_entities(game_state, entity_player_owner, polygon_damage_area, polygon_hit.damage)
end

def handle_skill_effects(game_state, player, effect, execution_duration_ms) do
Effect.put_effect_to_entity(game_state, player, player.id, execution_duration_ms, effect)
def handle_on_owner_effect(game_state, player, skill) do
Effect.put_effect_to_entity(game_state, player, player.id, skill.execution_duration_ms, skill.on_owner_effect)
end

defp calculate_angle_directions(amount, angle_between, base_direction) do
Expand Down
10 changes: 4 additions & 6 deletions apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,15 @@ defmodule Arena.GameUpdater do
end

def handle_info(
{:delayed_effect_application, _player_id, nil, _execution_duration_ms},
{:delayed_effect_application, _player_id, %{on_owner_effect: nil}},
state
) do
{:noreply, state}
end

def handle_info({:delayed_effect_application, player_id, effect_to_apply, execution_duration_ms}, state) do
def handle_info({:delayed_effect_application, player_id, skill}, state) do
player = Map.get(state.game_state.players, player_id)

game_state =
Skill.handle_skill_effects(state.game_state, player, effect_to_apply, execution_duration_ms)
game_state = Skill.handle_on_owner_effect(state.game_state, player, skill)

{:noreply, %{state | game_state: game_state}}
end
Expand Down Expand Up @@ -1689,7 +1687,7 @@ defmodule Arena.GameUpdater do
if entity.id == pool.aditional_info.owner_id do
game_state
else
Effect.put_effect_to_entity(game_state, entity, pool.id, pool.aditional_info.effect_to_apply)
Effect.put_effect_to_entity(game_state, entity, pool.id, pool.aditional_info.effect)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@ defmodule ConfiguratorWeb.CustomComponents do
use Phoenix.Component

def effect_show(%{effect: nil} = assigns) do
assigns = assign(assigns, :label, Map.get(assigns, :label, "Show Effect"))

~H"""
<.button type="button" phx-click={show_modal("no-effect")}>Show effect</.button>
<.button type="button" phx-click={show_modal("no-effect")}><%= @label %></.button>
<.modal id="no-effect">
<h3>No Effect</h3>
</.modal>
"""
end

def effect_show(assigns) do
assigns = assign(assigns, :label, Map.get(assigns, :label, "Show Effect"))

~H"""
<.button type="button" phx-click={show_modal("effect-show-#{@effect.id}")}>Show effect</.button>
<.button type="button" phx-click={show_modal("effect-show-#{@effect.id}")}><%= @label %></.button>
<.modal id={"effect-show-#{@effect.id}"}>
<.list>
<:item title="Name"><%= @effect.name %></:item>
<:item title="Duration ms"><%= @effect.duration_ms %></:item>
<:item title="Remove on action"><%= @effect.remove_on_action %></:item>
<:item title="Apply effect once"><%= @effect.one_time_application %></:item>
<:item title="Allow more that one effect instance"><%= @effect.allow_multiple_effects %></:item>
<:item title="Allow multiple instances"><%= @effect.allow_multiple_effects %></:item>
<:item title="Consume projectile"><%= @effect.consume_projectile %></:item>
</.list>
<%= for effect_mechanic <- @effect.effect_mechanics do %>
Expand Down Expand Up @@ -58,7 +62,7 @@ defmodule ConfiguratorWeb.CustomComponents do

def effect_form(assigns) do
~H"""
<.button type="button" phx-click={show_modal("effect-form")}>Edit effect</.button>
<.button type="button" phx-click={show_modal("effect-form")}><%= "Edit #{@field}" %></.button>
<.modal id="effect-form">
<.inputs_for :let={effect_f} field={@form[@field]}>
<.input field={effect_f[:name]} type="text" label="Name" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
<:col :let={skill} label="Cooldown (ms)"><%= skill.cooldown_ms %></:col>
<:col :let={skill} label="Execution duration (ms)"><%= skill.execution_duration_ms %></:col>
<:col :let={skill} label="Inmune while executing"><%= skill.inmune_while_executing %></:col>
<:col :let={skill} label="Is passive"><%= skill.is_passive %></:col>
<:col :let={skill} label="Max autoaim range"><%= skill.max_autoaim_range %></:col>
<:col :let={skill} label="Stamina cost"><%= skill.stamina_cost %></:col>
<:col :let={skill} label="Mana cost"><%= skill.mana_cost %></:col>

<:action :let={skill}>
<%= if not is_nil(skill.on_owner_effect) do %>
<.effect_show effect={skill.on_owner_effect} label="On Owner Effect" />
<% end %>
<.button type="button" phx-click={show_modal("skill-mechanics-#{skill.id}")}>Mechanics</.button>
<.modal id={"skill-mechanics-#{skill.id}"}>
<.header>
Mechanics for the skill
</.header>
<%= for mechanic <- skill.mechanics do %>
<.mechanic_show mechanic={mechanic} />
<.effect_show effect={mechanic.effect} />

<%= if not is_nil(mechanic.on_arrival_mechanic) do %>
<.button type="button" phx-click={show_modal("on-arrival-mechanic-modal")}>Show on arrival mechanic</.button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
<:item title="Remove on collision"><%= @mechanic.remove_on_collision %></:item>
<:item title="Speed"><%= @mechanic.speed %></:item>
<:item title="Shape of entity"><%= @mechanic.shape %></:item>
<:item title="vertices"><%= Jason.encode!(@mechanic.vertices) %></:item>
<:item title="Vertices"><%= Jason.encode!(@mechanic.vertices) %></:item>
</.list>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<.input field={fp[:range]} type="number" label="Range" />
<.input field={fp[:remove_on_collision]} type="checkbox" label="Remove on collision" />
<.input field={fp[:speed]} type="number" label="speed" />
<.input field={fp[:activation_delay]} type="number" label="Pool activation delay" />
<.input field={fp[:activation_delay_ms]} type="number" label="Activation delay ms" />
<.input field={fp[:preparation_delay_ms]} type="number" label="Preparation delay ms" />
<.input field={fp[:activate_on_proximity]} type="checkbox" label="Activate on proximity" />
<%= if fp.data.effect do %>
<.effect_form form={fp} field={:effect} />
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<.link href={~p"/versions/#{@version}/skills/#{@skill}/edit"}>
<.button>Edit skill</.button>
</.link>
<.effect_show effect={@skill.effect_to_apply} />
<.effect_show effect={@skill.on_owner_effect} label="On Owner Effect" />
</:actions>
</.header>

Expand Down Expand Up @@ -40,6 +40,9 @@
<%= for mechanic <- @skill.mechanics do %>
<.mechanic_show mechanic={mechanic} />
<.effect_show effect={mechanic.effect} />
<%= if not is_nil(mechanic.on_collide_effect) do %>
<.effect_show effect={mechanic.on_collide_effect.effect} label="On Collide Effect" />
<% end %>

<.button type="button" phx-click={show_modal("on-arrival-mechanic-modal")}>Show on arrival mechanic</.button>
<.modal id="on-arrival-mechanic-modal">
Expand All @@ -56,6 +59,7 @@
</.header>
<%= for mechanic <- mechanic.on_explode_mechanics do %>
<.mechanic_show mechanic={mechanic} />
<.effect_show effect={mechanic.effect} />
<% end %>
</.modal>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<.input field={f[:mana_cost]} type="number" label="Mana cost" />

<.skill_mechanic_inputs skill_form={f} />
<%= if f.data.effect_to_apply do %>
<.effect_form form={f} field={:effect_to_apply} />
<%= if f.data.on_owner_effect do %>
<.effect_form form={f} field={:on_owner_effect} />
<% end %>

<:actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<.input field={fp[:range]} type="number" label="Range" />
<.input field={fp[:remove_on_collision]} type="checkbox" label="Remove on collision" />
<.input field={fp[:speed]} type="number" label="speed" />
<.input field={fp[:activation_delay]} type="number" label="Pool activation delay" />
<.input field={fp[:activation_delay_ms]} type="number" label="Activation delay ms" />
<.input field={fp[:preparation_delay_ms]} type="number" label="Preparation delay ms" />
<.input field={fp[:activate_on_proximity]} type="checkbox" label="Activate on proximity" />
<%= if fp.data.effect do %>
<.effect_form form={fp} field={:effect} />
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
<.input type="hidden" field={fs[:game_id]} />

<.skill_mechanic_inputs skill_form={fs} />
<%= if fs.data.effect_to_apply do %>
<.effect_form form={fs} field={:effect_to_apply} />
<%= if fs.data.on_owner_effect do %>
<.effect_form form={fs} field={:on_owner_effect} />
<% end %>
</div>
</.inputs_for>
Expand Down
6 changes: 3 additions & 3 deletions apps/game_backend/lib/game_backend/units/skills/mechanic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule GameBackend.Units.Skills.Mechanic do

alias GameBackend.Items.ConsumableItem
alias GameBackend.Units.Skills.Skill
alias GameBackend.Units.Skills.Mechanics.{ApplyEffectsTo, PassiveEffect, OnCollideEffects}
alias GameBackend.Units.Skills.Mechanics.{ApplyEffectsTo, PassiveEffect, OnCollideEffect}

schema "mechanics" do
field(:amount, :integer)
Expand Down Expand Up @@ -52,7 +52,7 @@ defmodule GameBackend.Units.Skills.Mechanic do
belongs_to(:passive_effects, PassiveEffect)
belongs_to(:on_arrival_mechanic, __MODULE__)
belongs_to(:parent_mechanic, __MODULE__, foreign_key: :parent_mechanic_id)
embeds_one(:on_collide_effects, OnCollideEffects)
embeds_one(:on_collide_effect, OnCollideEffect)
embeds_one(:effect, GameBackend.CurseOfMirra.Effect)
end

Expand Down Expand Up @@ -93,7 +93,7 @@ defmodule GameBackend.Units.Skills.Mechanic do
|> cast_assoc(:parent_mechanic, with: &assoc_changeset/2)
|> cast_assoc(:on_arrival_mechanic, with: &assoc_changeset/2)
|> cast_assoc(:on_explode_mechanics, with: &assoc_changeset/2)
|> cast_embed(:on_collide_effects)
|> cast_embed(:on_collide_effect)
|> cast_embed(:effect)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule GameBackend.Units.Skills.Mechanics.OnCollideEffects do
defmodule GameBackend.Units.Skills.Mechanics.OnCollideEffect do
@moduledoc """
A schema that defines the strategy for how a mechanic will choose its targets.
"""
Expand Down
6 changes: 3 additions & 3 deletions apps/game_backend/lib/game_backend/units/skills/skill.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule GameBackend.Units.Skills.Skill do
belongs_to(:next_skill, __MODULE__)
has_many(:mechanics, Mechanic, on_replace: :delete)
belongs_to(:version, Version)
embeds_one(:effect_to_apply, GameBackend.CurseOfMirra.Effect)
embeds_one(:on_owner_effect, GameBackend.CurseOfMirra.Effect)

timestamps()
end
Expand Down Expand Up @@ -75,7 +75,7 @@ defmodule GameBackend.Units.Skills.Skill do
|> foreign_key_constraint(:characters, name: "characters_basic_skill_id_fkey")
|> cooldown_mechanism_validation()
|> validate_combo_fields()
|> cast_embed(:effect_to_apply)
|> cast_embed(:on_owner_effect)
end

@doc false
Expand All @@ -88,7 +88,7 @@ defmodule GameBackend.Units.Skills.Skill do
|> foreign_key_constraint(:characters, name: "characters_basic_skill_id_fkey")
|> cooldown_mechanism_validation()
|> validate_combo_fields()
|> cast_embed(:effect_to_apply)
|> cast_embed(:on_owner_effect)
end

defp cooldown_mechanism_validation(changeset) do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule GameBackend.Repo.Migrations.RenameSkillAndMechanicEffects do
use Ecto.Migration

def change do
rename table(:skills), :effect_to_apply, to: :on_owner_effect
rename table(:mechanics), :on_collide_effects, to: :on_collide_effect
end
end
6 changes: 3 additions & 3 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ simple_shoot = %{
"offset" => 0
}
],
"on_collide_effects" => %{
"on_collide_effect" => %{
"apply_effect_to_entity_type" => [
"pool"
],
Expand Down Expand Up @@ -760,7 +760,7 @@ skills = [
"offset" => 0
}
],
"effect_to_apply" => invisible_effect,
"on_owner_effect" => invisible_effect,
"version_id" => version.id
},
%{
Expand Down Expand Up @@ -910,7 +910,7 @@ skills = [
"offset" => 0
}
],
"effect_to_apply" => whirlwind_effect,
"on_owner_effect" => whirlwind_effect,
"version_id" => version.id
},
%{
Expand Down

0 comments on commit 66967d3

Please sign in to comment.