1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-21 20:27:47 +00:00

fixed player position updates i think

This commit is contained in:
Tahir Akhlaq 2017-06-07 02:59:27 +01:00
parent dd552ba69d
commit b640c87c69
3 changed files with 64 additions and 36 deletions

View file

@ -540,7 +540,7 @@ namespace FFXIVClassic_Map_Server.Actors
return zoneId; return zoneId;
} }
public bool IsFacing(float x, float y, byte checkAngle = 45) public bool IsFacing(float x, float y)
{ {
var rot1 = this.rotation; var rot1 = this.rotation;
@ -554,6 +554,26 @@ namespace FFXIVClassic_Map_Server.Actors
return rot1 == (float)dRot; return rot1 == (float)dRot;
} }
public bool IsFacing(Actor target)
{
if (target == null)
{
Program.Log.Error("[{0}][{1}] IsFacing no target!", actorId, actorName);
return false;
}
var rot1 = this.rotation;
var dX = this.positionX - target.positionX;
var dY = this.positionY - target.positionY;
var rot2 = Math.Atan2(dY, dX);
var dRot = Math.PI - rot2 + Math.PI / 2;
return rot1 == (float)dRot;
}
public void LookAt(Actor actor) public void LookAt(Actor actor)
{ {
if (actor != null) if (actor != null)

View file

@ -161,6 +161,8 @@ namespace FFXIVClassic_Map_Server.Actors
public void UpdateActorPosition(Actor actor) public void UpdateActorPosition(Actor actor)
{ {
this.hasMoved = true;
int gridX = (int)actor.positionX / boundingGridSize; int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionZ / boundingGridSize; int gridY = (int)actor.positionZ / boundingGridSize;
@ -202,7 +204,6 @@ namespace FFXIVClassic_Map_Server.Actors
mActorBlock[gridOldX, gridOldY].Remove(actor); mActorBlock[gridOldX, gridOldY].Remove(actor);
mActorBlock[gridX, gridY].Add(actor); mActorBlock[gridX, gridY].Add(actor);
} }
this.hasMoved = true;
} }
public List<Actor> GetActorsAroundPoint(float x, float y, int checkDistance) public List<Actor> GetActorsAroundPoint(float x, float y, int checkDistance)

View file

@ -252,7 +252,7 @@ namespace FFXIVClassic_Map_Server.Actors
{ {
// make sure we dont tell player to despawn us twice // make sure we dont tell player to despawn us twice
targId = player.actorId; targId = player.actorId;
player.QueuePacket(RemoveActorPacket.BuildPacket(player.actorId, actorId)); //player.QueuePacket(RemoveActorPacket.BuildPacket(player.actorId, actorId));
} }
} }
this.isMovingToSpawn = true; this.isMovingToSpawn = true;
@ -268,6 +268,8 @@ namespace FFXIVClassic_Map_Server.Actors
this.lastMoveUpdate = this.lastMoveUpdate.AddSeconds(-5); this.lastMoveUpdate = this.lastMoveUpdate.AddSeconds(-5);
} }
} }
Player closestPlayer = null;
float closestPlayerDistance = 1000.0f;
foreach (var actor in zone.GetActorsAroundActor(this, 65)) foreach (var actor in zone.GetActorsAroundActor(this, 65))
{ {
@ -278,7 +280,7 @@ namespace FFXIVClassic_Map_Server.Actors
// dont despawn again if we already told target to despawn us // dont despawn again if we already told target to despawn us
if (despawnOutOfRange && player.actorId != targId) if (despawnOutOfRange && player.actorId != targId)
{ {
player.QueuePacket(RemoveActorPacket.BuildPacket(player.actorId, this.actorId)); //player.QueuePacket(RemoveActorPacket.BuildPacket(player.actorId, this.actorId));
continue; continue;
} }
@ -289,43 +291,48 @@ namespace FFXIVClassic_Map_Server.Actors
// find distance between self and target // find distance between self and target
var distance = Utils.Distance(positionX, positionY, positionZ, player.positionX, player.positionY, player.positionZ); var distance = Utils.Distance(positionX, positionY, positionZ, player.positionX, player.positionY, player.positionZ);
int maxDistance = player == target ? 27 : 15; int maxDistance = player == target ? 27 : 10;
// check target isnt too far // check target isnt too far
if (distance <= maxDistance) // todo: create cone thing for IsFacing
if (distance <= maxDistance && distance <= closestPlayerDistance && (IsFacing(player) || true))
{ {
closestPlayerDistance = distance;
closestPlayer = player;
foundActor = true; foundActor = true;
if (!hasMoved)
{
if (distance >= 3)
{
FollowTarget(player, 2.4f, 5);
}
// 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; }
}
if (foundActor)
{
if (!hasMoved)
{
if (closestPlayerDistance >= 3)
{
FollowTarget(closestPlayer, 2.4f, 5);
}
// too close, spread out
else if (closestPlayerDistance <= 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);
}
} }
} }
var diffMove = (DateTime.Now - lastMoveUpdate); var diffMove = (DateTime.Now - lastMoveUpdate);