SetInstance() public static méthode

public static SetInstance ( PlayerIntellect instance ) : void
instance PlayerIntellect
Résultat void
Exemple #1
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnTick()"/>.</summary>
        protected override void OnTick()
        {
            base.OnTick();

            //single mode. recreate player units if need
            if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo)
                {
                    if (PlayerManager.Instance != null)
                    {
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.Intellect == null || player.Intellect.ControlledObject == null)
                            {
                                ServerOrSingle_CreatePlayerUnit(player);
                            }
                        }
                    }
                }
            }

            //networking mode
            if (EntitySystemWorld.Instance.IsServer())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo)
                {
                    if (PlayerManager.Instance != null)
                    {
                        UserManagementServerNetworkService userManagementService =
                            GameNetworkServer.Instance.UserManagementService;

                        //remove users
again:
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.User != null && player.User != userManagementService.ServerUser)
                            {
                                NetworkNode.ConnectedNode connectedNode = player.User.ConnectedNode;
                                if (connectedNode == null ||
                                    connectedNode.Status != NetworkConnectionStatuses.Connected)
                                {
                                    if (player.Intellect != null)
                                    {
                                        PlayerIntellect playerIntellect = player.Intellect as PlayerIntellect;
                                        if (playerIntellect != null)
                                        {
                                            playerIntellect.TryToRestoreMainControlledUnit();
                                        }

                                        if (player.Intellect.ControlledObject != null)
                                        {
                                            player.Intellect.ControlledObject.Die();
                                        }
                                        player.Intellect.SetShouldDelete();
                                        player.Intellect = null;
                                    }

                                    PlayerManager.Instance.ServerOrSingle_RemovePlayer(player);

                                    goto again;
                                }
                            }
                        }

                        //add users
                        foreach (UserManagementServerNetworkService.UserInfo user in
                                 userManagementService.Users)
                        {
                            //check whether "EntitySystem" service on the client
                            if (user.ConnectedNode != null)
                            {
                                if (!user.ConnectedNode.RemoteServices.Contains("EntitySystem"))
                                {
                                    continue;
                                }
                            }

                            PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                         ServerOrSingle_GetPlayer(user);

                            if (player == null)
                            {
                                player = PlayerManager.Instance.Server_AddClientPlayer(user);

                                PlayerIntellect intellect = (PlayerIntellect)Entities.Instance.
                                                            Create("PlayerIntellect", World.Instance);
                                intellect.PostCreate();

                                player.Intellect = intellect;

                                if (GameNetworkServer.Instance.UserManagementService.ServerUser != user)
                                {
                                    //player on client
                                    RemoteEntityWorld remoteEntityWorld = GameNetworkServer.Instance.
                                                                          EntitySystemService.GetRemoteEntityWorld(user);
                                    intellect.Server_SendSetInstanceToClient(remoteEntityWorld);
                                }
                                else
                                {
                                    //player on this server
                                    PlayerIntellect.SetInstance(intellect);
                                }
                            }
                        }

                        //create units
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.Intellect != null && player.Intellect.ControlledObject == null)
                            {
                                ServerOrSingle_CreatePlayerUnit(player);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        internal void DoActionsAfterMapCreated()
        {
            if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo)
                {
                    string playerName = "__SinglePlayer__";

                    //create Player
                    PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                 ServerOrSingle_GetPlayer(playerName);
                    if (player == null)
                    {
                        player = PlayerManager.Instance.Single_AddSinglePlayer(playerName);
                    }

                    //create PlayerIntellect
                    PlayerIntellect intellect = null;
                    {
                        //find already created PlayerIntellect
                        foreach (Entity entity in World.Instance.Children)
                        {
                            intellect = entity as PlayerIntellect;
                            if (intellect != null)
                            {
                                break;
                            }
                        }

                        if (intellect == null)
                        {
                            intellect = (PlayerIntellect)Entities.Instance.Create("PlayerIntellect",
                                                                                  World.Instance);
                            intellect.PostCreate();

                            player.Intellect = intellect;
                        }

                        //set instance
                        if (PlayerIntellect.Instance == null)
                        {
                            PlayerIntellect.SetInstance(intellect);
                        }
                    }

                    //create unit
                    if (intellect.ControlledObject == null)
                    {
                        SpawnPoint spawnPoint = null;
                        if (shouldChangeMapSpawnPointName != null)
                        {
                            spawnPoint = Entities.Instance.GetByName(shouldChangeMapSpawnPointName)
                                         as SpawnPoint;
                            if (spawnPoint == null)
                            {
                                Log.Error("GameWorld: SpawnPoint with name \"{0}\" is not defined.",
                                          shouldChangeMapSpawnPointName);
                            }
                        }

                        Unit unit;
                        if (spawnPoint != null)
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player, spawnPoint);
                        }
                        else
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player);
                        }

                        if (shouldChangeMapPlayerCharacterInformation != null)
                        {
                            PlayerCharacter playerCharacter = (PlayerCharacter)unit;
                            playerCharacter.ApplyChangeMapInformation(
                                shouldChangeMapPlayerCharacterInformation, spawnPoint);
                        }
                        else
                        {
                            if (unit != null)
                            {
                                intellect.LookDirection = SphereDir.FromVector(
                                    unit.Rotation.GetForward());
                            }
                        }
                    }
                }
            }

            shouldChangeMapName                       = null;
            shouldChangeMapSpawnPointName             = null;
            shouldChangeMapPlayerCharacterInformation = null;
        }