Skip to content

Commit

Permalink
Refactor CurrencyRewards, fix experience, add amount to rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
lotuuu committed Jun 12, 2024
1 parent ca3b7b4 commit ae17889
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 125 deletions.
23 changes: 11 additions & 12 deletions client/Assets/Scripts/BackendConnection/SocketConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,27 @@ private List<Campaign> ParseCampaignsFromResponse(Protobuf.Messages.Campaigns ca
levelNumber = (int)level.LevelNumber,
campaignId = level.CampaignId,
units = levelUnits,
currencyRewards = GetLevelCurrencyRewards(level),
itemRewards = level.ItemRewards.Select(itemReward => new ItemReward
currencyRewards = level.CurrencyRewards.Select(currencyReward => new CurrencyReward
{
currency = GlobalUserData.Instance.AvailableCurrencies.Find(currency => currency.name == currencyReward.Currency.Name),
amount = (int)currencyReward.Amount
}).ToList(),
itemRewards = level.ItemRewards.Select(itemReward =>
new ItemReward
{
itemTemplate = GlobalUserData.Instance.AvailableItemTemplates.Find(itemTemplate => itemTemplate.name.ToLower() == itemReward.ItemTemplateName.ToLower()),
level = (int)itemReward.Level
amount = (int)itemReward.Amount
}).ToList(),
unitRewards = level.UnitRewards.Select(unitReward => new UnitReward
{
character = availableCharacters.Find(character => character.name.ToLower() == unitReward.CharacterName.ToLower()),
rank = (int)unitReward.Rank
rank = (int)unitReward.Rank,
amount = (int)unitReward.Amount
}).ToList(),
experienceReward = (int)level.ExperienceReward,
status = levelStatus
});


if (levelStatus == LevelProgress.Status.Unlocked)
{
levelStatus = LevelProgress.Status.Locked;
Expand Down Expand Up @@ -843,13 +849,6 @@ private void AwaitFuseUnitsResponse(byte[] data, Action<Unit> onSuccess, Action<
}
}

private Dictionary<string, int> GetLevelCurrencyRewards(Level level)
{
Dictionary<string, int> rewards = level.CurrencyRewards.ToDictionary(currencyReward => currencyReward.Currency.Name, currencyReward => (int)currencyReward.Amount);
rewards.Add("Experience", (int)level.ExperienceReward);
return rewards;
}

public void GetAfkRewards(string userId, Action<List<AfkReward>> onAfkRewardsReceived)
{
GetAfkRewards getAfkRewardsRequest = new GetAfkRewards
Expand Down
21 changes: 14 additions & 7 deletions client/Assets/Scripts/Battle/BattleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private void HandleBattleResult(bool result)
Debug.LogError(ex.Message);
}
GlobalUserData user = GlobalUserData.Instance;
user.AddCurrencies(GetLevelRewards());
user.AddCurrencies(GetLevelCurrencyRewards());
victorySplash.GetComponentInChildren<RewardsUIContainer>().Populate(CreateRewardsList());
victorySplash.SetActive(true);
victorySplash.GetComponent<AudioSource>().Play();
Expand Down Expand Up @@ -303,9 +303,14 @@ private void ProcessExecutionsReceived(IEnumerable<Protobuf.Messages.Action> act
}
}

private Dictionary<string, int> GetLevelRewards()
private Dictionary<string, int> GetLevelCurrencyRewards()
{
Dictionary<string, int> rewards = LevelProgress.selectedLevelData.currencyRewards;
Dictionary<string, int> rewards = new();
foreach (var currencyReward in LevelProgress.selectedLevelData.currencyRewards)
{
rewards.Add(currencyReward.currency.name, currencyReward.amount);
}

if (LevelProgress.selectedLevelData.experienceReward > 0)
{
rewards.Add("Experience", LevelProgress.selectedLevelData.experienceReward);
Expand Down Expand Up @@ -337,10 +342,7 @@ private List<UIReward> CreateRewardsList()

foreach (var currencyReward in LevelProgress.selectedLevelData.currencyRewards)
{
if (currencyReward.Value > 0)
{
rewards.Add(new CurrencyUIReward(currencyReward.Key, currencyReward.Value));
}
rewards.Add(new CurrencyUIReward(currencyReward));
}

foreach (var unitReward in LevelProgress.selectedLevelData.unitRewards)
Expand All @@ -353,6 +355,11 @@ private List<UIReward> CreateRewardsList()
rewards.Add(new ItemUIReward(itemReward));
}

if (LevelProgress.selectedLevelData.experienceReward > 0)
{
rewards.Add(new ExperienceUIReward(LevelProgress.selectedLevelData.experienceReward));
}

return rewards;
}

Expand Down
6 changes: 6 additions & 0 deletions client/Assets/Scripts/Campaign/CurrencyReward.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class CurrencyReward
{

public Currency currency;
public int amount;
}
11 changes: 11 additions & 0 deletions client/Assets/Scripts/Campaign/CurrencyReward.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/Assets/Scripts/Campaign/ItemReward.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public class ItemReward
{
public ItemTemplate itemTemplate;
public int level;
public int amount;
}
3 changes: 1 addition & 2 deletions client/Assets/Scripts/Campaign/LevelData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class LevelData
public string campaignId;
public List<Unit> units;

public Dictionary<string, int> currencyRewards = new Dictionary<string, int>();

public List<CurrencyReward> currencyRewards = new();
public List<ItemReward> itemRewards = new();
public List<UnitReward> unitRewards = new();

Expand Down
1 change: 1 addition & 0 deletions client/Assets/Scripts/Campaign/UnitReward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ public class UnitReward
{
public Character character;
public int rank;
public int amount;
}
Loading

0 comments on commit ae17889

Please sign in to comment.