//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.GameServer.RemoteView.World;
using System.Runtime.InteropServices;
using MUnique.OpenMU.DataModel.Configuration;
using MUnique.OpenMU.GameLogic;
using MUnique.OpenMU.GameLogic.Views;
using MUnique.OpenMU.GameLogic.Views.World;
using MUnique.OpenMU.Network;
using MUnique.OpenMU.Network.Packets.ServerToClient;
using MUnique.OpenMU.Network.PlugIns;
using MUnique.OpenMU.PlugIns;
///
/// The default implementation of the which is forwarding everything to the game client with specific data packets.
///
[PlugIn]
[Display(Name = nameof(PlugInResources.ShowSkillAnimationPlugIn_Name), Description = nameof(PlugInResources.ShowSkillAnimationPlugIn_Description), ResourceType = typeof(PlugInResources))]
[Guid("a25cc420-c848-4a87-81e5-b86c4241af35")]
[MinimumClient(3, 0, ClientLanguage.Invariant)]
public class ShowSkillAnimationPlugIn : IShowSkillAnimationPlugIn
{
///
/// The combo skill identifier.
///
internal const ushort ComboSkillId = 59;
private const ushort NovaStartSkillId = 58;
private const short ForceSkillId = 60;
private const short ForceWaveSkillId = 66;
private readonly RemotePlayer _player;
///
/// Initializes a new instance of the class.
///
/// The player.
public ShowSkillAnimationPlugIn(RemotePlayer player) => this._player = player;
///
public ValueTask ShowSkillAnimationAsync(IAttacker attacker, IAttackable? target, Skill skill, bool effectApplied)
{
return this.ShowSkillAnimationAsync(attacker, target, skill.Number, effectApplied);
}
///
public async ValueTask ShowSkillAnimationAsync(IAttacker attacker, IAttackable? target, short skillNumber, bool effectApplied)
{
if (skillNumber == ForceWaveSkillId)
{
skillNumber = ForceSkillId;
}
var playerId = attacker.GetId(this._player);
var targetId = target is { } t ? (effectApplied ? (ushort)(t.GetId(this._player) | 0x8000) : t.GetId(this._player)) : (ushort)0;
var skillId = NumberConversionExtensions.ToUnsigned(skillNumber);
await this._player.Connection.SendSkillAnimationAsync(skillId, playerId, targetId).ConfigureAwait(false);
}
///
public async ValueTask ShowComboAnimationAsync(IAttacker attacker, IAttackable? target)
{
var playerId = attacker.GetId(this._player);
var targetId = ((IIdentifiable?)target ?? attacker).GetId(this._player);
await this._player.Connection.SendSkillAnimationAsync(ComboSkillId, playerId, targetId).ConfigureAwait(false);
}
///
public async ValueTask ShowNovaStartAsync(IAttacker attacker)
{
var playerId = attacker.GetId(this._player);
await this._player.Connection.SendSkillAnimationAsync(NovaStartSkillId, playerId, 0).ConfigureAwait(false);
}
}