public void ObjectDeSpawnCheck()
{
//We wrap our function inside a catcher
try
{
if (this.Character.Spawning) return;
//Set default spawn range
int spawnrange = 110;
//Make sure that the character is not null, and not despawning allready!
if (this.Character != null && !this.Character.deSpawning && this != null)
{
//Set our loop (active) bool to true so we cant do it double same way.
this.Character.deSpawning = true;
//Region helper objects
#region Helper objects
//Repeat for each helper object
for (int i = 0; i < Systems.HelperObject.Count; i++)
{
//If our object is not null, and the object is spawned to our character
if (Systems.HelperObject[i] != null && Systems.HelperObject[i].Spawned(this.Character.Information.UniqueID))
{
//Make sure that its going out of range instead of in range
if (this.Character.Position.x >= (Systems.HelperObject[i].x - 50) && this.Character.Position.x <= ((Systems.HelperObject[i].x - 50) + spawnrange) && this.Character.Position.y >= (Systems.HelperObject[i].y - 50) && this.Character.Position.y <= ((Systems.HelperObject[i].y - 50) + spawnrange))
{
}
//When out of range start despawn
else
{
//Make sure we are on the same sectors (To prevent overlaps).
//Make sure the despawning object is not null
if (Systems.HelperObject[i].UniqueID != 0)
{
//Then we remove the spawn
Systems.HelperObject[i].Spawn.Remove(this.Character.Information.UniqueID);
//And send despawn packet
client.Send(Packet.ObjectDeSpawn(Systems.HelperObject[i].UniqueID));
}
}
}
}
#endregion
//Region for objects
#region Objects
for (int i = 0; i < Systems.Objects.Count; i++)
{
//Make sure the object in this case is not null
if (Systems.Objects[i] != null)
{
//If the object is spawned to us but not in death state
if (Systems.Objects[i].Spawned(Character.Information.UniqueID) && !Systems.Objects[i].Die)
{
//The range we chosen
if (Systems.Objects[i].x >= (Character.Position.x - 50) && Systems.Objects[i].x <= ((Character.Position.x - 50) + spawnrange) && Systems.Objects[i].y >= (Character.Position.y - 50) && Systems.Objects[i].y <= ((Character.Position.y - 50) + spawnrange))
{
}
//If out of range start despawn
else
{
//Make sure the id and unique id are not null
if (Systems.Objects[i].UniqueID != 0 && !Systems.Objects[i].Die)
{
//Start removing our spawn
Systems.Objects[i].Spawn.Remove(Character.Information.UniqueID);
//Despawn packet sending
client.Send(Packet.ObjectDeSpawn(Systems.Objects[i].UniqueID));
//Console.WriteLine("DE- Spawning {0}", Data.ObjectBase[Systems.Objects[i].ID].Name);
}
}
}
}
}
#endregion
/*
#region Special objects
for (int i = 0; i < Systems.SpecialObjects.Count; i++)
{
//Make sure the object in this case is not null
if (Systems.SpecialObjects[i] != null)
{
//If the object is spawned to us but not in death state
if (Systems.SpecialObjects[i].Spawned(Character.Information.UniqueID))
{
//The range we chosen
if (Systems.SpecialObjects[i].x >= (Character.Position.x - 50) && Systems.SpecialObjects[i].x <= ((Character.Position.x - 50) + spawnrange) && Systems.SpecialObjects[i].y >= (Character.Position.y - 50) && Systems.SpecialObjects[i].y <= ((Character.Position.y - 50) + spawnrange))
{
}
//If out of range start despawn
else
{
//Sector check as we do above.
//if (Character.Position.xSec == Systems.Objects[i].xSec && Character.Position.ySec == Systems.Objects[i].ySec)
{
//Make sure the id and unique id are not null
if (Systems.SpecialObjects[i].UniqueID != 0)
{
//Start removing our spawn
Systems.SpecialObjects[i].Spawn.Remove(Character.Information.UniqueID);
//Despawn packet sending
client.Send(Packet.ObjectDeSpawn(Systems.SpecialObjects[i].UniqueID));
//Console.WriteLine("DE- Spawning {0}", Data.ObjectBase[Systems.Objects[i].ID].Name);
}
}
}
}
}
}
#endregion
*/
//Region for clients
#region Clients
for (int i = 0; i < Systems.clients.Count; i++)
{
if (Systems.clients[i] != null && Systems.clients[i] != this && Character.Spawned(Systems.clients[i].Character.Information.UniqueID))
{
if (Systems.clients[i].Character.Position.x >= (Character.Position.x - 50) && Systems.clients[i].Character.Position.x <= ((Character.Position.x - 50) + spawnrange) && Systems.clients[i].Character.Position.y >= (Character.Position.y - 50) && Systems.clients[i].Character.Position.y <= ((Character.Position.y - 50) + spawnrange))
{
}
else
{
if (Character.Spawned(Systems.clients[i].Character.Information.UniqueID))
{
//Extra check before we send the packet update
if (Systems.clients[i].Character.Information.UniqueID != 0)
{
Character.Spawn.Remove(Systems.clients[i].Character.Information.UniqueID);
client.Send(Packet.ObjectDeSpawn(Systems.clients[i].Character.Information.UniqueID));
}
}
ObjectDePlayerSpawn(Systems.clients[i]);
}
}
}
#endregion
//Region for items
#region Items
for (int i = 0; i < Systems.WorldItem.Count; i++)
{
if (Systems.WorldItem[i] != null && Systems.WorldItem[i].Spawned(Character.Information.UniqueID) && Systems.WorldItem[i].UniqueID != 0)
{
if (Systems.WorldItem[i].x >= (Character.Position.x - 50) && Systems.WorldItem[i].x <= ((Character.Position.x - 50) + spawnrange) && Systems.WorldItem[i].y >= (Character.Position.y - 50) && Systems.WorldItem[i].y <= ((Character.Position.y - 50) + spawnrange))
{
}
else
{
if (Systems.WorldItem[i].Spawned(Character.Information.UniqueID) && Systems.WorldItem[i].Model != 0)
{
if (Systems.WorldItem[i].UniqueID != 0)
{
Systems.WorldItem[i].Spawn.Remove(Character.Information.UniqueID);
client.Send(Packet.ObjectDeSpawn(Systems.WorldItem[i].UniqueID));
}
}
}
}
}
#endregion
//Set bool to false so we can use the loop again
this.Character.deSpawning = false;
}
//Set bool to false so we can use the loop again (incase something happened and we are null).
this.Character.deSpawning = false;
}
catch (Exception ex)
{
//If any exception is made we disable the loop
this.Character.deSpawning = false;
Console.WriteLine("Despawn error {0}", ex);
Systems.Debugger.Write(ex);
}
}