Skip to content

Commit

Permalink
Apply position changes to Gondwana code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 committed Jun 9, 2024
1 parent b0d12d2 commit f59ed07
Show file tree
Hide file tree
Showing 67 changed files with 275 additions and 479 deletions.
1 change: 1 addition & 0 deletions GameServer/GameClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions GameServer/Geometry/Coordinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) };

Expand Down
2 changes: 1 addition & 1 deletion GameServer/Geometry/CoordinateTransitionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions GameServer/Geometry/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
29 changes: 0 additions & 29 deletions GameServer/Territory/AreaCoordinate.cs

This file was deleted.

5 changes: 3 additions & 2 deletions GameServer/Territory/RvRTerritory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DOL.Database;
using DOL.GS;
using DOL.GS.Geometry;
using DOL.GS.Keeps;
using DOL.MobGroups;
using DOLDatabase.Tables;
Expand All @@ -16,7 +17,7 @@ public class RvRTerritory
: Territory
{
/// <inheritdoc />
public RvRTerritory(Zone zone, List<IArea> 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<IArea> 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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions GameServer/Territory/Territory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,11 +38,11 @@ public Territory(Zone zone, List<IArea> 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;
Expand Down Expand Up @@ -106,11 +107,11 @@ public Territory(Zone zone, List<IArea> areas, GameNPC boss, TerritoryDb db)
}
}

public Territory(eType type, Zone zone, List<IArea> areas, string name, GameNPC boss, Vector3? portalPosition, ushort regionID, MobGroup group = null)
public Territory(eType type, Zone zone, List<IArea> 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;
Expand Down Expand Up @@ -207,7 +208,7 @@ public List<IArea> Areas
get;
}

public Vector3? PortalPosition
public Coordinate? PortalCoordinate
{
get;
set;
Expand Down Expand Up @@ -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<TerritoryBanner>().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<TerritoryBanner>().ForEach(i => i.Emblem = add && m_ownerGuild != null ? m_ownerGuild.Emblem : i.OriginalEmblem);
}
else
{
Expand Down Expand Up @@ -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
{
Expand Down
17 changes: 9 additions & 8 deletions GameServer/Territory/TerritoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IArea>{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<IArea>{area}, (area as AbstractArea)?.Description ?? "New territory", boss, coords, regionId, group);

try
{
Expand All @@ -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
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
Expand Down
12 changes: 4 additions & 8 deletions GameServer/_scripts/AmteScripts/GameObjects/Coffre/GameCoffre.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using DOL.MobGroups;
using DOL.Events;
using DOL.GS.GameEvents;
using DOL.GS.Geometry;

namespace DOL.GS.Scripts
{
Expand Down Expand Up @@ -486,7 +487,7 @@ private TPPoint GetSmartNextTPPoint(IList<DBTPPoint> tpPoints)

foreach (var tpPoint in tpPoints)
{
int playerCount = WorldMgr.GetPlayersCloseToSpot(tpPoint.Region, (float)tpPoint.X, (float)tpPoint.Y, (float)tpPoint.Z, 1500).OfType<GamePlayer>().Count(); // Using 1500 directly
int playerCount = WorldMgr.GetPlayersCloseToSpot(Position.Create(tpPoint.Region, tpPoint.X, tpPoint.Y, tpPoint.Z), 1500).OfType<GamePlayer>().Count(); // Using 1500 directly
if (playerCount > maxPlayerCount)
{
maxPlayerCount = playerCount;
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion GameServer/_scripts/AmteScripts/GameObjects/CustomVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
24 changes: 12 additions & 12 deletions GameServer/_scripts/AmteScripts/GameObjects/FollowingFriendMob.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<AbstractArea>().FirstOrDefault(a => a.DbArea != null && a.DbArea.ObjectId == AreaToEnter) != null)
&& CurrentRegion.GetAreasOfSpot(Coordinate).OfType<AbstractArea>().FirstOrDefault(a => a.DbArea != null && a.DbArea.ObjectId == AreaToEnter) != null)
return false;
if (PlayerFollow != null && PlayerFollow == player)
{
Expand Down Expand Up @@ -248,7 +248,7 @@ public void ResetFriendMob()
AddToWorld();
}

public void Reset()
public override void Reset()
{
ResetFriendMobs();
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit f59ed07

Please sign in to comment.