1+ namespace DOL . GS . Geometry ;
2+
3+ public struct Position
4+ {
5+ public ushort RegionID { get ; init ; } = 0 ;
6+ public Coordinate Coordinate { get ; init ; } = Coordinate . Zero ;
7+ public Angle Orientation { get ; init ; } = Angle . Zero ;
8+
9+ public int X => Coordinate . X ;
10+ public int Y => Coordinate . Y ;
11+ public int Z => Coordinate . Z ;
12+
13+ public Region Region => WorldMgr . GetRegion ( RegionID ) ;
14+
15+ public Position ( ) { }
16+
17+ public static Position Create ( ushort regionID , int x , int y , int z , ushort heading )
18+ => new ( ) { RegionID = regionID , Coordinate = Coordinate . Create ( x , y , z ) , Orientation = Angle . Heading ( heading ) } ;
19+
20+ public static Position Create ( ushort regionID , int x = 0 , int y = 0 , int z = 0 , Angle ? orientation = null )
21+ => new ( ) { RegionID = regionID , Coordinate = Coordinate . Create ( x , y , z ) , Orientation = orientation ?? Angle . Zero } ;
22+
23+ public static Position CreateInZone ( ushort zoneID , int x = 0 , int y = 0 , int z = 0 , ushort heading = 0 )
24+ {
25+ var zone = WorldMgr . GetZone ( zoneID ) ;
26+ return Create ( zone . ZoneRegion . ID , x + zone . Offset . X , y + zone . Offset . Y , z + zone . Offset . Z , heading ) ;
27+ }
28+
29+ public static Position Create ( ushort regionID , Coordinate coordinate , ushort heading = 0 )
30+ => new ( ) { RegionID = regionID , Coordinate = coordinate , Orientation = Angle . Heading ( heading ) } ;
31+
32+ public static Position Create ( ushort regionID , Coordinate coordinate , Angle orientation )
33+ => new ( ) { RegionID = regionID , Coordinate = coordinate , Orientation = orientation } ;
34+
35+ public Position With ( ushort ? regionID = null , int ? x = null , int ? y = null , int ? z = null , ushort ? heading = null )
36+ {
37+ var newOrientation = heading != null ? Angle . Heading ( ( ushort ) heading ) : Orientation ;
38+ var newRegionID = regionID ?? RegionID ;
39+ return Create ( newRegionID , Coordinate . With ( x , y , z ) , newOrientation ) ;
40+ }
41+
42+ public Position With ( Coordinate coordinate )
43+ => Create ( RegionID , coordinate , Orientation ) ;
44+
45+ public Position With ( Angle orientation )
46+ => Create ( RegionID , Coordinate , orientation ) ;
47+
48+ public Position TurnedAround ( )
49+ => With ( orientation : Orientation + Angle . Degrees ( 180 ) ) ;
50+
51+ public static Position operator + ( Position a , Vector b )
52+ => a . With ( coordinate : a . Coordinate + b ) ;
53+
54+ public static Position operator - ( Position a , Vector b )
55+ => a . With ( coordinate : a . Coordinate - b ) ;
56+
57+ public static bool operator == ( Position a , Position b )
58+ => a . Equals ( b ) ;
59+
60+ public static bool operator != ( Position a , Position b )
61+ => ! a . Equals ( b ) ;
62+
63+ public override bool Equals ( object obj )
64+ {
65+ if ( obj is Position otherPos )
66+ {
67+ return otherPos . RegionID == RegionID
68+ && otherPos . Coordinate . Equals ( Coordinate )
69+ && otherPos . Orientation == Orientation ;
70+ }
71+ return false ;
72+ }
73+
74+ public override int GetHashCode ( )
75+ => base . GetHashCode ( ) ;
76+
77+ public override string ToString ( )
78+ => $ "({ Coordinate } , { Orientation . InHeading } )";
79+
80+ public readonly static Position Nowhere = Create ( regionID : ushort . MaxValue , Coordinate . Nowhere , Angle . Zero ) ;
81+ public readonly static Position Zero = new ( ) ;
82+ }
0 commit comments