/*************************************************************************
* ModernUO *
* Copyright 2019-2023 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: WorldLocation.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
*************************************************************************/
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace Server;
public struct WorldLocation : IPoint3D, IComparable, IEquatable, IEquatable,
ISpanFormattable, ISpanParsable
{
internal Point3D _loc;
internal Map _map;
public static readonly WorldLocation Zero = new(0, 0, 0, Map.Internal);
[CommandProperty(AccessLevel.Counselor)]
public Point3D Location
{
get => _loc;
set => _loc = value;
}
[CommandProperty(AccessLevel.Counselor)]
public int X
{
get => _loc.m_X;
set => _loc.m_X = value;
}
[CommandProperty(AccessLevel.Counselor)]
public int Y
{
get => _loc.m_Y;
set => _loc.m_Y = value;
}
[CommandProperty(AccessLevel.Counselor)]
public int Z
{
get => _loc.m_Z;
set => _loc.m_Z = value;
}
[CommandProperty(AccessLevel.Counselor)]
public Map Map
{
get => _map;
set => _map = value;
}
public WorldLocation(IEntity e) : this(e.Location, e.Map)
{
}
public WorldLocation(Point2D p, Map map) : this(p.X, p.Y, 0, map)
{
}
public WorldLocation(int x, int y, Map map) : this(x, y, 0, map)
{
}
public WorldLocation(Point3D p, Map map)
{
_loc = p;
_map = map;
}
public WorldLocation(int x, int y, int z, Map map)
{
_loc.m_X = x;
_loc.m_Y = y;
_loc.m_Z = z;
_map = map;
}
public bool Equals(WorldLocation other) =>
_loc.Equals(other._loc) && _map?.MapID == other._map?.MapID;
public bool Equals(IEntity other) =>
!ReferenceEquals(other, null) && _loc == other.Location &&
_map?.MapID == other.Map?.MapID;
public override bool Equals(object obj) =>
obj is WorldLocation other && Equals(other);
public override int GetHashCode() => HashCode.Combine(_loc, _map);
public int CompareTo(WorldLocation other)
{
var locComparison = _loc.CompareTo(other._loc);
return locComparison != 0 ? locComparison : Comparer