mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-07-25 20:08:20 +02:00
moved pathing crap out of actor
- despawn actors on moving too far from spawn - added clampy stuff (<3 devi)
This commit is contained in:
parent
bd97e72774
commit
a62475e81e
12 changed files with 308 additions and 239 deletions
|
@ -47,6 +47,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
|
||||
public bool hasMoved = false;
|
||||
public bool isAtSpawn = true;
|
||||
|
||||
public EventList eventConditions;
|
||||
|
||||
public Actor(uint actorId)
|
||||
|
@ -82,6 +83,15 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
}
|
||||
}
|
||||
|
||||
public void ResetMoveSpeedsToDefault()
|
||||
{
|
||||
this.moveSpeeds[0] = SetActorSpeedPacket.DEFAULT_STOP;
|
||||
this.moveSpeeds[1] = SetActorSpeedPacket.DEFAULT_WALK;
|
||||
this.moveSpeeds[2] = SetActorSpeedPacket.DEFAULT_RUN;
|
||||
this.moveSpeeds[3] = SetActorSpeedPacket.DEFAULT_ACTIVE;
|
||||
hasMoved = true;
|
||||
}
|
||||
|
||||
public SubPacket CreateAddActorPacket(uint playerActorId, byte val)
|
||||
{
|
||||
return AddActorPacket.BuildPacket(actorId, playerActorId, val);
|
||||
|
@ -151,10 +161,6 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
positionX = pos.X;
|
||||
positionY = pos.Y;
|
||||
positionZ = pos.Z;
|
||||
|
||||
if (target != null)
|
||||
LookAt(target);
|
||||
|
||||
//Program.Server.GetInstance().mLuaEngine.OnPath(actor, position, positionUpdates)
|
||||
}
|
||||
lastMoveUpdate = DateTime.Now;
|
||||
|
@ -358,108 +364,9 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
|
||||
public void Update(double deltaTime)
|
||||
{
|
||||
// todo: this is retarded
|
||||
if (this is Zone || this is Area || this is Player)
|
||||
return;
|
||||
|
||||
var diffTime = (DateTime.Now - lastAiUpdate);
|
||||
|
||||
// todo: this too
|
||||
if (diffTime.Milliseconds >= deltaTime)
|
||||
if (this is Character)
|
||||
{
|
||||
bool foundActor = false;
|
||||
bool skipFollow = false;
|
||||
|
||||
// leash back to spawn
|
||||
if (this.oldPositionX != 0.0f && this.oldPositionY != 0.0f && this.oldPositionZ != 0.0f)
|
||||
{
|
||||
var spawnDistance = Utils.Distance(positionX, positionY, positionZ, oldPositionX, oldPositionY, oldPositionZ);
|
||||
|
||||
if (spawnDistance >= 45)
|
||||
{
|
||||
skipFollow = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var actor in ((Area)zone).GetActorsAroundActor(this, 50))
|
||||
{
|
||||
if (actor is Player && actor != this)
|
||||
{
|
||||
var player = actor as Player;
|
||||
|
||||
if (skipFollow)
|
||||
{
|
||||
// todo: despawn self for player
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
var distance = Utils.Distance(positionX, positionY, positionZ, player.positionX, player.positionY, player.positionZ);
|
||||
|
||||
int maxDistance = player == target ? 25 : 15;
|
||||
|
||||
if (distance <= maxDistance)
|
||||
{
|
||||
foundActor = true;
|
||||
|
||||
if (!hasMoved)
|
||||
{
|
||||
if (distance >= 3)
|
||||
{
|
||||
FollowTarget(player, 2.0f);
|
||||
}
|
||||
// too close, spread out
|
||||
else if (distance <= 0.64f)
|
||||
{
|
||||
var minRadius = 0.65f;
|
||||
var maxRadius = 0.85f;
|
||||
|
||||
var angle = Program.Random.NextDouble() * Math.PI * 2;
|
||||
var radius = Math.Sqrt(Program.Random.NextDouble() * (maxRadius - minRadius)) + minRadius;
|
||||
|
||||
float x = (float)(radius * Math.Cos(angle));
|
||||
float z = (float)(radius * Math.Sin(angle));
|
||||
|
||||
positionUpdates.Add(new utils.Vector3(positionX + x, positionY, positionZ + z));
|
||||
|
||||
hasMoved = true;
|
||||
}
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
LookAt(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
var diffMove = (DateTime.Now - lastMoveUpdate);
|
||||
|
||||
// 5 seconds before back to spawn
|
||||
if (diffMove.Seconds >= 5 && !foundActor)
|
||||
{
|
||||
// leash to spawn
|
||||
this.isAtSpawn = Utils.Distance(positionX, positionY, positionZ, oldPositionX, oldPositionY, oldPositionZ) <= 25.0f;
|
||||
|
||||
if (this.target == null && skipFollow)
|
||||
{
|
||||
// not in spawn range
|
||||
if (!this.isAtSpawn)
|
||||
{
|
||||
PathTo(oldPositionX, oldPositionY, oldPositionZ, 3.0f);
|
||||
}
|
||||
// within spawn range, find a random point
|
||||
else if (diffMove.Seconds >= 15)
|
||||
{
|
||||
//Program.Log.Error("Picking random point to walk to! ");
|
||||
PathTo(oldPositionX, oldPositionY, oldPositionZ, 2.5f, 25, 8.5f);
|
||||
}
|
||||
}
|
||||
this.target = null;
|
||||
}
|
||||
lastAiUpdate = DateTime.Now;
|
||||
((Character)this).Update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -673,88 +580,6 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
|
||||
rotation = (float)dRot;
|
||||
}
|
||||
|
||||
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 sw = new System.Diagnostics.Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
var path = utils.NavmeshUtils.GetPath(((Zone)GetZone()), pos, dest, stepSize, maxPath, polyRadius);
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
if (oldPositionX == 0.0f && oldPositionY == 0.0f && oldPositionZ == 0.0f)
|
||||
{
|
||||
oldPositionX = positionX;
|
||||
oldPositionY = positionY;
|
||||
oldPositionZ = positionZ;
|
||||
}
|
||||
|
||||
// todo: something went wrong
|
||||
if (path.Count == 0)
|
||||
{
|
||||
positionX = oldPositionX;
|
||||
positionY = oldPositionY;
|
||||
positionZ = oldPositionZ;
|
||||
}
|
||||
|
||||
positionUpdates = path;
|
||||
|
||||
this.hasMoved = true;
|
||||
this.isAtSpawn = false;
|
||||
|
||||
sw.Stop();
|
||||
((Zone)zone).pathCalls++;
|
||||
((Zone)zone).pathCallTime += 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)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
var player = target as Player;
|
||||
|
||||
if (this.target != target)
|
||||
{
|
||||
#region super important performance critical code
|
||||
var chatMode = Program.Random.Next(12);
|
||||
var emphasis = Program.Random.Next(9);
|
||||
var drag = Program.Random.Next(7);
|
||||
|
||||
string oni = "ONI";
|
||||
string chan = "CHA";
|
||||
|
||||
for(var i = 0; i < emphasis; ++i)
|
||||
oni += "I";
|
||||
|
||||
for (var i = 0; i < drag; ++i)
|
||||
chan += "A";
|
||||
|
||||
oni += "-";
|
||||
chan += "N";
|
||||
|
||||
|
||||
player.SendMessage((uint)chatMode, "Rowena", oni + chan);
|
||||
#endregion
|
||||
|
||||
this.target = target;
|
||||
}
|
||||
this.moveState = player.moveState;
|
||||
this.moveSpeeds = player.moveSpeeds;
|
||||
|
||||
PathTo(player.positionX, player.positionY, player.positionZ, stepSize, maxPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPath()
|
||||
{
|
||||
// todo: lua function onPath in mob script
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue