~ruther/NosSmooth

ref: d45c0f088bb74f87198ea0ea38a063a3468ddf37 NosSmooth/Core/NosSmooth.Game/Data/Social/Group.cs -rw-r--r-- 2.2 KiB
d45c0f08 — NotKappa Move VNum property to ILivingEntity 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
53
54
55
56
57
58
//
//  Group.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.Entities;
using NosSmooth.Game.Data.Maps;
using NosSmooth.Packets.Enums.Entities;
using OneOf;
using Remora.Results;

namespace NosSmooth.Game.Data.Social;

/// <summary>
/// Represents nostale group of players or pets and partners.
/// </summary>
/// <param name="Id">The id of the group.</param>
/// <param name="Members">The members of the group. (excluding the character)</param>
public record Group(short? Id, IReadOnlyList<GroupMember>? Members)
{
    /// <summary>
    /// Gets the living entities from the map associated with group members.
    /// </summary>
    /// <remarks>
    /// If a group member is not found on the map, null will be returned instead on its position.
    /// </remarks>
    /// <param name="game">The map to get map from.</param>
    /// <returns>The living entities representing group members.</returns>
    public IReadOnlyList<Player?> GetLivingEntities(Game game)
        => GetLivingEntities(game.CurrentMap);

    /// <summary>
    /// Gets the living entities from the map associated with group members.
    /// </summary>
    /// <remarks>
    /// If a group member is not found on the map, null will be returned instead on its position.
    /// </remarks>
    /// <param name="map">The map to get entities from.</param>
    /// <returns>The living entities representing group members.</returns>
    public IReadOnlyList<Player?> GetLivingEntities(Map? map)
        => GetLivingEntities(map?.Entities);

    /// <summary>
    /// Gets the living entities from the map associated with group members.
    /// </summary>
    /// <remarks>
    /// If a group member is not found on the map, null will be returned instead on its position.
    /// </remarks>
    /// <param name="entities">The entities to look at.</param>
    /// <returns>The living entities representing group members.</returns>
    public IReadOnlyList<Player?> GetLivingEntities(MapEntities? entities)
    {
        return (IReadOnlyList<Player?>?)Members?
            .Select(x => entities?.GetEntity<Player>(x.PlayerId))
            .ToList() ?? Array.Empty<Player?>();
    }
}
Do not follow this link