~ruther/NosSmooth

ref: 05c2624a4a566cda726bfd76e8a8dc4affc463b1 NosSmooth/Data/NosSmooth.Data.NOSFiles/InfoService.cs -rw-r--r-- 1.9 KiB
05c2624a — František Boháček feat(data): add database nostale data implementation 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
//
//  InfoService.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.Data.Abstractions;
using NosSmooth.Data.Abstractions.Infos;
using NosSmooth.Data.Abstractions.Language;
using NosSmooth.Data.NOSFiles.Parsers;
using Remora.Results;

namespace NosSmooth.Data.NOSFiles;

/// <inheritdoc />
internal class InfoService : IInfoService
{
    private readonly NostaleData _nostaleData;

    /// <summary>
    /// Initializes a new instance of the <see cref="InfoService"/> class.
    /// </summary>
    /// <param name="nostaleData">The parsed data.</param>
    public InfoService(NostaleData nostaleData)
    {
        _nostaleData = nostaleData;
    }

    /// <inheritdoc />
    public Result<IItemInfo> GetItemInfo(int vnum)
    {
        if (!_nostaleData.Items.ContainsKey(vnum))
        {
            return new NotFoundError($"Couldn't find item {vnum}");
        }

        return Result<IItemInfo>.FromSuccess(_nostaleData.Items[vnum]);
    }

    /// <inheritdoc />
    public Result<IMapInfo> GetMapInfo(int id)
    {
        if (!_nostaleData.Maps.ContainsKey(id))
        {
            return new NotFoundError($"Couldn't find item {id}");
        }

        return Result<IMapInfo>.FromSuccess(_nostaleData.Maps[id]);
    }

    /// <inheritdoc />
    public Result<IMonsterInfo> GetMonsterInfo(int vnum)
    {
        if (!_nostaleData.Monsters.ContainsKey(vnum))
        {
            return new NotFoundError($"Couldn't find item {vnum}");
        }

        return Result<IMonsterInfo>.FromSuccess(_nostaleData.Monsters[vnum]);
    }

    /// <inheritdoc />
    public Result<ISkillInfo> GetSkillInfo(int vnum)
    {
        if (!_nostaleData.Skills.ContainsKey(vnum))
        {
            return new NotFoundError($"Couldn't find item {vnum}");
        }

        return Result<ISkillInfo>.FromSuccess(_nostaleData.Skills[vnum]);
    }
}
Do not follow this link