Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/MUnique/OpenMU
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-n committed Dec 13, 2023
2 parents c56b989 + a6554bb commit ef3b746
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
16 changes: 12 additions & 4 deletions src/GameLogic/PlayerActions/Items/MoveItemAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MUnique.OpenMU.GameLogic.PlayerActions.Items;

using System.ComponentModel;
using MUnique.OpenMU.DataModel.Configuration.Items;
using MUnique.OpenMU.GameLogic.PlugIns;
using MUnique.OpenMU.GameLogic.Views;
using MUnique.OpenMU.GameLogic.Views.Inventory;
Expand Down Expand Up @@ -234,11 +235,18 @@ private async ValueTask<Movement> CanMoveAsync(Player player, Item item, byte to
if (itemDefinition.ItemSlot.ItemSlots.Contains(toSlot) &&
player.CompliesRequirements(item))
{
if (itemDefinition.ItemSlot.ItemSlots.Contains(RightHandSlot)
&& itemDefinition.ItemSlot.ItemSlots.Contains(LeftHandSlot)
&& toSlot == RightHandSlot
&& storage.GetItem(LeftHandSlot)?.Definition!.Width >= 2)
static bool IsOneHandedOrShield(ItemDefinition definition) =>
(definition.ItemSlot!.ItemSlots.Contains(RightHandSlot) && definition.ItemSlot.ItemSlots.Contains(LeftHandSlot)) || definition.Group == 6;

if ((toSlot == LeftHandSlot
&& itemDefinition.Width >= 2
&& storage.GetItem(RightHandSlot)?.Definition!.Group == 6)
|| (toSlot == RightHandSlot
&& IsOneHandedOrShield(itemDefinition)
&& storage.GetItem(LeftHandSlot)?.Definition!.Width >= 2))
{
// Attempting to equip a two-handed item to the left hand slot when a shield is in the right hand slot,
// or trying to equip a one-handed weapon or shield to the right hand slot when a two-handed item is in the left hand slot.
return Movement.None;
}

Expand Down
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 ef3b746

Please sign in to comment.