Skip to content

Commit

Permalink
Use quest definition instead of hard-coded numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
halflumi committed Dec 11, 2023
1 parent 528e59f commit ca574e0
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/GameLogic/PlayerActions/Quests/QuestCompletionAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,35 @@ public async ValueTask CompleteQuestAsync(Player player, short group, short numb

foreach (var reward in activeQuest.Rewards)
{
await AddRewardAsync(player, reward).ConfigureAwait(false);
await AddRewardAsync(player, reward, activeQuest).ConfigureAwait(false);
}

await questState.ClearAsync(player.PersistenceContext).ConfigureAwait(false);
await player.InvokeViewPlugInAsync<IQuestCompletionResponsePlugIn>(p => p.QuestCompletedAsync(activeQuest)).ConfigureAwait(false);
}

private static async ValueTask AddRewardAsync(Player player, QuestReward reward)
private static async ValueTask AddRewardAsync(Player player, QuestReward reward, QuestDefinition quest)
{
switch (reward.RewardType)
{
case QuestRewardType.Attribute:
var attribute = player.SelectedCharacter!.Attributes.FirstOrDefault(a => a.Definition == reward.AttributeReward);
if (attribute is null)
{
attribute = player.PersistenceContext.CreateNew<StatAttribute>(reward.AttributeReward, 0);
player.SelectedCharacter.Attributes.Add(attribute);
}

// Compensate level-up points when gaining Hero Status beyond level 220.
if (reward.AttributeReward?.Id == Stats.GainHeroStatusQuestCompleted.Id && attribute.Value == 0)
case QuestRewardType.Attribute:
var attribute = player.SelectedCharacter!.Attributes.FirstOrDefault(a => a.Definition == reward.AttributeReward);
if (attribute is null)
{
player.SelectedCharacter!.LevelUpPoints += (int)player.Attributes![Stats.Level] - 220;
}

attribute.Value += reward.Value;

await player.InvokeViewPlugInAsync<ILegacyQuestRewardPlugIn>(p => p.ShowAsync(player, QuestRewardType.Attribute, reward.Value, attribute.Definition)).ConfigureAwait(false);
attribute = player.PersistenceContext.CreateNew<StatAttribute>(reward.AttributeReward, 0);
player.SelectedCharacter.Attributes.Add(attribute);
}

attribute.Value += reward.Value;

// Compensate level-up points when doing a quest at a later level.
if (attribute.Definition == Stats.PointsPerLevelUp)
{
var playerLevel = (int)player.Attributes![Stats.Level];
player.SelectedCharacter.LevelUpPoints += (playerLevel - quest.MinimumCharacterLevel) * reward.Value;
}

await player.InvokeViewPlugInAsync<ILegacyQuestRewardPlugIn>(p => p.ShowAsync(player, QuestRewardType.Attribute, reward.Value, attribute.Definition)).ConfigureAwait(false);
break;
case QuestRewardType.Item:
var item = player.PersistenceContext.CreateNew<Item>();
Expand Down

0 comments on commit ca574e0

Please sign in to comment.