DarkEmu_GameServer.Systems.ObjectSpawnCheck C# (CSharp) Метод

ObjectSpawnCheck() публичный Метод

public ObjectSpawnCheck ( ) : void
Результат void
        public void ObjectSpawnCheck()
        {
            try
            {
                if (this.Character.deSpawning) return;
                int spawnrange = 80;
                lock (this)
                {
                    //Make sure character info is not null or not spawning yet allready.
                    if (this.Character != null && !this.Character.Spawning)
                    {
                        //Set spawn state to true so cannot be doubled
                        this.Character.Spawning = true;

                        //Repeat for each client ingame
                        #region Clients
                        for (int i = 0; i < Systems.clients.Count; i++)
                        {
                            //Get defined information for the client
                            Systems playerspawn = Systems.clients[i];
                            //Make sure that the spawning case is not ourselfs, or not spawned yet and not null
                            if (playerspawn != null && playerspawn != this && !Character.Spawned(playerspawn.Character.Information.UniqueID) && playerspawn.Character.Information.Name != this.Character.Information.Name)
                            {
                                //If our position is lower or higher then 50 + spawnrange of that of the player
                                if (playerspawn.Character.Position.x >= (Character.Position.x - 50) && playerspawn.Character.Position.x <= ((Character.Position.x - 50) + spawnrange) && playerspawn.Character.Position.y >= (Character.Position.y - 50) && playerspawn.Character.Position.y <= ((Character.Position.y - 50) + spawnrange))
                                {
                                    //Make sure the unique id is not null
                                    if (playerspawn.Character.Information.UniqueID != 0)
                                    {
                                        Character.Spawn.Add(playerspawn.Character.Information.UniqueID);
                                        client.Send(Packet.ObjectSpawn(playerspawn.Character));
                                    }
                                    //Spawn ourselfs to the other players currently in spawn range.
                                    ObjectPlayerSpawn(playerspawn);
                                }
                            }
                        }
                        #endregion
                        //Repeat for each helper object
                        #region Helper objects
                        for (int i = 0; i < Systems.HelperObject.Count; i++)
                        {
                            //If the helper object is not null , or not spawned for us yet and the unique id is not null
                            if (Systems.HelperObject[i] != null && !Systems.HelperObject[i].Spawned(this.Character.Information.UniqueID))
                            {
                                //If our position is lower or higher then 50 + spawnrange of that of the object
                                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))
                                {
                                    if (Systems.HelperObject[i].UniqueID != 0)
                                    {
                                        //Add our spawn
                                        Systems.HelperObject[i].Spawn.Add(this.Character.Information.UniqueID);
                                        //Send visual packet
                                        this.client.Send(Packet.ObjectSpawn(Systems.HelperObject[i]));
                                    }
                                }
                            }
                        }
                        #endregion
                        /*
                        #region Special objects
                        for (int i = 0; i < Systems.SpecialObjects.Count; i++)
                        {
                            //If the special object is not null , or not spawned for us yet and the unique id is not null
                            if (Systems.SpecialObjects[i] != null && !Systems.SpecialObjects[i].Spawned(this.Character.Information.UniqueID))
                            {
                                //If our position is lower or higher then 50 + spawnrange of that of the object
                                if (this.Character.Position.x >= (Systems.SpecialObjects[i].x - 50) && this.Character.Position.x <= ((Systems.SpecialObjects[i].x - 50) + spawnrange) && this.Character.Position.y >= (Systems.SpecialObjects[i].y - 50) && this.Character.Position.y <= ((Systems.SpecialObjects[i].y - 50) + spawnrange))
                                {
                                    if (Systems.SpecialObjects[i].UniqueID != 0)
                                    {
                                        //Add our spawn
                                        Systems.SpecialObjects[i].Spawn.Add(this.Character.Information.UniqueID);
                                        //Send visual packet
                                        client.Send(Packet.ObjectSpawn(Systems.SpecialObjects[i]));
                                        //Console.WriteLine("Spawning {0}", Data.ObjectBase[Systems.Objects[i].ID].Name);
                                    }
                                }
                            }
                        }
                        #endregion
                         */
                        //Repeat for each object
                        #region Objects
                        for (int i = 0; i < Systems.Objects.Count; i++)
                        {
                            //If the helper object is not null , or not spawned for us yet and the unique id is not null
                            if (Systems.Objects[i] != null && !Systems.Objects[i].Spawned(this.Character.Information.UniqueID))
                            {
                                //If our position is lower or higher then 50 + spawnrange of that of the object
                                if (this.Character.Position.x >= (Systems.Objects[i].x - 50) && this.Character.Position.x <= ((Systems.Objects[i].x - 50) + spawnrange) && this.Character.Position.y >= (Systems.Objects[i].y - 50) && this.Character.Position.y <= ((Systems.Objects[i].y - 50) + spawnrange))
                                {
                                    if (Systems.Objects[i].UniqueID != 0 && !Systems.Objects[i].Die)
                                    {
                                        //Add our spawn
                                        Systems.Objects[i].Spawn.Add(this.Character.Information.UniqueID);
                                        //Send visual packet
                                        client.Send(Packet.ObjectSpawn(Systems.Objects[i]));
                                        //Console.WriteLine("Spawning {0}", Data.ObjectBase[Systems.Objects[i].ID].Name);
                                    }
                                }
                            }
                        }
                        #endregion
                        //Repeat for each world item
                        #region Helper objects
                        for (int i = 0; i < Systems.WorldItem.Count; i++)
                        {
                            //If the helper object is not null , or not spawned for us yet and the unique id is not null
                            if (Systems.WorldItem[i] != null && !Systems.WorldItem[i].Spawned(this.Character.Information.UniqueID))
                            {
                                //If our position is lower or higher then 50 + spawnrange of that of the object
                                if (this.Character.Position.x >= (Systems.WorldItem[i].x - 50) && this.Character.Position.x <= ((Systems.WorldItem[i].x - 50) + spawnrange) && this.Character.Position.y >= (Systems.WorldItem[i].y - 50) && this.Character.Position.y <= ((Systems.WorldItem[i].y - 50) + spawnrange))
                                {
                                    if (Systems.WorldItem[i].UniqueID != 0)
                                    {
                                        //Add our spawn
                                        Systems.WorldItem[i].Spawn.Add(this.Character.Information.UniqueID);
                                        //Send visual packet
                                        this.client.Send(Packet.ObjectSpawn(Systems.WorldItem[i]));
                                    }
                                }
                            }
                        }
                        #endregion
                        //If we are riding a horse and its not spawned to the player yet
                        #region Transports
                        if (Character.Transport.Right)
                        {
                            //If not spawned
                            if (!Character.Transport.Spawned)
                            {
                                //Set bool true
                                Character.Transport.Spawned = true;
                                //Spawn horse object
                                Character.Transport.Horse.SpawnMe();
                                //Send visual update player riding horse
                                Character.Transport.Horse.Send(Packet.Player_UpToHorse(this.Character.Information.UniqueID, true, Character.Transport.Horse.UniqueID));
                            }
                        }
                        #endregion
                        //Reset bool to false so we can re-loop the function
                        this.Character.Spawning = false;
                        ObjectDeSpawnCheck();
                    }
                    //If something wrong happened and we are null, we set our bool false as well.
                    this.Character.Spawning = false;
                }
            }
            catch (Exception ex)
            {
                //If any exception happens we disable the loop bool for re-use
                this.Character.Spawning = false;
                Console.WriteLine("Spawn check error {0}", ex);
                Systems.Debugger.Write(ex);
            }
        }

Usage Example

Пример #1
0
 /////////////////////////////////////////////////////////////////////////////////
 // Spawn system (Spawn our char to others).
 /////////////////////////////////////////////////////////////////////////////////
 void ObjectPlayerSpawn(Systems s)
 {
     try
     {
         if (!s.Character.Spawned(this.Character.Information.UniqueID) && this.Character.Information.UniqueID != 0 && !s.Character.Spawning)
         {
             //We loop the spawn check for the player that needs it.
             s.ObjectSpawnCheck();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Object player spawn error {0}", ex);
         Systems.Debugger.Write(ex);
     }
 }
All Usage Examples Of DarkEmu_GameServer.Systems::ObjectSpawnCheck
Systems