//
// DialogOpenResponder.cs
//
// Copyright (c) František Boháček. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using NosSmooth.Core.Packets;
using NosSmooth.Game.Data.Dialogs;
using NosSmooth.Game.Events.Core;
using NosSmooth.Game.Events.Ui;
using NosSmooth.Packets.Enums;
using NosSmooth.Packets.Server.UI;
using Remora.Results;
namespace NosSmooth.Game.PacketHandlers.Ui;
///
/// A responder to dialog events that calls DialogOpen.
///
public class DialogOpenResponder : IPacketResponder, IPacketResponder,
IPacketResponder, IPacketResponder, IPacketResponder
{
private readonly EventDispatcher _eventDispatcher;
///
/// Initializes a new instance of the class.
///
/// The event dispatcher.
public DialogOpenResponder(EventDispatcher eventDispatcher)
{
_eventDispatcher = eventDispatcher;
}
///
public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default)
{
var packet = packetArgs.Packet;
if (packet.Type != QnamlType.Dialog)
{
return Task.FromResult(Result.FromSuccess());
}
return _eventDispatcher.DispatchEvent
(
new DialogOpenedEvent
(
new Dialog
(
packet.AcceptCommand,
null,
packet.Message,
Array.Empty()
)
),
ct
);
}
///
public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default)
{
var packet = packetArgs.Packet;
if (packet.Type != QnamlType.Dialog)
{
return Task.FromResult(Result.FromSuccess());
}
return _eventDispatcher.DispatchEvent
(
new DialogOpenedEvent
(
new Dialog
(
packet.AcceptCommand,
null,
packet.MessageConst,
packet.Parameters
)
),
ct
);
}
///
public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default)
{
var packet = packetArgs.Packet;
return _eventDispatcher.DispatchEvent
(
new DialogOpenedEvent
(
new Dialog
(
packet.AcceptCommand,
null,
packet.Message,
Array.Empty()
)
),
ct
);
}
///
public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default)
{
var packet = packetArgs.Packet;
return _eventDispatcher.DispatchEvent
(
new DialogOpenedEvent
(
new Dialog
(
packet.AcceptCommand,
packet.DenyCommand,
packet.Message,
Array.Empty()
)
),
ct
);
}
///
public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default)
{
var packet = packetArgs.Packet;
return _eventDispatcher.DispatchEvent
(
new DialogOpenedEvent
(
new Dialog
(
packet.AcceptCommand,
packet.DenyCommand,
packet.MessageConst,
packet.Parameters
)
),
ct
);
}
}