~ruther/NosSmooth.Local

ref: 06f078dcbeef77ec800477bc8057e5ac9bcde926 NosSmooth.Local/src/Samples/HighLevel/SimplePiiBot/Responders/EntityJoinedResponder.cs -rw-r--r-- 1.5 KiB
06f078dc — František Boháček chore: update dependencies 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
//  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;

/// <summary>
/// Responds to entity joined map event.
/// </summary>
public class EntityJoinedResponder : IGameResponder<EntityJoinedMapEvent>
{
    private readonly Bot _bot;
    private readonly NostaleChatPacketApi _chatApi;

    /// <summary>
    /// Initializes a new instance of the <see cref="EntityJoinedResponder"/> class.
    /// </summary>
    /// <param name="bot">The bot.</param>
    /// <param name="chatApi">The chat packet api.</param>
    public EntityJoinedResponder(Bot bot, NostaleChatPacketApi chatApi)
    {
        _bot = bot;
        _chatApi = chatApi;
    }

    /// <inheritdoc />
    public async Task<Result> 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();
    }
}
Do not follow this link