diff --git a/src/GameLogic/PlayerActions/Quests/QuestCompletionAction.cs b/src/GameLogic/PlayerActions/Quests/QuestCompletionAction.cs index 22bfce1d3..8dbb73f61 100644 --- a/src/GameLogic/PlayerActions/Quests/QuestCompletionAction.cs +++ b/src/GameLogic/PlayerActions/Quests/QuestCompletionAction.cs @@ -6,6 +6,7 @@ namespace MUnique.OpenMU.GameLogic.PlayerActions.Quests; using MUnique.OpenMU.AttributeSystem; using MUnique.OpenMU.DataModel.Configuration.Quests; +using MUnique.OpenMU.GameLogic.Attributes; using MUnique.OpenMU.GameLogic.Views.Character; using MUnique.OpenMU.GameLogic.Views.Inventory; using MUnique.OpenMU.GameLogic.Views.Quest; @@ -85,28 +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(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(reward.AttributeReward, 0); - player.SelectedCharacter.Attributes.Add(attribute); - } - - attribute.Value += reward.Value; - - await player.InvokeViewPlugInAsync(p => p.ShowAsync(player, QuestRewardType.Attribute, reward.Value, attribute.Definition)).ConfigureAwait(false); + case QuestRewardType.Attribute: + var attribute = player.SelectedCharacter!.Attributes.FirstOrDefault(a => a.Definition == reward.AttributeReward); + if (attribute is null) + { + attribute = player.PersistenceContext.CreateNew(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(p => p.ShowAsync(player, QuestRewardType.Attribute, reward.Value, attribute.Definition)).ConfigureAwait(false); break; case QuestRewardType.Item: var item = player.PersistenceContext.CreateNew();