~ruther/NosSmooth

ref: 18b22db021c0bbd6bfb5739721e01710a86c6a6d NosSmooth/Core/NosSmooth.Game/Apis/NostaleSkillsPacketApi.cs -rw-r--r-- 7.5 KiB
18b22db0 — František Boháček feat: add packet api for chat and skills 3 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
//  NostaleSkillsPacketApi.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 NosCore.Packets.ClientPackets.Battle;
using NosCore.Shared.Enumerations;
using NosSmooth.Core.Client;
using NosSmooth.Game.Data.Characters;
using NosSmooth.Game.Data.Entities;
using NosSmooth.Game.Errors;
using Remora.Results;

namespace NosSmooth.Game.Apis;

/// <summary>
/// Packet api for using character skills.
/// </summary>
public class NostaleSkillsPacketApi
{
    private readonly INostaleClient _client;

    /// <summary>
    /// Initializes a new instance of the <see cref="NostaleSkillsPacketApi"/> class.
    /// </summary>
    /// <param name="client">The nostale client.</param>
    public NostaleSkillsPacketApi(INostaleClient client)
    {
        _client = client;
    }

    /// <summary>
    /// Use the given (targetable) skill on specified entity.
    /// </summary>
    /// <remarks>
    /// For skills that can be used only on self, use <paramref name="entityId"/> of the character.
    /// For skills that cannot be targeted on an entity, proceed to <see cref="UseSkillAt"/>.
    /// </remarks>
    /// <param name="skillVNum">The id of the skill.</param>
    /// <param name="entityId">The id of the entity to use the skill on.</param>
    /// <param name="entityType">The type of the supplied entity.</param>
    /// <param name="mapX">The x coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)</param>
    /// <param name="mapY">The y coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> UseSkillOn(long skillVNum, long entityId, VisualType entityType, short? mapX = default, short? mapY = default)
    {
        return _client.SendPacketAsync(new UseSkillPacket
        {
            CastId = skillVNum,
            MapX = mapX,
            MapY = mapY,
            TargetId = entityId,
            TargetVisualType = entityType
        });
    }

    /// <summary>
    /// Use the given (targetable) skill on specified entity.
    /// </summary>
    /// <remarks>
    /// For skills that can be used only on self, use <paramref name="entityId"/> of the character.
    /// For skills that cannot be targeted on an entity, proceed to <see cref="UseSkillAt"/>.
    /// </remarks>
    /// <param name="skillVNum">The id of the skill.</param>
    /// <param name="entity">The entity to use the skill on.</param>
    /// <param name="mapX">The x coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)</param>
    /// <param name="mapY">The y coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> UseSkillOn(long skillVNum, ILivingEntity entity, short? mapX = default, short? mapY = default)
    {
        return _client.SendPacketAsync(new UseSkillPacket
        {
            CastId = skillVNum,
            MapX = mapX,
            MapY = mapY,
            TargetId = entity.Id,
            TargetVisualType = entity.Type
        });
    }

    /// <summary>
    /// Use the given (targetable) skill on specified entity.
    /// </summary>
    /// <remarks>
    /// The skill won't be used if it is on cooldown.
    /// For skills that can be used only on self, use <paramref name="entityId"/> of the character.
    /// For skills that cannot be targeted on an entity, proceed to <see cref="UseSkillAt"/>.
    /// </remarks>
    /// <param name="skill">The skill to use.</param>
    /// <param name="entity">The entity to use the skill on.</param>
    /// <param name="mapX">The x coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)</param>
    /// <param name="mapY">The y coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> UseSkillOn(Skill skill, ILivingEntity entity, short? mapX = default, short? mapY = default)
    {
        if (skill.IsOnCooldown)
        {
            return Task.FromResult<Result>(new SkillOnCooldownError(skill));
        }

        return _client.SendPacketAsync(new UseSkillPacket
        {
            CastId = skill.SkillVNum,
            MapX = mapX,
            MapY = mapY,
            TargetId = entity.Id,
            TargetVisualType = entity.Type
        });
    }

    /// <summary>
    /// Use the given (targetable) skill on specified entity.
    /// </summary>
    /// <remarks>
    /// For skills that can be used only on self, use <paramref name="entityId"/> of the character.
    /// For skills that cannot be targeted on an entity, proceed to <see cref="UseSkillAt"/>.
    /// </remarks>
    /// <param name="skill">The skill to use.</param>
    /// <param name="entityId">The id of the entity to use the skill on.</param>
    /// <param name="entityType">The type of the supplied entity.</param>
    /// <param name="mapX">The x coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)</param>
    /// <param name="mapY">The y coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> UseSkillOn(Skill skill, long entityId, VisualType entityType, short? mapX = default, short? mapY = default)
    {
        if (skill.IsOnCooldown)
        {
            return Task.FromResult<Result>(new SkillOnCooldownError(skill));
        }

        return _client.SendPacketAsync(new UseSkillPacket
        {
            CastId = skill.SkillVNum,
            MapX = mapX,
            MapY = mapY,
            TargetId = entityId,
            TargetVisualType = entityType
        });
    }

    /// <summary>
    /// Use the given (aoe) skill on the specified place.
    /// </summary>
    /// <remarks>
    /// For skills that can have targets, proceed to <see cref="UseSkillOn"/>.
    /// </remarks>
    /// <param name="skillVNum">The id of the skill.</param>
    /// <param name="mapX">The x coordinate to use the skill at.</param>
    /// <param name="mapY">The y coordinate to use the skill at.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> UseSkillAt(long skillVNum, short mapX, short mapY)
    {
        return _client.SendPacketAsync(new UseAoeSkillPacket
        {
            CastId = skillVNum, MapX = mapX, MapY = mapY
        });
    }

    /// <summary>
    /// Use the given (aoe) skill on the specified place.
    /// </summary>
    /// <remarks>
    /// For skills that can have targets, proceed to <see cref="UseSkillOn"/>.
    /// </remarks>
    /// <param name="skill">The skill to use.</param>
    /// <param name="mapX">The x coordinate to use the skill at.</param>
    /// <param name="mapY">The y coordinate to use the skill at.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> UseSkillAt(Skill skill, short mapX, short mapY)
    {
        if (skill.IsOnCooldown)
        {
            return Task.FromResult<Result>(new SkillOnCooldownError(skill));
        }

        return _client.SendPacketAsync(new UseAoeSkillPacket
        {
            CastId = skill.SkillVNum, MapX = mapX, MapY = mapY
        });
    }
}
Do not follow this link