Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into change-servers-dns-to…
Browse files Browse the repository at this point in the history
…-champions
  • Loading branch information
Nico-Sanchez committed Aug 7, 2024
2 parents 03eefb2 + de9df27 commit 3b1e79a
Show file tree
Hide file tree
Showing 113 changed files with 3,606 additions and 1,105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arena-brazil-staging-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Brazil Arena staging
name: "[STAGING-BRAZIL] Deploy to Brazil Arena Staging"
on:
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arena-brazil-testing-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Brazil Arena testing
name: "[TESTING-BRAZIL] Deploy to Brazil Arena testing"
on:
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arena-brazil-testing-deploys.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Deploy to Brazil Arena testing multiple envs"
name: "[TESTING-BRAZIL] Deploy to Brazil Arena testing multiple envs"
on:
workflow_dispatch:
inputs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arena-europe-testing-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Europe Arena testing
name: "[TESTING-EUROPE] Deploy to Europe Arena testing"
on:
workflow_dispatch:

Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/central-europe-testing-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Europe Central testing
name: "[CENTRAL-EUROPE] Deploy to Europe Central testing"
on:
workflow_dispatch:

Expand Down Expand Up @@ -52,6 +52,8 @@ jobs:
BOT_MANAGER_PORT: ${{ vars.BOT_MANAGER_PORT }}
BOT_MANAGER_HOST: ${{ vars.LOADTEST_CLIENT_HOST }}
CONFIGURATOR_HOST: ${{ vars.CONFIGURATOR_HOST }}
CONFIGURATOR_GOOGLE_CLIENT_ID: ${{ vars.CONFIGURATOR_GOOGLE_CLIENT_ID }}
CONFIGURATOR_GOOGLE_CLIENT_SECRET: ${{ secrets.CONFIGURATOR_GOOGLE_CLIENT_SECRET }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
JWT_PRIVATE_KEY_BASE_64: ${{ secrets.JWT_PRIVATE_KEY_BASE_64 }}
Expand All @@ -72,6 +74,8 @@ jobs:
BOT_MANAGER_PORT=${BOT_MANAGER_PORT} \
BOT_MANAGER_HOST=${BOT_MANAGER_HOST} \
CONFIGURATOR_HOST=${CONFIGURATOR_HOST} \
CONFIGURATOR_GOOGLE_CLIENT_ID=${CONFIGURATOR_GOOGLE_CLIENT_ID} \
CONFIGURATOR_GOOGLE_CLIENT_SECRET=${CONFIGURATOR_GOOGLE_CLIENT_SECRET} \
DATABASE_URL=${DATABASE_URL} \
SECRET_KEY_BASE=${SECRET_KEY_BASE} \
JWT_PRIVATE_KEY_BASE_64=${JWT_PRIVATE_KEY_BASE_64} \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/loadtest-brazil-client-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Brazil Loadtest Client
name: "[LOADTEST-CLIENT-BRAZIL] Deploy to Brazil Loadtest Client"
on:
workflow_dispatch:
inputs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/loadtest-brazil-server-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Brazil Loadtest Server
name: "[LOADTEST-SERVER-BRAZIL] Deploy to Brazil Loadtest Server"
on:
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/loadtest-europe-client-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Europe Loadtest Client
name: "[LOADTEST-CLIENT-EUROPE] Deploy to Europe Loadtest Client"
on:
workflow_dispatch:
inputs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/loadtest-europe-server-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Europe Loadtest Server
name: "[LOADTEST-SERVER-EUROPE] Deploy to Europe Loadtest Server"
on:
workflow_dispatch:

Expand Down
117 changes: 71 additions & 46 deletions apps/arena/lib/arena/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,28 @@ defmodule Arena.Configuration do
|> File.read()

config = Jason.decode!(config_json, [{:keys, :atoms}])
characters = parse_characters_config(get_characters_config())
client_config = get_client_config()
game_config = get_game_configuration()
map_config = parse_map_config(get_map_config())
items_config = get_consumable_items_configuration()

config
|> Map.put(:characters, characters)
|> Map.put(:game, game_config)
|> Map.put(:map, map_config)
|> Map.put(:characters, characters)
|> Map.put(:items, items_config)
|> Map.merge(get_current_game_configuration())
|> Map.put(:client_config, client_config)
end

defp get_map_config() do
defp get_current_game_configuration do
gateway_url = Application.get_env(:arena, :gateway_url)

{:ok, payload} =
Finch.build(:get, "#{gateway_url}/curse/configuration/map", [{"content-type", "application/json"}])
Finch.build(:get, "#{gateway_url}/curse/configuration/current", [{"content-type", "application/json"}])
|> Finch.request(Arena.Finch)

Jason.decode!(payload.body, [{:keys, :atoms}])
|> Map.update!(:map, fn maps ->
map = Enum.random(maps)
parse_map_config(map)
end)
|> Map.update!(:characters, fn characters ->
parse_characters_config(characters)
end)
end

defp get_client_config() do
Expand All @@ -46,36 +45,6 @@ defmodule Arena.Configuration do
Jason.decode!(config_json, [{:keys, :atoms}])
end

defp get_characters_config() do
gateway_url = Application.get_env(:arena, :gateway_url)

{:ok, payload} =
Finch.build(:get, "#{gateway_url}/curse/configuration/characters", [{"content-type", "application/json"}])
|> Finch.request(Arena.Finch)

Jason.decode!(payload.body, [{:keys, :atoms}])
end

defp get_game_configuration() do
gateway_url = Application.get_env(:arena, :gateway_url)

{:ok, payload} =
Finch.build(:get, "#{gateway_url}/curse/configuration/game", [{"content-type", "application/json"}])
|> Finch.request(Arena.Finch)

Jason.decode!(payload.body, [{:keys, :atoms}])
end

def get_consumable_items_configuration() do
gateway_url = Application.get_env(:arena, :gateway_url)

{:ok, payload} =
Finch.build(:get, "#{gateway_url}/curse/configuration/consumable_items", [{"content-type", "application/json"}])
|> Finch.request(Arena.Finch)

Jason.decode!(payload.body, [{:keys, :atoms}])
end

defp parse_characters_config(characters) do
Enum.map(characters, fn character ->
character_skills = %{
Expand All @@ -84,17 +53,25 @@ defmodule Arena.Configuration do
"3" => parse_skill_config(character.dash_skill)
}

Map.put(character, :skills, character_skills)
%{character | mana_recovery_damage_multiplier: maybe_to_float(character.mana_recovery_damage_multiplier)}
|> Map.put(:skills, character_skills)
|> Map.drop([:basic_skill, :ultimate_skill, :dash_skill])
end)
end

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}
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}
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}
end
Expand All @@ -107,11 +84,42 @@ defmodule Arena.Configuration do
"time" ->
raise "Invalid Skill config for `#{skill_config[:name]}` cooldown_ms should be a number greater than or equal to zero"

