~ruther/NosSmooth

ref: db9c5956f264c8d2ad0a3ab5550175cb4de7d0bb NosSmooth/Core/NosSmooth.Game/Extensions/SkillsExtensions.cs -rw-r--r-- 2.0 KiB
db9c5956 — Rutherther feat(game): add handling of packets for maps and entities 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
//
//  SkillsExtensions.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.Data.Characters;
using Remora.Results;

namespace NosSmooth.Game.Extensions;

/// <summary>
/// Contains extension methods for <see cref="Skills"/>.
/// </summary>
public static class SkillsExtensions
{
    /// <summary>
    /// Tries to get the skill of the specified vnum.
    /// </summary>
    /// <param name="skills">The skills of the player.</param>
    /// <param name="castId">The cast id to search for.</param>
    /// <returns>The skill, if found.</returns>
    public static Result<Skill> TryGetSkillByCastId(this Skills skills, short castId)
    {
        if (skills.PrimarySkill.Info?.CastId == castId)
        {
            return skills.PrimarySkill;
        }

        if (skills.SecondarySkill.Info?.CastId == castId)
        {
            return skills.SecondarySkill;
        }

        foreach (Skill skill in skills.OtherSkills)
        {
            if (skill.Info?.CastId == castId)
            {
                return skill;
            }
        }

        return new NotFoundError();
    }

    /// <summary>
    /// Tries to get the skill of the specified vnum.
    /// </summary>
    /// <param name="skills">The skills of the player.</param>
    /// <param name="skillVNum">The vnum to search for.</param>
    /// <returns>The skill, if found.</returns>
    public static Result<Skill> TryGetSkillByVNum(this Skills skills, long skillVNum)
    {
        if (skills.PrimarySkill.SkillVNum == skillVNum)
        {
            return skills.PrimarySkill;
        }

        if (skills.SecondarySkill.SkillVNum == skillVNum)
        {
            return skills.SecondarySkill;
        }

        foreach (Skill skill in skills.OtherSkills)
        {
            if (skill.SkillVNum == skillVNum)
            {
                return skill;
            }
        }

        return new NotFoundError();
    }
}
Do not follow this link