baseline: OpenMU upstream b5a0961 (fresh source)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// <copyright file="PlayerShopClosedPlugIn.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameServer.RemoteView.PlayerShop;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using MUnique.OpenMU.GameLogic;
|
||||
using MUnique.OpenMU.GameLogic.Views;
|
||||
using MUnique.OpenMU.GameLogic.Views.PlayerShop;
|
||||
using MUnique.OpenMU.Network.Packets.ServerToClient;
|
||||
using MUnique.OpenMU.PlugIns;
|
||||
|
||||
/// <summary>
|
||||
/// The default implementation of the <see cref="IPlayerShopClosedPlugIn"/> which is forwarding everything to the game client with specific data packets.
|
||||
/// </summary>
|
||||
[PlugIn]
|
||||
[Display(Name = nameof(PlugInResources.PlayerShopClosedPlugIn_Name), Description = nameof(PlugInResources.PlayerShopClosedPlugIn_Description), ResourceType = typeof(PlugInResources))]
|
||||
[Guid("351cf726-5091-4995-9228-81c089d1da16")]
|
||||
public class PlayerShopClosedPlugIn : IPlayerShopClosedPlugIn
|
||||
{
|
||||
private readonly RemotePlayer _player;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerShopClosedPlugIn"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player.</param>
|
||||
public PlayerShopClosedPlugIn(RemotePlayer player) => this._player = player;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask PlayerShopClosedAsync(Player playerWithClosedShop)
|
||||
{
|
||||
var playerId = playerWithClosedShop.GetId(this._player);
|
||||
await this._player.Connection.SendPlayerShopClosedAsync(playerId).ConfigureAwait(false);
|
||||
|
||||
// The following usually just needs to be sent to all players which currently have the shop dialog open
|
||||
// For the sake of simplicity, we send it to all players.
|
||||
await this._player.Connection.SendClosePlayerShopDialogAsync(playerId).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// <copyright file="PlayerShopOpenedPlugIn.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameServer.RemoteView.PlayerShop;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using MUnique.OpenMU.GameLogic;
|
||||
using MUnique.OpenMU.GameLogic.Views.PlayerShop;
|
||||
using MUnique.OpenMU.Network.Packets.ServerToClient;
|
||||
using MUnique.OpenMU.PlugIns;
|
||||
|
||||
/// <summary>
|
||||
/// The default implementation of the <see cref="IPlayerShopOpenedPlugIn"/> which is forwarding everything to the game client with specific data packets.
|
||||
/// </summary>
|
||||
[PlugIn]
|
||||
[Display(Name = nameof(PlugInResources.PlayerShopOpenedPlugIn_Name), Description = nameof(PlugInResources.PlayerShopOpenedPlugIn_Description), ResourceType = typeof(PlugInResources))]
|
||||
[Guid("c61e9a96-57d0-4bf1-9667-62b0c2104314")]
|
||||
public class PlayerShopOpenedPlugIn : IPlayerShopOpenedPlugIn
|
||||
{
|
||||
private readonly RemotePlayer _player;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerShopOpenedPlugIn"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player.</param>
|
||||
public PlayerShopOpenedPlugIn(RemotePlayer player) => this._player = player;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask PlayerShopOpenedAsync(Player playerWithShop)
|
||||
{
|
||||
await this._player.InvokeViewPlugInAsync<IShowShopsOfPlayersPlugIn>(p => p.ShowShopsOfPlayersAsync(new List<Player>(1) { playerWithShop })).ConfigureAwait(false);
|
||||
if (this._player == playerWithShop && this._player.Connection is { } connection)
|
||||
{
|
||||
// Success of opening the own shop
|
||||
await connection.SendPlayerShopOpenSuccessfulAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// <copyright file="ShowShopItemListExtendedPlugIn.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameServer.RemoteView.PlayerShop;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using MUnique.OpenMU.GameLogic;
|
||||
using MUnique.OpenMU.GameLogic.Views;
|
||||
using MUnique.OpenMU.GameLogic.Views.PlayerShop;
|
||||
using MUnique.OpenMU.Network;
|
||||
using MUnique.OpenMU.Network.Packets.ServerToClient;
|
||||
using MUnique.OpenMU.Network.PlugIns;
|
||||
using MUnique.OpenMU.PlugIns;
|
||||
|
||||
/// <summary>
|
||||
/// The extended implementation of the <see cref="IShowShopItemListPlugIn"/> which is forwarding everything to the game client with specific data packets.
|
||||
/// </summary>
|
||||
[PlugIn]
|
||||
[Display(Name = nameof(PlugInResources.ShowShopItemListExtendedPlugIn_Name), Description = nameof(PlugInResources.ShowShopItemListExtendedPlugIn_Description), ResourceType = typeof(PlugInResources))]
|
||||
[Guid("D64E9027-4801-46EE-9FD0-2FC66C33FE32")]
|
||||
[MinimumClient(106, 3, ClientLanguage.Invariant)]
|
||||
public class ShowShopItemListExtendedPlugIn : IShowShopItemListPlugIn
|
||||
{
|
||||
private readonly RemotePlayer _player;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ShowShopItemListExtendedPlugIn"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player.</param>
|
||||
public ShowShopItemListExtendedPlugIn(RemotePlayer player) => this._player = player;
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// Maybe cache the result, because a lot of players could request the same list. However, this isn't critical.
|
||||
/// </remarks>
|
||||
public async ValueTask ShowShopItemListAsync(Player requestedPlayer, bool isUpdate)
|
||||
{
|
||||
var connection = this._player.Connection;
|
||||
if (connection is null || requestedPlayer.ShopStorage is null || requestedPlayer.SelectedCharacter is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var itemSerializer = this._player.ItemSerializer;
|
||||
var playerId = requestedPlayer.GetId(this._player);
|
||||
var items = requestedPlayer.ShopStorage.Items.ToList();
|
||||
int Write()
|
||||
{
|
||||
var size = PlayerShopItemListExtendedRef.GetRequiredSize(items.Count, PlayerShopItemExtendedRef.GetRequiredSize(itemSerializer.NeededSpace));
|
||||
var span = connection.Output.GetSpan(size)[..size];
|
||||
_ = new PlayerShopItemListExtendedRef(span)
|
||||
{
|
||||
Action = isUpdate
|
||||
? PlayerShopItemListExtended.ActionKind.UpdateAfterItemChange
|
||||
: PlayerShopItemListExtended.ActionKind.ByRequest,
|
||||
ItemCount = (byte)items.Count,
|
||||
PlayerId = playerId,
|
||||
PlayerName = requestedPlayer.SelectedCharacter.Name,
|
||||
ShopName = requestedPlayer.SelectedCharacter.StoreName,
|
||||
};
|
||||
|
||||
int headerSize = PlayerShopItemListExtendedRef.GetRequiredSize(0, 0);
|
||||
int actualSize = headerSize;
|
||||
int i = 0;
|
||||
foreach (var item in items)
|
||||
{
|
||||
var itemBlock = new PlayerShopItemExtendedRef(span[actualSize..]);
|
||||
itemBlock.ItemSlot = item.ItemSlot;
|
||||
itemBlock.MoneyPrice = (uint)(item.StorePrice ?? 0);
|
||||
|
||||
// todo: when we can define a price in items, set PriceItemType and RequiredItemAmount
|
||||
var itemSize = itemSerializer.SerializeItem(itemBlock.ItemData, item);
|
||||
actualSize += PlayerShopItemExtendedRef.GetRequiredSize(itemSize);
|
||||
i++;
|
||||
}
|
||||
|
||||
span.Slice(0, actualSize).SetPacketSize();
|
||||
return actualSize;
|
||||
}
|
||||
|
||||
await connection.SendAsync(Write).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// <copyright file="ShowShopItemListPlugIn.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameServer.RemoteView.PlayerShop;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using MUnique.OpenMU.GameLogic;
|
||||
using MUnique.OpenMU.GameLogic.Views;
|
||||
using MUnique.OpenMU.GameLogic.Views.PlayerShop;
|
||||
using MUnique.OpenMU.Network;
|
||||
using MUnique.OpenMU.Network.Packets.ServerToClient;
|
||||
using MUnique.OpenMU.PlugIns;
|
||||
|
||||
/// <summary>
|
||||
/// The default implementation of the <see cref="IShowShopItemListPlugIn"/> which is forwarding everything to the game client with specific data packets.
|
||||
/// </summary>
|
||||
[PlugIn]
|
||||
[Display(Name = nameof(PlugInResources.ShowShopItemListPlugIn_Name), Description = nameof(PlugInResources.ShowShopItemListPlugIn_Description), ResourceType = typeof(PlugInResources))]
|
||||
[Guid("14220c30-8a5e-458b-8fb5-f4c6bbc2c4a9")]
|
||||
public class ShowShopItemListPlugIn : IShowShopItemListPlugIn
|
||||
{
|
||||
private readonly RemotePlayer _player;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ShowShopItemListPlugIn"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player.</param>
|
||||
public ShowShopItemListPlugIn(RemotePlayer player) => this._player = player;
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>
|
||||
/// Maybe cache the result, because a lot of players could request the same list. However, this isn't critical.
|
||||
/// </remarks>
|
||||
public async ValueTask ShowShopItemListAsync(Player requestedPlayer, bool isUpdate)
|
||||
{
|
||||
var connection = this._player.Connection;
|
||||
if (connection is null || requestedPlayer.ShopStorage is null || requestedPlayer.SelectedCharacter is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var itemSerializer = this._player.ItemSerializer;
|
||||
var playerId = requestedPlayer.GetId(this._player);
|
||||
var items = requestedPlayer.ShopStorage.Items.ToList();
|
||||
int Write()
|
||||
{
|
||||
var size = PlayerShopItemListRef.GetRequiredSize(items.Count);
|
||||
var span = connection.Output.GetSpan(size)[..size];
|
||||
var packet = new PlayerShopItemListRef(span)
|
||||
{
|
||||
Action = isUpdate ? PlayerShopItemList.ActionKind.UpdateAfterItemChange : PlayerShopItemList.ActionKind.ByRequest,
|
||||
ItemCount = (byte)items.Count,
|
||||
PlayerId = playerId,
|
||||
PlayerName = requestedPlayer.SelectedCharacter.Name,
|
||||
ShopName = requestedPlayer.SelectedCharacter.StoreName,
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
foreach (var item in items)
|
||||
{
|
||||
var itemBlock = packet[i];
|
||||
itemBlock.ItemSlot = item.ItemSlot;
|
||||
itemBlock.Price = (uint)(item.StorePrice ?? 0);
|
||||
itemSerializer.SerializeItem(itemBlock.ItemData, item);
|
||||
i++;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
await connection.SendAsync(Write).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// <copyright file="ShowShopsOfPlayersPlugIn.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.GameServer.RemoteView.PlayerShop;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using MUnique.OpenMU.GameLogic;
|
||||
using MUnique.OpenMU.GameLogic.Views;
|
||||
using MUnique.OpenMU.GameLogic.Views.PlayerShop;
|
||||
using MUnique.OpenMU.Network;
|
||||
using MUnique.OpenMU.Network.Packets.ServerToClient;
|
||||
using MUnique.OpenMU.PlugIns;
|
||||
|
||||
/// <summary>
|
||||
/// The default implementation of the <see cref="IShowShopsOfPlayersPlugIn"/> which is forwarding everything to the game client with specific data packets.
|
||||
/// </summary>
|
||||
[PlugIn]
|
||||
[Display(Name = nameof(PlugInResources.ShowShopsOfPlayersPlugIn_Name), Description = nameof(PlugInResources.ShowShopsOfPlayersPlugIn_Description), ResourceType = typeof(PlugInResources))]
|
||||
[Guid("619df3b3-6559-4336-975f-04a2f5867f38")]
|
||||
public class ShowShopsOfPlayersPlugIn : IShowShopsOfPlayersPlugIn
|
||||
{
|
||||
private readonly RemotePlayer _player;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ShowShopsOfPlayersPlugIn"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player.</param>
|
||||
public ShowShopsOfPlayersPlugIn(RemotePlayer player) => this._player = player;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask ShowShopsOfPlayersAsync(ICollection<Player> playersWithShop)
|
||||
{
|
||||
var connection = this._player.Connection;
|
||||
if (connection is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int Write()
|
||||
{
|
||||
var size = PlayerShopsRef.GetRequiredSize(playersWithShop.Count);
|
||||
var span = connection.Output.GetSpan(size)[..size];
|
||||
var packet = new PlayerShopsRef(span)
|
||||
{
|
||||
ShopCount = (byte)playersWithShop.Count,
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
foreach (var shopPlayer in playersWithShop)
|
||||
{
|
||||
var shopBlock = packet[i];
|
||||
if (shopPlayer.ShopStorage is not null
|
||||
&& shopPlayer.SelectedCharacter?.StoreName is { } storeName)
|
||||
{
|
||||
shopBlock.PlayerId = shopPlayer.GetId(this._player);
|
||||
shopBlock.StoreName = storeName;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
await connection.SendAsync(Write).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user