diff --git a/GameServer/GameClient.cs b/GameServer/GameClient.cs index 640f195a..c4c23f41 100644 --- a/GameServer/GameClient.cs +++ b/GameServer/GameClient.cs @@ -27,6 +27,7 @@ using DOL.Database; using DOL.Events; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using DOL.GS.ServerProperties; using DOL.Language; diff --git a/GameServer/Geometry/Coordinate.cs b/GameServer/Geometry/Coordinate.cs index 2c6961ae..9ff4b0d9 100644 --- a/GameServer/Geometry/Coordinate.cs +++ b/GameServer/Geometry/Coordinate.cs @@ -8,6 +8,8 @@ public struct Coordinate public int Y => coordinate.Y; public int Z => coordinate.Z; + public static Coordinate Create(System.Numerics.Vector3 v) => new () { coordinate = Vector.Create((int)v.X, (int)v.Y, (int)v.Z) }; + public static Coordinate Create(int x = 0, int y = 0, int z = 0) => new() { coordinate = Vector.Create(x, y, z) }; diff --git a/GameServer/Geometry/CoordinateTransitionExtensions.cs b/GameServer/Geometry/CoordinateTransitionExtensions.cs index b23ed72d..1d6976bc 100644 --- a/GameServer/Geometry/CoordinateTransitionExtensions.cs +++ b/GameServer/Geometry/CoordinateTransitionExtensions.cs @@ -15,5 +15,5 @@ public static Point2D ToPoint2D(this Coordinate coordinate) [Obsolete("This extension is transitional and going to be removed.")] public static Coordinate ToCoordinate(this IPoint3D point) - => Coordinate.Create(point.X, point.Y, point.Z); + => Coordinate.Create((int)point.Position.X, (int)point.Position.Y, (int)point.Position.Z); } \ No newline at end of file diff --git a/GameServer/Geometry/Vector.cs b/GameServer/Geometry/Vector.cs index 5526ddad..c5aa54d5 100644 --- a/GameServer/Geometry/Vector.cs +++ b/GameServer/Geometry/Vector.cs @@ -70,6 +70,12 @@ public override int GetHashCode() public static Vector operator *(double factor, Vector vec) => vec * factor; + public static Vector operator /(Vector vec, double factor) + => Create((int)(vec.X / factor), (int)(vec.Y / factor), (int)(vec.Z / factor)); + + public static Vector operator /(double factor, Vector vec) + => vec / factor; + public static Vector operator +(Vector vecA, Vector vecB) => Create(vecA.X + vecB.X, vecA.Y + vecB.Y, vecA.Z + vecB.Z); diff --git a/GameServer/Territory/AreaCoordinate.cs b/GameServer/Territory/AreaCoordinate.cs deleted file mode 100644 index 49d8f354..00000000 --- a/GameServer/Territory/AreaCoordinate.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DOL.Territories -{ - public class AreaCoordinate - { - public float X - { - get; - set; - } - - public float Y - { - get; - set; - } - - public float Z - { - get; - set; - } - } -} \ No newline at end of file diff --git a/GameServer/Territory/RvRTerritory.cs b/GameServer/Territory/RvRTerritory.cs index 3fac75de..b0ef5572 100644 --- a/GameServer/Territory/RvRTerritory.cs +++ b/GameServer/Territory/RvRTerritory.cs @@ -1,5 +1,6 @@ using DOL.Database; using DOL.GS; +using DOL.GS.Geometry; using DOL.GS.Keeps; using DOL.MobGroups; using DOLDatabase.Tables; @@ -16,7 +17,7 @@ public class RvRTerritory : Territory { /// - public RvRTerritory(Zone zone, List areas, string name, GameNPC boss, Vector3? portalPosition, ushort regionID, MobGroup group) : base(eType.Normal, zone, areas, name, boss, portalPosition, regionID, group) + public RvRTerritory(Zone zone, List areas, string name, GameNPC boss, Coordinate? portalCoordinate, ushort regionID, MobGroup group) : base(eType.Normal, zone, areas, name, boss, portalCoordinate, regionID, group) { //add new areas to region //only in memory @@ -50,7 +51,7 @@ public void Reset() { OwnerGuild = null; // reset keep - AbstractGameKeep keep = GameServer.KeepManager.GetKeepCloseToSpot(RegionId, Boss.Position, 100000); + AbstractGameKeep keep = GameServer.KeepManager.GetKeepCloseToSpot(Boss.Position, 100000); keep.TempRealm = eRealm.None; keep.Reset(keep.TempRealm); // reset all doors diff --git a/GameServer/Territory/Territory.cs b/GameServer/Territory/Territory.cs index 3a4befcb..17310f74 100644 --- a/GameServer/Territory/Territory.cs +++ b/GameServer/Territory/Territory.cs @@ -3,6 +3,7 @@ using DOL.GameEvents; using DOL.gameobjects.CustomNPC; using DOL.GS; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using DOL.GS.PropertyCalc; using DOL.GS.ServerProperties; @@ -37,11 +38,11 @@ public Territory(Zone zone, List areas, GameNPC boss, TerritoryDb db) this.Areas = areas; if (db.PortalX == null || db.PortalY == null || db.PortalZ == null) { - this.PortalPosition = null; + this.PortalCoordinate = null; } else { - this.PortalPosition = new Vector3(db.PortalX.Value, db.PortalY.Value, db.PortalZ.Value); + this.PortalCoordinate = Coordinate.Create(db.PortalX.Value, db.PortalY.Value, db.PortalZ.Value); } this.Zone = zone; this.RegionId = db.RegionId; @@ -106,11 +107,11 @@ public Territory(Zone zone, List areas, GameNPC boss, TerritoryDb db) } } - public Territory(eType type, Zone zone, List areas, string name, GameNPC boss, Vector3? portalPosition, ushort regionID, MobGroup group = null) + public Territory(eType type, Zone zone, List areas, string name, GameNPC boss, Coordinate? portalCoordinate, ushort regionID, MobGroup group = null) { this.Type = type; this.Areas = areas; - this.PortalPosition = portalPosition; + this.PortalCoordinate = portalCoordinate; this.Zone = zone; this.RegionId = regionID; this.Name = name; @@ -207,7 +208,7 @@ public List Areas get; } - public Vector3? PortalPosition + public Coordinate? PortalCoordinate { get; set; @@ -624,7 +625,7 @@ private void ToggleBannerUnsafe(bool add) if (area is Circle circle) { - Zone.GetObjectsInRadius(Zone.eGameObjectType.ITEM, circle.Position.X, circle.Position.Y, circle.Position.Z, (ushort)circle.Radius, new ArrayList(), true).OfType().ForEach(i => i.Emblem = add && m_ownerGuild != null ? m_ownerGuild.Emblem : i.OriginalEmblem); + Zone.GetObjectsInRadius(Zone.eGameObjectType.ITEM, circle.Coordinate, (ushort)circle.Radius, new ArrayList(), true).OfType().ForEach(i => i.Emblem = add && m_ownerGuild != null ? m_ownerGuild.Emblem : i.OriginalEmblem); } else { @@ -1168,11 +1169,11 @@ protected virtual void SaveIntoDatabaseUnsafe() db.ClaimedTime = ClaimedTime; db.Expiration = Expiration; db.Type = (int)Type; - if (this.PortalPosition != null) + if (this.PortalCoordinate != null) { - db.PortalX = (int)this.PortalPosition.Value.X; - db.PortalY = (int)this.PortalPosition.Value.Y; - db.PortalZ = (int)this.PortalPosition.Value.Z; + db.PortalX = (int)this.PortalCoordinate.Value.X; + db.PortalY = (int)this.PortalCoordinate.Value.Y; + db.PortalZ = (int)this.PortalCoordinate.Value.Z; } else { diff --git a/GameServer/Territory/TerritoryManager.cs b/GameServer/Territory/TerritoryManager.cs index 9f113051..d172b79f 100644 --- a/GameServer/Territory/TerritoryManager.cs +++ b/GameServer/Territory/TerritoryManager.cs @@ -4,6 +4,7 @@ using DOL.GameEvents; using DOL.GS; using DOL.GS.Commands; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using DOL.GS.PropertyCalc; using DOL.GS.ServerProperties; @@ -428,18 +429,18 @@ public Territory AddTerritory(Territory.eType type, IArea area, string areaId, u } var coords = GetCoordinates(area); - if (coords == null) + if (coords == Coordinate.Nowhere) { return null; } - var zone = region.GetZone(coords.X, coords.Y); + var zone = region.GetZone(coords); if (zone == null) { return null; } - var territory = new Territory(type, zone, new List{area}, (area as AbstractArea)?.Description ?? "New territory", boss, new Vector3(coords.X, coords.Y, coords.Z), regionId, group); + var territory = new Territory(type, zone, new List{area}, (area as AbstractArea)?.Description ?? "New territory", boss, coords, regionId, group); try { @@ -455,14 +456,14 @@ public Territory AddTerritory(Territory.eType type, IArea area, string areaId, u return territory; } - public static AreaCoordinate GetCoordinates(IArea area) + public static Coordinate GetCoordinates(IArea area) { return area switch { - DOL.GS.Area.Circle circle => new AreaCoordinate() { X = circle.Position.X, Y = circle.Position.Y, Z = circle.Position.Z }, - Square sq => new AreaCoordinate() { X = sq.Position.X, Y = sq.Position.Y, Z = sq.Position.Z }, - Polygon poly => new AreaCoordinate() { X = poly.Position.X, Y = poly.Position.Y, Z = poly.Position.Z }, - _ => null + DOL.GS.Area.Circle circle => circle.Coordinate, + Square sq => sq.Coordinate, + Polygon poly => poly.Coordinate, + _ => Coordinate.Nowhere }; } diff --git a/GameServer/_scripts/AmteScripts/GameObjects/Coffre/CoffrexPlayer.cs b/GameServer/_scripts/AmteScripts/GameObjects/Coffre/CoffrexPlayer.cs index 8774ac61..dcda774c 100644 --- a/GameServer/_scripts/AmteScripts/GameObjects/Coffre/CoffrexPlayer.cs +++ b/GameServer/_scripts/AmteScripts/GameObjects/Coffre/CoffrexPlayer.cs @@ -56,20 +56,6 @@ public string CoffreID } } - [DataElement(AllowDbNull = false)] - public DateTime LastTimeRowUpdated - { - get - { - return m_lasttimerowupdated; - } - set - { - Dirty = true; - m_lasttimerowupdated = value; - } - } - public CoffrexPlayer() { } diff --git a/GameServer/_scripts/AmteScripts/GameObjects/Coffre/GameCoffre.cs b/GameServer/_scripts/AmteScripts/GameObjects/Coffre/GameCoffre.cs index 62ba0978..048015a0 100644 --- a/GameServer/_scripts/AmteScripts/GameObjects/Coffre/GameCoffre.cs +++ b/GameServer/_scripts/AmteScripts/GameObjects/Coffre/GameCoffre.cs @@ -13,6 +13,7 @@ using DOL.MobGroups; using DOL.Events; using DOL.GS.GameEvents; +using DOL.GS.Geometry; namespace DOL.GS.Scripts { @@ -486,7 +487,7 @@ private TPPoint GetSmartNextTPPoint(IList tpPoints) foreach (var tpPoint in tpPoints) { - int playerCount = WorldMgr.GetPlayersCloseToSpot(tpPoint.Region, (float)tpPoint.X, (float)tpPoint.Y, (float)tpPoint.Z, 1500).OfType().Count(); // Using 1500 directly + int playerCount = WorldMgr.GetPlayersCloseToSpot(Position.Create(tpPoint.Region, tpPoint.X, tpPoint.Y, tpPoint.Z), 1500).OfType().Count(); // Using 1500 directly if (playerCount > maxPlayerCount) { maxPlayerCount = playerCount; @@ -820,10 +821,7 @@ private void HandlePopMob() { var mob = new AmteMob(new NpcTemplate(template)) { - Position = new Vector3(Position.X, Position.Y, Position.Z), - Heading = Heading, - CurrentRegionID = CurrentRegionID, - CurrentRegion = CurrentRegion, + Position = this.Position, Size = 50, Name = template.Name }; @@ -1022,10 +1020,8 @@ public override void LoadFromDatabase(DataObject obj) DBCoffre coffre = obj as DBCoffre; if (coffre == null) return; Name = coffre.Name; - Position = new Vector3(coffre.X, coffre.Y, coffre.Z); - Heading = (ushort)(coffre.Heading & 0xFFF); + Position = Position.Create(coffre.Region, coffre.X, coffre.Y, coffre.Z, coffre.Heading); HasPickableAnim = coffre.HasPickableAnim; - CurrentRegionID = coffre.Region; Model = coffre.Model; LastOpen = coffre.LastOpen; ItemInterval = coffre.ItemInterval; diff --git a/GameServer/_scripts/AmteScripts/GameObjects/CustomVault.cs b/GameServer/_scripts/AmteScripts/GameObjects/CustomVault.cs index de66b799..7afbd24b 100644 --- a/GameServer/_scripts/AmteScripts/GameObjects/CustomVault.cs +++ b/GameServer/_scripts/AmteScripts/GameObjects/CustomVault.cs @@ -59,7 +59,7 @@ public override bool Interact(GamePlayer player) return true; } - protected void AddObserver(GamePlayer player) + public override void AddObserver(GamePlayer player) { lock (_vaultLock) { diff --git a/GameServer/_scripts/AmteScripts/GameObjects/FollowingFriendMob.cs b/GameServer/_scripts/AmteScripts/GameObjects/FollowingFriendMob.cs index 9fe0ce0c..c0bd2fb9 100644 --- a/GameServer/_scripts/AmteScripts/GameObjects/FollowingFriendMob.cs +++ b/GameServer/_scripts/AmteScripts/GameObjects/FollowingFriendMob.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Numerics; using System.Timers; using DOL.AI.Brain; using DOL.Database; using DOL.Events; using DOL.GS; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using DOL.GS.Scripts; using DOL.MobGroups; @@ -59,7 +59,7 @@ public override bool Interact(GamePlayer player) { if (!base.Interact(player) && (IsPeaceful || WaitingInArea || (((StandardMobBrain)Brain).AggroLevel == 0 && ((StandardMobBrain)Brain).AggroRange == 0)) - && CurrentRegion.GetAreasOfSpot(Position).OfType().FirstOrDefault(a => a.DbArea != null && a.DbArea.ObjectId == AreaToEnter) != null) + && CurrentRegion.GetAreasOfSpot(Coordinate).OfType().FirstOrDefault(a => a.DbArea != null && a.DbArea.ObjectId == AreaToEnter) != null) return false; if (PlayerFollow != null && PlayerFollow == player) { @@ -248,7 +248,7 @@ public void ResetFriendMob() AddToWorld(); } - public void Reset() + public override void Reset() { ResetFriendMobs(); } @@ -346,14 +346,14 @@ protected override int FollowTimerCallback(RegionTimer callingTimer) } //Calculate the difference between our position and the players position - var diff = followTarget.Position - Position; - + var diff = followTarget.Coordinate - Coordinate; + //SH: Removed Z checks when one of the two Z values is zero(on ground) float distanceToTarget; if (followTarget.Position.Z == 0 || Position.Z == 0) - distanceToTarget = (float)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y); + distanceToTarget = GetDistance2DTo(followTarget); else - distanceToTarget = (float)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y + diff.Z * diff.Z); + distanceToTarget = GetDistanceTo(followTarget); //Are we in range still? if (followTarget == PlayerFollow) @@ -405,10 +405,10 @@ protected override int FollowTimerCallback(RegionTimer callingTimer) if (area != null && !WaitingInArea) { StopFollowing(); - var targetPos = new Vector3(area.DbArea.X, area.DbArea.Y, area.DbArea.Z); + var targetPos = Coordinate.Create(area.DbArea.X, area.DbArea.Y, area.DbArea.Z); var angle = Math.Atan2(targetPos.Y - Position.Y, targetPos.X - Position.X); - targetPos.X = area.DbArea.X + (float)Math.Cos(angle) * Util.Random(200, 300); - targetPos.Y = area.DbArea.Y + (float)Math.Sin(angle) * Util.Random(200, 300); + + targetPos += Vector.Create(Angle.Radians(angle), Util.Random(200, 300)); WaitingInArea = true; followTarget.Notify(GameLivingEvent.BringAFriend, followTarget, new BringAFriendArgs(this, true)); PathTo(targetPos, 130); @@ -421,12 +421,12 @@ protected override int FollowTimerCallback(RegionTimer callingTimer) // follow on distance diff = (diff / distanceToTarget) * m_followMinDist; - var newPos = followTarget.Position - diff; + var newPos = followTarget.Coordinate - diff; if (followTarget == PlayerFollow) { var speed = MaxSpeed; - if (GameMath.GetDistance2D(Position, followTarget.Position) < 200) + if (IsWithinRadius(followTarget, 200)) speed = 0; PathTo(newPos, speed); } diff --git a/GameServer/_scripts/AmteScripts/GameObjects/FollowingMob.cs b/GameServer/_scripts/AmteScripts/GameObjects/FollowingMob.cs index fd67a1a6..58c80012 100644 --- a/GameServer/_scripts/AmteScripts/GameObjects/FollowingMob.cs +++ b/GameServer/_scripts/AmteScripts/GameObjects/FollowingMob.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; -using System.Numerics; using DOL.AI.Brain; using DOL.Database; using DOL.Events; using DOL.GS; +using DOL.GS.Geometry; using DOL.GS.Scripts; namespace DOL.GS.Scripts @@ -130,14 +130,15 @@ protected override int FollowTimerCallback(RegionTimer callingTimer) } //Calculate the difference between our position and the players position - var diff = followTarget.Position - Position; + var diff = followTarget.Coordinate - Coordinate; //SH: Removed Z checks when one of the two Z values is zero(on ground) float distance; if (followTarget.Position.Z == 0 || Position.Z == 0) - distance = (float)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y); + distance = GetDistance2DTo(followTarget); else - distance = (float)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y + diff.Z * diff.Z); + distance = GetDistanceTo(followTarget); + //if distance is greater then the max follow distance, stop following and return home if (distance > m_followMaxDist) @@ -188,22 +189,21 @@ protected override int FollowTimerCallback(RegionTimer callingTimer) // follow on distance diff = (diff / distance) * m_followMinDist; - var newPos = followTarget.Position - diff; + var newCoordinate = followTarget.Coordinate - diff; if (followTarget == MobFollow) { var angle = (m_Angle + followTarget.Heading / GameMath.RADIAN_TO_HEADING) % (Math.PI * 2); + Vector direction = Vector.Create(Angle.Radians(angle), m_DistMob); - newPos.X = followTarget.Position.X + (float)Math.Cos(angle) * m_DistMob; - newPos.Y = followTarget.Position.Y + (float)Math.Sin(angle) * m_DistMob; - + newCoordinate += direction; var speed = MaxSpeed; - if (GameMath.GetDistance2D(Position, newPos) < 500) + if (GameMath.GetDistance2D(Coordinate, newCoordinate) < 500) speed = (short)Math.Min(MaxSpeed, MobFollow.CurrentSpeed + 6); - PathTo(newPos, speed); + PathTo(newCoordinate, speed); } else - PathTo(newPos, MaxSpeed); + PathTo(newCoordinate, MaxSpeed); return ServerProperties.Properties.GAMENPC_FOLLOWCHECK_TIME; } diff --git a/GameServer/_scripts/AmteScripts/GameObjects/GameBoatAmte.cs b/GameServer/_scripts/AmteScripts/GameObjects/GameBoatAmte.cs index 56ee031e..87f1d23f 100644 --- a/GameServer/_scripts/AmteScripts/GameObjects/GameBoatAmte.cs +++ b/GameServer/_scripts/AmteScripts/GameObjects/GameBoatAmte.cs @@ -1,8 +1,8 @@ -using System.Numerics; using DOL.AI.Brain; using DOL.Database; using DOL.GS.PacketHandler; using DOL.GS.Movement; +using DOL.GS.Geometry; namespace DOL.GS { @@ -79,11 +79,10 @@ public override bool AddToWorld() { if (!base.AddToWorld()) return false; SetOwnBrain(new BlankBrain()); - Reset(); return true; } - public void Reset() + public override void Reset() { if (IsMoving) StopMoving(); @@ -104,13 +103,11 @@ public override void LoadFromDatabase(DataObject obj) Mob npc = (Mob)obj; Name = npc.Name; GuildName = npc.Guild; - Position = new Vector3(npc.X, npc.Y, npc.Z); - m_Heading = (ushort)(npc.Heading & 0xFFF); + Position = Position.Create(npc.Region, npc.X, npc.Y, npc.Z, npc.Heading); m_maxSpeedBase = (short)npc.Speed; // TODO db has currently senseless information here, mob type db required if (m_maxSpeedBase == 0) m_maxSpeedBase = 600; m_currentSpeed = 0; - CurrentRegionID = npc.Region; Realm = (eRealm)npc.Realm; Model = npc.Model; Size = npc.Size; diff --git a/GameServer/_scripts/AmteScripts/GameObjects/MageMob/MageMobBrain.cs b/GameServer/_scripts/AmteScripts/GameObjects/MageMob/MageMobBrain.cs index f45e3621..16052ab9 100644 --- a/GameServer/_scripts/AmteScripts/GameObjects/MageMob/MageMobBrain.cs +++ b/GameServer/_scripts/AmteScripts/GameObjects/MageMob/MageMobBrain.cs @@ -4,6 +4,7 @@ using DOL.GS; using DOL.GS.Scripts; using System.Numerics; +using DOL.GS.Geometry; namespace DOL.AI.Brain { @@ -38,13 +39,13 @@ public override void Think() ///The target to flee. protected virtual void CalculateFleeTarget(GameLiving target) { - ushort TargetAngle = (ushort)((Body.GetHeading(target) + 2048) % 4096); + ushort TargetAngle = Body.GetAngleTo(target.Coordinate).InHeading; var fleePoint = Body.GetPointFromHeading(TargetAngle, 300); - var point = PathingMgr.Instance.GetClosestPoint(Body.CurrentZone, new Vector3(fleePoint, Body.Position.Z), 128, 128, 256); + var point = PathingMgr.Instance.GetClosestPointAsync(Body.CurrentZone, Coordinate.Create(fleePoint.X, fleePoint.Y, Body.Position.Z), 128, 128, 256); Body.StopFollowing(); Body.StopAttack(); - Body.PathTo(point.HasValue ? point.Value : new Vector3(fleePoint, Body.Position.Z), Body.MaxSpeed); + Body.PathTo(point.HasValue ? Coordinate.Create(point.Value) : Coordinate.Create(fleePoint.X, fleePoint.Y, Body.Position.Z), Body.MaxSpeed); } } diff --git a/GameServer/_scripts/AmteScripts/GameObjects/PlaceAssise.cs b/GameServer/_scripts/AmteScripts/GameObjects/PlaceAssise.cs index 37648682..82b601cf 100644 --- a/GameServer/_scripts/AmteScripts/GameObjects/PlaceAssise.cs +++ b/GameServer/_scripts/AmteScripts/GameObjects/PlaceAssise.cs @@ -3,6 +3,7 @@ using DOL.Database; using DOL.GS.PacketHandler; using DOL.Language; +using DOL.GS.Geometry; namespace DOL.GS.Scripts { @@ -59,8 +60,7 @@ public override void LoadFromDatabase(DataObject obj) Mob npc = (Mob)obj; Name = npc.Name; GuildName = npc.Guild; - Position = new Vector3(npc.X, npc.Y, npc.Z); - m_Heading = (ushort)(npc.Heading & 0xFFF); + Position = Position.Create(npc.Region, npc.X, npc.Y, npc.Z, (ushort)(npc.Heading & 0xFFF)); m_maxSpeedBase = (short)npc.Speed; // TODO db has currently senseless information here, mob type db required if (m_maxSpeedBase == 0) m_maxSpeedBase = 600; @@ -86,7 +86,7 @@ public override void SaveIntoDatabase() mob.X = (int)Position.X; mob.Y = (int)Position.Y; mob.Z = (int)Position.Z; - mob.Heading = Heading; + mob.Heading = Position.Orientation.InHeading; mob.Speed = MaxSpeedBase; mob.Region = CurrentRegionID; mob.Realm = (byte)Realm; diff --git a/GameServer/_scripts/AmteScripts/GameObjects/SplitMob.cs b/GameServer/_scripts/AmteScripts/GameObjects/SplitMob.cs index dc188af6..a32f1cbe 100644 --- a/GameServer/_scripts/AmteScripts/GameObjects/SplitMob.cs +++ b/GameServer/_scripts/AmteScripts/GameObjects/SplitMob.cs @@ -8,6 +8,7 @@ using DOL.Events; using DOL.Database; using DOL.GS.PacketHandler; +using DOL.GS.Geometry; using log4net; namespace DOL.GS.Scripts @@ -56,11 +57,10 @@ public void Split(GamePlayer player) } + public void SetVariables(GameNPC mob) { - mob.Position = new System.Numerics.Vector3(this.Position.X + 10, this.Position.Y + 10, this.Position.Z); - mob.CurrentRegion = this.CurrentRegion; - mob.Heading = this.Heading; + mob.Position = Position.With(Coordinate.Create(this.Coordinate.X + 10, this.Coordinate.Y + 10, this.Coordinate.Z)); mob.Level = this.Level; mob.Realm = this.Realm; mob.Name = "Split's Minion"; diff --git a/GameServer/_scripts/AmteScripts/Managers/AmtenaelRules.cs b/GameServer/_scripts/AmteScripts/Managers/AmtenaelRules.cs index eb078b73..a747c447 100644 --- a/GameServer/_scripts/AmteScripts/Managers/AmtenaelRules.cs +++ b/GameServer/_scripts/AmteScripts/Managers/AmtenaelRules.cs @@ -156,15 +156,15 @@ public override void OnRegionChanged(DOLEvent e, object sender, EventArgs args) /// /// /// - public override void OnPlayerTeleport(GamePlayer player, GameLocation source, Teleport destination) + public override void OnPlayerTeleport(GamePlayer player, Teleport destination) { // Since region change already starts an immunity timer we only want to do this if a player // is teleporting within the same region - if (source.RegionID == destination.RegionID) + if (player.CurrentRegionID == destination.RegionID) { StartPVEImmunityTimer(player, Properties.TIMER_PVE_TELEPORT * 1000); } - base.OnPlayerTeleport(player, source, destination); + base.OnPlayerTeleport(player, destination); } /// @@ -1073,7 +1073,7 @@ public override void OnPlayerKilled(GamePlayer killedPlayer, GameObject killer) if (!BG && living is GamePlayer) { - AbstractGameKeep keep = GameServer.KeepManager.GetKeepCloseToSpot(living.CurrentRegionID, living.Position, 16000); + AbstractGameKeep keep = GameServer.KeepManager.GetKeepCloseToSpot(living.Position, 16000); if (keep != null) { byte bonus = 0; diff --git a/GameServer/_scripts/AmteScripts/PvP/PvpManager.cs b/GameServer/_scripts/AmteScripts/PvP/PvpManager.cs index a29bc591..44a81d7e 100644 --- a/GameServer/_scripts/AmteScripts/PvP/PvpManager.cs +++ b/GameServer/_scripts/AmteScripts/PvP/PvpManager.cs @@ -7,6 +7,7 @@ using DOL.Database; using DOL.Events; using DOL.GS; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using log4net; @@ -17,7 +18,7 @@ public class PvpManager private static readonly TimeSpan _startTime = new TimeSpan(14, 0, 0); private static readonly TimeSpan _endTime = _startTime.Add(TimeSpan.FromHours(8)); private const int _checkInterval = 30 * 1000; // 30 seconds - private static readonly GameLocation _stuckSpawn = new GameLocation("", 51, 434303, 493165, 3088, 1069); + private static readonly Position _stuckSpawn = Position.Create(51, 434303, 493165, 3088, 1069); #region Static part private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -57,7 +58,7 @@ public static void OnServerStopped(DOLEvent e, object sender, EventArgs args) /// /// <regionID, Tuple<TPs, spawnAlb, spawnMid, spawnHib>> /// - private readonly Dictionary> _maps = new Dictionary>(); + private readonly Dictionary> _maps = new(); private PvpManager() { @@ -83,7 +84,7 @@ public IEnumerable FindPvPMaps() var spawn = WorldMgr.GetNPCsByNameFromRegion("SPAWN", id, eRealm.None).FirstOrDefault(); if (spawn == null) continue; - _maps.Add(id, new Tuple(spawn, new GameLocation("Spawn", spawn))); + _maps.Add(id, new Tuple(spawn, spawn.Position)); } return (from m in _maps select m.Key); } diff --git a/GameServer/_scripts/AmteScripts/RvR/RvrManager.cs b/GameServer/_scripts/AmteScripts/RvR/RvrManager.cs index f04649ae..b77157b1 100644 --- a/GameServer/_scripts/AmteScripts/RvR/RvrManager.cs +++ b/GameServer/_scripts/AmteScripts/RvR/RvrManager.cs @@ -8,6 +8,7 @@ using DOL.Database; using DOL.Events; using DOL.GS; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using DOL.GS.ServerProperties; using DOL.Language; @@ -51,7 +52,7 @@ public class RvrManager private static DateTime _startTime = DateTime.Today.AddHours(23D).Add(TimeSpan.FromMinutes(5)); //20H00 private static DateTime _endTime = _startTime.Add(TimeSpan.FromMinutes(20)); //2H00 + 1 private const int _checkInterval = 30 * 1000; // 30 seconds - private static readonly GameLocation _stuckSpawn = new GameLocation("", 51, 434303, 493165, 3088, 1069); + private static readonly Position _stuckSpawn = Position.Create(51, 434303, 493165, 3088, 1069); private Dictionary> RvrStats = new Dictionary>(); private Dictionary Scores = new Dictionary(); private Dictionary kills = new Dictionary(); @@ -172,7 +173,7 @@ public void OnControlChange(string lordId, Guild guild) m.Realm = guild.Realm; }); map.RvRTerritory.Boss.Realm = guild.Realm; - AbstractGameKeep keep = GameServer.KeepManager.GetKeepCloseToSpot(map.RvRTerritory.RegionId, map.RvRTerritory.Boss.Position, 100000); + AbstractGameKeep keep = GameServer.KeepManager.GetKeepCloseToSpot(map.RvRTerritory.Boss.Position, 100000); keep.TempRealm = guild.Realm; keep.Reset(guild.Realm); keep.Guild = guild; @@ -186,7 +187,7 @@ public void OnControlChange(string lordId, Guild guild) public RvRTerritory GetRvRTerritory(ushort regionId) { - var map = this._maps.Values.FirstOrDefault(v => v.RvRTerritory != null && v.Location.RegionID.Equals(regionId)); + var map = this._maps.Values.FirstOrDefault(v => v.RvRTerritory != null && v.Position.RegionID.Equals(regionId)); if (map == null) { @@ -348,16 +349,16 @@ public IEnumerable InitMapsAndTerritories() // _maps.Add(name, map); //}); - _regions = _maps.Values.GroupBy(v => v.Location.RegionID).Select(v => v.Key).OrderBy(v => v); + _regions = _maps.Values.GroupBy(v => v.Position.RegionID).Select(v => v.Key).OrderBy(v => v); _regions.Foreach(r => this.RvrStats.Add(r, new string[] { })); - return from m in _maps select m.Value.Location.RegionID; + return from m in _maps select m.Value.Position.RegionID; } private RvRMap BuildRvRMap(GameNPC initNpc) { RvRTerritory rvrTerritory = null; - if (!_maps.Values.Any(v => v.Location.RegionID.Equals(initNpc.CurrentRegionID))) + if (!_maps.Values.Any(v => v.Position.RegionID.Equals(initNpc.CurrentRegionID))) { var lord = (LordRvR)(initNpc.CurrentRegion.Objects.FirstOrDefault(o => o is LordRvR)); @@ -369,12 +370,12 @@ private RvRMap BuildRvRMap(GameNPC initNpc) var areaName = string.IsNullOrEmpty(lord.GuildName) ? initNpc.Name : lord.GuildName; var area = new Area.Circle(areaName, lord.Position.X, lord.Position.Y, lord.Position.Z, RVR_RADIUS); - rvrTerritory = new RvRTerritory(lord.CurrentZone, new List{area}, area.Description, lord, area.Position, lord.CurrentRegionID, null); + rvrTerritory = new RvRTerritory(lord.CurrentZone, new List{area}, area.Description, lord, area.Coordinate, lord.CurrentRegionID, null); } return new RvRMap() { - Location = new GameLocation(initNpc.Name, initNpc.CurrentRegionID, initNpc.Position.X, initNpc.Position.Y, initNpc.Position.Z), + Position = initNpc.Position, RvRTerritory = rvrTerritory }; } @@ -610,7 +611,7 @@ public bool Close() m.RvRTerritory.Reset(); }); - this._maps.Values.GroupBy(v => v.Location.RegionID).ForEach(region => + this._maps.Values.GroupBy(v => v.Position.RegionID).ForEach(region => { var characters = GameServer.Database.SelectObjects(c => c.Region == +region.Key); foreach (DOLCharacters chr in characters) @@ -815,7 +816,7 @@ private bool AddPlayerToCorrectZone(GamePlayer player, string realm) // } //} - player.MoveTo(_maps[key].Location); + player.MoveTo(_maps[key].Position); player.Bind(true); return true; } @@ -922,7 +923,7 @@ public IList GetStatistics(GamePlayer player) long prHib = clients.Where(c => c.Player.Realm == eRealm.Hibernia).Sum(c => c.Player.Guild.RealmPoints); long prMid = clients.Where(c => c.Player.Realm == eRealm.Midgard).Sum(c => c.Player.Guild.RealmPoints); - var maps = this._maps.Values.Where(m => m.RvRTerritory != null && m.Location.RegionID.Equals(player.CurrentRegionID)); + var maps = this._maps.Values.Where(m => m.RvRTerritory != null && m.Position.RegionID.Equals(player.CurrentRegionID)); if (maps != null) { @@ -977,7 +978,7 @@ public bool IsAllowedToAttack(GameLiving attacker, GameLiving defender, bool qui public bool IsRvRRegion(ushort id) { - return _maps.Values.Any(v => v.Location.RegionID.Equals(id)); + return _maps.Values.Any(v => v.Position.RegionID.Equals(id)); } private static void _MessageToLiving(GameLiving living, string message) @@ -990,6 +991,6 @@ private static void _MessageToLiving(GameLiving living, string message) public class RvRMap { public RvRTerritory RvRTerritory { get; set; } - public GameLocation Location { get; set; } + public Position Position { get; set; } } } diff --git a/GameServer/_scripts/AmteScripts/SpecialItems/FeuArtificeItem.cs b/GameServer/_scripts/AmteScripts/SpecialItems/FeuArtificeItem.cs index 1b59e479..1570d1e7 100644 --- a/GameServer/_scripts/AmteScripts/SpecialItems/FeuArtificeItem.cs +++ b/GameServer/_scripts/AmteScripts/SpecialItems/FeuArtificeItem.cs @@ -14,6 +14,7 @@ using DOL.Database; using DOL.Events; using DOL.Language; +using Vector = DOL.GS.Geometry.Vector; namespace DOL.GS.Scripts { @@ -158,7 +159,7 @@ private static Dictionary CreateMobs(GameObject obj) Level = 1, Model = 1, Realm = 0, - Position = obj.Position + new Vector3(0, 0, 800), + Position = obj.Position + Vector.Create(0, 0, 800), CurrentRegion = obj.CurrentRegion }; @@ -171,26 +172,26 @@ private static Dictionary CreateMobs(GameObject obj) //Pyramide: //Base - mobs[2].Position += new Vector3(250, 250, 0); - mobs[3].Position += new Vector3(250, 0, 0); - mobs[4].Position += new Vector3(250, -250, 0); - mobs[5].Position += new Vector3(0, -250, 0); - mobs[6].Position -= new Vector3(250, 250, 0); - mobs[7].Position -= new Vector3(250, 0, 0); - mobs[8].Position += new Vector3(-250, 250, 0); - mobs[9].Position += new Vector3(0, 250, 0); + mobs[2].Position += Vector.Create(250, 250, 0); + mobs[3].Position += Vector.Create(250, 0, 0); + mobs[4].Position += Vector.Create(250, -250, 0); + mobs[5].Position += Vector.Create(0, -250, 0); + mobs[6].Position -= Vector.Create(250, 250, 0); + mobs[7].Position -= Vector.Create(250, 0, 0); + mobs[8].Position += Vector.Create(-250, 250, 0); + mobs[9].Position += Vector.Create(0, 250, 0); //2e étage - mobs[10].Position += new Vector3(+125, +125, 250); - mobs[11].Position += new Vector3(+125, -125, 250); - mobs[12].Position += new Vector3(-125, -125, 250); - mobs[13].Position += new Vector3(-125, +125, 250); + mobs[10].Position += Vector.Create(+125, +125, 250); + mobs[11].Position += Vector.Create(+125, -125, 250); + mobs[12].Position += Vector.Create(-125, -125, 250); + mobs[13].Position += Vector.Create(-125, +125, 250); - mobs[14].Position += new Vector3(0, 0, 250); + mobs[14].Position += Vector.Create(0, 0, 250); mobs[14].Size = 75; //Sommet - mobs[15].Position += new Vector3(0, 0, 500); + mobs[15].Position += Vector.Create(0, 0, 500); mobs[15].Size = 100; foreach (KeyValuePair mob in mobs) diff --git a/GameServer/_scripts/AmteScripts/Spells/GuarksTeleport.cs b/GameServer/_scripts/AmteScripts/Spells/GuarksTeleport.cs index 1529ee9b..b997349b 100644 --- a/GameServer/_scripts/AmteScripts/Spells/GuarksTeleport.cs +++ b/GameServer/_scripts/AmteScripts/Spells/GuarksTeleport.cs @@ -22,7 +22,6 @@ using DOL.Language; using DOL.GS.PacketHandler; using AmteScripts.Managers; -using DOL.Language; namespace DOL.GS.Spells { diff --git a/GameServer/behaviour/Actions/MoveToAction.cs b/GameServer/behaviour/Actions/MoveToAction.cs index 0dd0adde..479faebd 100644 --- a/GameServer/behaviour/Actions/MoveToAction.cs +++ b/GameServer/behaviour/Actions/MoveToAction.cs @@ -23,27 +23,28 @@ using DOL.Events; using DOL.GS.Behaviour.Attributes; using DOL.GS.Behaviour; +using DOL.GS.Geometry; namespace DOL.GS.Behaviour.Actions { [ActionAttribute(ActionType = eActionType.MoveTo)] - public class MoveToAction : AbstractAction + public class MoveToAction : AbstractAction { public MoveToAction(GameNPC defaultNPC, Object p, Object q) : base(defaultNPC, eActionType.MoveTo, p, q) { } - public MoveToAction(GameNPC defaultNPC, GameLocation location, GameLiving npc) - : this(defaultNPC, (object)location, (object)npc) { } + public MoveToAction(GameNPC defaultNPC, Position position, GameLiving npc) + : this(defaultNPC, (object)position, (object)npc) { } public override void Perform(DOLEvent e, object sender, EventArgs args) { GameLiving npc = Q; - if (P is GameLocation location) + if (P is Position position) { - npc.MoveTo(location.Position); + npc.MoveTo(position); } else { diff --git a/GameServer/behaviour/Actions/TeleportAction.cs b/GameServer/behaviour/Actions/TeleportAction.cs index f922ec1b..01c1b13f 100644 --- a/GameServer/behaviour/Actions/TeleportAction.cs +++ b/GameServer/behaviour/Actions/TeleportAction.cs @@ -16,6 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ +using DOL.Database; using System; using System.Collections.Generic; using System.Text; @@ -29,7 +30,7 @@ namespace DOL.GS.Behaviour.Actions { [ActionAttribute(ActionType = eActionType.Teleport, DefaultValueQ = 0)] - public class TeleportAction : AbstractAction + public class TeleportAction : AbstractAction { public TeleportAction(GameNPC defaultNPC, Object p, Object q) @@ -38,7 +39,7 @@ public TeleportAction(GameNPC defaultNPC, Object p, Object q) } - public TeleportAction(GameNPC defaultNPC, GameLocation location, int fuzzyRadius) + public TeleportAction(GameNPC defaultNPC, Teleport location, int fuzzyRadius) : this(defaultNPC, (object)location, (object)fuzzyRadius) { } @@ -46,16 +47,16 @@ public TeleportAction(GameNPC defaultNPC, GameLocation location, int fuzzyRadius public override void Perform(DOLEvent e, object sender, EventArgs args) { GamePlayer player = BehaviourUtils.GuessGamePlayerFromNotify(e, sender, args); - GameLocation location = P; + Teleport location = P; int radius = Q; - if (location.Name != null) + if (location.TeleportID != null) { - player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Behaviour.TeleportAction.TeleportedToLoc", player, location.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); + player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Behaviour.TeleportAction.TeleportedToLoc", player, location.TeleportID), eChatType.CT_System, eChatLoc.CL_SystemWindow); } var randomOffset = Vector.Create(x: Util.Random(-radius, radius), y: Util.Random(-radius, radius)); - player.MoveTo(location.Position + randomOffset); + player.MoveTo(location.GetPosition() + randomOffset); } } } diff --git a/GameServer/commands/gmcommands/GMTerritories.cs b/GameServer/commands/gmcommands/GMTerritories.cs index 7420c68c..852d711e 100644 --- a/GameServer/commands/gmcommands/GMTerritories.cs +++ b/GameServer/commands/gmcommands/GMTerritories.cs @@ -3,6 +3,7 @@ using DOL.Geometry; using DOL.GS; using DOL.GS.Commands; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using DOL.Language; using DOL.MobGroups; @@ -409,12 +410,12 @@ public void OnCommand(GameClient client, string[] args) return; } } - Vector3 position; + Coordinate position; if (args.Length > arg) { if (string.Equals(args[arg], "remove")) { - territory.PortalPosition = null; + territory.PortalCoordinate = null; client.SendTranslation("Commands.GM.GMTerritories.PortalRemoved", eChatType.CT_System, eChatLoc.CL_SystemWindow, territory.Name); return; } @@ -438,14 +439,13 @@ public void OnCommand(GameClient client, string[] args) client.SendTranslation("Commands.GM.GMTerritories.BadCoordinate", eChatType.CT_System, eChatLoc.CL_SystemWindow, args[arg + 2]); return; } - position = new Vector3(x, y, z); + position = Coordinate.Create(x, y, z); } else { - var playerPosition = client.Player.Position; - position = new Vector3((int)playerPosition.X, (int)playerPosition.Y, (int)playerPosition.Z); + position = client.Player.Coordinate; } - territory.PortalPosition = position; + territory.PortalCoordinate = position; territory.SaveIntoDatabase(); client.SendTranslation("Commands.GM.GMTerritories.PortalSet", eChatType.CT_System, eChatLoc.CL_SystemWindow, territory.Name, position.X, position.Y, position.Z); } diff --git a/GameServer/commands/gmcommands/Instance.cs b/GameServer/commands/gmcommands/Instance.cs index 6915d9c2..a1e60c64 100644 --- a/GameServer/commands/gmcommands/Instance.cs +++ b/GameServer/commands/gmcommands/Instance.cs @@ -306,8 +306,7 @@ public void OnCommand(GameClient client, string[] args) } // save current position for use with /instance exit - GameLocation saveLocation = new GameLocation(player.Name + "_exit", player.CurrentRegionID, player.Position, player.Heading); - player.TempProperties.setProperty(saveLocation.Name, saveLocation); + player.TempProperties.setProperty(player.Name + "_exit", player.Position); bool success = true; diff --git a/GameServer/commands/gmcommands/KeepComponent.cs b/GameServer/commands/gmcommands/KeepComponent.cs index db2f6881..2c6018dc 100644 --- a/GameServer/commands/gmcommands/KeepComponent.cs +++ b/GameServer/commands/gmcommands/KeepComponent.cs @@ -166,14 +166,8 @@ so must find an other way to find it.... .With(Angle.Heading(component.ComponentHeading * 1024) + myKeep.Orientation); component.ComponentHeading = (client.Player.Orientation - myKeep.Orientation).InDegrees / 90; component.Keep = myKeep; - //todo good formula - //component.ComponentX = (component.X - myKeep.X) / 148; - //component.ComponentY = (myKeep.Y - component.Y) / 148; - - //component.ComponentX = (int)((148 * Math.Sin(angle) * myKeep.X - 148 * Math.Sin(angle) * client.Player.X + client.Player.Y - myKeep.Y) - // / (148 * Math.Sin(angle) - 148 * 148 * 2 * Math.Sin(angle) * Math.Cos(angle))); - //component.ComponentY = (int)((myKeep.Y - client.Player.Y + 148 * Math.Sin(angle) * component.ComponentX) / (148 * Math.Cos(angle))); - + + var angle = myKeep.Orientation.InRadians; component.ComponentX = CalcCX(client.Player, myKeep, angle); component.ComponentY = CalcCY(client.Player, myKeep, angle); @@ -357,5 +351,4 @@ public int CalcCY(GamePlayer player, AbstractGameKeep myKeep, double angle) } } } - } -} \ No newline at end of file +} diff --git a/GameServer/commands/gmcommands/earthquake.cs b/GameServer/commands/gmcommands/earthquake.cs index 4b5e26bd..605119e8 100644 --- a/GameServer/commands/gmcommands/earthquake.cs +++ b/GameServer/commands/gmcommands/earthquake.cs @@ -2,6 +2,7 @@ using DOL.GS.PacketHandler; using DOL.GS.Commands; using DOL.Geometry; +using DOL.GS.Geometry; using DOL.Language; namespace DOL.GS.Scripts @@ -31,7 +32,7 @@ public void OnCommand(GameClient client, string[] args) } else { - var tempGroundTarget = client.Player.GroundTarget ?? System.Numerics.Vector3.Zero;// as System.Numerics.Vector3; + var tempGroundTarget = client.Player.GroundTargetPosition;// as System.Numerics.Vector3; x = (int)tempGroundTarget.X; y = (int)tempGroundTarget.Y; z = (int)tempGroundTarget.Z; @@ -97,7 +98,7 @@ public void OnCommand(GameClient client, string[] args) pakBis.WriteIntLowEndian((uint)y); pakBis.WriteIntLowEndian((uint)z); pakBis.Write(BitConverter.GetBytes(radius), 0, sizeof(System.Single)); - int distance = (int)System.Numerics.(int)player.Coordinate.DistanceTo(client.Player.Position); + int distance = (int)player.Coordinate.DistanceTo(client.Player.Position); float newIntensity = intensity * (1 - distance / radius); pakBis.Write(BitConverter.GetBytes(newIntensity), 0, sizeof(System.Single)); pakBis.Write(BitConverter.GetBytes(duration), 0, sizeof(System.Single)); diff --git a/GameServer/commands/gmcommands/jump.cs b/GameServer/commands/gmcommands/jump.cs index c127ea96..80dae7ea 100644 --- a/GameServer/commands/gmcommands/jump.cs +++ b/GameServer/commands/gmcommands/jump.cs @@ -344,7 +344,7 @@ public void OnCommand(GameClient client, string[] args) { Stack positions; - positions = client.Player.TempProperties.getProperty(TEMP_KEY_JUMP, null) as Stack; + positions = client.Player.TempProperties.getProperty(TEMP_KEY_JUMP, null) as Stack; if (positions == null) { diff --git a/GameServer/commands/gmcommands/keep.cs b/GameServer/commands/gmcommands/keep.cs index c1f1895b..38d3692a 100644 --- a/GameServer/commands/gmcommands/keep.cs +++ b/GameServer/commands/gmcommands/keep.cs @@ -18,6 +18,7 @@ */ using System; using DOL.Database; +using DOL.GS.Geometry; using DOL.GS.Keeps; using DOL.Language; @@ -93,7 +94,7 @@ public void OnCommand(GameClient client, string[] args) AbstractGameKeep myKeep = (AbstractGameKeep)client.Player.TempProperties.getProperty(TEMP_KEEP_LAST, null); if (myKeep == null) myKeep = (client.Player.TargetObject as GameKeepComponent)?.Keep; - if (myKeep == null) myKeep = GameServer.KeepManager.GetKeepCloseToSpot(client.Player.CurrentRegionID, client.Player, 10000); + if (myKeep == null) myKeep = GameServer.KeepManager.GetKeepCloseToSpot(client.Player.Position, 10000); switch (args[1]) diff --git a/GameServer/commands/gmcommands/mob.cs b/GameServer/commands/gmcommands/mob.cs index a1d34b73..5f7fb3a4 100644 --- a/GameServer/commands/gmcommands/mob.cs +++ b/GameServer/commands/gmcommands/mob.cs @@ -1436,7 +1436,7 @@ private void info(GameClient client, GameNPC targetMob, string[] args) info.Add(" "); - info.Add(" + Position (X, Y, Z, H): " + targetMob.Position.ToString("F0") + ", " + targetMob.Heading); + info.Add(" + Position (X, Y, Z, H): " + targetMob.Position); if (targetMob.GuildName != null && targetMob.GuildName.Length > 0) info.Add(" + Guild: " + targetMob.GuildName); diff --git a/GameServer/commands/gmcommands/tppoint.cs b/GameServer/commands/gmcommands/tppoint.cs index 21b30297..b1625790 100644 --- a/GameServer/commands/gmcommands/tppoint.cs +++ b/GameServer/commands/gmcommands/tppoint.cs @@ -19,6 +19,7 @@ using System; using System.Collections; using DOL.Database; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using DOL.Language; @@ -47,9 +48,7 @@ private void CreateTempTPPointObject(GameClient client, TPPoint pp, string name) GameStaticItem obj = new GameStaticItem(); // Fill the object variables - obj.Position = new System.Numerics.Vector3((float)pp.Position.X, (float)pp.Position.Y, (float)pp.Position.Z + 1);// raise a bit off of ground level - obj.CurrentRegion = client.Player.CurrentRegion; - obj.Heading = client.Player.Heading; + obj.Position = Position.Create(pp.Region, pp.Position.X, pp.Position.Y, pp.Position.Z + 1);// raise a bit off of ground level obj.Name = name; obj.Model = 488; obj.Emblem = 0; diff --git a/GameServer/commands/gmcommands/xmob.cs b/GameServer/commands/gmcommands/xmob.cs index 2b007d23..1189b1c4 100644 --- a/GameServer/commands/gmcommands/xmob.cs +++ b/GameServer/commands/gmcommands/xmob.cs @@ -3,6 +3,7 @@ using System.Reflection; using DOL.AI; using DOL.AI.Brain; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; namespace DOL.GS.Commands @@ -232,14 +233,14 @@ public void OnCommand(GameClient client, string[] args) for (int i = 0; i < setupmobs.Count / 2; i++) { ushort h = (ushort)(4096 / (setupmobs.Count / 2) * i); - System.Numerics.Vector2 loc = client.Player.GetPointFromHeading(h, 150); + var loc = client.Player.GetPointFromHeading(h, 150); spawnsetupmob(client, setupmobs[i], realm, (int)loc.X, (int)loc.Y, h); } for (int i = setupmobs.Count / 2; i < setupmobs.Count; i++) { ushort h = (ushort)(4096 / (setupmobs.Count - setupmobs.Count / 2) * i); - System.Numerics.Vector2 loc = client.Player.GetPointFromHeading(h, 250); + var loc = client.Player.GetPointFromHeading(h, 250); spawnsetupmob(client, setupmobs[i], realm, (int)loc.X, (int)loc.Y, h); } client.Out.SendMessage(setupmobs.Count + " setup mob spawned!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); @@ -295,9 +296,7 @@ public void OnCommand(GameClient client, string[] args) mob.LoadTemplate(targetMob.NPCTemplate); //Fill the object variables - mob.Position = new System.Numerics.Vector3(Util.Random((int)client.Player.Position.X - 250 / 2, (int)client.Player.Position.X + 250 / 2), Util.Random((int)client.Player.Position.Y - 250 / 2, (int)client.Player.Position.Y + 250 / 2), client.Player.Position.Z); - mob.CurrentRegion = client.Player.CurrentRegion; - mob.Heading = (ushort)Util.Random(1, 4100); + mob.Position = client.Player.Position.With(Angle.Heading(Util.Random(1, 4100))) + Vector.Create(Util.Random(-250, 250), Util.Random(-250, 250), Util.Random(-250, 250)); mob.Level = targetMob.Level; mob.Realm = targetMob.Realm; mob.Name = targetMob.Name; @@ -522,10 +521,8 @@ public void OnCommand(GameClient client, string[] args) private void spawnsetupmob(GameClient client, GameNPC mob, eRealm realm, int x, int y, ushort h) { //Fill the object variables - mob.Position = new System.Numerics.Vector3(x, y, client.Player.Position.Z); - mob.Heading = h; + mob.Position = client.Player.Position.With(null, x, y); - mob.CurrentRegion = client.Player.CurrentRegion; mob.Level = 50; if (mob is GameTrainingDummy) mob.Realm = eRealm.None; @@ -567,9 +564,7 @@ private void copy(GameClient client, GameNPC targetMob, ushort radius) mob.LoadTemplate(targetMob.NPCTemplate); //Fill the object variables - mob.Position = new System.Numerics.Vector3(Util.Random((int)client.Player.Position.X - radius, (int)client.Player.Position.X + radius), Util.Random((int)client.Player.Position.Y - radius, (int)client.Player.Position.Y + radius), client.Player.Position.Z); - mob.CurrentRegion = client.Player.CurrentRegion; - mob.Heading = (ushort)Util.Random(1, 4100); + mob.Position = client.Player.Position.With(Angle.Heading(Util.Random(1, 4100))) + Vector.Create(Util.Random(-250, 250), Util.Random(-250, 250), Util.Random(-250, 250)); mob.Level = targetMob.Level; mob.Realm = targetMob.Realm; mob.Name = targetMob.Name; @@ -655,10 +650,7 @@ private void remove(GameNPC targetMob) private void move(GameClient client, GameNPC targetMob, ushort radius) { - - int X = Util.Random((int)client.Player.Position.X - radius / 2, (int)client.Player.Position.X + radius / 2); - int Y = Util.Random((int)client.Player.Position.Y - radius / 2, (int)client.Player.Position.Y + radius / 2); - targetMob.MoveTo(client.Player.CurrentRegionID, X, Y, client.Player.Position.Z, (ushort)Util.Random(1, 4100)); + targetMob.MoveTo(client.Player.Position.With(Angle.Heading(Util.Random(1, 4100))) + Vector.Create(Util.Random(-radius, radius), Util.Random(-radius, radius), Util.Random(-radius, radius))); targetMob.SaveIntoDatabase(); } diff --git a/GameServer/commands/playercommands/guild.cs b/GameServer/commands/playercommands/guild.cs index bcc4df50..bd5cd2ca 100644 --- a/GameServer/commands/playercommands/guild.cs +++ b/GameServer/commands/playercommands/guild.cs @@ -1842,7 +1842,7 @@ double GetBuffBonusPercentage(Guild guild) return; } - if (territory.PortalPosition == null) + if (territory.PortalCoordinate == null) { client.SendTranslation("Commands.Players.Guild.TerritoryPortal.NotSupported"); return; @@ -2054,7 +2054,7 @@ double GetBuffBonusPercentage(Guild guild) return; } - if (!target.MoveTo(player.CurrentRegionID, player.Position, player.Heading)) + if (!target.MoveTo(player.Position)) { player.SendTranslatedMessage("Commands.Players.Guild.MoveDefender.BadPosition", eChatType.CT_System, eChatLoc.CL_SystemWindow); } @@ -2135,7 +2135,7 @@ double GetBuffBonusPercentage(Guild guild) if (Properties.GUILD_COMBAT_ZONE_DISTANCE_FROM_AREAS > 0) { - AbstractArea closeArea = (AbstractArea)region.FindAnyAreaInRadius(player.Position, Properties.GUILD_COMBAT_ZONE_DISTANCE_FROM_AREAS, true); + AbstractArea closeArea = (AbstractArea)region.FindAnyAreaInRadius(player.Coordinate, Properties.GUILD_COMBAT_ZONE_DISTANCE_FROM_AREAS, true); if (closeArea != null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Commands.Players.Guild.CombatZone.TooCloseToArea", closeArea.GetDescriptionForPlayer(player)), eChatType.CT_System, eChatLoc.CL_SystemWindow); @@ -3323,7 +3323,7 @@ double GetBuffBonusPercentage(Guild guild) client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Commands.Players.Guild.NotMember"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } - AbstractGameKeep keep = GameServer.KeepManager.GetKeepCloseToSpot(client.Player.CurrentRegionID, client.Player.Position, WorldMgr.VISIBILITY_DISTANCE); + AbstractGameKeep keep = GameServer.KeepManager.GetKeepCloseToSpot(client.Player.Position, WorldMgr.VISIBILITY_DISTANCE); if (keep == null) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Commands.Players.Guild.ClaimNotNear"), eChatType.CT_System, eChatLoc.CL_SystemWindow); diff --git a/GameServer/commands/playercommands/range.cs b/GameServer/commands/playercommands/range.cs index 12844c36..461403bd 100644 --- a/GameServer/commands/playercommands/range.cs +++ b/GameServer/commands/playercommands/range.cs @@ -42,7 +42,7 @@ public void OnCommand(GameClient client, string[] args) "Commands.Players.Range.NeedTarget")); else if (living == null || (living != null && client.Account.PrivLevel > 1)) { - var range = client.Player.GetDistanceTo(client.Player.TargetObject.Position); + var range = client.Player.GetDistanceTo(client.Player.TargetObject); DisplayMessage( client, LanguageMgr.GetTranslation( diff --git a/GameServer/gameobjects/CustomNPC/GameBoatStableMaster.cs b/GameServer/gameobjects/CustomNPC/GameBoatStableMaster.cs index f176b36a..b5674711 100644 --- a/GameServer/gameobjects/CustomNPC/GameBoatStableMaster.cs +++ b/GameServer/gameobjects/CustomNPC/GameBoatStableMaster.cs @@ -26,6 +26,7 @@ using DOL.GS.PacketHandler; using log4net; using DOL.GS.Finance; +using DOL.GS.Geometry; namespace DOL.GS { diff --git a/GameServer/gameobjects/CustomNPC/GameStableMaster.cs b/GameServer/gameobjects/CustomNPC/GameStableMaster.cs index d64148aa..c90d7685 100644 --- a/GameServer/gameobjects/CustomNPC/GameStableMaster.cs +++ b/GameServer/gameobjects/CustomNPC/GameStableMaster.cs @@ -27,6 +27,7 @@ using log4net; using System.Linq; using DOL.GS.Finance; +using DOL.GS.Geometry; namespace DOL.GS { diff --git a/GameServer/gameobjects/CustomNPC/GuildPortalNPC.cs b/GameServer/gameobjects/CustomNPC/GuildPortalNPC.cs index 4873e70a..18b55bbf 100644 --- a/GameServer/gameobjects/CustomNPC/GuildPortalNPC.cs +++ b/GameServer/gameobjects/CustomNPC/GuildPortalNPC.cs @@ -10,21 +10,19 @@ using log4net; using DOL.GS.Spells; using DOL.Territories; -using System.Numerics; +using DOL.GS.Geometry; namespace DOL.GS { public class GuildPortalNPC : GameNPC { - public readonly record struct SavedCoordinates(ushort RegionID, Vector3 Position, ushort Heading); - public Guild OwningGuild { get; init; } public Territories.Territory LinkedTerritory { get; init; } private readonly object m_coordinatesLockObject = new(); - private Dictionary m_savedCoordinates = new(); + private readonly Dictionary m_savedCoordinates = new(); private GuildPortalNPC(Territories.Territory territory, GamePlayer spawner) : base() { @@ -36,7 +34,7 @@ public static GuildPortalNPC Create(Territories.Territory territory, GamePlayer { GuildPortalNPC portalNpc = new GuildPortalNPC(territory, spawner); portalNpc.LoadedFromScript = true; - portalNpc.Position = territory.PortalPosition.Value; + portalNpc.Position = Position.Create(territory.RegionId, territory.PortalCoordinate.Value, Angle.Zero); portalNpc.CurrentRegionID = territory.RegionId; portalNpc.Heading = 1000; portalNpc.Model = 1438; @@ -54,7 +52,7 @@ public void SummonPlayer(GamePlayer player) pl.Out.SendSpellEffectAnimation(player, player, 4310, 0, false, 1); lock (m_coordinatesLockObject) { - m_savedCoordinates.TryAdd(player, new SavedCoordinates(player.CurrentRegionID, player.Position, player.Heading)); + m_savedCoordinates.TryAdd(player, player.Position); } player.MoveTo(CurrentRegionID, Position.X, Position.Y, Position.Z, Heading); player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Commands.Players.Guild.TerritoryPortal.Summoned", LinkedTerritory.Name), eChatType.CT_System, eChatLoc.CL_SystemWindow); @@ -62,7 +60,7 @@ public void SummonPlayer(GamePlayer player) public override bool Interact(GamePlayer player) { - SavedCoordinates returnCoordinates; + Position returnCoordinates; lock (m_coordinatesLockObject) { @@ -73,7 +71,7 @@ public override bool Interact(GamePlayer player) } foreach (GamePlayer pl in player.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) pl.Out.SendSpellEffectAnimation(player, player, 4310, 0, false, 1); - player.MoveTo(returnCoordinates.RegionID, returnCoordinates.Position.X, returnCoordinates.Position.Y, returnCoordinates.Position.Z, returnCoordinates.Heading); + player.MoveTo(returnCoordinates); return true; } } diff --git a/GameServer/gameobjects/CustomNPC/ShadowNPC.cs b/GameServer/gameobjects/CustomNPC/ShadowNPC.cs index d70ff1b5..7af60746 100644 --- a/GameServer/gameobjects/CustomNPC/ShadowNPC.cs +++ b/GameServer/gameobjects/CustomNPC/ShadowNPC.cs @@ -4,13 +4,13 @@ using DOL.Events; using DOL.Geometry; using DOL.GS; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using DOL.Language; using DOLDatabase.Tables; using System; using System.Collections.Generic; using System.Linq; -using System.Numerics; using System.Text; using System.Threading.Tasks; @@ -60,18 +60,16 @@ public ShadowNPC(GamePlayer player) : base() this.player = player; IControlledBrain brain = new ShadowBrain(player); SetOwnBrain(brain as AI.ABrain); - int x, y, z; - ushort heading; - Region region; - - GetPlayerLocation(out x, out y, out z, out heading, out region); - - Position = new System.Numerics.Vector3(x, y, z); - Heading = heading; - CurrentRegion = region; AddToWorld(); } + /// + public override bool AddToWorld() + { + Position = GetPlayerPosition(); + return base.AddToWorld(); + } + public override string Name { get => "Combine List"; set => base.Name = value; } public string KeyWord { @@ -244,25 +242,15 @@ private string BuildList(string title) return result; } - protected virtual void GetPlayerLocation(out int x, out int y, out int z, out ushort heading, out Region region) + protected virtual Position GetPlayerPosition() { - Vector2 point = player.GetPointFromHeading(player.Heading, 64); - x = (int)point.X; - y = (int)point.Y; - z = (int)player.Position.Z; - heading = (ushort)((player.Heading + 2048) % 4096); - region = player.CurrentRegion; + var point = player.GetPointFromHeading(player.Orientation.InHeading, 64); + return Position.Create(player.Position.RegionID, point.X, point.Y, player.Position.Z, player.Orientation.InHeading).TurnedAround(); } public virtual void MoveToPlayer() { - int x, y, z; - ushort heading; - Region region; - - GetPlayerLocation(out x, out y, out z, out heading, out region); - - MoveTo(region.ID, x, y, z, heading); + MoveTo(GetPlayerPosition()); } public void Interact(string message) diff --git a/GameServer/gameobjects/FeuDeCamp.cs b/GameServer/gameobjects/FeuDeCamp.cs index 4af12e45..e89941ba 100644 --- a/GameServer/gameobjects/FeuDeCamp.cs +++ b/GameServer/gameobjects/FeuDeCamp.cs @@ -140,10 +140,8 @@ public override bool AddToWorld() m_RealFeu = new GameStaticItem(); m_RealFeu.Name = Name = "Feu de Camp"; - m_RealFeu.Position = new System.Numerics.Vector3(Position.X, Position.Y, Position.Z); + m_RealFeu.Position = Position; m_RealFeu.Model = Model; - m_RealFeu.CurrentRegion = CurrentRegion; - m_RealFeu.Heading = Heading; m_RealFeu.AddToWorld(); @@ -156,7 +154,7 @@ void ProximityCheck(object sender, ElapsedEventArgs e) { - foreach (GamePlayer Player in WorldMgr.GetPlayersCloseToSpot(this.Position.X, this.Position.Y, this.Position.Z, Radius)) + foreach (GamePlayer Player in WorldMgr.GetPlayersCloseToSpot(this.Position, Radius)) { if (Player.IsSitting) { @@ -301,12 +299,10 @@ public static void EventPlayerDropItem(DOLEvent e, object sender, ManaTrapDamagePercent = Feu.ManaTrapDamagePercent, HealthTrapDamagePercent = Feu.HealthTrapDamagePercent, IsEnduranceType = Feu.IsEnduranceType, - HealthPercentRate = Feu.HealthPercentRate + HealthPercentRate = Feu.HealthPercentRate, + Position = Player.Position }; - firecamp.Position = new System.Numerics.Vector3(Player.Position.X, Player.Position.Y, Player.Position.Z); - firecamp.CurrentRegion = Player.CurrentRegion; - firecamp.Heading = Player.Heading; firecamp.AddToWorld(); Args.GroundItem.Delete(); diff --git a/GameServer/gameobjects/GameHouseVault.cs b/GameServer/gameobjects/GameHouseVault.cs index 780e6406..6f7cb409 100644 --- a/GameServer/gameobjects/GameHouseVault.cs +++ b/GameServer/gameobjects/GameHouseVault.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using DOL.Database; using DOL.GS.Housing; +using DOL.GS.Geometry; namespace DOL.GS { diff --git a/GameServer/gameobjects/GameLiving.cs b/GameServer/gameobjects/GameLiving.cs index 8288731d..c663dff5 100644 --- a/GameServer/gameobjects/GameLiving.cs +++ b/GameServer/gameobjects/GameLiving.cs @@ -2518,7 +2518,7 @@ protected override void OnTick() } } - ticksToTarget = 1 + owner.GetDistanceTo( attackTarget ) * 100 / 150; // 150 units per 1/10s + ticksToTarget = (int)(1 + owner.GetDistanceTo( attackTarget ) * 100 / 150); // 150 units per 1/10s } else { diff --git a/GameServer/gameobjects/GameObject.cs b/GameServer/gameobjects/GameObject.cs index 92973c37..e55abd46 100644 --- a/GameServer/gameobjects/GameObject.cs +++ b/GameServer/gameobjects/GameObject.cs @@ -312,8 +312,9 @@ public virtual IList CurrentAreas { get { - return CurrentZone?.GetAreasOfSpot(Coordinate) ?? new List(); + return CurrentZone?.GetAreasOfSpot(Coordinate) ?? new List(); } + set { } } diff --git a/GameServer/gameobjects/GamePlayer.cs b/GameServer/gameobjects/GamePlayer.cs index bdec086e..d3cf8ecd 100644 --- a/GameServer/gameobjects/GamePlayer.cs +++ b/GameServer/gameobjects/GamePlayer.cs @@ -1750,7 +1750,6 @@ public virtual void Release(eReleaseType releaseCommand, bool forced) { if (BindRegion != 163) { - relRegion = 163; switch (Realm) { case eRealm.Albion: @@ -1869,7 +1868,7 @@ public virtual void Release(eReleaseType releaseCommand, bool forced) int oldRegion = CurrentRegionID; - if (oldRegion != relRegion) + if (oldRegion != releasePosition.RegionID) { Out.SendPlayerRevive(this); Out.SendUpdatePoints(); @@ -10953,8 +10952,6 @@ public override bool MoveTo(Position position) IsJumping = true; } bool hasPetToMove = false; - //Remove the last update tick property, to prevent speedhack messages during zoning and teleporting! - LastPositionUpdateTick = 0; if (ControlledBrain != null && ControlledBrain.WalkState != eWalkState.Stay) { @@ -10966,7 +10963,6 @@ public override bool MoveTo(Position position) //Set the new destination //Current Speed = 0 when moved ... else X,Y,Z continue to be modified CurrentSpeed = 0; - MovementStartTick = GameTimer.GetTickCount(); Position = position; //Remove the last update tick property, to prevent speedhack messages during zoning and teleporting! @@ -10974,9 +10970,6 @@ public override bool MoveTo(Position position) //If the destination is in another region if (position.RegionID != positionBeforePort.RegionID) { - //Set our new region - CurrentRegionID = regionID; - //Send the region update packet, the rest will be handled //by the packethandlers Out.SendRegionChanged(); @@ -13536,11 +13529,6 @@ public override void SaveIntoDatabase() lock (LastUniquePositions) { DBCharacter.SetPosition(LastUniquePositions[LastUniquePositions.Length - 1]); - DBCharacter.Xpos = (int)loc.Position.X; - DBCharacter.Ypos = (int)loc.Position.Y; - DBCharacter.Zpos = (int)loc.Position.Z; - DBCharacter.Region = loc.RegionID; - DBCharacter.Direction = loc.Heading; } } GameServer.Database.SaveObject(DBCharacter); diff --git a/GameServer/gameobjects/Spawner.cs b/GameServer/gameobjects/Spawner.cs index 647e1f72..5aa85f6d 100644 --- a/GameServer/gameobjects/Spawner.cs +++ b/GameServer/gameobjects/Spawner.cs @@ -1,6 +1,7 @@ using DOL.AI.Brain; using DOL.Database; using DOL.Events; +using DOL.GS.Geometry; using DOL.GS.Styles; using DOL.MobGroups; using DOLDatabase.Tables; @@ -359,12 +360,8 @@ private void InstanciateMobs() private void SetCircularPosition(GameNPC npc, int index, int total, float distance) { double angle = (Math.PI * 2 * index) / total; - float xOffset = (float)Math.Cos(angle) * distance; - float yOffset = (float)Math.Sin(angle) * distance; - npc.Position = new System.Numerics.Vector3(Position.X + xOffset, Position.Y + yOffset, Position.Z); - npc.Heading = Heading; - npc.CurrentRegion = WorldMgr.GetRegion(CurrentRegionID); + npc.Position = Position + Vector.Create(Angle.Radians(angle), distance); npc.LoadedFromScript = true; npc.AddToWorld(); npc.OwnerID = InternalID; diff --git a/GameServer/gameutils/GameMath.cs b/GameServer/gameutils/GameMath.cs index 8fb650ae..e714b055 100644 --- a/GameServer/gameutils/GameMath.cs +++ b/GameServer/gameutils/GameMath.cs @@ -1,11 +1,14 @@ using System; using DOL.GS; using DOL.GS.Geometry; +using System.Numerics; namespace DOL { public static class GameMath { + public static Vector2 ToVector2(this Vector3 v) => new Vector2(v.X, v.Y); + /// /// The factor to convert a heading value to radians /// diff --git a/GameServer/gameutils/TPPoint.cs b/GameServer/gameutils/TPPoint.cs index ab07e6db..dd5edeb4 100644 --- a/GameServer/gameutils/TPPoint.cs +++ b/GameServer/gameutils/TPPoint.cs @@ -95,7 +95,7 @@ public eTPPointType Type } public DBTPPoint DbTPPoint { get => dbTPPoint; set => dbTPPoint = value; } - public ushort Region { get => region; set => region = value; } + public ushort Region { get => Position.RegionID; } public TPPoint GetNextTPPoint() { diff --git a/GameServer/quests/JsonQuests/Goals/BringAFriendGoal.cs b/GameServer/quests/JsonQuests/Goals/BringAFriendGoal.cs index 789f7d5f..651a74d9 100644 --- a/GameServer/quests/JsonQuests/Goals/BringAFriendGoal.cs +++ b/GameServer/quests/JsonQuests/Goals/BringAFriendGoal.cs @@ -2,6 +2,7 @@ using DOL.Events; using DOL.MobGroups; using DOL.GS.Behaviour; +using DOL.GS.Geometry; using System; using System.Collections.Generic; using System.Linq; @@ -36,13 +37,13 @@ public BringAFriendGoal(DataQuestJson quest, int goalId, dynamic db) : base(ques } if (db.AreaRadius != null && db.AreaRadius != "" && db.AreaRegion != null && db.AreaRegion != "" && db.AreaCenter != null) { - m_area = new Area.Circle($"{quest.Name} EnterAreaGoal {goalId}", new Vector3((float)db.AreaCenter.X, (float)db.AreaCenter.Y, (float)db.AreaCenter.Z), (int)db.AreaRadius); + m_area = new Area.Circle($"{quest.Name} EnterAreaGoal {goalId}", Coordinate.Create((int)((float)db.AreaCenter.X), (int)((float)db.AreaCenter.Y), (int)((float)db.AreaCenter.Z)), (int)db.AreaRadius); m_area.DisplayMessage = false; m_areaRegion = db.AreaRegion; var reg = WorldMgr.GetRegion(m_areaRegion); reg.AddArea(m_area); - PointA = new QuestZonePoint(reg.GetZone(m_area.Position), m_area.Position); + PointA = new QuestZonePoint(reg.GetZone(m_area.Coordinate), m_area.Coordinate); } } @@ -50,7 +51,7 @@ public override Dictionary GetDatabaseJsonObject() { var dict = base.GetDatabaseJsonObject(); dict.Add("TargetName", m_target); - dict.Add("AreaCenter", m_area.Position); + dict.Add("AreaCenter", m_area.Coordinate); dict.Add("AreaRadius", m_area.Radius); dict.Add("AreaRegion", m_areaRegion); return dict; diff --git a/GameServer/quests/JsonQuests/Goals/EnterAreaGoal.cs b/GameServer/quests/JsonQuests/Goals/EnterAreaGoal.cs index 2ab1ea0e..062b6e6f 100644 --- a/GameServer/quests/JsonQuests/Goals/EnterAreaGoal.cs +++ b/GameServer/quests/JsonQuests/Goals/EnterAreaGoal.cs @@ -1,5 +1,6 @@ using DOL.Events; using DOL.GS.Behaviour; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using System; using System.Collections.Generic; @@ -20,19 +21,19 @@ public class EnterAreaGoal : DataQuestJsonGoal public EnterAreaGoal(DataQuestJson quest, int goalId, dynamic db) : base(quest, goalId, (object)db) { m_text = db.Text; - m_area = new Area.Circle($"{quest.Name} EnterAreaGoal {goalId}", new Vector3((float)db.AreaCenter.X, (float)db.AreaCenter.Y, (float)db.AreaCenter.Z), (int)db.AreaRadius); + m_area = new Area.Circle($"{quest.Name} EnterAreaGoal {goalId}", Coordinate.Create((int)((float)db.AreaCenter.X), (int)((float)db.AreaCenter.Y), (int)((float)db.AreaCenter.Z)), (int)db.AreaRadius); m_area.DisplayMessage = false; m_areaRegion = db.AreaRegion; var reg = WorldMgr.GetRegion(m_areaRegion); reg.AddArea(m_area); - PointA = new QuestZonePoint(reg.GetZone(m_area.Position), m_area.Position); + PointA = new QuestZonePoint(reg.GetZone(m_area.Coordinate), m_area.Coordinate); } public override Dictionary GetDatabaseJsonObject() { var dict = base.GetDatabaseJsonObject(); - dict.Add("AreaCenter", m_area.Position); + dict.Add("AreaCenter", m_area.Coordinate); dict.Add("AreaRadius", m_area.Radius); dict.Add("AreaRegion", m_areaRegion); dict.Add("Text", m_text); diff --git a/GameServer/quests/JsonQuests/Goals/KillGoal.cs b/GameServer/quests/JsonQuests/Goals/KillGoal.cs index cbbb78ca..2e90f8c1 100644 --- a/GameServer/quests/JsonQuests/Goals/KillGoal.cs +++ b/GameServer/quests/JsonQuests/Goals/KillGoal.cs @@ -1,4 +1,5 @@ using DOL.Events; +using DOL.GS.Geometry; using System; using System.Collections.Generic; using System.Linq; @@ -28,13 +29,13 @@ public KillGoal(DataQuestJson quest, int goalId, dynamic db) : base(quest, goalI if (db.AreaRadius != null && db.AreaRadius != "" && db.AreaRegion != null && db.AreaRegion != "" && db.AreaCenter != null) { hasArea = true; - m_area = new Area.Circle($"{quest.Name} EnterAreaGoal {goalId}", new Vector3((float)db.AreaCenter.X, (float)db.AreaCenter.Y, (float)db.AreaCenter.Z), (int)db.AreaRadius); + m_area = new Area.Circle($"{quest.Name} EnterAreaGoal {goalId}", Coordinate.Create((int)((float)db.AreaCenter.X), (int)((float)db.AreaCenter.Y), (int)((float)db.AreaCenter.Z)), (int)db.AreaRadius); m_area.DisplayMessage = false; m_areaRegion = db.AreaRegion; var reg = WorldMgr.GetRegion(m_areaRegion); reg.AddArea(m_area); - PointA = new QuestZonePoint(reg.GetZone(m_area.Position), m_area.Position); + PointA = new QuestZonePoint(reg.GetZone(m_area.Coordinate), m_area.Coordinate); } else { @@ -48,7 +49,7 @@ public override Dictionary GetDatabaseJsonObject() dict.Add("TargetName", m_target.Name); dict.Add("TargetRegion", m_target.CurrentRegionID); dict.Add("KillCount", m_killCount); - dict.Add("AreaCenter", m_area.Position); + dict.Add("AreaCenter", m_area.Coordinate); dict.Add("AreaRadius", m_area.Radius); dict.Add("AreaRegion", m_areaRegion); return dict; @@ -64,7 +65,7 @@ public override void NotifyActive(PlayerQuest quest, PlayerGoalState goal, DOLEv { var killed = killedArgs.Target; if (killed == null || m_target.Name != killed.Name || m_target.CurrentRegion != killed.CurrentRegion - || (hasArea && !m_area.IsContaining(killed.Position, false))) + || (hasArea && !m_area.IsContaining(killed.Coordinate, false))) return; AdvanceGoal(quest, goal); } diff --git a/GameServer/quests/JsonQuests/Goals/KillGroupMobGoal.cs b/GameServer/quests/JsonQuests/Goals/KillGroupMobGoal.cs index 3188b354..92b209cb 100644 --- a/GameServer/quests/JsonQuests/Goals/KillGroupMobGoal.cs +++ b/GameServer/quests/JsonQuests/Goals/KillGroupMobGoal.cs @@ -1,5 +1,6 @@ using DOL.Database; using DOL.Events; +using DOL.GS.Geometry; using DOL.MobGroups; using DOLDatabase.Tables; using System; @@ -32,17 +33,17 @@ public KillGroupMobGoal(DataQuestJson quest, int goalId, dynamic db) : base(ques if (db.AreaRadius != null && db.AreaRadius != "" && db.AreaRegion != null && db.AreaRegion != "" && db.AreaCenter != null) { hasArea = true; - m_area = new Area.Circle($"{quest.Name} KillGroupMobGoal {goalId}", new Vector3((float)db.AreaCenter.X, (float)db.AreaCenter.Y, (float)db.AreaCenter.Z), (int)db.AreaRadius); + m_area = new Area.Circle($"{quest.Name} KillGroupMobGoal {goalId}", Coordinate.Create((int)((float)db.AreaCenter.X), (int)((float)db.AreaCenter.Y), (int)((float)db.AreaCenter.Z)), (int)db.AreaRadius); m_area.DisplayMessage = !false; m_areaRegion = db.AreaRegion; var reg = WorldMgr.GetRegion(m_areaRegion); reg.AddArea(m_area); - PointA = new QuestZonePoint(reg.GetZone(m_area.Position), m_area.Position); + PointA = new QuestZonePoint(reg.GetZone(m_area.Coordinate), m_area.Coordinate); } else if (m_region != null && db.AreaCenter != null) { - var pos = new Vector3((float)db.AreaCenter.X, (float)db.AreaCenter.Y, (float)db.AreaCenter.Z); + var pos = Coordinate.Create((int)((float)db.AreaCenter.X), (int)((float)db.AreaCenter.Y), (int)((float)db.AreaCenter.Z)); PointA = new QuestZonePoint(m_region.GetZone(pos), pos); } } @@ -52,7 +53,7 @@ public override Dictionary GetDatabaseJsonObject() var dict = base.GetDatabaseJsonObject(); dict.Add("TargetName", m_targetName); dict.Add("TargetRegion", m_regionId); - dict.Add("AreaCenter", m_area.Position); + dict.Add("AreaCenter", m_area.Coordinate); dict.Add("AreaRadius", m_area.Radius); dict.Add("AreaRegion", m_areaRegion); return dict; @@ -72,7 +73,7 @@ public override void NotifyActive(PlayerQuest quest, PlayerGoalState goal, DOLEv if (killed == null || m_region != killed.CurrentRegion - || (hasArea && !m_area.IsContaining(killed.Position, false))) + || (hasArea && !m_area.IsContaining(killed.Coordinate, false))) return; if (killed is GameNPC killedNpc && MobGroupManager.Instance.Groups.TryGetValue(m_targetName, out MobGroup targetGroup) && !targetGroup.IsAllDead(killedNpc)) diff --git a/GameServer/quests/JsonQuests/Goals/KillPlayerGoal.cs b/GameServer/quests/JsonQuests/Goals/KillPlayerGoal.cs index 6eaee6b6..ea795c3f 100644 --- a/GameServer/quests/JsonQuests/Goals/KillPlayerGoal.cs +++ b/GameServer/quests/JsonQuests/Goals/KillPlayerGoal.cs @@ -1,4 +1,5 @@ using DOL.Events; +using DOL.GS.Geometry; using System; using System.Collections.Generic; using System.Linq; @@ -28,13 +29,13 @@ public KillPlayerGoal(DataQuestJson quest, int goalId, dynamic db) : base(quest, if (db.AreaRadius != null && db.AreaRadius != "" && db.AreaRegion != null && db.AreaRegion != "" && db.AreaCenter != null) { hasArea = true; - m_area = new Area.Circle($"{quest.Name} KillPlayerGoal {goalId}", new Vector3((float)db.AreaCenter.X, (float)db.AreaCenter.Y, (float)db.AreaCenter.Z), (int)db.AreaRadius); + m_area = new Area.Circle($"{quest.Name} KillPlayerGoal {goalId}", Coordinate.Create((int)((float)db.AreaCenter.X), (int)((float)db.AreaCenter.Y), (int)((float)db.AreaCenter.Z)), (int)db.AreaRadius); m_area.DisplayMessage = false; m_areaRegion = db.AreaRegion; var reg = WorldMgr.GetRegion(m_areaRegion); reg.AddArea(m_area); - PointA = new QuestZonePoint(reg.GetZone(m_area.Position), m_area.Position); + PointA = new QuestZonePoint(reg.GetZone(m_area.Coordinate), m_area.Coordinate); } } @@ -43,7 +44,7 @@ public override Dictionary GetDatabaseJsonObject() var dict = base.GetDatabaseJsonObject(); dict.Add("TargetRegion", m_regionId); dict.Add("KillCount", m_killCount); - dict.Add("AreaCenter", m_area.Position); + dict.Add("AreaCenter", m_area.Coordinate); dict.Add("AreaRadius", m_area.Radius); dict.Add("AreaRegion", m_areaRegion); return dict; @@ -60,7 +61,7 @@ public override void NotifyActive(PlayerQuest quest, PlayerGoalState goal, DOLEv var killed = killedArgs.Target; if (killed == null || (m_region != null && m_region != killed.CurrentRegion) || !(killed is GamePlayer) - || (hasArea && !m_area.IsContaining(killed.Position, false))) + || (hasArea && !m_area.IsContaining(killed.Coordinate, false))) return; AdvanceGoal(quest, goal); } diff --git a/GameServer/quests/JsonQuests/Goals/UseItemGoal.cs b/GameServer/quests/JsonQuests/Goals/UseItemGoal.cs index 5dccea35..36ee9ebf 100644 --- a/GameServer/quests/JsonQuests/Goals/UseItemGoal.cs +++ b/GameServer/quests/JsonQuests/Goals/UseItemGoal.cs @@ -1,6 +1,7 @@ using DOL.Database; using DOL.Events; using DOL.GS.Behaviour; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using System; using System.Collections.Generic; @@ -34,13 +35,13 @@ public UseItemGoal(DataQuestJson quest, int goalId, dynamic db) : base(quest, go if (db.AreaRadius != null && db.AreaRadius != "" && db.AreaRegion != null && db.AreaRegion != "" && db.AreaCenter != null) { hasArea = true; - m_area = new Area.Circle($"{quest.Name} EnterAreaGoal {goalId}", new Vector3((float)db.AreaCenter.X, (float)db.AreaCenter.Y, (float)db.AreaCenter.Z), (int)db.AreaRadius); + m_area = new Area.Circle($"{quest.Name} EnterAreaGoal {goalId}", Coordinate.Create((int)((float)db.AreaCenter.X), (int)((float)db.AreaCenter.Y), (int)((float)db.AreaCenter.Z)), (int)db.AreaRadius); m_area.DisplayMessage = false; m_areaRegion = db.AreaRegion; var reg = WorldMgr.GetRegion(m_areaRegion); reg.AddArea(m_area); - PointA = new QuestZonePoint(reg.GetZone(m_area.Position), m_area.Position); + PointA = new QuestZonePoint(reg.GetZone(m_area.Coordinate), m_area.Coordinate); } if (db.TargetName != null && db.TargetName != "" && db.TargetRegion != null && db.TargetRegion != "") { @@ -61,7 +62,7 @@ public override Dictionary GetDatabaseJsonObject() dict.Add("TargetName", m_target.Name); dict.Add("DestroyItem", destroyItem); dict.Add("TargetRegion", m_target.CurrentRegionID); - dict.Add("AreaCenter", m_area.Position); + dict.Add("AreaCenter", m_area.Coordinate); dict.Add("AreaRadius", m_area.Radius); dict.Add("AreaRegion", m_areaRegion); dict.Add("Text", m_text); @@ -71,7 +72,7 @@ public override Dictionary GetDatabaseJsonObject() public override void NotifyActive(PlayerQuest quest, PlayerGoalState goal, DOLEvent e, object sender, EventArgs args) { var player = quest.Owner; - if ((!hasArea || (hasArea && m_area.IsContaining(player.Position, false))) && e == GamePlayerEvent.UseSlot && args is UseSlotEventArgs useSlot) + if ((!hasArea || (hasArea && m_area.IsContaining(player.Coordinate, false))) && e == GamePlayerEvent.UseSlot && args is UseSlotEventArgs useSlot) { var usedItem = player.Inventory.GetItem((eInventorySlot)useSlot.Slot); if (usedItem.Id_nb == QuestItem.Id_nb && (m_target == null || player.TargetObject == m_target)) diff --git a/GameServer/quests/JsonQuests/IQuest.cs b/GameServer/quests/JsonQuests/IQuest.cs index c06d408f..26ac9e69 100644 --- a/GameServer/quests/JsonQuests/IQuest.cs +++ b/GameServer/quests/JsonQuests/IQuest.cs @@ -1,5 +1,6 @@ using System; using DOL.Database; +using DOL.GS.Geometry; using System.Collections.Generic; using System.Numerics; @@ -81,15 +82,15 @@ public QuestZonePoint(ushort zoneId, ushort x, ushort y) public QuestZonePoint(GameObject obj) { ZoneId = obj.CurrentZone.ZoneSkinID; - X = (ushort)(obj.Position.X - obj.CurrentZone.XOffset); - Y = (ushort)(obj.Position.Y - obj.CurrentZone.YOffset); + X = (ushort)(obj.Position.X - obj.CurrentZone.Offset.X); + Y = (ushort)(obj.Position.Y - obj.CurrentZone.Offset.Y); } - public QuestZonePoint(Zone zone, Vector3 globalPos) + public QuestZonePoint(Zone zone, Coordinate globalPos) { ZoneId = zone.ZoneSkinID; - X = (ushort)(globalPos.X - zone.XOffset); - Y = (ushort)(globalPos.Y - zone.YOffset); + X = (ushort)(globalPos.X - zone.Offset.X); + Y = (ushort)(globalPos.Y - zone.Offset.Y); } public static QuestZonePoint None => new QuestZonePoint { ZoneId = 0, X = 0, Y = 0 }; diff --git a/GameServer/spells/Animist/SummonAnimistFnF.cs b/GameServer/spells/Animist/SummonAnimistFnF.cs index 6d03706e..c5adaa0f 100644 --- a/GameServer/spells/Animist/SummonAnimistFnF.cs +++ b/GameServer/spells/Animist/SummonAnimistFnF.cs @@ -44,7 +44,7 @@ public override bool CheckBeginCast(GameLiving selectedTarget) return false; } - foreach (GameNPC npc in Caster.CurrentRegion.GetNPCsInRadius(Caster.GroundTargetCoordinate.Coordinate, (ushort)Properties.TURRET_AREA_CAP_RADIUS, false, true)) + foreach (GameNPC npc in Caster.CurrentRegion.GetNPCsInRadius(Caster.GroundTargetPosition.Coordinate, (ushort)Properties.TURRET_AREA_CAP_RADIUS, false, true)) if (npc.Brain is TurretFNFBrain) nCount++; diff --git a/GameServer/spells/EarthquakeSpellHandler.cs b/GameServer/spells/EarthquakeSpellHandler.cs index 88e34b7c..c9d024e9 100644 --- a/GameServer/spells/EarthquakeSpellHandler.cs +++ b/GameServer/spells/EarthquakeSpellHandler.cs @@ -1,5 +1,6 @@ using DOL.Geometry; using DOL.GS.Effects; +using DOL.GS.Geometry; using DOL.GS.PacketHandler; using DOL.GS.PlayerClass; using System; @@ -11,7 +12,11 @@ public class EarthquakeSpellHandler : SpellHandler { uint unk1 = 0; float radius, intensity, duration, delay = 0; - int x, y, z = 0; + private Coordinate Coordinate + { + get; + set; + } public EarthquakeSpellHandler(GameLiving caster, Spell spell, SpellLine spellLine) : base(caster, spell, spellLine) { @@ -29,14 +34,11 @@ public override bool StartSpell(GameLiving targetObject) } if (Caster.GroundTargetPosition == Position.Nowhere) { - x = (int)Caster.Position.X; - y = (int)Caster.Position.Y; + Coordinate = Caster.Coordinate; } else { - x = (int)Caster.Position.X; - y = (int)Caster.Position.Y; - z = (int)Caster.Position.Z; + Coordinate = Caster.GroundTargetPosition.Coordinate; } /*if (args.Length > 1) { @@ -81,13 +83,13 @@ public override bool StartSpell(GameLiving targetObject) if (Caster is GamePlayer player) { - int distance = (int)System.Numerics.(int)player.Coordinate.DistanceTo(new System.Numerics.Vector3(x, y, player.Position.Z)); + int distance = (int)player.Coordinate.DistanceTo(Coordinate, true); float newIntensity = intensity * (1 - distance / radius); GSTCPPacketOut pak = new GSTCPPacketOut(0x47); pak.WriteIntLowEndian(unk1); - pak.WriteIntLowEndian((uint)x); - pak.WriteIntLowEndian((uint)y); - pak.WriteIntLowEndian((uint)z); + pak.WriteIntLowEndian((uint)Coordinate.X); + pak.WriteIntLowEndian((uint)Coordinate.Y); + pak.WriteIntLowEndian((uint)Coordinate.Z); pak.Write(BitConverter.GetBytes(radius), 0, sizeof(float)); pak.Write(BitConverter.GetBytes(newIntensity), 0, sizeof(float)); pak.Write(BitConverter.GetBytes(duration), 0, sizeof(float)); @@ -130,13 +132,13 @@ public override void OnSpellPulse(PulsingSpellEffect effect) if (Caster is GamePlayer player) { - int distance = (int)System.Numerics.(int)player.Coordinate.DistanceTo(new System.Numerics.Vector3(x, y, player.Position.Z)); + int distance = (int)player.Coordinate.DistanceTo(Coordinate, true); float newIntensity = intensity * (1 - distance / radius); GSTCPPacketOut pak = new GSTCPPacketOut(0x47); pak.WriteIntLowEndian(unk1); - pak.WriteIntLowEndian((uint)x); - pak.WriteIntLowEndian((uint)y); - pak.WriteIntLowEndian((uint)z); + pak.WriteIntLowEndian((uint)Coordinate.X); + pak.WriteIntLowEndian((uint)Coordinate.Y); + pak.WriteIntLowEndian((uint)Coordinate.Z); pak.Write(BitConverter.GetBytes(radius), 0, sizeof(float)); pak.Write(BitConverter.GetBytes(newIntensity), 0, sizeof(float)); pak.Write(BitConverter.GetBytes(duration), 0, sizeof(float)); @@ -158,7 +160,7 @@ public override void OnSpellPulse(PulsingSpellEffect effect) public override void ApplyEffectOnTarget(GameLiving target, double effectiveness) { - int distance = (int)System.Numerics.(int)target.Coordinate.DistanceTo(new System.Numerics.Vector3(x, y, target.Position.Z)); + int distance = (int)target.Coordinate.DistanceTo(Coordinate, true); if (distance > radius) { CancelPulsingSpell(target, Spell.SpellType); @@ -173,9 +175,9 @@ public override void ApplyEffectOnTarget(GameLiving target, double effectiveness return; GSTCPPacketOut pakBis = new GSTCPPacketOut(0x47); pakBis.WriteIntLowEndian(unk1); - pakBis.WriteIntLowEndian((uint)x); - pakBis.WriteIntLowEndian((uint)y); - pakBis.WriteIntLowEndian((uint)z); + pakBis.WriteIntLowEndian((uint)Coordinate.X); + pakBis.WriteIntLowEndian((uint)Coordinate.Y); + pakBis.WriteIntLowEndian((uint)Coordinate.Z); pakBis.Write(BitConverter.GetBytes(radius), 0, sizeof(float)); pakBis.Write(BitConverter.GetBytes(newIntensity), 0, sizeof(float)); pakBis.Write(BitConverter.GetBytes(duration), 0, sizeof(float)); diff --git a/GameServer/spells/PlayerPortal.cs b/GameServer/spells/PlayerPortal.cs index b605011e..d78cddf8 100644 --- a/GameServer/spells/PlayerPortal.cs +++ b/GameServer/spells/PlayerPortal.cs @@ -92,12 +92,8 @@ public override void OnEffectStart(GameSpellEffect effect) secondPortalNPC = CreatePortalNPC(secondPortalNPC, player); // set to player bind location - secondPortal.CurrentRegion = WorldMgr.GetRegion((ushort)player.BindRegion); - secondPortal.Position = new Vector3(player.BindXpos, player.BindYpos, player.BindZpos); - secondPortal.Heading = (ushort)player.BindHeading; - secondPortalNPC.CurrentRegion = WorldMgr.GetRegion((ushort)player.BindRegion); - secondPortalNPC.Position = new Vector3(player.BindXpos, player.BindYpos, player.BindZpos); - secondPortalNPC.Heading = (ushort)player.BindHeading; + secondPortal.Position = player.BindPosition; + secondPortalNPC.Position = player.BindPosition; if (player == null) return; diff --git a/GameServer/spells/TeleportSpellHandler.cs b/GameServer/spells/TeleportSpellHandler.cs index b1b15196..bc89e9ae 100644 --- a/GameServer/spells/TeleportSpellHandler.cs +++ b/GameServer/spells/TeleportSpellHandler.cs @@ -10,7 +10,7 @@ public class TeleportSpellHandler : SpellHandler public TeleportSpellHandler(GameLiving caster, Spell spell, SpellLine spellLine) : base(caster, spell, spellLine) { TPPoint tPPoint = TeleportMgr.LoadTP((ushort)Spell.LifeDrainReturn); - zoneName = WorldMgr.GetRegion(tPPoint.Region).GetZone((float)tPPoint.Position.X, (float)tPPoint.Position.Y).Description; + zoneName = WorldMgr.GetRegion(tPPoint.Region).GetZone(tPPoint.Position.Coordinate).Description; } public override void ApplyEffectOnTarget(GameLiving target, double effectiveness) @@ -37,7 +37,7 @@ public override void ApplyEffectOnTarget(GameLiving target, double effectiveness } } target.TPPoint = tPPoint; - target.MoveTo(tPPoint.Region, (float)tPPoint.Position.X, (float)tPPoint.Position.Y, (float)tPPoint.Position.Z, target.GetHeading(target)); + target.MoveTo(tPPoint.Position.With(target.Orientation)); } } public override string ShortDescription diff --git a/GameServer/spells/negative/SuperFearBrain.cs b/GameServer/spells/negative/SuperFearBrain.cs index 77202af9..b20fb46c 100644 --- a/GameServer/spells/negative/SuperFearBrain.cs +++ b/GameServer/spells/negative/SuperFearBrain.cs @@ -17,8 +17,8 @@ * */ using System; -using System.Numerics; using DOL.GS; +using DOL.GS.Geometry; namespace DOL.AI.Brain { @@ -29,15 +29,15 @@ public class SuperFearBrain : FearBrain /// Calculate flee target. /// ///The target to flee. - protected virtual void CalculateFleeTarget(GameLiving target) + protected override void CalculateFleeTarget(GameLiving target) { - ushort TargetAngle = (ushort)((Body.GetHeading(target) + 2048) % 4096); + ushort TargetAngle = Body.GetAngleTo(target.Coordinate).InHeading; var fleePoint = Body.GetPointFromHeading(TargetAngle, 450); - var point = PathingMgr.Instance.GetClosestPoint(Body.CurrentZone, new Vector3(fleePoint, Body.Position.Z), 128, 128, 256); + var point = PathingMgr.Instance.GetClosestPointAsync(Body.CurrentZone, Coordinate.Create(fleePoint.X, fleePoint.Y, Body.Position.Z), 128, 128, 256); Body.StopFollowing(); Body.StopAttack(); - Body.PathTo(point.HasValue ? point.Value : new Vector3(fleePoint, Body.Position.Z), Body.MaxSpeed); + Body.PathTo(point.HasValue ? Coordinate.Create(point.Value) : Coordinate.Create(fleePoint.X, fleePoint.Y, Body.Position.Z), Body.MaxSpeed); //set speed to 130% m_maxSpeedBuff = (short)(Body.MaxSpeedBase * 0.3); Body.MaxSpeedBase = (short)(Body.MaxSpeedBase * 1.3); diff --git a/GameServer/world/WorldMgr.cs b/GameServer/world/WorldMgr.cs index 3aaa28f2..0f44ae70 100644 --- a/GameServer/world/WorldMgr.cs +++ b/GameServer/world/WorldMgr.cs @@ -1277,145 +1277,6 @@ public static void RemoveSessionID(int id) return; } - //Various functions to get a list of players/mobs/items - #region getdistance - /// - /// Get's the distance of two GameObjects - /// - /// Object1 - /// Object2 - /// The distance in units or -1 if they are not the same Region - [Obsolete("Use Point3D.GetDistance")] - public static float GetDistance(GameObject obj1, GameObject obj2) - { - if (obj1 == null || obj2 == null || obj1.CurrentRegion != obj2.CurrentRegion) - return -1; - return GetDistance(obj1.X, obj1.Y, obj1.Z, obj2.X, obj2.Y, obj2.Z); - } - - /// - /// Get's the distance of two GameObjects - /// - /// Object1 - /// Object2 - /// Factor for Z distance use lower 0..1 to lower Z influence - /// The distance in units or -1 if they are not the same Region - [Obsolete("Use Point3D.GetDistance")] - public static float GetDistance(GameObject obj1, GameObject obj2, float zfactor) - { - if (obj1 == null || obj2 == null || obj1.CurrentRegion != obj2.CurrentRegion) - return -1; - return GetDistance(obj1.X, obj1.Y, obj1.Z, obj2.X, obj2.Y, obj2.Z, zfactor); - } - - /// - /// Gets the distance of two arbitary points in space - /// - /// X of Point1 - /// Y of Point1 - /// Z of Point1 - /// X of Point2 - /// Y of Point2 - /// Z of Point2 - /// The distance - [Obsolete("Use Point3D.GetDistance")] - public static float GetDistance(float x1, float y1, float z1, float x2, float y2, float z2) - { - var xdiff = x1 - x2; - var ydiff = y1 - y2; - var zdiff = z1 - z2; - return (float)Math.Sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff); - } - - /// - /// Gets the distance of two arbitary points in space - /// - /// X of Point1 - /// Y of Point1 - /// Z of Point1 - /// X of Point2 - /// Y of Point2 - /// Z of Point2 - /// Factor for Z distance use lower 0..1 to lower Z influence - /// The distance - [Obsolete("Use Point3D.GetDistance")] - public static float GetDistance(float x1, float y1, float z1, float x2, float y2, float z2, float zfactor) - { - var xdiff = x1 - x2; - var ydiff = y1 - y2; - var zdiff = ((z1 - z2) * zfactor); - return (float)Math.Sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff); - } - - /// - /// Gets the distance of an Object to an arbitary point - /// - /// GameObject used as Point1 - /// X of Point2 - /// Y of Point2 - /// Z of Point2 - /// The distance - [Obsolete("Use Point3D.GetDistance")] - public static float GetDistance(GameObject obj, float x, float y, float z) - { - return GetDistance(obj.X, obj.Y, obj.Z, x, y, z); - } - #endregion get distance - - #region check distance - [Obsolete("Use Point3D.IsWithinRadius")] - public static bool CheckDistance(float x1, float y1, float z1, float x2, float y2, float z2, int radius) - { - return CheckSquareDistance(x1, y1, z1, x2, y2, z2, radius * radius); - } - [Obsolete("Use Point3D.IsWithinRadius")] - public static bool CheckDistance(Vector3 obj, Vector3 obj2, int radius) - { - return CheckDistance(obj.X, obj.Y, obj.Z, obj2.X, obj2.Y, obj2.Z, radius); - } - [Obsolete("Use Point3D.IsWithinRadius")] - public static bool CheckDistance(GameObject obj, float x2, float y2, float z2, int radius) - { - return CheckDistance(obj.X, obj.Y, obj.Z, x2, y2, z2, radius); - } - [Obsolete("Use Point3D.IsWithinRadius")] - public static bool CheckDistance(GameObject obj, GameObject obj2, int radius) - { - if (obj == null || obj2 == null) - return false; - if (obj.CurrentRegion != obj2.CurrentRegion) - return false; - return CheckDistance(obj.X, obj.Y, obj.Z, obj2.X, obj2.Y, obj2.Z, radius); - } - #endregion - #region check square distance - [Obsolete("Use Point3D.IsWithinRadius")] - private static bool CheckSquareDistance(float x1, float y1, float z1, float x2, float y2, float z2, int squareRadius) - { - var xdiff = x1 - x2; - var ydiff = y1 - y2; - var zdiff = z1 - z2; - return (xdiff * xdiff + ydiff * ydiff + zdiff * zdiff <= squareRadius); - } - [Obsolete("Use Point3D.IsWithinRadius")] - private static bool CheckSquareDistance(Vector3 obj, Vector3 obj2, int squareRadius) - { - return CheckSquareDistance(obj.X, obj.Y, obj.Z, obj2.X, obj2.Y, obj2.Z, squareRadius); - } - [Obsolete("Use Point3D.IsWithinRadius")] - private static bool CheckSquareDistance(GameObject obj, float x2, float y2, float z2, int squareRadius) - { - return CheckSquareDistance(obj.X, obj.Y, obj.Z, x2, y2, z2, squareRadius); - } - [Obsolete("Use Point3D.IsWithinRadius")] - private static bool CheckSquareDistance(GameObject obj, GameObject obj2, int squareRadius) - { - if (obj.CurrentRegion != obj2.CurrentRegion) - return false; - return CheckSquareDistance(obj.X, obj.Y, obj.Z, obj2.X, obj2.Y, obj2.Z, squareRadius); - } - #endregion - /// /// Returns the number of playing Clients inside a realm /// diff --git a/GameServer/world/geometry/AABoundingBox.cs b/GameServer/world/geometry/AABoundingBox.cs index 6fd2c4e6..9b36196c 100644 --- a/GameServer/world/geometry/AABoundingBox.cs +++ b/GameServer/world/geometry/AABoundingBox.cs @@ -6,7 +6,7 @@ namespace DOL.GS.Geometry public readonly struct AABoundingBox : ICollider { public readonly Vector3 Min; - public readonly Vector3 Max; + public readonly System.Numerics.Vector3 Max; public AABoundingBox Box => this; public AABoundingBox(Vector3 min, Vector3 max) diff --git a/GameServer/world/pathing/GamePath.cs b/GameServer/world/pathing/GamePath.cs index 32e831fc..77223358 100644 --- a/GameServer/world/pathing/GamePath.cs +++ b/GameServer/world/pathing/GamePath.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using System.Numerics; +using DOL.GS.Geometry; +using System.Collections.Generic; namespace DOL.GS { @@ -17,7 +17,7 @@ public enum MarkerModel public string Name; public Region Region; public bool HasLavaEffect = false; - public List<(GameLocation point, short speed, MarkerModel model)> Points = new List<(GameLocation point, short speed, MarkerModel model)>(); + public List<(Coordinate point, short speed, MarkerModel model)> Points = new List<(Coordinate point, short speed, MarkerModel model)>(); public List DebugObjs = new List(); @@ -27,7 +27,7 @@ public GamePath(string name, Region region) Region = region; } - public void Append(GameLocation point, short speed, MarkerModel model = MarkerModel.Brown) + public void Append(Coordinate point, short speed, MarkerModel model = MarkerModel.Brown) { Points.Add((point, speed, model)); } @@ -40,10 +40,9 @@ public void Show() { //Create a new object var obj = new GameStaticItem(); - obj.Position = pt.Position + Vector3.UnitZ; + obj.Position = Position.Create(Region.ID, pt); obj.CurrentRegion = Region; - obj.Heading = pt.Heading; - obj.Name = $"{pt.Name}--{speed} spd"; + obj.Name = $"{pt.ToString()}--{speed} spd"; obj.Model = 2965; switch (model) { diff --git a/GameServer/world/pathing/IPathingMgr.cs b/GameServer/world/pathing/IPathingMgr.cs index 08c561c4..0ff2583d 100644 --- a/GameServer/world/pathing/IPathingMgr.cs +++ b/GameServer/world/pathing/IPathingMgr.cs @@ -25,7 +25,7 @@ public interface IPathingMgr /// Returns the closest point on the navmesh, if available, or no point found. /// Returns the input position if no navmesh is available /// - Vector3? GetClosestPointAsync(Zone zone, Vector3 position, float xRange = 256f, float yRange = 256f, float zRange = 256f); + Vector3? GetClosestPointAsync(Zone zone, Coordinate position, float xRange = 256f, float yRange = 256f, float zRange = 256f); /// /// True if pathing is enabled for the specified zone diff --git a/GameServer/world/pathing/LocalPathingMgr.cs b/GameServer/world/pathing/LocalPathingMgr.cs index e2ee3ab0..f9baf1ed 100644 --- a/GameServer/world/pathing/LocalPathingMgr.cs +++ b/GameServer/world/pathing/LocalPathingMgr.cs @@ -270,10 +270,10 @@ private static float[] CoordinateToRecastFloatArray(Coordinate loc) /// /// Returns the closest point on the navmesh (UNTESTED! EXPERIMENTAL! WILL GO SUPERNOVA ON USE! MAYBE!?) /// - public Vector3? GetClosestPointAsync(Zone zone, Vector3 position, float xRange = 256f, float yRange = 256f, float zRange = 256f) + public Vector3? GetClosestPointAsync(Zone zone, Coordinate position, float xRange = 256f, float yRange = 256f, float zRange = 256f) { if (!_navmeshPtrs.ContainsKey(zone.ID)) - return position; // Assume the point is safe if we don't have a navmesh + return position.ToSysVector3(); // Assume the point is safe if we don't have a navmesh //GSStatistics.Paths.Inc(); Vector3? result = null; @@ -284,7 +284,7 @@ private static float[] CoordinateToRecastFloatArray(Coordinate loc) _navmeshQueries.Value.Add(zone.ID, query); } var ptrs = _navmeshPtrs[zone.ID]; - var center = ToRecastFloats(position + Vector3.UnitZ * 8); + var center = ToRecastFloats(position.ToSysVector3() + Vector3.UnitZ * 8); var outVec = new float[3]; var defaultInclude = (dtPolyFlags.ALL ^ dtPolyFlags.DISABLED); diff --git a/GameServer/world/pathing/NullPathingMgr.cs b/GameServer/world/pathing/NullPathingMgr.cs index 9ad0aadf..e5a2e931 100644 --- a/GameServer/world/pathing/NullPathingMgr.cs +++ b/GameServer/world/pathing/NullPathingMgr.cs @@ -23,9 +23,9 @@ public void Stop() public Vector3? GetRandomPointAsync(Zone zone, Coordinate center, float radius) => null; - public Vector3? GetClosestPointAsync(Zone zone, Vector3 position, float xRange = 256, float yRange = 256, float zRange = 256) + public Vector3? GetClosestPointAsync(Zone zone, Coordinate position, float xRange = 256, float yRange = 256, float zRange = 256) { - return position; + return position.ToSysVector3(); } public bool HasNavmesh(Zone zone) diff --git a/GameServer/world/pathing/PathCalculator.cs b/GameServer/world/pathing/PathCalculator.cs index aa96fe44..07098fda 100644 --- a/GameServer/world/pathing/PathCalculator.cs +++ b/GameServer/world/pathing/PathCalculator.cs @@ -74,6 +74,11 @@ public static bool IsSupported(GameNPC o) /// public bool DidFindPath { get; private set; } + /// + /// True if this path should be visualized + /// + public bool VisualizePath { get; set; } + /// /// Creates a path calculator for the given NPC /// diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 2b88eaee..3730a606 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -46,7 +46,7 @@ - +