//
// EntityJoinedResponder.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.Game.Apis;
using NosSmooth.Game.Data.Entities;
using NosSmooth.Game.Events.Core;
using NosSmooth.Game.Events.Entities;
using NosSmooth.Packets.Enums;
using NosSmooth.Packets.Enums.Players;
using Remora.Results;
namespace SimplePiiBot.Responders;
///
/// Responds to entity joined map event.
///
public class EntityJoinedResponder : IGameResponder
{
private readonly Bot _bot;
private readonly NostaleChatPacketApi _chatApi;
///
/// Initializes a new instance of the class.
///
/// The bot.
/// The chat packet api.
public EntityJoinedResponder(Bot bot, NostaleChatPacketApi chatApi)
{
_bot = bot;
_chatApi = chatApi;
}
///
public async Task Respond(EntityJoinedMapEvent gameEvent, CancellationToken ct = default)
{
if (gameEvent.Entity is Player player)
{
if (player.Authority > AuthorityType.User)
{
var result = await _bot.StopAsync(ct);
await _chatApi.ReceiveSystemMessageAsync("A GM has joined the map, stopping the bot.", ct: ct);
return result;
}
}
return Result.FromSuccess();
}
}