"mana" ->
raise "Invalid Skill config for `#{skill_config[:name]}` mana_cost should be a number greater than or equal to zero"

_ ->
raise "Invalid Skill config for `#{skill_config[:name]}` cooldown_mechanism is invalid, should be either `time` or `stamina`"
end
end

defp parse_combo_config(
%{
is_combo?: true,
reset_combo_ms: reset_combo_ms,
next_skill: nil
} = skill_config
)
when reset_combo_ms >= 0 do
skill_config
end

defp parse_combo_config(
%{
is_combo?: true,
reset_combo_ms: reset_combo_ms,
next_skill: next_skill
} = skill_config
)
when reset_combo_ms >= 0 do
Map.put(skill_config, :next_skill, parse_skill_config(next_skill))
end

defp parse_combo_config(%{is_combo?: true} = skill_config) do
raise "Invalid Skill config for `#{skill_config[:name]}` reset_combo_ms is invalid, should be equal or greater than zero"
end

defp parse_combo_config(skill_config), do: skill_config

defp parse_mechanics_config(mechanics_config) do
Enum.reduce(mechanics_config, [], fn mechanic_config, acc ->
mechanic = parse_mechanic_config(mechanic_config)
Expand Down Expand Up @@ -147,14 +155,13 @@ defmodule Arena.Configuration do
## The not so small problem we have is that our code expects floats so we still need to parse
## the strings, but end up with regular floats
defp parse_map_config(map_config) do
## We're looking to play in random maps
map_config = Enum.random(map_config)

%{
map_config
| radius: maybe_to_float(map_config.radius),
initial_positions: Enum.map(map_config.initial_positions, &parse_position/1),
obstacles: Enum.map(map_config.obstacles, &parse_obstacle/1)
obstacles: Enum.map(map_config.obstacles, &parse_obstacle/1),
pools: Enum.map(map_config.pools, &parse_pool/1),
bushes: Enum.map(map_config.bushes, &parse_bush/1)
}
end

Expand All @@ -168,6 +175,15 @@ defmodule Arena.Configuration do
}
end

defp parse_bush(bush) do
%{
bush
| position: parse_position(bush.position),
vertices: Enum.map(bush.vertices, &parse_position/1),
radius: maybe_to_float(bush.radius)
}
end

