Skip to content

Commit

Permalink
Add quest open and close script handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Sep 24, 2023
1 parent 49f8400 commit 192e1ba
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -13,7 +14,7 @@ public class FieldOnPacketUserQuestCompleteRequestPlug : IPipelinePlug<FieldOnPa
private readonly IQuestManager _manager;

public FieldOnPacketUserQuestCompleteRequestPlug(IQuestManager manager) => _manager = manager;

public async Task Handle(IPipelineContext ctx, FieldOnPacketUserQuestCompleteRequest message)
{
var result = await _manager.Check(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FieldOnPacketUserQuestScriptEndRequest>
{
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)
);
}
}
Original file line number Diff line number Diff line change
@@ -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<FieldOnPacketUserQuestScriptStartRequest>
{
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)
);
}
}

0 comments on commit 192e1ba

Please sign in to comment.