2015-10-05 19:36:15 -04:00
|
|
|
|
using FFXIVClassic_Map_Server.dataobjects;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FFXIVClassic_Map_Server
|
|
|
|
|
{
|
|
|
|
|
class Zone
|
|
|
|
|
{
|
|
|
|
|
public uint mapId;
|
2015-10-13 19:15:44 -04:00
|
|
|
|
public ushort weatherNormal, weatherCommon, weatherRare;
|
|
|
|
|
public ushort bgmDay, bgmNight, bgmBattle;
|
2015-10-05 19:36:15 -04:00
|
|
|
|
public int boundingGridSize = 200;
|
2015-10-13 19:15:44 -04:00
|
|
|
|
public int minX = -1000, minY = -1000, maxX = 1000, maxY = 1000;
|
|
|
|
|
private int numXBlocks, numYBlocks;
|
|
|
|
|
private int halfWidth, halfHeight;
|
|
|
|
|
private List<Actor>[,] actorBlock;
|
2015-10-05 19:36:15 -04:00
|
|
|
|
|
2015-10-13 19:15:44 -04:00
|
|
|
|
public Zone()
|
|
|
|
|
{
|
|
|
|
|
numXBlocks = (maxX - minX) / boundingGridSize;
|
|
|
|
|
numYBlocks = (maxY - minY) / boundingGridSize;
|
|
|
|
|
actorBlock = new List<Actor>[numXBlocks, numYBlocks];
|
|
|
|
|
halfWidth = numXBlocks / 2;
|
|
|
|
|
halfHeight = numYBlocks / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Actor Management
|
2015-10-05 19:36:15 -04:00
|
|
|
|
|
|
|
|
|
public void addActorToZone(Actor actor)
|
|
|
|
|
{
|
|
|
|
|
int gridX = (int)actor.positionX / boundingGridSize;
|
|
|
|
|
int gridY = (int)actor.positionY / boundingGridSize;
|
|
|
|
|
|
2015-10-13 19:15:44 -04:00
|
|
|
|
gridX += halfWidth;
|
|
|
|
|
gridY += halfHeight;
|
|
|
|
|
|
|
|
|
|
//Boundries
|
|
|
|
|
if (gridX < 0)
|
|
|
|
|
gridX = 0;
|
|
|
|
|
if (gridX >= numXBlocks)
|
|
|
|
|
gridX = numXBlocks - 1;
|
|
|
|
|
if (gridY < 0)
|
|
|
|
|
gridY = 0;
|
|
|
|
|
if (gridY >= numYBlocks)
|
|
|
|
|
gridY = numYBlocks - 1;
|
|
|
|
|
|
2015-10-05 19:36:15 -04:00
|
|
|
|
lock (actorBlock)
|
2015-10-13 19:15:44 -04:00
|
|
|
|
actorBlock[gridX, gridY].Add(actor);
|
2015-10-05 19:36:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeActorToZone(Actor actor)
|
|
|
|
|
{
|
|
|
|
|
int gridX = (int)actor.positionX / boundingGridSize;
|
|
|
|
|
int gridY = (int)actor.positionY / boundingGridSize;
|
|
|
|
|
|
2015-10-13 19:15:44 -04:00
|
|
|
|
gridX += halfWidth;
|
|
|
|
|
gridY += halfHeight;
|
|
|
|
|
|
|
|
|
|
//Boundries
|
|
|
|
|
if (gridX < 0)
|
|
|
|
|
gridX = 0;
|
|
|
|
|
if (gridX >= numXBlocks)
|
|
|
|
|
gridX = numXBlocks - 1;
|
|
|
|
|
if (gridY < 0)
|
|
|
|
|
gridY = 0;
|
|
|
|
|
if (gridY >= numYBlocks)
|
|
|
|
|
gridY = numYBlocks - 1;
|
|
|
|
|
|
2015-10-05 19:36:15 -04:00
|
|
|
|
lock (actorBlock)
|
2015-10-13 19:15:44 -04:00
|
|
|
|
actorBlock[gridX, gridY].Remove(actor);
|
2015-10-05 19:36:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateActorPosition(Actor actor)
|
|
|
|
|
{
|
|
|
|
|
int gridX = (int)actor.positionX / boundingGridSize;
|
|
|
|
|
int gridY = (int)actor.positionY / boundingGridSize;
|
|
|
|
|
|
2015-10-13 19:15:44 -04:00
|
|
|
|
gridX += halfWidth;
|
|
|
|
|
gridY += halfHeight;
|
|
|
|
|
|
|
|
|
|
//Boundries
|
|
|
|
|
if (gridX < 0)
|
|
|
|
|
gridX = 0;
|
|
|
|
|
if (gridX >= numXBlocks)
|
|
|
|
|
gridX = numXBlocks - 1;
|
|
|
|
|
if (gridY < 0)
|
|
|
|
|
gridY = 0;
|
|
|
|
|
if (gridY >= numYBlocks)
|
|
|
|
|
gridY = numYBlocks - 1;
|
|
|
|
|
|
2015-10-05 19:36:15 -04:00
|
|
|
|
int gridOldX = (int)actor.oldPositionX / boundingGridSize;
|
|
|
|
|
int gridOldY = (int)actor.oldPositionY / boundingGridSize;
|
|
|
|
|
|
2015-10-13 19:15:44 -04:00
|
|
|
|
gridOldX += halfWidth;
|
|
|
|
|
gridOldY += halfHeight;
|
|
|
|
|
|
|
|
|
|
//Boundries
|
|
|
|
|
if (gridOldX < 0)
|
|
|
|
|
gridOldX = 0;
|
|
|
|
|
if (gridOldX >= numXBlocks)
|
|
|
|
|
gridOldX = numXBlocks - 1;
|
|
|
|
|
if (gridOldY < 0)
|
|
|
|
|
gridOldY = 0;
|
|
|
|
|
if (gridOldY >= numYBlocks)
|
|
|
|
|
gridOldY = numYBlocks - 1;
|
|
|
|
|
|
2015-10-05 19:36:15 -04:00
|
|
|
|
//Still in same block
|
|
|
|
|
if (gridX == gridOldX && gridY == gridOldY)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
lock (actorBlock)
|
2015-10-13 19:15:44 -04:00
|
|
|
|
actorBlock[gridOldX, gridOldY].Remove(actor);
|
2015-10-05 19:36:15 -04:00
|
|
|
|
lock (actorBlock)
|
2015-10-13 19:15:44 -04:00
|
|
|
|
actorBlock[gridX, gridY].Add(actor);
|
2015-10-05 19:36:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Actor> getActorsAroundPoint(float x, float y, int checkDistance)
|
|
|
|
|
{
|
|
|
|
|
int gridX = (int)x/boundingGridSize;
|
|
|
|
|
int gridY = (int)y/boundingGridSize;
|
|
|
|
|
|
2015-10-13 19:15:44 -04:00
|
|
|
|
gridX += halfWidth;
|
|
|
|
|
gridY += halfHeight;
|
|
|
|
|
|
|
|
|
|
//Boundries
|
|
|
|
|
if (gridX < 0)
|
|
|
|
|
gridX = 0;
|
|
|
|
|
if (gridX >= numXBlocks)
|
|
|
|
|
gridX = numXBlocks - 1;
|
|
|
|
|
if (gridY < 0)
|
|
|
|
|
gridY = 0;
|
|
|
|
|
if (gridY >= numYBlocks)
|
|
|
|
|
gridY = numYBlocks - 1;
|
|
|
|
|
|
|
|
|
|
List<Actor> result = new List<Actor>();
|
|
|
|
|
|
|
|
|
|
for (int gx = gridX - checkDistance; gx <= gridX + checkDistance; gx++)
|
|
|
|
|
{
|
|
|
|
|
for (int gy = gridY - checkDistance; gy <= gridY + checkDistance; gy++)
|
|
|
|
|
{
|
|
|
|
|
result.AddRange(actorBlock[gx, gy]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Actor> getActorsAroundActor(Actor actor, int checkDistance)
|
|
|
|
|
{
|
|
|
|
|
int gridX = (int)actor.positionX / boundingGridSize;
|
|
|
|
|
int gridY = (int)actor.positionY / boundingGridSize;
|
|
|
|
|
|
|
|
|
|
gridX += halfWidth;
|
|
|
|
|
gridY += halfHeight;
|
|
|
|
|
|
|
|
|
|
//Boundries
|
|
|
|
|
if (gridX < 0)
|
|
|
|
|
gridX = 0;
|
|
|
|
|
if (gridX >= numXBlocks)
|
|
|
|
|
gridX = numXBlocks - 1;
|
|
|
|
|
if (gridY < 0)
|
|
|
|
|
gridY = 0;
|
|
|
|
|
if (gridY >= numYBlocks)
|
|
|
|
|
gridY = numYBlocks - 1;
|
|
|
|
|
|
2015-10-05 19:36:15 -04:00
|
|
|
|
List<Actor> result = new List<Actor>();
|
|
|
|
|
|
|
|
|
|
for (int gx = gridX - checkDistance; gx <= gridX + checkDistance; gx++)
|
|
|
|
|
{
|
|
|
|
|
for (int gy = gridY - checkDistance; gy <= gridY + checkDistance; gy++)
|
|
|
|
|
{
|
2015-10-13 19:15:44 -04:00
|
|
|
|
result.AddRange(actorBlock[gx, gy]);
|
2015-10-05 19:36:15 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2015-10-13 19:15:44 -04:00
|
|
|
|
|
|
|
|
|
#endregion
|
2015-10-05 19:36:15 -04:00
|
|
|
|
}
|
|
|
|
|
}
|