2017-06-12 20:13:26 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using FFXIVClassic_Map_Server.Actors;
|
2017-07-02 20:01:24 +01:00
|
|
|
|
using FFXIVClassic_Map_Server;
|
|
|
|
|
using FFXIVClassic_Map_Server.utils;
|
|
|
|
|
using FFXIVClassic.Common;
|
|
|
|
|
using FFXIVClassic_Map_Server.actors.area;
|
2017-08-02 23:06:11 +01:00
|
|
|
|
using FFXIVClassic_Map_Server.packets.send.actor;
|
2017-06-12 20:13:26 +01:00
|
|
|
|
|
|
|
|
|
namespace FFXIVClassic_Map_Server.actors.chara.ai
|
|
|
|
|
{
|
2017-08-02 23:06:11 +01:00
|
|
|
|
// todo: path flags, check for obstacles etc
|
|
|
|
|
public enum PathFindFlags
|
|
|
|
|
{
|
|
|
|
|
None,
|
|
|
|
|
Scripted = 0x01,
|
|
|
|
|
IgnoreNav = 0x02,
|
|
|
|
|
}
|
2017-06-12 20:13:26 +01:00
|
|
|
|
class PathFind
|
|
|
|
|
{
|
|
|
|
|
private Character owner;
|
2017-08-02 23:06:11 +01:00
|
|
|
|
private List<Vector3> path;
|
|
|
|
|
private bool canFollowPath;
|
|
|
|
|
|
|
|
|
|
private PathFindFlags pathFlags;
|
2017-06-12 20:13:26 +01:00
|
|
|
|
|
|
|
|
|
public PathFind(Character owner)
|
|
|
|
|
{
|
|
|
|
|
this.owner = owner;
|
|
|
|
|
}
|
2017-07-02 20:01:24 +01:00
|
|
|
|
|
2017-08-02 23:06:11 +01:00
|
|
|
|
public void PreparePath(Vector3 dest, float stepSize = 0.70f, int maxPath = 40, float polyRadius = 0.0f)
|
|
|
|
|
{
|
|
|
|
|
PreparePath(dest.X, dest.Y, dest.Z, stepSize, maxPath, polyRadius);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-02 20:01:24 +01:00
|
|
|
|
// todo: is this class even needed?
|
2017-08-02 23:06:11 +01:00
|
|
|
|
public void PreparePath(float x, float y, float z, float stepSize = 0.70f, int maxPath = 40, float polyRadius = 0.0f)
|
2017-07-02 20:01:24 +01:00
|
|
|
|
{
|
|
|
|
|
var pos = new Vector3(owner.positionX, owner.positionY, owner.positionZ);
|
|
|
|
|
var dest = new Vector3(x, y, z);
|
|
|
|
|
var zone = (Zone)owner.GetZone();
|
|
|
|
|
var sw = new System.Diagnostics.Stopwatch();
|
|
|
|
|
sw.Start();
|
|
|
|
|
|
2017-08-02 23:06:11 +01:00
|
|
|
|
if ((pathFlags & PathFindFlags.IgnoreNav) != 0)
|
|
|
|
|
path = new List<Vector3>(1) { new Vector3(x, y, z) };
|
|
|
|
|
else
|
|
|
|
|
path = NavmeshUtils.GetPath(zone, pos, dest, stepSize, maxPath, polyRadius);
|
2017-07-02 20:01:24 +01:00
|
|
|
|
|
|
|
|
|
if (path != null)
|
|
|
|
|
{
|
|
|
|
|
if (owner.oldPositionX == 0.0f && owner.oldPositionY == 0.0f && owner.oldPositionZ == 0.0f)
|
|
|
|
|
{
|
|
|
|
|
owner.oldPositionX = owner.positionX;
|
|
|
|
|
owner.oldPositionY = owner.positionY;
|
|
|
|
|
owner.oldPositionZ = owner.positionZ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo: something went wrong
|
|
|
|
|
if (path.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
owner.positionX = owner.oldPositionX;
|
|
|
|
|
owner.positionY = owner.oldPositionY;
|
|
|
|
|
owner.positionZ = owner.oldPositionZ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sw.Stop();
|
|
|
|
|
zone.pathCalls++;
|
|
|
|
|
zone.pathCallTime += sw.ElapsedMilliseconds;
|
|
|
|
|
|
|
|
|
|
if (path.Count == 1)
|
|
|
|
|
Program.Log.Info($"mypos: {owner.positionX} {owner.positionY} {owner.positionZ} | targetPos: {x} {y} {z} | step {stepSize} | maxPath {maxPath} | polyRadius {polyRadius}");
|
|
|
|
|
|
|
|
|
|
Program.Log.Error("[{0}][{1}] Created {2} points in {3} milliseconds", owner.actorId, owner.actorName, path.Count, sw.ElapsedMilliseconds);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-02 23:06:11 +01:00
|
|
|
|
|
|
|
|
|
public void PathInRange(Vector3 dest, float minRange, float maxRange)
|
|
|
|
|
{
|
|
|
|
|
PathInRange(dest.X, dest.Y, dest.Z, minRange, maxRange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PathInRange(float x, float y, float z, float minRange, float maxRange = 5.0f)
|
|
|
|
|
{
|
|
|
|
|
var dest = owner.FindRandomPoint(x, y, z, minRange, maxRange);
|
|
|
|
|
PreparePath(dest.X, dest.Y, dest.Z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void SetPathFlags(PathFindFlags flags)
|
|
|
|
|
{
|
|
|
|
|
this.pathFlags = flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsFollowingPath()
|
|
|
|
|
{
|
|
|
|
|
return path.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsFollowingScriptedPath()
|
|
|
|
|
{
|
|
|
|
|
return (pathFlags & PathFindFlags.Scripted) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FollowPath()
|
|
|
|
|
{
|
|
|
|
|
if (path?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var point = path[0];
|
|
|
|
|
|
|
|
|
|
owner.OnPath(point);
|
|
|
|
|
owner.QueuePositionUpdate(point);
|
|
|
|
|
path.Remove(point);
|
|
|
|
|
|
|
|
|
|
if (path.Count == 0)
|
|
|
|
|
owner.LookAt(point.X, point.Y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
// todo:
|
|
|
|
|
path?.Clear();
|
|
|
|
|
pathFlags = PathFindFlags.None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private float GetSpeed()
|
|
|
|
|
{
|
|
|
|
|
float baseSpeed = owner.GetSpeed();
|
|
|
|
|
|
|
|
|
|
// todo: get actual speed crap
|
|
|
|
|
if (owner.currentSubState != SetActorStatePacket.SUB_STATE_NONE)
|
|
|
|
|
{
|
|
|
|
|
if (owner.currentSubState == SetActorStatePacket.SUB_STATE_MONSTER)
|
|
|
|
|
{
|
|
|
|
|
owner.ChangeSpeed(0.0f, SetActorSpeedPacket.DEFAULT_WALK - 2.0f, SetActorSpeedPacket.DEFAULT_RUN - 2.0f, SetActorSpeedPacket.DEFAULT_ACTIVE - 2.0f);
|
|
|
|
|
}
|
|
|
|
|
// baseSpeed += ConfigConstants.SPEED_MOD;
|
|
|
|
|
}
|
|
|
|
|
return baseSpeed;
|
|
|
|
|
}
|
2017-06-12 20:13:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|