From 192e1ba8bdf40bab26df63b1a76a7cc96864baa6 Mon Sep 17 00:00:00 2001 From: Kaioru Date: Sun, 24 Sep 2023 20:07:59 +0800 Subject: [PATCH] Add quest open and close script handling --- ...eldOnPacketUserQuestCompleteRequestPlug.cs | 3 +- ...ldOnPacketUserQuestScriptEndRequestPlug.cs | 40 +++++++++++++++++++ ...OnPacketUserQuestScriptStartRequestPlug.cs | 40 +++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptEndRequestPlug.cs create mode 100644 src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptStartRequestPlug.cs diff --git a/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestCompleteRequestPlug.cs b/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestCompleteRequestPlug.cs index 9096540ad..e48a9839a 100644 --- a/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestCompleteRequestPlug.cs +++ b/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestCompleteRequestPlug.cs @@ -3,6 +3,7 @@ using Edelstein.Common.Gameplay.Packets; using Edelstein.Common.Utilities.Packets; using Edelstein.Protocol.Gameplay.Game.Contracts; +using Edelstein.Protocol.Gameplay.Game.Conversations; using Edelstein.Protocol.Gameplay.Game.Quests; using Edelstein.Protocol.Utilities.Pipelines; @@ -13,7 +14,7 @@ public class FieldOnPacketUserQuestCompleteRequestPlug : IPipelinePlug _manager = manager; - + public async Task Handle(IPipelineContext ctx, FieldOnPacketUserQuestCompleteRequest message) { var result = await _manager.Check( diff --git a/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptEndRequestPlug.cs b/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptEndRequestPlug.cs new file mode 100644 index 000000000..8c95565e5 --- /dev/null +++ b/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptEndRequestPlug.cs @@ -0,0 +1,40 @@ +using Edelstein.Common.Gameplay.Game.Conversations; +using Edelstein.Common.Gameplay.Game.Conversations.Speakers; +using Edelstein.Protocol.Gameplay.Game.Contracts; +using Edelstein.Protocol.Gameplay.Game.Conversations; +using Edelstein.Protocol.Gameplay.Game.Conversations.Speakers; +using Edelstein.Protocol.Gameplay.Game.Quests; +using Edelstein.Protocol.Utilities.Pipelines; + +namespace Edelstein.Common.Gameplay.Game.Plugs; + +public class FieldOnPacketUserQuestScriptEndRequestPlug : IPipelinePlug +{ + private readonly IQuestManager _manager; + private readonly INamedConversationManager _scriptManager; + + public FieldOnPacketUserQuestScriptEndRequestPlug(IQuestManager manager, INamedConversationManager scriptManager) + { + _manager = manager; + _scriptManager = scriptManager; + } + + public async Task Handle(IPipelineContext ctx, FieldOnPacketUserQuestScriptEndRequest message) + { + var result = await _manager.Check( + QuestAction.End, + message.Template, + message.User + ); + + if (message.Template.CheckEnd.ScriptEnd == null) return; + + var conversation = await _scriptManager.Retrieve(message.Template.CheckEnd.ScriptEnd) as IConversation ?? new FallbackConversation(message.Template.CheckEnd.ScriptEnd); + + _ = message.User.Converse( + conversation, + c => new ConversationSpeaker(c, message.NPCTemplateID ?? 9010000), + c => new ConversationSpeaker(c, flags: ConversationSpeakerFlags.NPCReplacedByUser) + ); + } +} diff --git a/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptStartRequestPlug.cs b/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptStartRequestPlug.cs new file mode 100644 index 000000000..d8deb511d --- /dev/null +++ b/src/common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptStartRequestPlug.cs @@ -0,0 +1,40 @@ +using Edelstein.Common.Gameplay.Game.Conversations; +using Edelstein.Common.Gameplay.Game.Conversations.Speakers; +using Edelstein.Protocol.Gameplay.Game.Contracts; +using Edelstein.Protocol.Gameplay.Game.Conversations; +using Edelstein.Protocol.Gameplay.Game.Conversations.Speakers; +using Edelstein.Protocol.Gameplay.Game.Quests; +using Edelstein.Protocol.Utilities.Pipelines; + +namespace Edelstein.Common.Gameplay.Game.Plugs; + +public class FieldOnPacketUserQuestScriptStartRequestPlug : IPipelinePlug +{ + private readonly IQuestManager _manager; + private readonly INamedConversationManager _scriptManager; + + public FieldOnPacketUserQuestScriptStartRequestPlug(IQuestManager manager, INamedConversationManager scriptManager) + { + _manager = manager; + _scriptManager = scriptManager; + } + + public async Task Handle(IPipelineContext ctx, FieldOnPacketUserQuestScriptStartRequest message) + { + var result = await _manager.Check( + QuestAction.Start, + message.Template, + message.User + ); + + if (message.Template.CheckStart.ScriptStart == null) return; + + var conversation = await _scriptManager.Retrieve(message.Template.CheckStart.ScriptStart) as IConversation ?? new FallbackConversation(message.Template.CheckStart.ScriptStart); + + _ = message.User.Converse( + conversation, + c => new ConversationSpeaker(c, message.NPCTemplateID ?? 9010000), + c => new ConversationSpeaker(c, flags: ConversationSpeakerFlags.NPCReplacedByUser) + ); + } +}