mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-05-20 08:26:59 -04:00
moved vector3 to common
- changed distance checks to distance squared - reexported central thanalan navmesh with cell size 0.60, height 0.26, radius 0.5, edge error 1.3, merged region size 30 - todo: main logic loop per zone and move this into proper ai classes
This commit is contained in:
@@ -40,7 +40,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
public string className;
|
||||
public List<LuaParam> classParams;
|
||||
|
||||
public List<utils.Vector3> positionUpdates = new List<utils.Vector3>();
|
||||
public List<Vector3> positionUpdates = new List<Vector3>();
|
||||
public DateTime lastMoveUpdate;
|
||||
public Actor target;
|
||||
|
||||
@@ -158,12 +158,16 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
if (hasMoved)
|
||||
{
|
||||
var pos = positionUpdates[0];
|
||||
positionUpdates.Remove(pos);
|
||||
|
||||
if (this is Character)
|
||||
((Character)this).OnPath(ref pos);
|
||||
|
||||
positionX = pos.X;
|
||||
positionY = pos.Y;
|
||||
positionZ = pos.Z;
|
||||
//Program.Server.GetInstance().mLuaEngine.OnPath(actor, position, positionUpdates)
|
||||
|
||||
positionUpdates.RemoveAt(0);
|
||||
}
|
||||
lastMoveUpdate = DateTime.Now;
|
||||
return MoveActorToPositionPacket.BuildPacket(actorId, playerActorId, positionX, positionY, positionZ, rotation, moveState);
|
||||
@@ -609,10 +613,10 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
rotation = (float)dRot;
|
||||
}
|
||||
|
||||
public void QueuePositionUpdate(utils.Vector3 pos)
|
||||
public void QueuePositionUpdate(Vector3 pos)
|
||||
{
|
||||
if (positionUpdates == null)
|
||||
positionUpdates = new List<utils.Vector3>();
|
||||
positionUpdates = new List<Vector3>();
|
||||
|
||||
positionUpdates.Add(pos);
|
||||
this.hasMoved = true;
|
||||
@@ -620,7 +624,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
|
||||
public void QueuePositionUpdate(float x, float y, float z)
|
||||
{
|
||||
QueuePositionUpdate(new utils.Vector3(x, y, z));
|
||||
QueuePositionUpdate(new Vector3(x, y, z));
|
||||
}
|
||||
|
||||
public void ClearPositionUpdates()
|
||||
@@ -628,7 +632,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
positionUpdates.Clear();
|
||||
}
|
||||
|
||||
public utils.Vector3 FindRandomPointAroundActor(float minRadius, float maxRadius)
|
||||
public Vector3 FindRandomPointAroundActor(float minRadius, float maxRadius)
|
||||
{
|
||||
var angle = Program.Random.NextDouble() * Math.PI * 2;
|
||||
var radius = Math.Sqrt(Program.Random.NextDouble() * (maxRadius - minRadius)) + minRadius;
|
||||
@@ -636,7 +640,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
float x = (float)(radius * Math.Cos(angle));
|
||||
float z = (float)(radius * Math.Sin(angle));
|
||||
|
||||
return new utils.Vector3(positionX + x, positionY, positionZ + z);
|
||||
return new Vector3(positionX + x, positionY, positionZ + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -33,23 +33,20 @@ namespace FFXIVClassic_Map_Server.actors.area
|
||||
public Zone(uint id, string zoneName, ushort regionId, string classPath, ushort bgmDay, ushort bgmNight, ushort bgmBattle, bool isIsolated, bool isInn, bool canRideChocobo, bool canStealth, bool isInstanceRaid, bool loadNavMesh = false)
|
||||
: base(id, zoneName, regionId, classPath, bgmDay, bgmNight, bgmBattle, isIsolated, isInn, canRideChocobo, canStealth, isInstanceRaid)
|
||||
{
|
||||
var navMeshName = loadNavMesh ? zoneName + ".snb" : "";
|
||||
|
||||
if (navMeshName != "")
|
||||
if (loadNavMesh)
|
||||
{
|
||||
try
|
||||
{
|
||||
tiledNavMesh = utils.NavmeshUtils.LoadNavmesh(tiledNavMesh, navMeshName);
|
||||
tiledNavMesh = utils.NavmeshUtils.LoadNavmesh(tiledNavMesh, zoneName + ".snb");
|
||||
navMeshQuery = new SharpNav.NavMeshQuery(tiledNavMesh, 100);
|
||||
|
||||
if (tiledNavMesh != null)
|
||||
if (tiledNavMesh != null && tiledNavMesh.Tiles[0].PolyCount > 0)
|
||||
Program.Log.Info($"Loaded navmesh for {zoneName}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Program.Log.Error(e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -119,8 +119,8 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
|
||||
public void PathTo(float x, float y, float z, float stepSize = 0.70f, int maxPath = 40, float polyRadius = 0.0f)
|
||||
{
|
||||
var pos = new utils.Vector3(positionX, positionY, positionZ);
|
||||
var dest = new utils.Vector3(x, y, z);
|
||||
var pos = new Vector3(positionX, positionY, positionZ);
|
||||
var dest = new Vector3(x, y, z);
|
||||
|
||||
var sw = new System.Diagnostics.Stopwatch();
|
||||
sw.Start();
|
||||
@@ -156,11 +156,11 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
if (path.Count == 1)
|
||||
Program.Log.Info($"mypos: {positionX} {positionY} {positionZ} | targetPos: {x} {y} {z} | step {stepSize} | maxPath {maxPath} | polyRadius {polyRadius}");
|
||||
|
||||
//Program.Log.Error("[{0}][{1}] Created {2} points in {3} milliseconds", actorId, actorName, path.Count, sw.ElapsedMilliseconds);
|
||||
Program.Log.Error("[{0}][{1}] Created {2} points in {3} milliseconds", actorId, actorName, path.Count, sw.ElapsedMilliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
public void FollowTarget(Actor target, float stepSize = 1.2f, int maxPath = 25)
|
||||
public void FollowTarget(Actor target, float stepSize = 1.2f, int maxPath = 25, float radius = 0.0f)
|
||||
{
|
||||
var player = target as Player;
|
||||
|
||||
@@ -202,13 +202,20 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
this.moveState = player.moveState;
|
||||
this.moveSpeeds = player.moveSpeeds;
|
||||
|
||||
PathTo(player.positionX, player.positionY, player.positionZ, stepSize, maxPath);
|
||||
PathTo(player.positionX, player.positionY, player.positionZ, stepSize, maxPath, radius);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPath()
|
||||
public void OnPath(ref Vector3 point)
|
||||
{
|
||||
// todo: lua function onPath in mob script
|
||||
if (positionUpdates != null && positionUpdates.Count > 0)
|
||||
{
|
||||
if (point == positionUpdates[positionUpdates.Count - 1])
|
||||
{
|
||||
var myPos = new Vector3(positionX, positionY, positionZ);
|
||||
//point = NavmeshUtils.GetPath((Zone)zone, myPos, point, 0.35f, 1, 0.000001f, true)?[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(double deltaTime)
|
||||
@@ -234,22 +241,21 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
if (diffTime.Milliseconds >= deltaTime)
|
||||
{
|
||||
bool foundActor = false;
|
||||
bool despawnOutOfRange = false;
|
||||
|
||||
var targId = target != null ? actorId : 0;
|
||||
|
||||
// leash back to spawn
|
||||
if (!isMovingToSpawn && this.oldPositionX != 0.0f && this.oldPositionY != 0.0f && this.oldPositionZ != 0.0f)
|
||||
{
|
||||
var spawnDistance = Utils.Distance(positionX, positionY, positionZ, oldPositionX, oldPositionY, oldPositionZ);
|
||||
//var spawnDistanceSq = Utils.DistanceSquared(positionX, positionY, positionZ, oldPositionX, oldPositionY, oldPositionZ);
|
||||
|
||||
// todo: actual spawn leash and modifiers read from table
|
||||
// set a leash to path back to spawn even if have target
|
||||
if (spawnDistance >= 55)
|
||||
// (50 yalms)
|
||||
if (Utils.DistanceSquared(positionX, positionY, positionZ, oldPositionX, oldPositionY, oldPositionZ) >= 3025)
|
||||
{
|
||||
this.isMovingToSpawn = true;
|
||||
this.target = null;
|
||||
this.lastMoveUpdate = this.lastMoveUpdate.AddSeconds(-5);
|
||||
this.hasMoved = false;
|
||||
ClearPositionUpdates();
|
||||
}
|
||||
}
|
||||
@@ -260,7 +266,8 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
var player = target as Player;
|
||||
|
||||
// deaggro if zoning/logging
|
||||
if (player.playerSession.isUpdatesLocked || player.isZoneChanging || player.isZoning)
|
||||
// todo: player.isZoning seems to be busted
|
||||
if (player.playerSession.isUpdatesLocked)
|
||||
{
|
||||
target = null;
|
||||
ClearPositionUpdates();
|
||||
@@ -268,7 +275,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
}
|
||||
|
||||
Player closestPlayer = null;
|
||||
float closestPlayerDistance = 1000.0f;
|
||||
float closestPlayerDistanceSq = 1000.0f;
|
||||
|
||||
// dont bother checking for any in-range players if going back to spawn
|
||||
if (!this.isMovingToSpawn)
|
||||
@@ -280,19 +287,20 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
var player = actor as Player;
|
||||
|
||||
// skip if zoning/logging
|
||||
if (player != null && player.isZoning || player.isZoning || player.playerSession.isUpdatesLocked)
|
||||
// todo: player.isZoning seems to be busted
|
||||
if (player != null && player.playerSession.isUpdatesLocked)
|
||||
continue;
|
||||
|
||||
// find distance between self and target
|
||||
var distance = Utils.Distance(positionX, positionY, positionZ, player.positionX, player.positionY, player.positionZ);
|
||||
var distanceSq = Utils.DistanceSquared(positionX, positionY, positionZ, player.positionX, player.positionY, player.positionZ);
|
||||
|
||||
int maxDistance = player == target ? 27 : 10;
|
||||
int maxDistanceSq = player == target ? 900 : 100;
|
||||
|
||||
// check target isnt too far
|
||||
// todo: create cone thing for IsFacing
|
||||
if (distance <= maxDistance && distance <= closestPlayerDistance && (IsFacing(player) || true))
|
||||
if (distanceSq <= maxDistanceSq && distanceSq <= closestPlayerDistanceSq && (IsFacing(player) || true))
|
||||
{
|
||||
closestPlayerDistance = distance;
|
||||
closestPlayerDistanceSq = distanceSq;
|
||||
closestPlayer = player;
|
||||
foundActor = true;
|
||||
}
|
||||
@@ -306,12 +314,12 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
if (!hasMoved)
|
||||
{
|
||||
// todo: include model size and mob specific distance checks
|
||||
if (closestPlayerDistance >= 3)
|
||||
if (closestPlayerDistanceSq >= 9)
|
||||
{
|
||||
FollowTarget(closestPlayer, 2.4f, 5);
|
||||
FollowTarget(closestPlayer, 2.5f, 4);
|
||||
}
|
||||
// too close, spread out
|
||||
else if (closestPlayerDistance <= 0.64f)
|
||||
else if (closestPlayerDistanceSq <= 0.85f)
|
||||
{
|
||||
QueuePositionUpdate(target.FindRandomPointAroundActor(0.65f, 0.85f));
|
||||
}
|
||||
@@ -328,14 +336,15 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
// time elapsed since last move update
|
||||
var diffMove = (DateTime.Now - lastMoveUpdate);
|
||||
|
||||
// todo: modifier for DelayBeforeRoamToSpawn
|
||||
// player disappeared
|
||||
if (diffMove.Seconds >= 5 && !foundActor)
|
||||
if (!foundActor && diffMove.Seconds >= 5)
|
||||
{
|
||||
// dont path if havent moved before
|
||||
if (oldPositionX != 0.0f && oldPositionY != 0.0f && oldPositionZ != 0.0f)
|
||||
if (!hasMoved && oldPositionX != 0.0f && oldPositionY != 0.0f && oldPositionZ != 0.0f)
|
||||
{
|
||||
// check within spawn radius
|
||||
this.isAtSpawn = Utils.Distance(positionX, positionY, positionZ, oldPositionX, oldPositionY, oldPositionZ) <= 25.0f;
|
||||
this.isAtSpawn = Utils.DistanceSquared(positionX, positionY, positionZ, oldPositionX, oldPositionY, oldPositionZ) <= 625.0f;
|
||||
|
||||
// make sure we have no target
|
||||
if (this.target == null)
|
||||
@@ -346,10 +355,11 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||
PathTo(oldPositionX, oldPositionY, oldPositionZ, 2.8f);
|
||||
}
|
||||
// within spawn range, find a random point
|
||||
else if (diffMove.Seconds >= 15 && !hasMoved)
|
||||
else if (diffMove.Seconds >= 15)
|
||||
{
|
||||
// pick a random point within 10 yalms or spawn
|
||||
PathTo(oldPositionX, oldPositionY, oldPositionZ, 2.5f, 7, 10.5f);
|
||||
// todo: polyRadius isnt euclidean distance..
|
||||
// pick a random point within 10 yalms of spawn
|
||||
PathTo(oldPositionX, oldPositionY, oldPositionZ, 2.5f, 7, 2.5f);
|
||||
|
||||
// face destination
|
||||
if (positionUpdates.Count > 0)
|
||||
|
Reference in New Issue
Block a user