Skip to content

Commit

Permalink
Implemented logic to create lost map items.
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-n committed Jun 9, 2024
1 parent c3823e4 commit 211d24c
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/GameLogic/DroppedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ private async ValueTask<bool> TryStackOnItemAsync(Player player, Item stackTarge

player.Logger.LogInformation("Item '{0}' got picked up by player '{1}'. Durability of available stack {2} increased to {3}", this, player, stackTarget, stackTarget.Durability);
this.DisposeAndDelete(null);
if (player.GameContext.PlugInManager.GetPlugInPoint<PlugIns.IItemStackedPlugIn>() is { } itemStackedPlugIn)
{
await itemStackedPlugIn.ItemStackedAsync(player, this.Item, stackTarget).ConfigureAwait(false);
}

return true;
}

Expand Down
9 changes: 8 additions & 1 deletion src/GameLogic/PlayerActions/Items/MoveItemAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,18 @@ public async ValueTask MoveItemAsync(Player player, byte fromSlot, Storages from
break;
}

if (movement != Movement.None
if (movement is not Movement.None
&& player.GameContext.PlugInManager.GetPlugInPoint<PlugIns.IItemMovedPlugIn>() is { } itemMovedPlugIn)
{
await itemMovedPlugIn.ItemMovedAsync(player, item).ConfigureAwait(false);
}

if (movement is not (Movement.None or Movement.Normal)
&& toItemStorage?.GetItem(toSlot) is { } target
&& player.GameContext.PlugInManager.GetPlugInPoint<PlugIns.IItemStackedPlugIn>() is { } itemStackedPlugIn)
{
await itemStackedPlugIn.ItemStackedAsync(player, item, target).ConfigureAwait(false);
}
}

