Skip to content

Commit

Permalink
Merge pull request #395 from halflumi/hero-status-compensation
Browse files Browse the repository at this point in the history
Compensate level-up points when gaining Hero Status beyond level 220
  • Loading branch information
sven-n authored Dec 11, 2023
2 parents 5602541 + ca574e0 commit a6554bb
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/GameLogic/PlayerActions/Quests/QuestCompletionAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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);
}

attribute.Value += reward.Value;

await player.InvokeViewPlugInAsync<ILegacyQuestRewardPlugIn>(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<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 a6554bb

Please sign in to comment.