defp parse_status_cycle(%{raised: _} = status_cycle) do
%{status_cycle | raised: parse_raised(status_cycle.raised)}
end
Expand All @@ -184,6 +200,15 @@ defmodule Arena.Configuration do
%{mechanics | polygon_hit: %{polygon_hit | vertices: Enum.map(polygon_hit.vertices, &parse_position/1)}}
end

defp parse_pool(pool) do
%{
pool
| position: parse_position(pool.position),
vertices: Enum.map(pool.vertices, &parse_position/1),
radius: maybe_to_float(pool.radius)
}
end

defp parse_position(%{x: x, y: y}) do
%{x: maybe_to_float(x), y: maybe_to_float(y)}
end
Expand Down
49 changes: 37 additions & 12 deletions apps/arena/lib/arena/entities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ defmodule Arena.Entities do
stamina_interval: character.stamina_interval,
cooldown_multiplier: 1,
recharging_stamina: false,
max_mana: character.base_mana,
mana: 50,
mana_recovery_strategy: character.mana_recovery_strategy,
mana_recovery_time_interval_ms: character.mana_recovery_time_interval_ms,
mana_recovery_time_amount: character.mana_recovery_time_amount,
mana_recovery_time_last_at: now,
mana_recovery_damage_multiplier: character.mana_recovery_damage_multiplier,
last_natural_healing_update: now,
natural_healing_interval: character.natural_healing_interval,
last_damage_received: now,
last_skill_triggered: now,
last_skill_triggered_inside_bush: now,
natural_healing_damage_interval: character.natural_healing_damage_interval,
character_name: character.name,
forced_movement: false,
Expand Down Expand Up @@ -138,22 +146,28 @@ defmodule Arena.Entities do
is_moving: false,
aditional_info: %{
collisionable: true,
status: ""
status: "",
type: ""
}
}
end

def new_pool(pool_params) do
now = DateTime.utc_now() |> DateTime.to_unix(:millisecond)

duration_ms =
if pool_params[:duration_ms] && pool_params[:activation_delay] do
pool_params.duration_ms + pool_params.activation_delay
end

%{
id: pool_params.id,
category: :pool,
shape: :circle,
shape: get_shape(pool_params.shape),
name: "Pool " <> Integer.to_string(pool_params.id),
position: pool_params.position,
radius: pool_params.radius,
vertices: [],
vertices: pool_params.vertices,
speed: 0.0,
direction: %{
x: 0.0,
Expand All @@ -165,10 +179,10 @@ defmodule Arena.Entities do
owner_id: pool_params.owner_id,
effects: [],
stat_multiplier: 0,
duration_ms: pool_params.duration_ms + pool_params.activation_delay,
duration_ms: duration_ms,
pull_immunity: true,
spawn_at: now,
status: :WAITING,
status: pool_params.status,
skill_key: pool_params.skill_key
},
collides_with: []
Expand Down Expand Up @@ -213,6 +227,7 @@ defmodule Arena.Entities do
is_moving: false,
aditional_info: %{
collisionable: obstacle_collisionable?(params),
collide_with_projectiles: obstacle_collide_with_projectiles?(params),
statuses_cycle: params.statuses_cycle,
status: params.base_status,
type: params.type,
Expand Down Expand Up @@ -376,7 +391,8 @@ defmodule Arena.Entities do
visible_players: entity.aditional_info.visible_players,
on_bush: entity.aditional_info.on_bush,
forced_movement: entity.aditional_info.forced_movement,
bounty_completed: entity.aditional_info.bounty_completed
bounty_completed: entity.aditional_info.bounty_completed,
mana: entity.aditional_info.mana
}}
end

Expand All @@ -403,7 +419,8 @@ defmodule Arena.Entities do
%Arena.Serialization.Obstacle{
color: "red",
collisionable: entity.aditional_info.collisionable,
status: entity.aditional_info.status
status: entity.aditional_info.status,
type: entity.aditional_info.type
}}
end

Expand Down Expand Up @@ -470,16 +487,24 @@ defmodule Arena.Entities do
put_in(entity, [:aditional_info, :cooldowns], %{})
end

def obstacle_collisionable?(%{type: "static"}) do
true
end

def obstacle_collisionable?(params) do
def obstacle_collisionable?(%{type: "dynamic"} = params) do
%{base_status: base_status, statuses_cycle: statuses_cycle} = params

base_status_params =
Map.get(statuses_cycle, String.to_existing_atom(base_status))

base_status_params.make_obstacle_collisionable
end

def obstacle_collisionable?(_params) do
true
end

def obstacle_collide_with_projectiles?(%{type: "lake"}) do
false
end

def obstacle_collide_with_projectiles?(_params) do
true
end
end
Loading

0 comments on commit 3b1e79a

Please sign in to comment.