Updates Data to JSON (#159)
This commit is contained in:
parent
d2f7e08de4
commit
1246a135f7
61 changed files with 18005 additions and 9152 deletions
173
Projects/Server/Geometry/WorldLocation.cs
Normal file
173
Projects/Server/Geometry/WorldLocation.cs
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: WorldLocation.cs - Created: 2020/05/31 - Updated: 2020/05/31 *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
[Parsable]
|
||||
public struct WorldLocation : IPoint3D, IComparable<WorldLocation>, IEquatable<object>, IEquatable<WorldLocation>, IEquatable<IEntity>
|
||||
{
|
||||
internal Point3D m_Loc;
|
||||
internal Map m_Map;
|
||||
|
||||
public static readonly WorldLocation Zero = new WorldLocation(0, 0, 0, Map.Internal);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor)]
|
||||
public Point3D Location
|
||||
{
|
||||
get => m_Loc;
|
||||
set => m_Loc = value;
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor)]
|
||||
public int X
|
||||
{
|
||||
get => m_Loc.m_X;
|
||||
set => m_Loc.m_X = value;
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor)]
|
||||
public int Y
|
||||
{
|
||||
get => m_Loc.m_Y;
|
||||
set => m_Loc.m_Y = value;
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor)]
|
||||
public int Z
|
||||
{
|
||||
get => m_Loc.m_Z;
|
||||
set => m_Loc.m_Z = value;
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor)]
|
||||
public Map Map
|
||||
{
|
||||
get => m_Map;
|
||||
set => m_Map = value;
|
||||
}
|
||||
|
||||
public WorldLocation(IEntity e) : this(e.Location.X, e.Location.Y, e.Location.Z, e.Map)
|
||||
{
|
||||
}
|
||||
|
||||
public WorldLocation(IPoint2D 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(IPoint3D p, Map map) : this(p.X, p.Y, p.Z, map)
|
||||
{
|
||||
}
|
||||
|
||||
public WorldLocation(int x, int y, int z, Map map)
|
||||
{
|
||||
m_Loc.m_X = x;
|
||||
m_Loc.m_Y = y;
|
||||
m_Loc.m_Z = z;
|
||||
m_Map = map;
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
$"({m_Loc.m_X}, {m_Loc.m_Y}, {m_Loc.m_Z}, {m_Map?.ToString() ?? "(-null-)"})";
|
||||
|
||||
public bool Equals(WorldLocation other) =>
|
||||
m_Loc.Equals(other.m_Loc) && m_Map.MapID == other.m_Map.MapID;
|
||||
|
||||
public bool Equals(IEntity other) =>
|
||||
!ReferenceEquals(other, null) && m_Loc == other.Location &&
|
||||
m_Map.MapID == other.Map.MapID;
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
obj is WorldLocation other && Equals(other);
|
||||
|
||||
public override int GetHashCode() => HashCode.Combine(m_Loc, m_Map);
|
||||
|
||||
public int CompareTo(WorldLocation other)
|
||||
{
|
||||
var locComparison = m_Loc.CompareTo(other.m_Loc);
|
||||
if (locComparison != 0) return locComparison;
|
||||
return Comparer<Map>.Default.Compare(m_Map, other.m_Map);
|
||||
}
|
||||
|
||||
public static implicit operator Point3D(WorldLocation worldLocation) => worldLocation.Location;
|
||||
|
||||
public static bool operator ==(WorldLocation l, WorldLocation r) =>
|
||||
l.m_Loc == r.m_Loc && l.m_Map == r.m_Map;
|
||||
|
||||
public static bool operator ==(WorldLocation l, IEntity r) =>
|
||||
!ReferenceEquals(r, null) && l.m_Loc == r.Location && l.m_Map == r.Map;
|
||||
|
||||
public static bool operator !=(WorldLocation l, WorldLocation r) => l.m_Loc != r.m_Loc && l.m_Map != r.m_Map;
|
||||
|
||||
public static bool operator !=(WorldLocation l, IEntity r) =>
|
||||
!ReferenceEquals(r, null) && l.m_Loc != r.Location && l.m_Map != r.Map;
|
||||
|
||||
public static bool operator >(WorldLocation l, WorldLocation r) => l.m_Loc > r.m_Loc && l.m_Map == r.m_Map;
|
||||
|
||||
public static bool operator >(WorldLocation l, IEntity r) =>
|
||||
!ReferenceEquals(r, null) && l.m_Loc > r.Location && l.m_Map == r.Map;
|
||||
|
||||
public static bool operator <(WorldLocation l, WorldLocation r) => l.m_Loc < r.m_Loc && l.m_Map == r.m_Map;
|
||||
|
||||
public static bool operator <(WorldLocation l, IEntity r) =>
|
||||
!ReferenceEquals(r, null) && l.m_Loc < r.Location && l.m_Map == r.Map;
|
||||
|
||||
public static bool operator >=(WorldLocation l, WorldLocation r) => l.m_Loc >= r.m_Loc && l.m_Map == r.m_Map;
|
||||
|
||||
public static bool operator >=(WorldLocation l, IEntity r) =>
|
||||
!ReferenceEquals(r, null) && l.m_Loc >= r.Location && l.m_Map == r.Map;
|
||||
|
||||
public static bool operator <=(WorldLocation l, WorldLocation r) => l.m_Loc <= r.m_Loc && l.m_Map == r.m_Map;
|
||||
|
||||
public static bool operator <=(WorldLocation l, IEntity r) =>
|
||||
!ReferenceEquals(r, null) && l.m_Loc <= r.Location && l.m_Map == r.Map;
|
||||
|
||||
public static WorldLocation Parse(string value)
|
||||
{
|
||||
var start = value.IndexOf('(');
|
||||
var end = value.IndexOf(',', start + 1);
|
||||
|
||||
Utility.ToInt32(value.Substring(start + 1, end - (start + 1)).Trim(), out int x);
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf(',', start + 1);
|
||||
|
||||
Utility.ToInt32(value.Substring(start + 1, end - (start + 1)).Trim(), out int y);
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf(',', start + 1);
|
||||
|
||||
Utility.ToInt32(value.Substring(start + 1, end - (start + 1)).Trim(), out int z);
|
||||
|
||||
start = end;
|
||||
end = value.IndexOf(')', start + 1);
|
||||
|
||||
var map = Map.Parse(value.Substring(start + 1, end - (start + 1)).Trim());
|
||||
|
||||
return new WorldLocation(x, y, z, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue