~ruther/NosSmooth

ref: a3695aba35931b8e8bd1a575c2188aaa9840ca81 NosSmooth/Extensions/NosSmooth.Extensions.Combat/Responders/SkillUseResponder.cs -rw-r--r-- 1.6 KiB
a3695aba — Rutherther chore: update version 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
//
//  SkillUseResponder.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.Packets;
using NosSmooth.Packets.Server.Battle;
using Remora.Results;

namespace NosSmooth.Extensions.Combat.Responders;

/// <summary>
/// Responds to su packet.
/// </summary>
public class SuResponder : IPacketResponder<SuPacket>, IPacketResponder<BsPacket>
{
    private readonly CombatManager _combatManager;
    private readonly Game.Game _game;

    /// <summary>
    /// Initializes a new instance of the <see cref="SuResponder"/> class.
    /// </summary>
    /// <param name="combatManager">The combat manager.</param>
    /// <param name="game">The game.</param>
    public SuResponder(CombatManager combatManager, Game.Game game)
    {
        _combatManager = combatManager;
        _game = game;
    }

    /// <inheritdoc />
    public Task<Result> Respond(PacketEventArgs<SuPacket> packetArgs, CancellationToken ct = default)
    {
        if (packetArgs.Packet.CasterEntityId == _game.Character?.Id)
        {
            Task.Run(() => _combatManager.CancelSkillTokensAsync(default));
        }
        return Task.FromResult(Result.FromSuccess());
    }

    /// <inheritdoc />
    public Task<Result> Respond(PacketEventArgs<BsPacket> packetArgs, CancellationToken ct = default)
    {
        if (packetArgs.Packet.CasterEntityId == _game.Character?.Id)
        {
            Task.Run(() => _combatManager.CancelSkillTokensAsync(default));
        }
        return Task.FromResult(Result.FromSuccess());
    }
}
Do not follow this link