~ruther/NosSmooth

ref: 2023.12 NosSmooth/Samples/FileClient/Responders/InventoryInitializedResponder.cs -rw-r--r-- 1.7 KiB
58d87434 — Rutherther chore: bump versions 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
//
//  InventoryInitializedResponder.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.Enums;
using NosSmooth.Data.Abstractions.Language;
using NosSmooth.Game.Data.Items;
using NosSmooth.Game.Events.Core;
using NosSmooth.Game.Events.Inventory;
using NosSmooth.Game.Extensions;
using Remora.Results;

namespace FileClient.Responders;

/// <inheritdoc />
public class InventoryInitializedResponder : IGameResponder<InventoryInitializedEvent>
{
    private readonly ILanguageService _languageService;

    /// <summary>
    /// Initializes a new instance of the <see cref="InventoryInitializedResponder"/> class.
    /// </summary>
    /// <param name="languageService">The langauge service.</param>
    public InventoryInitializedResponder(ILanguageService languageService)
    {
        _languageService = languageService;

    }

    /// <inheritdoc />
    public async Task<Result> Respond(InventoryInitializedEvent gameEvent, CancellationToken ct = default)
    {
        foreach (var bag in gameEvent.Inventory)
        {
            foreach (var slot in bag)
            {
                var item = slot.Item;
                if (item?.Info is not null && bag.Type != item.Info.BagType)
                {
                    var translatedResult = await _languageService.GetTranslationAsync(item.Info.Name, Language.Cz, ct);
                    var entity = translatedResult.Entity;

                    Console.WriteLine(entity + $", {item.ItemVNum} is: {bag.Type}, should be: {item.Info.BagType.Convert()}");
                }
            }
        }

        return Result.FromSuccess();
    }
}
Do not follow this link