Esempio n. 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 ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    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 ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights) //iNCIN -- OK NOW
                {
                    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.SetForDeletion(true);
                                        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);
                                }

                                //player.Intellect = intellect;
                                if (player.User.Faction == null)
                                {
                                    return;
                                }
                                FactionType f = (FactionType)EntityTypes.Instance.GetByName(player.User.Faction);
                                player.Intellect.Faction = f;
                            }
                        }

                        //create units
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.Intellect != null && player.Intellect.ControlledObject == null)
                            {
                                if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                                {
                                    ServerOrSingle_CreatePlayerUnit(player);
                                }
                                else
                                {
                                    ServerOrSingle_CreatePlayerUnit(player);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 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 ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    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)
                    {
                        MapObject spawnPoint = null;
                        if (!string.IsNullOrEmpty(needChangeMapSpawnPointName))
                        {
                            spawnPoint = Entities.Instance.GetByName(needChangeMapSpawnPointName) as MapObject;
                            if (spawnPoint == null)
                            {
                                Log.Warning("GameWorld: Object with name \"{0}\" does not exist.",
                                            needChangeMapSpawnPointName);
                            }
                        }

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

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

            needChangeMapName                       = null;
            needChangeMapSpawnPointName             = null;
            needChangeMapPlayerCharacterInformation = null;
        }