-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quest open and close script handling
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...common/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptEndRequestPlug.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...mmon/Edelstein.Common.Gameplay.Game/Plugs/FieldOnPacketUserQuestScriptStartRequestPlug.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |