From e5809176b69e449e345c3ff09bc6911e041e2622 Mon Sep 17 00:00:00 2001 From: Agustin Escobar <106101218+agustinesco@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:57:33 -0300 Subject: [PATCH] [GH-852] Configurator: Migrate power up config (#853) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Delete already migrated items config * Add power up fields to game config * Show and edit new power up fields from game configurator * Use new power up fields from config instead of json * Add power ups fields to game seeds * Remove unnecessary power up fields from config.json * Fix game configuration creation * Remove missing power_up from json config * Update apps/configurator/lib/configurator_web/controllers/game_configuration_html/game_configuration_form.html.heex Co-authored-by: Tomás Villegas <67444519+tvillegas98@users.noreply.github.com> --------- Co-authored-by: Tomás Villegas <67444519+tvillegas98@users.noreply.github.com> --- apps/arena/lib/arena/configuration.ex | 12 ++++ apps/arena/lib/arena/entities.ex | 10 ++-- apps/arena/lib/arena/game_updater.ex | 16 +++--- apps/arena/priv/config.json | 57 ------------------- .../game_configuration_form.html.heex | 27 +++++++++ .../game_configuration_html/show.html.heex | 18 ++++++ .../curse_of_mirra/game_configuration.ex | 36 +++++++++++- ..._power_up_config_to_game_configuration.exs | 15 +++++ priv/repo/seeds.exs | 21 ++++++- 9 files changed, 139 insertions(+), 73 deletions(-) create mode 100644 apps/game_backend/priv/repo/migrations/20240812142938_add_power_up_config_to_game_configuration.exs diff --git a/apps/arena/lib/arena/configuration.ex b/apps/arena/lib/arena/configuration.ex index 0858aea4a..be207e3f6 100644 --- a/apps/arena/lib/arena/configuration.ex +++ b/apps/arena/lib/arena/configuration.ex @@ -35,6 +35,9 @@ defmodule Arena.Configuration do |> Map.update!(:characters, fn characters -> parse_characters_config(characters) end) + |> Map.update!(:game, fn game -> + parse_game_config(game) + end) end defp get_client_config() do @@ -213,6 +216,15 @@ defmodule Arena.Configuration do %{x: maybe_to_float(x), y: maybe_to_float(y)} end + defp parse_game_config(game_config) do + %{ + game_config + | power_up_damage_modifier: maybe_to_float(game_config.power_up_damage_modifier), + power_up_health_modifier: maybe_to_float(game_config.power_up_health_modifier), + power_up_radius: maybe_to_float(game_config.power_up_radius) + } + end + defp maybe_to_float(nil), do: nil defp maybe_to_float(float_integer) when is_integer(float_integer) do diff --git a/apps/arena/lib/arena/entities.ex b/apps/arena/lib/arena/entities.ex index adaa207d6..7d29193ea 100644 --- a/apps/arena/lib/arena/entities.ex +++ b/apps/arena/lib/arena/entities.ex @@ -52,7 +52,7 @@ defmodule Arena.Entities do character_name: character.name, forced_movement: false, power_ups: 0, - power_up_damage_modifier: config.power_ups.power_up.power_up_damage_modifier, + power_up_damage_modifier: config.game.power_up_damage_modifier, inventory: nil, damage_immunity: false, pull_immunity: false, @@ -104,14 +104,14 @@ defmodule Arena.Entities do } end - def new_power_up(id, position, direction, owner_id, power_up) do + def new_power_up(id, position, direction, owner_id, game_config) do %{ id: id, category: :power_up, shape: :circle, name: "Power Up" <> Integer.to_string(id), position: position, - radius: power_up.radius, + radius: game_config.power_up_radius, vertices: [], speed: 0.0, direction: direction, @@ -121,8 +121,8 @@ defmodule Arena.Entities do status: :UNAVAILABLE, remove_on_collision: true, pull_immunity: true, - power_up_damage_modifier: power_up.power_up_damage_modifier, - power_up_health_modifier: power_up.power_up_health_modifier + power_up_damage_modifier: game_config.power_up_damage_modifier, + power_up_health_modifier: game_config.power_up_health_modifier } } end diff --git a/apps/arena/lib/arena/game_updater.ex b/apps/arena/lib/arena/game_updater.ex index 29ebc2c96..6ae4f38d6 100644 --- a/apps/arena/lib/arena/game_updater.ex +++ b/apps/arena/lib/arena/game_updater.ex @@ -497,7 +497,7 @@ defmodule Arena.GameUpdater do ) do entry = %{killer_id: killer_id, victim_id: victim_id} victim = Map.get(game_state.players, victim_id) - amount_of_power_ups = get_amount_of_power_ups(victim, game_config.power_ups.power_ups_per_kill) + amount_of_power_ups = get_amount_of_power_ups(victim, game_config.game.power_ups_per_kill) game_state = game_state @@ -1549,12 +1549,12 @@ defmodule Arena.GameUpdater do victim, amount ) do - distance_to_power_up = game_config.power_ups.power_up.distance_to_power_up + distance_to_power_up = game_config.game.distance_to_power_up Enum.reduce(1..amount//1, game_state, fn _, game_state -> random_position = random_position_in_map( - game_config.power_ups.power_up.radius, + game_config.game.power_up_radius, game_state.external_wall, game_state.obstacles, victim.position, @@ -1569,10 +1569,10 @@ defmodule Arena.GameUpdater do random_position, victim.direction, victim.id, - game_config.power_ups.power_up + game_config.game ) - Process.send_after(self(), {:activate_power_up, last_id}, game_config.power_ups.power_up.activation_delay_ms) + Process.send_after(self(), {:activate_power_up, last_id}, game_config.game.power_up_activation_delay_ms) game_state |> put_in([:power_ups, last_id], power_up) @@ -1581,12 +1581,12 @@ defmodule Arena.GameUpdater do end defp get_amount_of_power_ups(%{aditional_info: %{power_ups: power_ups}}, power_ups_per_kill) do - Enum.sort_by(power_ups_per_kill, fn %{minimum_amount: minimum} -> minimum end, :desc) - |> Enum.find(fn %{minimum_amount: minimum} -> + Enum.sort_by(power_ups_per_kill, fn %{minimum_amount_of_power_ups: minimum} -> minimum end, :desc) + |> Enum.find(fn %{minimum_amount_of_power_ups: minimum} -> minimum <= power_ups end) |> case do - %{amount_of_drops: amount} -> amount + %{amount_of_power_ups_to_drop: amount} -> amount _ -> 0 end end diff --git a/apps/arena/priv/config.json b/apps/arena/priv/config.json index afec851b7..6997faf12 100644 --- a/apps/arena/priv/config.json +++ b/apps/arena/priv/config.json @@ -1,61 +1,4 @@ { - "items": [ - { - "name": "golden_clock", - "radius": 200.0, - "effects": [ - "golden_clock_effect" - ], - "mechanics": {} - }, - { - "name": "magic_boots", - "radius": 200.0, - "effects": [ - "magic_boots_effect" - ], - "mechanics": {} - }, - { - "name": "mirra_blessing", - "radius": 200.0, - "effects": [ - "mirra_blessing_effect" - ], - "mechanics": {} - }, - { - "name": "giant", - "radius": 200.0, - "effects": [ - "giant_effect" - ], - "mechanics": {} - } - ], - "power_ups": { - "power_ups_per_kill": [ - { - "minimum_amount": 0, - "amount_of_drops": 1 - }, - { - "minimum_amount": 2, - "amount_of_drops": 2 - }, - { - "minimum_amount": 6, - "amount_of_drops": 3 - } - ], - "power_up": { - "distance_to_power_up": 400, - "power_up_damage_modifier": 0.08, - "power_up_health_modifier": 0.08, - "radius": 200.0, - "activation_delay_ms": 500 - } - }, "effects": [ { "name": "invisible", diff --git a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/game_configuration_form.html.heex b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/game_configuration_form.html.heex index fda33877b..4734ecbed 100644 --- a/apps/configurator/lib/configurator_web/controllers/game_configuration_html/game_configuration_form.html.heex +++ b/apps/configurator/lib/configurator_web/controllers/game_configuration_html/game_configuration_form.html.heex @@ -29,6 +29,33 @@ <.input field={f[:field_of_view_inside_bush]} type="number" label="Field of view inside bush" /> <.input field={f[:time_visible_in_bush_after_skill]} type="number" label="Field of view inside bush" /> +