Skip to content

Commit

Permalink
Improve new field naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ncontinanza committed May 21, 2024
1 parent f5740cb commit 3d2b6b1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apps/champions/lib/champions/battle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Champions.Battle do
{:level_valid, true} <- {:level_valid, level_valid?(level, current_level_id, user)},
units <- Units.get_selected_units(user_id),
{:max_units_met, true} <- {:max_units_met, Enum.count(units) <= (level.max_units || @default_max_units)},
{:can_afford, true} <- {:can_afford, Currencies.can_afford(user_id, level.attempt_costs)} do
{:can_afford, true} <- {:can_afford, Currencies.can_afford(user_id, level.attempt_cost)} do
units =
if level.campaign.super_campaign.name == "Dungeon" do
apply_buffs(units, user_id)
Expand All @@ -42,7 +42,7 @@ defmodule Champions.Battle do
{:ok, response} =
Multi.new()
|> Multi.run(:substract_currencies, fn _repo, _changes ->
Currencies.substract_currencies(user_id, level.attempt_costs)
Currencies.substract_currencies(user_id, level.attempt_cost)
end)
|> Multi.run(:run_battle, fn _repo, _changes -> run_battle(user_id, level, units) end)
|> Repo.transaction()
Expand Down
4 changes: 2 additions & 2 deletions apps/game_backend/lib/game_backend/campaigns/level.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule GameBackend.Campaigns.Level do
has_many(:item_rewards, ItemReward)
has_many(:unit_rewards, UnitReward)

embeds_many(:attempt_costs, CurrencyCost)
embeds_many(:attempt_cost, CurrencyCost)
timestamps()
end

Expand All @@ -38,7 +38,7 @@ defmodule GameBackend.Campaigns.Level do
|> cast_assoc(:currency_rewards)
|> cast_assoc(:item_rewards)
|> cast_assoc(:unit_rewards)
|> cast_embed(:attempt_costs)
|> cast_embed(:attempt_cost)
|> validate_required([:game_id, :level_number, :campaign_id])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule GameBackend.Repo.Migrations.AddCurrencyCostToLevels do

def change do
alter table(:levels) do
add(:attempt_costs, {:array, :map})
add(:attempt_cost, {:array, :map})
end
end
end
4 changes: 2 additions & 2 deletions apps/gateway/lib/gateway/serialization/gateway.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,10 @@ defmodule Gateway.Serialization.Level do

field(:experience_reward, 6, type: :uint32, json_name: "experienceReward")

field(:attempt_costs, 7,
field(:attempt_cost, 7,
repeated: true,
type: Gateway.Serialization.CurrencyCost,
json_name: "attemptCosts"
json_name: "attemptCost"
)
end

Expand Down
2 changes: 1 addition & 1 deletion apps/serialization/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ syntax = "proto3";
repeated Unit units = 4;
repeated CurrencyReward currency_rewards = 5;
uint32 experience_reward = 6;
repeated CurrencyCost attempt_costs = 7;
repeated CurrencyCost attempt_cost = 7;
}

message CurrencyReward {
Expand Down

0 comments on commit 3d2b6b1

Please sign in to comment.