private async ValueTask FullStackAsync(Player player, Item sourceItem, Item targetItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static Item CreateItem(Player gameMaster, ItemChatCommandArgs arguments)
{
var item = new TemporaryItem();
item.Definition = GetItemDefination(gameMaster, arguments);
item.Durability = item.Definition.Durability;
item.Durability = item.IsStackable() ? 1 : item.Definition.Durability;
item.HasSkill = item.Definition.Skill != null && arguments.Skill;
item.Level = GetItemLevel(item.Definition, arguments);
item.SocketCount = item.Definition.MaximumSockets;
Expand Down
24 changes: 24 additions & 0 deletions src/GameLogic/PlugIns/IItemStackedPlugIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// <copyright file="IItemStackedPlugIn.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

namespace MUnique.OpenMU.GameLogic.PlugIns;

using System.Runtime.InteropServices;
using MUnique.OpenMU.PlugIns;

/// <summary>
/// A plugin interface which is called when an item got moved by the player.
/// </summary>
[Guid("FCDE60E9-6183-4833-BF59-CE907F9EECCD")]
[PlugInPoint("Item stacked", "Plugins which are called when an item has been stacked by the player.")]
public interface IItemStackedPlugIn
{
/// <summary>
/// Is called when an item has been moved by the player.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="sourceItem">The source item.</param>
/// <param name="targetItem">The target item.</param>
ValueTask ItemStackedAsync(Player player, Item sourceItem, Item targetItem);
}
47 changes: 47 additions & 0 deletions src/GameLogic/PlugIns/SymbolOfKundunStackedPlugIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// <copyright file="SymbolOfKundunStackedPlugIn.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

namespace MUnique.OpenMU.GameLogic.PlugIns;

using System.Runtime.InteropServices;
using MUnique.OpenMU.PlugIns;

/// <summary>
/// This plugin transforms a stack of symbol of kundun into a lost map.
/// </summary>
[PlugIn(nameof(SymbolOfKundunStackedPlugIn), "This plugin transforms a stack of symbol of kundun into a lost map.")]
[Guid("F07A9CED-F43E-4824-9587-F5C3C3187A13")]
public sealed class SymbolOfKundunStackedPlugIn : IItemStackedPlugIn
{
private const byte SymbolOfKundunGroup = 14;
private const byte SymbolOfKundunNumber = 29;
private const byte LostMapGroup = 14;
private const byte LostMapNumber = 28;

/// <inheritdoc />
public async ValueTask ItemStackedAsync(Player player, Item sourceItem, Item targetItem)
{
if (targetItem.Definition is not { Group: SymbolOfKundunGroup, Number: SymbolOfKundunNumber })
{
return;
}

if (targetItem.Durability() < targetItem.Definition.Durability)
{
return;
}

var lostMap = player.GameContext.Configuration.Items.FirstOrDefault(item => item is { Group: LostMapGroup, Number: LostMapNumber });
if (lostMap is null)
{
player.Logger.LogWarning("Lost map definition not found.");
return;
}

await player.InvokeViewPlugInAsync<Views.Inventory.IItemRemovedPlugIn>(p => p.RemoveItemAsync(targetItem.ItemSlot)).ConfigureAwait(false);
targetItem.Definition = lostMap;
targetItem.Durability = 1;
await player.InvokeViewPlugInAsync<Views.Inventory.IItemAppearPlugIn>(p => p.ItemAppearAsync(targetItem)).ConfigureAwait(false);
}
}
87 changes: 87 additions & 0 deletions src/Persistence/Initialization/Updates/AddKalimaPlugIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// <copyright file="AddKalimaPlugIn.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>

using MUnique.OpenMU.DataModel.Configuration.Items;

namespace MUnique.OpenMU.Persistence.Initialization.Updates;

using System.Runtime.InteropServices;
using MUnique.OpenMU.DataModel.Configuration;
using MUnique.OpenMU.PlugIns;

/// <summary>
/// This adds the items required to enter the kalima map.
/// </summary>
[PlugIn(PlugInName, PlugInDescription)]
[Guid("0C99155F-1289-4E73-97F0-47CB67C3716F")]
public class AddKalimaPlugIn : UpdatePlugInBase
{
/// <summary>
/// The plug in name.
/// </summary>
internal const string PlugInName = "Add Kalima";

/// <summary>
/// The plug in description.
/// </summary>
internal const string PlugInDescription = "This adds the items required to enter the kalima map.";

/// <inheritdoc />
public override UpdateVersion Version => UpdateVersion.AddKalima;

/// <inheritdoc />
public override string DataInitializationKey => VersionSeasonSix.DataInitialization.Id;

/// <inheritdoc />
public override string Name => PlugInName;

/// <inheritdoc />
public override string Description => PlugInDescription;

/// <inheritdoc />
public override bool IsMandatory => true;

/// <inheritdoc />
public override DateTime CreatedAt => new(2024, 06, 09, 18, 0, 0, DateTimeKind.Utc);

/// <inheritdoc />
#pragma warning disable CS1998
protected override async ValueTask ApplyAsync(IContext context, GameConfiguration gameConfiguration)
#pragma warning restore CS1998
{
this.CreateLostMap(context, gameConfiguration);
this.CreateSymbolOfKundun(context, gameConfiguration);
}

private void CreateLostMap(IContext context, GameConfiguration gameConfiguration)
{
var itemDefinition = context.CreateNew<ItemDefinition>();
itemDefinition.Name = "Lost Map";
itemDefinition.Number = 28;
itemDefinition.Group = 14;
itemDefinition.DropsFromMonsters = false;
itemDefinition.Durability = 1;
itemDefinition.Width = 1;
itemDefinition.Height = 1;
itemDefinition.MaximumItemLevel = 7;
itemDefinition.SetGuid(itemDefinition.Group, itemDefinition.Number);
gameConfiguration.Items.Add(itemDefinition);
}

private void CreateSymbolOfKundun(IContext context, GameConfiguration gameConfiguration)
{
var itemDefinition = context.CreateNew<ItemDefinition>();
itemDefinition.Name = "Symbol of Kundun";
itemDefinition.Number = 29;
itemDefinition.Group = 14;
itemDefinition.DropLevel = 0;
itemDefinition.DropsFromMonsters = true;
itemDefinition.Durability = 5;
itemDefinition.Width = 1;
itemDefinition.Height = 1;
itemDefinition.MaximumItemLevel = 7;
itemDefinition.SetGuid(itemDefinition.Group, itemDefinition.Number);
gameConfiguration.Items.Add(itemDefinition);
}
}
7 changes: 6 additions & 1 deletion src/Persistence/Initialization/Updates/UpdateVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@ public enum UpdateVersion
/// <summary>
/// The version of the <see cref="AddPointsPerResetAttributePlugIn"/>.
/// </summary>
AddPointsPerResetByClassAttribute = 16
AddPointsPerResetByClassAttribute = 16,

/// <summary>
/// The version of the <see cref="AddKalimaPlugIn"/>.
/// </summary>
AddKalima = 17,
}
33 changes: 33 additions & 0 deletions src/Persistence/Initialization/VersionSeasonSix/Items/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@ public override void Initialize()
{
this.CreateLifeStone();
this.CreateGoldenCherryBlossomBranch();
this.CreateLostMap();
this.CreateSymbolOfKundun();
}

private void CreateLostMap()
{
var itemDefinition = this.Context.CreateNew<ItemDefinition>();
itemDefinition.Name = "Lost Map";
itemDefinition.Number = 28;
itemDefinition.Group = 14;
itemDefinition.DropsFromMonsters = false;
itemDefinition.Durability = 1;
itemDefinition.Width = 1;
itemDefinition.Height = 1;
itemDefinition.MaximumItemLevel = 7;
itemDefinition.SetGuid(itemDefinition.Group, itemDefinition.Number);
this.GameConfiguration.Items.Add(itemDefinition);
}

private void CreateSymbolOfKundun()
{
var itemDefinition = this.Context.CreateNew<ItemDefinition>();
itemDefinition.Name = "Symbol of Kundun";
itemDefinition.Number = 29;
itemDefinition.Group = 14;
itemDefinition.DropLevel = 0;
itemDefinition.DropsFromMonsters = true;
itemDefinition.Durability = 5;
itemDefinition.Width = 1;
itemDefinition.Height = 1;
itemDefinition.MaximumItemLevel = 7;
itemDefinition.SetGuid(itemDefinition.Group, itemDefinition.Number);
this.GameConfiguration.Items.Add(itemDefinition);
}

private void CreateLifeStone()
Expand Down

0 comments on commit 211d24c

Please sign in to comment.