// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.GameServer.RemoteView.Quest; using System.Runtime.InteropServices; using MUnique.OpenMU.GameLogic.Views.Quest; using MUnique.OpenMU.GameServer.MessageHandler.Quests; 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.CurrentlyActiveQuestsPlugIn_Name), Description = nameof(PlugInResources.CurrentlyActiveQuestsPlugIn_Description), ResourceType = typeof(PlugInResources))] [Guid("9851157D-97CA-42F3-840C-8448D02B49A4")] [MinimumClient(5, 0, ClientLanguage.Invariant)] public class CurrentlyActiveQuestsPlugIn : ICurrentlyActiveQuestsPlugIn { private readonly RemotePlayer _player; /// /// Initializes a new instance of the class. /// /// The player. public CurrentlyActiveQuestsPlugIn(RemotePlayer player) { this._player = player; } /// public async ValueTask ShowActiveQuestsAsync() { var connection = this._player.Connection; if (connection is null || this._player.SelectedCharacter is not { } character) { return; } int Write() { const int maxQuestsPerPacket = 62; var activeQuests = character.QuestStates .Where(state => state.Group != QuestConstants.LegacyQuestGroup && state.ActiveQuest != null) .Select(s => s.ActiveQuest!) .Take(maxQuestsPerPacket) .ToList(); var size = QuestStateListRef.GetRequiredSize(activeQuests.Count); var span = connection.Output.GetSpan(size)[..size]; var message = new QuestStateListRef(span); byte i = 0; foreach (var activeQuest in activeQuests) { var questIdentification = message[i]; questIdentification.Number = (ushort)activeQuest.Number; questIdentification.Group = (ushort)activeQuest.Group; i++; } message.QuestCount = i; return size; } await connection.SendAsync(Write).ConfigureAwait(false); } }