mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-07-31 14:56:20 +02:00
Implemented WeatherDirector , ZoneMaster, and WorldMaster in code. Zone objects has become the ZoneMaster actor object.
This commit is contained in:
parent
724445a54a
commit
1c845e62e3
9 changed files with 209 additions and 18 deletions
226
FFXIVClassic Map Server/actors/area/Zone.cs
Normal file
226
FFXIVClassic Map Server/actors/area/Zone.cs
Normal file
|
@ -0,0 +1,226 @@
|
|||
using FFXIVClassic_Lobby_Server.common;
|
||||
using FFXIVClassic_Lobby_Server.packets;
|
||||
using FFXIVClassic_Map_Server.dataobjects;
|
||||
using FFXIVClassic_Map_Server.lua;
|
||||
using FFXIVClassic_Map_Server.packets.send.actor;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FFXIVClassic_Map_Server
|
||||
{
|
||||
class Zone : Actor
|
||||
{
|
||||
public string zoneName;
|
||||
public ushort regionId;
|
||||
public bool canStealth, isInn, canRideChocobo, isInstanceRaid;
|
||||
public ushort weatherNormal, weatherCommon, weatherRare;
|
||||
public ushort bgmDay, bgmNight, bgmBattle;
|
||||
|
||||
public int boundingGridSize = 50;
|
||||
public int minX = -100, minY = -100, maxX = 100, maxY = 100;
|
||||
private int numXBlocks, numYBlocks;
|
||||
private int halfWidth, halfHeight;
|
||||
private List<Actor>[,] actorBlock;
|
||||
|
||||
public Zone(uint id, string zoneName, ushort regionId, bool canStealth, bool isInn, bool canRideChocobo, bool isInstanceRaid) : base(id)
|
||||
{
|
||||
|
||||
this.zoneName = zoneName;
|
||||
this.regionId = regionId;
|
||||
this.canStealth = canStealth;
|
||||
this.isInn = isInn;
|
||||
this.canRideChocobo = canRideChocobo;
|
||||
this.isInstanceRaid = isInstanceRaid;
|
||||
|
||||
this.displayNameId = 0;
|
||||
this.customDisplayName = "_areaMaster";
|
||||
this.actorName = String.Format("_areaMaster@{0:X5}",id<<8);
|
||||
|
||||
this.className = "ZoneMasterPrvI0";
|
||||
|
||||
numXBlocks = (maxX - minX) / boundingGridSize;
|
||||
numYBlocks = (maxY - minY) / boundingGridSize;
|
||||
actorBlock = new List<Actor>[numXBlocks, numYBlocks];
|
||||
halfWidth = numXBlocks / 2;
|
||||
halfHeight = numYBlocks / 2;
|
||||
|
||||
for (int y = 0; y < numYBlocks; y++)
|
||||
{
|
||||
for (int x = 0; x < numXBlocks; x++ )
|
||||
{
|
||||
actorBlock[x, y] = new List<Actor>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override SubPacket createScriptBindPacket(uint playerActorId)
|
||||
{
|
||||
List<LuaParam> lParams;
|
||||
lParams = LuaUtils.createLuaParamList("/Area/Zone/ZoneMasterPrvI0", false, true, zoneName, "", 0xFFFFFFFF, false, false, canStealth, isInn, false, false, false, false, false, false);
|
||||
return ActorInstantiatePacket.buildPacket(actorId, playerActorId, actorName, className, lParams);
|
||||
}
|
||||
|
||||
public override BasePacket getSpawnPackets(uint playerActorId)
|
||||
{
|
||||
List<SubPacket> subpackets = new List<SubPacket>();
|
||||
subpackets.Add(createAddActorPacket(playerActorId));
|
||||
subpackets.Add(createSpeedPacket(playerActorId));
|
||||
subpackets.Add(createSpawnPositonPacket(playerActorId, 0x1));
|
||||
subpackets.Add(createNamePacket(playerActorId));
|
||||
subpackets.Add(createStatePacket(playerActorId));
|
||||
subpackets.Add(createIsZoneingPacket(playerActorId));
|
||||
subpackets.Add(createScriptBindPacket(playerActorId));
|
||||
return BasePacket.createPacket(subpackets, true, false);
|
||||
}
|
||||
|
||||
#region Actor Management
|
||||
|
||||
public void addActorToZone(Actor actor)
|
||||
{
|
||||
int gridX = (int)actor.positionX / boundingGridSize;
|
||||
int gridY = (int)actor.positionZ / 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;
|
||||
|
||||
lock (actorBlock)
|
||||
actorBlock[gridX, gridY].Add(actor);
|
||||
}
|
||||
|
||||
public void removeActorToZone(Actor actor)
|
||||
{
|
||||
int gridX = (int)actor.positionX / boundingGridSize;
|
||||
int gridY = (int)actor.positionZ / 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;
|
||||
|
||||
lock (actorBlock)
|
||||
actorBlock[gridX, gridY].Remove(actor);
|
||||
}
|
||||
|
||||
public void updateActorPosition(Actor actor)
|
||||
{
|
||||
int gridX = (int)actor.positionX / boundingGridSize;
|
||||
int gridY = (int)actor.positionZ / 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;
|
||||
|
||||
int gridOldX = (int)actor.oldPositionX / boundingGridSize;
|
||||
int gridOldY = (int)actor.oldPositionZ / boundingGridSize;
|
||||
|
||||
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;
|
||||
|
||||
//Still in same block
|
||||
if (gridX == gridOldX && gridY == gridOldY)
|
||||
return;
|
||||
|
||||
lock (actorBlock)
|
||||
actorBlock[gridOldX, gridOldY].Remove(actor);
|
||||
lock (actorBlock)
|
||||
actorBlock[gridX, gridY].Add(actor);
|
||||
}
|
||||
|
||||
public List<Actor> getActorsAroundPoint(float x, float y, int checkDistance)
|
||||
{
|
||||
int gridX = (int)x/boundingGridSize;
|
||||
int gridY = (int)y/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;
|
||||
|
||||
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.positionZ / boundingGridSize;
|
||||
|
||||
gridX += halfWidth;
|
||||
gridY += halfHeight;
|
||||
|
||||
|
||||
|
||||
List<Actor> result = new List<Actor>();
|
||||
|
||||
for (int gy = ((gridY - checkDistance) < 0 ? 0 : (gridY - checkDistance)); gy <= ((gridY + checkDistance) >= numYBlocks ? numYBlocks - 1 : (gridY + checkDistance)); gy++)
|
||||
{
|
||||
for (int gx = ((gridX - checkDistance) < 0 ? 0 : (gridX - checkDistance)); gx <= ((gridX + checkDistance) >= numXBlocks ? numXBlocks - 1 : (gridX + checkDistance)); gx++)
|
||||
{
|
||||
result.AddRange(actorBlock[gx, gy]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue