PalacePal/Pal.Client/Floors/MemoryLocation.cs

67 lines
1.7 KiB
C#
Raw Normal View History

2023-02-18 20:12:36 +00:00
using System;
using System.Collections.Generic;
using System.Numerics;
using Pal.Client.Rendering;
using Pal.Common;
using Palace;
2023-03-30 20:01:43 +00:00
namespace Pal.Client.Floors;
/// <summary>
/// Base class for <see cref="MemoryLocation"/> and <see cref="EphemeralLocation"/>.
/// </summary>
internal abstract class MemoryLocation
2023-02-18 20:12:36 +00:00
{
2023-03-30 20:01:43 +00:00
public required EType Type { get; init; }
public required Vector3 Position { get; init; }
public bool Seen { get; set; }
2023-02-18 20:12:36 +00:00
2023-03-30 20:01:43 +00:00
public IRenderElement? RenderElement { get; set; }
2023-02-18 20:12:36 +00:00
2023-03-30 20:01:43 +00:00
public enum EType
{
Unknown,
2023-02-18 20:12:36 +00:00
2023-03-30 20:01:43 +00:00
Trap,
Hoard,
2023-02-18 20:12:36 +00:00
2023-03-30 20:01:43 +00:00
SilverCoffer,
GoldCoffer,
}
2023-02-18 20:12:36 +00:00
2023-03-30 20:01:43 +00:00
public override bool Equals(object? obj)
{
return obj is MemoryLocation otherLocation &&
Type == otherLocation.Type &&
PalaceMath.IsNearlySamePosition(Position, otherLocation.Position);
}
2023-02-18 20:12:36 +00:00
2023-03-30 20:01:43 +00:00
public override int GetHashCode()
{
return HashCode.Combine(Type, PalaceMath.GetHashCode(Position));
2023-02-18 20:12:36 +00:00
}
2023-03-30 20:01:43 +00:00
}
2023-02-18 20:12:36 +00:00
2023-03-30 20:01:43 +00:00
internal static class ETypeExtensions
{
public static MemoryLocation.EType ToMemoryType(this ObjectType objectType)
2023-02-18 20:12:36 +00:00
{
2023-03-30 20:01:43 +00:00
return objectType switch
2023-02-18 20:12:36 +00:00
{
2023-03-30 20:01:43 +00:00
ObjectType.Trap => MemoryLocation.EType.Trap,
ObjectType.Hoard => MemoryLocation.EType.Hoard,
_ => throw new ArgumentOutOfRangeException(nameof(objectType), objectType, null)
};
}
2023-03-30 20:01:43 +00:00
public static ObjectType ToObjectType(this MemoryLocation.EType type)
{
return type switch
{
2023-03-30 20:01:43 +00:00
MemoryLocation.EType.Trap => ObjectType.Trap,
MemoryLocation.EType.Hoard => ObjectType.Hoard,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
2023-02-18 20:12:36 +00:00
}
}