~ruther/NosSmooth

ref: 762fc34c97e8b1f6e9290426b8bc2a78122e28ba NosSmooth/Core/NosSmooth.Game/Data/Maps/Map.cs -rw-r--r-- 1.5 KiB
762fc34c — Rutherther Merge pull request #82 from Rutherther/feat/serialize-stackalloc 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
//
//  Map.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 System.Diagnostics.CodeAnalysis;
using NosSmooth.Data.Abstractions.Infos;
using NosSmooth.Game.Data.Info;

namespace NosSmooth.Game.Data.Maps;

/// <summary>
/// Represents nostale map.
/// </summary>
/// <param name="Id">The id of the map.</param>
/// <param name="Type">The type of the map.</param>
/// <param name="Info">The information about the map obtained from data assembly.</param>
/// <param name="Entities">The entities on the map.</param>
/// <param name="Portals">The portals on the map.</param>
public record Map
(
    long Id,
    byte Type,
    IMapInfo? Info,
    MapEntities Entities,
    IReadOnlyList<Portal> Portals
)
{
    /// <summary>
    /// Gets whether the given position lies on a portal.
    /// </summary>
    /// <param name="position">The position.</param>
    /// <param name="portal">The portal the position is on, if any.</param>
    /// <returns>Whether there was a portal at the specified position.</returns>
    public bool IsOnPortal(Position position, [NotNullWhen(true)] out Portal? portal)
    {
        foreach (var p in Portals)
        {
            // TODO: figure out the distance
            if (p.Position.DistanceSquared(position) < 3)
            {
                portal = p;
                return true;
            }
        }

        portal = null;
        return false;
    }
}
Do not follow this link