//
// 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;
///
/// Represents nostale group of players or pets and partners.
///
/// The id of the group.
/// The members of the group. (excluding the character)
public record Group(short? Id, IReadOnlyList? Members)
{
///
/// Gets the living entities from the map associated with group members.
///
///
/// If a group member is not found on the map, null will be returned instead on its position.
///
/// The map to get map from.
/// The living entities representing group members.
public IReadOnlyList GetLivingEntities(Game game)
=> GetLivingEntities(game.CurrentMap);
///
/// Gets the living entities from the map associated with group members.
///
///
/// If a group member is not found on the map, null will be returned instead on its position.
///
/// The map to get entities from.
/// The living entities representing group members.
public IReadOnlyList GetLivingEntities(Map? map)
=> GetLivingEntities(map?.Entities);
///
/// Gets the living entities from the map associated with group members.
///
///
/// If a group member is not found on the map, null will be returned instead on its position.
///
/// The entities to look at.
/// The living entities representing group members.
public IReadOnlyList GetLivingEntities(MapEntities? entities)
{
return (IReadOnlyList?)Members?
.Select(x => entities?.GetEntity(x.PlayerId))
.ToList() ?? Array.Empty();
}
}