Refactored how zones work. Cleaned out a lot of duplciations and smoothed out how Zones/PrivateAreas work.

This commit is contained in:
Filip Maj 2022-02-05 14:05:32 -05:00
parent 56ba641e2a
commit 563118372a
32 changed files with 247 additions and 417 deletions

View file

@ -119,7 +119,7 @@ namespace Meteor.Map
{
Zone zone = new Zone(reader.GetUInt32(0), reader.GetString(1), reader.GetUInt16(2), reader.GetString(3), reader.GetUInt16(4), reader.GetUInt16(5),
reader.GetUInt16(6), reader.GetBoolean(7), reader.GetBoolean(8), reader.GetBoolean(9), reader.GetBoolean(10), reader.GetBoolean(11), reader.GetBoolean(12));
zoneList[zone.zoneId] = zone;
zoneList[zone.ZoneId] = zone;
count1++;
}
}
@ -161,7 +161,7 @@ namespace Meteor.Map
if (zoneList.ContainsKey(parentZoneId))
{
Zone parent = zoneList[parentZoneId];
PrivateArea privArea = new PrivateArea(parent, reader.GetString("className"), reader.GetString("privateAreaName"), reader.GetUInt32("privateAreaType"), reader.GetUInt16("dayMusic"), reader.GetUInt16("nightMusic"), reader.GetUInt16("battleMusic"));
PrivateArea privArea = new PrivateArea(parent, reader.GetString("className"), reader.GetString("privateAreaName"), reader.GetInt32("privateAreaType"), reader.GetUInt16("dayMusic"), reader.GetUInt16("nightMusic"), reader.GetUInt16("battleMusic"));
parent.AddPrivateArea(privArea);
}
else
@ -276,7 +276,7 @@ namespace Meteor.Map
{
uint id = reader.GetUInt32("id");
string classPath = reader.GetString("classPath");
uint nameId = reader.GetUInt32("displayNameId");
int nameId = reader.GetInt32("displayNameId");
string eventConditions = null;
uint propertyFlags = reader.GetUInt32("propertyFlags");
@ -362,7 +362,7 @@ namespace Meteor.Map
customName = reader.GetString("customDisplayName");
string uniqueId = reader.GetString("uniqueId");
string privAreaName = reader.GetString("privateAreaName");
uint privAreaLevel = reader.GetUInt32("privateAreaLevel");
int privAreaType = reader.GetInt32("privateAreaLevel");
float x = reader.GetFloat("positionX");
float y = reader.GetFloat("positionY");
float z = reader.GetFloat("positionZ");
@ -370,7 +370,7 @@ namespace Meteor.Map
ushort state = reader.GetUInt16("actorState");
uint animId = reader.GetUInt32("animationId");
SpawnLocation spawn = new SpawnLocation(classId, uniqueId, zoneId, privAreaName, privAreaLevel, x, y, z, rot, state, animId);
SpawnLocation spawn = new SpawnLocation(classId, uniqueId, zoneId, privAreaName, privAreaType, x, y, z, rot, state, animId);
zone.AddSpawnLocation(spawn);
@ -546,7 +546,7 @@ namespace Meteor.Map
{
while (reader.Read())
{
area = area ?? Server.GetWorldManager().GetZone(reader.GetUInt16("zoneId"));
area = area ?? Server.GetWorldManager().GetArea(reader.GetUInt16("zoneId"));
int actorId = area.GetActorCount() + 1;
bnpc = area.GetBattleNpcById(id);
@ -711,14 +711,14 @@ namespace Meteor.Map
{
Area oldZone;
if (player.zone != null)
if (player.CurrentArea != null)
{
oldZone = player.zone;
oldZone = player.CurrentArea;
oldZone.RemoveActorFromZone(player);
}
//Add player to new zone and update
Zone newZone = GetZone(destinationZoneId);
Area newZone = GetArea(destinationZoneId);
//This server does not contain that zoneId
if (newZone == null)
@ -726,11 +726,9 @@ namespace Meteor.Map
newZone.AddActorToZone(player);
player.zone = newZone;
player.zoneId = destinationZoneId;
player.CurrentArea = newZone;
player.zone2 = null;
player.zoneId2 = 0;
player.SendSeamlessZoneInPackets();
@ -743,7 +741,7 @@ namespace Meteor.Map
public void MergeZones(Player player, uint mergedZoneId)
{
//Add player to new zone and update
Zone mergedZone = GetZone(mergedZoneId);
Area mergedZone = GetArea(mergedZoneId);
//This server does not contain that zoneId
if (mergedZone == null)
@ -752,7 +750,6 @@ namespace Meteor.Map
mergedZone.AddActorToZone(player);
player.zone2 = mergedZone;
player.zoneId2 = mergedZone.actorId;
player.SendMessage(0x20, "", "Merging Zones");
@ -773,26 +770,29 @@ namespace Meteor.Map
* ->If merge box, MergeZones
*/
if (player.zone == null)
if (player.CurrentArea == null)
return;
uint regionId = player.zone.regionId;
uint regionId = player.CurrentArea.RegionId;
if (!seamlessBoundryList.ContainsKey(regionId))
return;
foreach (SeamlessBoundry bounds in seamlessBoundryList[regionId])
{
uint zoneId = player.CurrentArea.ZoneId;
uint zoneId2 = player.zone2.ZoneId;
if (CheckPosInBounds(player.positionX, player.positionZ, bounds.zone1_x1, bounds.zone1_y1, bounds.zone1_x2, bounds.zone1_y2))
{
if (player.zoneId == bounds.zoneId1 && player.zoneId2 == 0)
if (zoneId == bounds.zoneId1 && zoneId2 == 0)
return;
DoSeamlessZoneChange(player, bounds.zoneId1);
}
else if (CheckPosInBounds(player.positionX, player.positionZ, bounds.zone2_x1, bounds.zone2_y1, bounds.zone2_x2, bounds.zone2_y2))
{
if (player.zoneId == bounds.zoneId2 && player.zoneId2 == 0)
if (zoneId == bounds.zoneId2 && zoneId2 == 0)
return;
DoSeamlessZoneChange(player, bounds.zoneId2);
@ -800,13 +800,13 @@ namespace Meteor.Map
else if (CheckPosInBounds(player.positionX, player.positionZ, bounds.merge_x1, bounds.merge_y1, bounds.merge_x2, bounds.merge_y2))
{
uint merged;
if (player.zoneId == bounds.zoneId1)
if (zoneId == bounds.zoneId1)
merged = bounds.zoneId2;
else
merged = bounds.zoneId1;
//Already merged
if (player.zoneId2 == merged)
if (zoneId2 == merged)
return;
MergeZones(player, merged);
@ -830,15 +830,11 @@ namespace Meteor.Map
//Moves actor to new zone, and sends packets to spawn at the given coords.
public void DoZoneChange(Player player, uint destinationZoneId, string destinationPrivateArea, int destinationPrivateAreaType, byte spawnType, float spawnX, float spawnY, float spawnZ, float spawnRotation)
{
{
//Add player to new zone and update
Area newArea;
if (destinationPrivateArea == null || destinationPrivateArea.Equals(""))
newArea = GetZone(destinationZoneId);
else //Add check for -1 if it is a instance
newArea = GetZone(destinationZoneId).GetPrivateArea(destinationPrivateArea, (uint)destinationPrivateAreaType);
//Add check for -1 if it is a instance
Area newArea = GetArea(destinationZoneId, destinationPrivateArea, destinationPrivateAreaType);
//This server does not contain that zoneId
if (newArea == null)
{
@ -849,20 +845,16 @@ namespace Meteor.Map
player.playerSession.LockUpdates(true);
Area oldZone = player.zone;
Area oldArea = player.CurrentArea;
//Remove player from currentZone if transfer else it's login
if (player.zone != null)
if (player.CurrentArea != null)
{
oldZone.RemoveActorFromZone(player);
oldArea.RemoveActorFromZone(player);
}
newArea.AddActorToZone(player);
//Update player actor's properties
player.zoneId = newArea is PrivateArea ? ((PrivateArea)newArea).GetParentZone().actorId : newArea.actorId;
player.privateArea = newArea is PrivateArea ? ((PrivateArea)newArea).GetPrivateAreaName() : null;
player.privateAreaType = newArea is PrivateArea ? ((PrivateArea)newArea).GetPrivateAreaType() : 0;
player.zone = newArea;
player.CurrentArea = newArea;
player.positionX = spawnX;
player.positionY = spawnY;
player.positionZ = spawnZ;
@ -879,8 +871,8 @@ namespace Meteor.Map
player.currentContentGroup.RemoveMember(player.actorId);
player.SetCurrentContentGroup(null);
if (oldZone is PrivateAreaContent)
((PrivateAreaContent)oldZone).CheckDestroy();
if (oldArea is PrivateAreaContent)
((PrivateAreaContent)oldArea).CheckDestroy();
}
//Send packets
@ -903,11 +895,11 @@ namespace Meteor.Map
public void DoPlayerMoveInZone(Player player, float spawnX, float spawnY, float spawnZ, float spawnRotation, byte spawnType = 0xF)
{
//Remove player from currentZone if transfer else it's login
if (player.zone != null)
if (player.CurrentArea != null)
{
player.playerSession.LockUpdates(true);
player.zone.RemoveActorFromZone(player);
player.zone.AddActorToZone(player);
player.CurrentArea.RemoveActorFromZone(player);
player.CurrentArea.AddActorToZone(player);
//Update player actor's properties;
player.positionX = spawnX;
@ -936,21 +928,17 @@ namespace Meteor.Map
player.playerSession.LockUpdates(true);
Area oldZone = player.zone;
Area oldArea = player.CurrentArea;
//Remove player from currentZone if transfer else it's login
if (player.zone != null)
if (player.CurrentArea != null)
{
oldZone.RemoveActorFromZone(player);
oldArea.RemoveActorFromZone(player);
}
contentArea.AddActorToZone(player);
//Update player actor's properties
player.zoneId = contentArea.GetParentZone().actorId;
player.privateArea = contentArea.GetPrivateAreaName();
player.privateAreaType = contentArea.GetPrivateAreaType();
player.zone = contentArea;
player.CurrentArea = contentArea;
player.positionX = spawnX;
player.positionY = spawnY;
player.positionZ = spawnZ;
@ -975,18 +963,14 @@ namespace Meteor.Map
public void DoZoneIn(Player player, bool isLogin, ushort spawnType)
{
//Add player to new zone and update
Area playerArea;
if (player.privateArea != null)
playerArea = GetPrivateArea(player.zoneId, player.privateArea, player.privateAreaType);
else
playerArea = GetZone(player.zoneId);
Area playerArea = player.CurrentArea;
//This server does not contain that zoneId
if (playerArea == null)
return;
//Set the current zone and add player
player.zone = playerArea;
player.CurrentArea = playerArea;
playerArea.AddActorToZone(player);
@ -1236,7 +1220,7 @@ namespace Meteor.Map
return;
}
Player inviter = (Player)invitee.GetZone().FindActorInArea(group.GetHost());
Player inviter = (Player)invitee.CurrentArea.FindActorInArea(group.GetHost());
//DeleteTradeGroup(group.groupIndex);
@ -1257,7 +1241,7 @@ namespace Meteor.Map
return;
}
Player invitee = (Player)inviter.GetZone().FindActorInArea(group.GetOther());
Player invitee = (Player)inviter.CurrentArea.FindActorInArea(group.GetOther());
inviter.SendGameMessage(GetActor(), 25042, 0x20); //You cancel the trade.
if (invitee != null)
@ -1276,7 +1260,7 @@ namespace Meteor.Map
return;
}
Player invitee = (Player)inviter.GetZone().FindActorInArea(group.GetOther());
Player invitee = (Player)inviter.CurrentArea.FindActorInArea(group.GetOther());
inviter.SendGameMessage(GetActor(), 25041, 0x20); //You cancel the trade.
if (invitee != null)
@ -1295,7 +1279,7 @@ namespace Meteor.Map
return;
}
Player inviter = (Player)invitee.GetZone().FindActorInArea(group.GetHost());
Player inviter = (Player)invitee.CurrentArea.FindActorInArea(group.GetHost());
if (inviter != null)
inviter.SendGameMessage(GetActor(), 25038, 0x20); //Your trade request fails
@ -1808,25 +1792,17 @@ namespace Meteor.Map
return null;
}
public Zone GetZone(uint zoneId)
public Area GetArea(uint zoneId, string privateAreaName = "", int privateAreaType = 0)
{
lock (zoneList)
{
if (!zoneList.ContainsKey(zoneId))
return null;
return zoneList[zoneId];
}
}
public PrivateArea GetPrivateArea(uint zoneId, string privateArea, uint privateAreaType)
{
lock (zoneList)
{
if (!zoneList.ContainsKey(zoneId))
return null;
return zoneList[zoneId].GetPrivateArea(privateArea, privateAreaType);
if (privateAreaName == null || privateAreaName.Equals(""))
return zoneList[zoneId];
else
return zoneList[zoneId].GetPrivateArea(privateAreaName, privateAreaType);
}
}