Fixed Bugs

This commit is contained in:
Jordan Maxwell 2016-08-19 16:32:14 -05:00
parent fb18c1fbe4
commit 46350a0724
3 changed files with 1604 additions and 1609 deletions

View File

@ -1,358 +1,358 @@
using FFXIVClassic_Map_Server; using FFXIVClassic_Map_Server;
using FFXIVClassic.Common; using FFXIVClassic.Common;
using FFXIVClassic_Map_Server.packets; using FFXIVClassic_Map_Server.packets;
using FFXIVClassic_Map_Server.actors.area; using FFXIVClassic_Map_Server.actors.area;
using FFXIVClassic_Map_Server.actors.chara.npc; using FFXIVClassic_Map_Server.actors.chara.npc;
using FFXIVClassic_Map_Server.dataobjects; using FFXIVClassic_Map_Server.dataobjects;
using FFXIVClassic_Map_Server.dataobjects.chara; using FFXIVClassic_Map_Server.dataobjects.chara;
using FFXIVClassic_Map_Server.lua; using FFXIVClassic_Map_Server.lua;
using FFXIVClassic_Map_Server.packets.send.actor; using FFXIVClassic_Map_Server.packets.send.actor;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using FFXIVClassic_Map_Server.packets.send; using FFXIVClassic_Map_Server.packets.send;
namespace FFXIVClassic_Map_Server.Actors namespace FFXIVClassic_Map_Server.Actors
{ {
class Area : Actor class Area : Actor
{ {
public string zoneName; public string zoneName;
public ushort regionId; public ushort regionId;
public bool isIsolated, canStealth, isInn, canRideChocobo, isInstanceRaid; public bool isIsolated, canStealth, isInn, canRideChocobo, isInstanceRaid;
public ushort weatherNormal, weatherCommon, weatherRare; public ushort weatherNormal, weatherCommon, weatherRare;
public ushort bgmDay, bgmNight, bgmBattle; public ushort bgmDay, bgmNight, bgmBattle;
protected string classPath; protected string classPath;
public int boundingGridSize = 50; public int boundingGridSize = 50;
public int minX = -1000, minY = -1000, maxX = 1000, maxY = 1000; public int minX = -1000, minY = -1000, maxX = 1000, maxY = 1000;
protected int numXBlocks, numYBlocks; protected int numXBlocks, numYBlocks;
protected int halfWidth, halfHeight; protected int halfWidth, halfHeight;
protected List<SpawnLocation> mSpawnLocations = new List<SpawnLocation>(); protected List<SpawnLocation> mSpawnLocations = new List<SpawnLocation>();
protected Dictionary<uint, Actor> mActorList = new Dictionary<uint, Actor>(); protected Dictionary<uint, Actor> mActorList = new Dictionary<uint, Actor>();
protected List<Actor>[,] mActorBlock; protected List<Actor>[,] mActorBlock;
LuaScript areaScript; LuaScript areaScript;
public Area(uint id, string zoneName, ushort regionId, string className, ushort bgmDay, ushort bgmNight, ushort bgmBattle, bool isIsolated, bool isInn, bool canRideChocobo, bool canStealth, bool isInstanceRaid) public Area(uint id, string zoneName, ushort regionId, string className, ushort bgmDay, ushort bgmNight, ushort bgmBattle, bool isIsolated, bool isInn, bool canRideChocobo, bool canStealth, bool isInstanceRaid)
: base(id) : base(id)
{ {
this.zoneName = zoneName; this.zoneName = zoneName;
this.regionId = regionId; this.regionId = regionId;
this.canStealth = canStealth; this.canStealth = canStealth;
this.isIsolated = isIsolated; this.isIsolated = isIsolated;
this.isInn = isInn; this.isInn = isInn;
this.canRideChocobo = canRideChocobo; this.canRideChocobo = canRideChocobo;
this.isInstanceRaid = isInstanceRaid; this.isInstanceRaid = isInstanceRaid;
this.bgmDay = bgmDay; this.bgmDay = bgmDay;
this.bgmNight = bgmNight; this.bgmNight = bgmNight;
this.bgmBattle = bgmBattle; this.bgmBattle = bgmBattle;
this.displayNameId = 0; this.displayNameId = 0;
this.customDisplayName = "_areaMaster"; this.customDisplayName = "_areaMaster";
this.actorName = String.Format("_areaMaster@{0:X5}",id<<8); this.actorName = String.Format("_areaMaster@{0:X5}",id<<8);
this.className = className; this.className = className;
numXBlocks = (maxX - minX) / boundingGridSize; numXBlocks = (maxX - minX) / boundingGridSize;
numYBlocks = (maxY - minY) / boundingGridSize; numYBlocks = (maxY - minY) / boundingGridSize;
mActorBlock = new List<Actor>[numXBlocks, numYBlocks]; mActorBlock = new List<Actor>[numXBlocks, numYBlocks];
halfWidth = numXBlocks / 2; halfWidth = numXBlocks / 2;
halfHeight = numYBlocks / 2; halfHeight = numYBlocks / 2;
for (int y = 0; y < numYBlocks; y++) for (int y = 0; y < numYBlocks; y++)
{ {
for (int x = 0; x < numXBlocks; x++ ) for (int x = 0; x < numXBlocks; x++ )
{ {
mActorBlock[x, y] = new List<Actor>(); mActorBlock[x, y] = new List<Actor>();
} }
} }
} }
public override SubPacket CreateScriptBindPacket(uint playerActorId) public override SubPacket CreateScriptBindPacket(uint playerActorId)
{ {
List<LuaParam> lParams; List<LuaParam> lParams;
lParams = LuaUtils.CreateLuaParamList(classPath, false, true, zoneName, "/Area/Zone/ZoneDefault", -1, (byte)1, true, false, false, false, false, false, false, false); lParams = LuaUtils.CreateLuaParamList(classPath, false, true, zoneName, "/Area/Zone/ZoneDefault", -1, (byte)1, true, false, false, false, false, false, false, false);
return ActorInstantiatePacket.BuildPacket(actorId, playerActorId, actorName, "ZoneDefault", lParams); return ActorInstantiatePacket.BuildPacket(actorId, playerActorId, actorName, "ZoneDefault", lParams);
} }
public override BasePacket GetSpawnPackets(uint playerActorId) public override BasePacket GetSpawnPackets(uint playerActorId)
{ {
List<SubPacket> subpackets = new List<SubPacket>(); List<SubPacket> subpackets = new List<SubPacket>();
subpackets.Add(CreateAddActorPacket(playerActorId, 0)); subpackets.Add(CreateAddActorPacket(playerActorId, 0));
subpackets.Add(CreateSpeedPacket(playerActorId)); subpackets.Add(CreateSpeedPacket(playerActorId));
subpackets.Add(CreateSpawnPositonPacket(playerActorId, 0x1)); subpackets.Add(CreateSpawnPositonPacket(playerActorId, 0x1));
subpackets.Add(CreateNamePacket(playerActorId)); subpackets.Add(CreateNamePacket(playerActorId));
subpackets.Add(CreateStatePacket(playerActorId)); subpackets.Add(CreateStatePacket(playerActorId));
subpackets.Add(CreateIsZoneingPacket(playerActorId)); subpackets.Add(CreateIsZoneingPacket(playerActorId));
subpackets.Add(CreateScriptBindPacket(playerActorId)); subpackets.Add(CreateScriptBindPacket(playerActorId));
return BasePacket.CreatePacket(subpackets, true, false); return BasePacket.CreatePacket(subpackets, true, false);
} }
#region Actor Management #region Actor Management
public void AddActorToZone(Actor actor) public void AddActorToZone(Actor actor)
{ {
if (!mActorList.ContainsKey(actor.actorId)) if (!mActorList.ContainsKey(actor.actorId))
mActorList.Add(actor.actorId, actor); mActorList.Add(actor.actorId, actor);
int gridX = (int)actor.positionX / boundingGridSize; int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionZ / boundingGridSize; int gridY = (int)actor.positionZ / boundingGridSize;
gridX += halfWidth; gridX += halfWidth;
gridY += halfHeight; gridY += halfHeight;
//Boundries //Boundries
if (gridX < 0) if (gridX < 0)
gridX = 0; gridX = 0;
if (gridX >= numXBlocks) if (gridX >= numXBlocks)
gridX = numXBlocks - 1; gridX = numXBlocks - 1;
if (gridY < 0) if (gridY < 0)
gridY = 0; gridY = 0;
if (gridY >= numYBlocks) if (gridY >= numYBlocks)
gridY = numYBlocks - 1; gridY = numYBlocks - 1;
lock (mActorBlock) lock (mActorBlock)
mActorBlock[gridX, gridY].Add(actor); mActorBlock[gridX, gridY].Add(actor);
} }
public void RemoveActorFromZone(Actor actor) public void RemoveActorFromZone(Actor actor)
{ {
mActorList.Remove(actor.actorId); mActorList.Remove(actor.actorId);
int gridX = (int)actor.positionX / boundingGridSize; int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionZ / boundingGridSize; int gridY = (int)actor.positionZ / boundingGridSize;
gridX += halfWidth; gridX += halfWidth;
gridY += halfHeight; gridY += halfHeight;
//Boundries //Boundries
if (gridX < 0) if (gridX < 0)
gridX = 0; gridX = 0;
if (gridX >= numXBlocks) if (gridX >= numXBlocks)
gridX = numXBlocks - 1; gridX = numXBlocks - 1;
if (gridY < 0) if (gridY < 0)
gridY = 0; gridY = 0;
if (gridY >= numYBlocks) if (gridY >= numYBlocks)
gridY = numYBlocks - 1; gridY = numYBlocks - 1;
lock (mActorBlock) lock (mActorBlock)
mActorBlock[gridX, gridY].Remove(actor); mActorBlock[gridX, gridY].Remove(actor);
} }
public void UpdateActorPosition(Actor actor) public void UpdateActorPosition(Actor actor)
{ {
int gridX = (int)actor.positionX / boundingGridSize; int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionZ / boundingGridSize; int gridY = (int)actor.positionZ / boundingGridSize;
gridX += halfWidth; gridX += halfWidth;
gridY += halfHeight; gridY += halfHeight;
//Boundries //Boundries
if (gridX < 0) if (gridX < 0)
gridX = 0; gridX = 0;
if (gridX >= numXBlocks) if (gridX >= numXBlocks)
gridX = numXBlocks - 1; gridX = numXBlocks - 1;
if (gridY < 0) if (gridY < 0)
gridY = 0; gridY = 0;
if (gridY >= numYBlocks) if (gridY >= numYBlocks)
gridY = numYBlocks - 1; gridY = numYBlocks - 1;
int gridOldX = (int)actor.oldPositionX / boundingGridSize; int gridOldX = (int)actor.oldPositionX / boundingGridSize;
int gridOldY = (int)actor.oldPositionZ / boundingGridSize; int gridOldY = (int)actor.oldPositionZ / boundingGridSize;
gridOldX += halfWidth; gridOldX += halfWidth;
gridOldY += halfHeight; gridOldY += halfHeight;
//Boundries //Boundries
if (gridOldX < 0) if (gridOldX < 0)
gridOldX = 0; gridOldX = 0;
if (gridOldX >= numXBlocks) if (gridOldX >= numXBlocks)
gridOldX = numXBlocks - 1; gridOldX = numXBlocks - 1;
if (gridOldY < 0) if (gridOldY < 0)
gridOldY = 0; gridOldY = 0;
if (gridOldY >= numYBlocks) if (gridOldY >= numYBlocks)
gridOldY = numYBlocks - 1; gridOldY = numYBlocks - 1;
//Still in same block //Still in same block
if (gridX == gridOldX && gridY == gridOldY) if (gridX == gridOldX && gridY == gridOldY)
return;
lock (mActorBlock)
{
mActorBlock[gridOldX, gridOldY].Remove(actor);
mActorBlock[gridX, gridY].Add(actor);
}
}
public List<Actor> GetActorsAroundPoint(float x, float y, int checkDistance)
{
checkDistance /= boundingGridSize;
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(mActorBlock[gx, gy]);
}
}
//Remove players if isolation zone
if (isIsolated)
{
for (int i = 0; i < result.Count; i++)
{
if (result[i] is Player)
result.RemoveAt(i);
}
}
return result;
}
public List<Actor> GetActorsAroundActor(Actor actor, int checkDistance)
{
checkDistance /= boundingGridSize;
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;
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(mActorBlock[gx, gy]);
}
}
//Remove players if isolation zone
if (isIsolated)
{
for (int i = 0; i < result.Count; i++)
{
if (result[i] is Player)
result.RemoveAt(i);
}
}
return result;
}
#endregion
public Actor FindActorInZone(uint id)
{
if (!mActorList.ContainsKey(id))
return null;
return mActorList[id];
}
public Player FindPCInZone(string name)
{
foreach (Actor a in mActorList.Values)
{
if (a is Player)
{
if (((Player)a).customDisplayName.ToLower().Equals(name.ToLower()))
return (Player)a;
}
}
return null;
}
public Player FindPCInZone(uint id)
{
if (!mActorList.ContainsKey(id))
return null;
return (Player)mActorList[id];
}
public void Clear()
{
//Clear All
mActorList.Clear();
for (int y = 0; y < numYBlocks; y++)
{
for (int x = 0; x < numXBlocks; x++)
{
mActorBlock[x, y].Clear();
}
}
}
public void BroadcastPacketAroundActor(Actor actor, SubPacket packet)
{
if (isIsolated)
return;
List<Actor> aroundActor = GetActorsAroundActor(actor, 50);
foreach (Actor a in aroundActor)
{
if (a is Player)
{
if (isIsolated && packet.header.sourceId != a.actorId)
continue;
SubPacket clonedPacket = new SubPacket(packet, actor.actorId);
Player p = (Player)a;
p.QueuePacket(clonedPacket);
}
}
}
public void SpawnActor(SpawnLocation location)
{
ActorClass actorClass = Server.GetWorldManager().GetActorClass(location.classId);
if (actorClass == null)
return; return;
Npc npc = new Npc(mActorList.Count + 1, actorClass, location.uniqueId, actorId, location.x, location.y, location.z, location.rot, location.state, location.animId, null); lock (mActorBlock)
npc.LoadEventConditions(actorClass.eventConditions); {
mActorBlock[gridOldX, gridOldY].Remove(actor);
AddActorToZone(npc); mActorBlock[gridX, gridY].Add(actor);
} }
}
public List<Actor> GetActorsAroundPoint(float x, float y, int checkDistance)
{
checkDistance /= boundingGridSize;
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(mActorBlock[gx, gy]);
}
}
//Remove players if isolation zone
if (isIsolated)
{
for (int i = 0; i < result.Count; i++)
{
if (result[i] is Player)
result.RemoveAt(i);
}
}
return result;
}
public List<Actor> GetActorsAroundActor(Actor actor, int checkDistance)
{
checkDistance /= boundingGridSize;
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;
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(mActorBlock[gx, gy]);
}
}
//Remove players if isolation zone
if (isIsolated)
{
for (int i = 0; i < result.Count; i++)
{
if (result[i] is Player)
result.RemoveAt(i);
}
}
return result;
}
#endregion
public Actor FindActorInZone(uint id)
{
if (!mActorList.ContainsKey(id))
return null;
return mActorList[id];
}
public Player FindPCInZone(string name)
{
foreach (Actor a in mActorList.Values)
{
if (a is Player)
{
if (((Player)a).customDisplayName.ToLower().Equals(name.ToLower()))
return (Player)a;
}
}
return null;
}
public Player FindPCInZone(uint id)
{
if (!mActorList.ContainsKey(id))
return null;
return (Player)mActorList[id];
}
public void Clear()
{
//Clear All
mActorList.Clear();
for (int y = 0; y < numYBlocks; y++)
{
for (int x = 0; x < numXBlocks; x++)
{
mActorBlock[x, y].Clear();
}
}
}
public void BroadcastPacketAroundActor(Actor actor, SubPacket packet)
{
if (isIsolated)
return;
List<Actor> aroundActor = GetActorsAroundActor(actor, 50);
foreach (Actor a in aroundActor)
{
if (a is Player)
{
if (isIsolated && packet.header.sourceId != a.actorId)
continue;
SubPacket clonedPacket = new SubPacket(packet, actor.actorId);
Player p = (Player)a;
p.QueuePacket(clonedPacket);
}
}
}
public void SpawnActor(SpawnLocation location)
{
ActorClass actorClass = Server.GetWorldManager().GetActorClass(location.classId);
if (actorClass == null)
return;
Npc npc = new Npc(mActorList.Count + 1, actorClass, location.uniqueId, actorId, location.x, location.y, location.z, location.rot, location.state, location.animId, null);
npc.LoadEventConditions(actorClass.eventConditions);
AddActorToZone(npc);
}
public void ChangeWeather(ushort weather, ushort transitionTime, Player player, bool zoneWide = false) public void ChangeWeather(ushort weather, ushort transitionTime, Player player, bool zoneWide = false)
{ {
weatherNormal = weather; weatherNormal = weather;
@ -372,6 +372,6 @@ namespace FFXIVClassic_Map_Server.Actors
} }
} }
} }
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,11 @@ namespace FFXIVClassic_Map_Server.lua
player.playerSession.QueuePacket(SetWeatherPacket.BuildPacket(player.actorId, weatherID, 1), true, false); player.playerSession.QueuePacket(SetWeatherPacket.BuildPacket(player.actorId, weatherID, 1), true, false);
} }
public void IssueChocobo(int appearanceId, string name)
{
player.IssueChocobo((byte) appearanceId, name);
}
public void GetParameter(string paramName) public void GetParameter(string paramName)
{ {