示例#1
0
    public static void RequestSpawn(Packet packet, CSteamID sender) //Run by Host Only
    {
        Message_RequestSpawn lastMessage = (Message_RequestSpawn)((PacketSingle)packet).message;

        Debug.Log("A player has requested for a spawn point");
        if (!Networker.hostLoaded)
        {
            Debug.Log("The host isn't ready yet, adding to queue");
            spawnRequestQueue.Enqueue(lastMessage);
            return;
        }
        if (spawnPoints == null || spawnPoints.Count == 0)
        {
            Debug.LogError("Spawn points was null, we won't be able to find any spawn point then");
            return;
        }
        Transform spawn = FindFreeSpawn(lastMessage.teaml);



        if (Networker.isHost)
        {
            Debug.Log("Telling connected client about AI units");
            AIManager.TellClientAboutAI(new CSteamID(lastMessage.senderSteamID));
        }
        GameObject localVehicle = VTOLAPI.GetPlayersVehicleGameObject();

        Debug.Log("The players spawn will be " + spawn);
        NetworkSenderThread.Instance.SendPacketToSpecificPlayer(sender, new Message_RequestSpawn_Result(new Vector3D(localVehicle.transform.position), localVehicle.transform.rotation, Networker.GenerateNetworkUID(), players.Count), EP2PSend.k_EP2PSendReliable);
    }
示例#2
0
    /// <summary>
    /// This gives all the people waiting their spawn points
    /// </summary>
    private static void SpawnRequestQueue() //Run by Host Only
    {
        Debug.Log($"Giving {spawnRequestQueue.Count} people their spawns");
        Transform lastSpawn;

        while (spawnRequestQueue.Count > 0)
        {
            Message_RequestSpawn lastMessage = spawnRequestQueue.Dequeue();
            lastSpawn = FindFreeSpawn(lastMessage.teaml);
            Debug.Log("The players spawn will be " + lastSpawn);


            if (Networker.isHost)
            {
                Debug.Log("Telling connected client about AI units");
                AIManager.TellClientAboutAI(new CSteamID(lastMessage.senderSteamID));
            }
            GameObject localVehicle = VTOLAPI.GetPlayersVehicleGameObject();
            NetworkSenderThread.Instance.SendPacketToSpecificPlayer(
                new CSteamID(lastMessage.senderSteamID),
                new Message_RequestSpawn_Result(new Vector3D(localVehicle.transform.position), localVehicle.transform.rotation, Networker.GenerateNetworkUID(), players.Count),
                EP2PSend.k_EP2PSendReliable);
        }
    }
示例#3
0
    public static List <Player> players = new List <Player>(); //This is the list of players
    /// <summary>
    /// This runs when the map has finished loading and hopefully
    /// when the player first can interact with the vehicle.
    /// </summary>
    public static IEnumerator MapLoaded()
    {
        Debug.Log("map loading started");
        while (VTMapManager.fetch == null || !VTMapManager.fetch.scenarioReady || FlightSceneManager.instance.switchingScene)
        {
            yield return(null);
        }
        Debug.Log("The map has loaded");
        gameLoaded = true;
        // As a client, when the map has loaded we are going to request a spawn point from the host
        SetPrefabs();

        carrierStart = FlightSceneManager.instance.playerActor.unitSpawn.unitSpawner.linkedToCarrier;

        if (!Networker.isHost)
        {
            FlightSceneManager.instance.playerActor.gameObject.transform.parent = null;
            Debug.Log($"Sending spawn request to host, host id: {Networker.hostID}, client id: {SteamUser.GetSteamID().m_SteamID}");
            Debug.Log("Killing all units currently on the map.");
            List <Actor> allActors = new List <Actor>();
            foreach (var actor in TargetManager.instance.allActors)
            {
                if (!actor.isPlayer)
                {
                    allActors.Add(actor);
                }
            }
            foreach (var actor in allActors)
            {
                TargetManager.instance.UnregisterActor(actor);
                GameObject.Destroy(actor.gameObject);
            }
            VTScenario.current.units.units.Clear();
            VTScenario.current.units.alliedUnits.Clear();
            VTScenario.current.units.enemyUnits.Clear();
            VTScenario.current.groups.DestroyAll();


            if (teamLeftie)
            {
                foreach (AirportManager airportManager in VTMapManager.fetch.airports)
                {
                    if (airportManager.team == Teams.Allied)
                    {
                        airportManager.team = Teams.Enemy;
                    }
                    else
                    if (airportManager.team == Teams.Enemy)
                    {
                        airportManager.team = Teams.Allied;
                    }
                }
            }


            var rearmPoints = GameObject.FindObjectsOfType <ReArmingPoint>();
            //back up option below

            if (teamLeftie)
            {
                foreach (ReArmingPoint rep in rearmPoints)
                {
                    if (rep.team == Teams.Allied)
                    {
                        rep.team      = Teams.Enemy;
                        rep.canArm    = true;
                        rep.canRefuel = true;
                    }
                    else
                    if (rep.team == Teams.Enemy)
                    {
                        rep.team = Teams.Allied;

                        rep.canArm    = true;
                        rep.canRefuel = true;
                    }
                }
            }


            Message_RequestSpawn msg = new Message_RequestSpawn(teamLeftie, SteamUser.GetSteamID().m_SteamID);
            NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, msg, EP2PSend.k_EP2PSendReliable);

            /*foreach (var actor in TargetManager.instance.allActors)
             * {
             *  VTScenario.current.units.AddSpawner(actor.unitSpawn.unitSpawner);
             * }*/
        }
        else
        {
            Debug.Log("Starting map loaded host routines");
            Networker.hostLoaded = true;
            Networker.hostReady  = true;
            foreach (var actor in TargetManager.instance.allActors)
            {
                AIManager.setupAIAircraft(actor);
            }
            NetworkSenderThread.Instance.SendPacketAsHostToAllClients(new Message_HostLoaded(true), EP2PSend.k_EP2PSendReliable);
            GameObject localVehicle = VTOLAPI.GetPlayersVehicleGameObject();
            if (localVehicle != null)
            {
                GenerateSpawns(localVehicle.transform);
                localUID = Networker.GenerateNetworkUID();
                UIDNetworker_Sender hostSender = localVehicle.AddComponent <UIDNetworker_Sender>();
                hostSender.networkUID = localUID;
                Debug.Log($"The host's uID is {localUID}");


                Transform hostTrans = localVehicle.transform;
                ///uncomment to randomise host spawn//
                ///

                localVehicle.transform.position = hostTrans.position;

                SpawnLocalVehicleAndInformOtherClients(localVehicle, hostTrans.transform.position, hostTrans.transform.rotation, localUID, 0);
            }
            else
            {
                Debug.Log("Local vehicle for host was null");
            }
            if (spawnRequestQueue.Count != 0)
            {
                SpawnRequestQueue();
            }
            Networker.alreadyInGame = true;
        }

        while (AIManager.AIsToSpawnQueue.Count > 0)
        {
            AIManager.SpawnAIVehicle(AIManager.AIsToSpawnQueue.Dequeue());
        }
        SpawnPlayersInPlayerSpawnQueue();


        if (!Networker.isHost)
        {
            // If the player is not the host, they only need a receiver?
            Debug.Log($"Player not the host, adding world data receiver");
            worldData = new GameObject();
            worldData.AddComponent <WorldDataNetworker_Receiver>();
        }
        else
        {
            // If the player is the host, setup the sender so they can send world data
            Debug.Log($"Player is the host, setting up the world data sender");
            worldData = new GameObject();
            worldData.AddComponent <WorldDataNetworker_Sender>();
        }
    }