Ejemplo n.º 1
0
    /// <summary>
    /// Returns a spawn point which isn't blocked by another player
    /// </summary>
    /// <returns>A free spawn point</returns>
    public static Transform FindFreeSpawn(bool leftie)
    {
        if (leftie) //leftie
        {
            Debug.Log($"Spawing a leftie");
            var rearmPoints = GameObject.FindObjectsOfType <ReArmingPoint>();

            ReArmingPoint        rearmPoint  = GameObject.FindObjectOfType <ReArmingPoint>();
            List <ReArmingPoint> EnemyPoints = new List <ReArmingPoint>();
            foreach (ReArmingPoint rep in rearmPoints)
            {
                if (rep.team == Teams.Enemy)
                {
                    EnemyPoints.Add(rep);
                }
            }


            if (EnemyPoints.Count() > 0)
            {
                Debug.Log($"found leftie spawn");
                rearmPoint = EnemyPoints[UnityEngine.Random.Range(0, EnemyPoints.Count - 1)];
                return(rearmPoint.transform);
            }
        }
        // Later on this will check the spawns if there is anyone sitting still at this spawn

        spawnTicker += 1;
        if (spawnTicker > spawnsCount - 1)
        {
            spawnTicker = 0;
        }
        return(spawnPoints[spawnTicker]);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Spawns a local vehicle, and sends the message to other clients to
    /// spawn their representation of this vehicle
    /// </summary>
    /// <param name="localVehicle">The local clients gameobject</param>
    public static void Update()
    {
        if (!firstSpawnDone)
        {
            if (carrierStart)

            {
                foreach (var actor in TargetManager.instance.allActors)
                {
                    if (actor.role == Actor.Roles.Ship)
                    {
                        carrierFound = true;
                    }
                }
            }
            ReArmingPoint[] rearmPoints = GameObject.FindObjectsOfType <ReArmingPoint>();
            ReArmingPoint   rearmPoint  = null;

            float lastRadius = 0;
            if (PlayerManager.carrierStart)
            {
                foreach (ReArmingPoint rep in rearmPoints)
                {
                    if (rep.team == Teams.Allied)
                    {
                        if (rep.radius < 19.0f)
                        {
                            rearmPoint = rep;
                        }
                    }
                }
            }
            if (rearmPoint != null && carrierFound && carrierStart)
            {
                RequestSpawn_Result(storedSpawnMessage);
            }
        }

        PlayerManager.SpawnPlayersInPlayerSpawnQueue();//addmitedly, this probably isnt the best place to put this, feel free to move it somewhere els
    }
Ejemplo n.º 3
0
    IEnumerator RespawnTimer()
    {
        Debug.Log("Starting respawn timer.");

        yield return(new WaitForSeconds(15));

        Debug.Log("Finished respawn timer.");

        ReArmingPoint[] rearmPoints = GameObject.FindObjectsOfType <ReArmingPoint>();
        ReArmingPoint   rearmPoint  = rearmPoints[Random.Range(0, rearmPoints.Length - 1)];

        float lastRadius = 0;

        if (PlayerManager.carrierStart)
        {
            foreach (ReArmingPoint rep in rearmPoints)
            {
                if (rep.team == Teams.Allied)
                {
                    if (rep.radius < 19.0f)
                    {
                        rearmPoint = rep;
                    }
                }
            }
        }
        else
        {
            foreach (ReArmingPoint rep in rearmPoints)
            {
                Debug.Log("finding rearm pt");
                if (rep.team == Teams.Allied && rep.CheckIsClear(actor))
                {
                    if (rep.radius > lastRadius)
                    {
                        rearmPoint = rep;
                        lastRadius = rep.radius;
                    }
                }
            }
        }



        //UnEject();
        //PutPlayerBackInAircraft();
        //RepairAircraft();

        //foreach (GearAnimator gear in gears) {
        //    gear.ExtendImmediate();
        //}

        //GetComponent<Rigidbody>().velocity = Vector3.zero;
        //transform.position = rearmPoint.transform.position + Vector3.up * 10;
        //transform.rotation = rearmPoint.transform.rotation;

        Destroy(VTOLAPI.GetPlayersVehicleGameObject());
        Destroy(detacher.cameraRig);
        Destroy(detacher.gameObject);
        Destroy(ejection.gameObject);
        Destroy(BlackoutEffect.instance);
        Destroy(GetComponent <PlayerSpawn>());

        foreach (EngineEffects effect in effects)
        {
            Destroy(effect);
        }
        //as much stuff as im destroying, some stuff is most likely getting through, future people, look into this

        AudioController.instance.ClearAllOpenings();

        UnitIconManager.instance.UnregisterAll();
        TargetManager.instance.detectedByAllies.Clear();
        TargetManager.instance.detectedByEnemies.Clear();

        foreach (var actor in TargetManager.instance.allActors)
        {
            if (actor != null)
            {
                actor.discovered = false;
                actor.drawIcon   = true;
                //actor.DiscoverActor();


                actor.permanentDiscovery = true;

                Traverse.Create(actor).Field("detectedByAllied").SetValue(false);
                Traverse.Create(actor).Field("detectedByEnemy").SetValue(false);

                if (actor.team == Teams.Allied)
                {
                    actor.DetectActor(Teams.Allied);
                    actor.UpdateKnownPosition(actor.team);
                }

                //actor.DiscoverActor(); <----------------breaks and only works on every 2nd spawn
                // UnitIconManager.instance.RegisterIcon(actor, 0.07f * actor.iconScale, actor.iconOffset);
            }
        }

        GameObject newPlayer = Instantiate(PilotSaveManager.currentVehicle.vehiclePrefab);

        FlightSceneManager.instance.playerActor = newPlayer.GetComponent <Actor>();
        FlightSceneManager.instance.playerActor.flightInfo.PauseGCalculations();
        FlightSceneManager.instance.playerActor.flightInfo.OverrideRecordedAcceleration(Vector3.zero);

        rearmPoint.voiceProfile.PlayMessage(GroundCrewVoiceProfile.GroundCrewMessages.Success);
        PilotSaveManager.currentScenario.totalBudget       = 999999;
        PilotSaveManager.currentScenario.initialSpending   = 0;
        PilotSaveManager.currentScenario.inFlightSpending  = 0;
        PilotSaveManager.currentScenario.equipConfigurable = true;
        Rigidbody rb = newPlayer.GetComponent <Rigidbody>();

        rb.detectCollisions = false;
        rearmPoint.BeginReArm();
        rb.velocity         = Vector3.zero;
        rb.detectCollisions = true;

        PlayerManager.SetupLocalAircraft(newPlayer, newPlayer.transform.position, newPlayer.transform.rotation, networkUID);

        lastMessage.UID      = networkUID;
        lastMessage.isLeftie = PlayerManager.teamLeftie;

        if (Networker.isHost)
        {
            NetworkSenderThread.Instance.SendPacketAsHostToAllClients(lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
        }
        else
        {
            NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
        }
    }
Ejemplo n.º 4
0
    public static void SpawnLocalVehicleAndInformOtherClients(GameObject localVehicle, Vector3 pos, Quaternion rot, ulong UID, int playercount = 0) //Both
    {
        Debug.Log("Sending our location to spawn our vehicle");
        VTOLVehicles currentVehicle = VTOLAPI.GetPlayersVehicleEnum();
        Actor        actor          = localVehicle.GetComponent <Actor>();
        Player       localPlayer    = new Player(SteamUser.GetSteamID(), localVehicle, currentVehicle, UID, PlayerManager.teamLeftie);

        AddToPlayerList(localPlayer);


        ReArmingPoint[] rearmPoints = GameObject.FindObjectsOfType <ReArmingPoint>();
        ReArmingPoint   rearmPoint  = rearmPoints[UnityEngine.Random.Range(0, rearmPoints.Length - 1)];
        int             rand        = UnityEngine.Random.Range(0, rearmPoints.Length - 1);
        int             counter     = 0;

        float lastRadius = 0.0f;

        Rigidbody rb = localVehicle.GetComponent <Rigidbody>();

        //rb.detectCollisions = false;
        if (PlayerManager.carrierStart)
        {
            foreach (ReArmingPoint rep in rearmPoints)
            {
                if (rep.team == Teams.Allied)
                {
                    if (rep.radius > 17.0f && rep.radius < 19.0f)
                    {
                        rearmPoint = rep;
                    }
                }
            }
        }
        else
        {
            foreach (ReArmingPoint rep in rearmPoints)
            {
                if (rep.team == Teams.Allied && rep.CheckIsClear(actor))
                {
                    if (rep.radius > lastRadius)
                    {
                        rearmPoint = rep;
                        lastRadius = rep.radius;
                    }
                }
            }
        }

        if (Networker.isHost && firstSpawnDone == false)
        {
            if (firstSpawnDone)
            {
                rearmPoint.BeginReArm();
            }
            rb.velocity = Vector3.zero;
        }
        else
        {
            if (teamLeftie)
            {
                rearmPoint.BeginReArm();
                rb.velocity = Vector3.zero;
            }
            else
            {
                if (firstSpawnDone == false)
                {
                    PlayerSpawn ps = GameObject.FindObjectOfType <PlayerSpawn>();
                    if (ps.initialSpeed < 5.0f)
                    {
                        rearmPoint.BeginReArm();
                        rb.velocity = Vector3.zero;
                    }
                }
            }
        }


        //prevent fall through ground
        if ((bool)VTMapGenerator.fetch)
        {
            VTMapGenerator.fetch.BakeColliderAtPosition(localVehicle.transform.position);
        }
        //rb.detectCollisions = true;
        SetupLocalAircraft(localVehicle, pos, rot, UID);


        firstSpawnDone = true;

        /*if(!firstSpawn)
         * if (!Networker.isHost) {
         * actor.health.Kill();
         *      localVehicle.transform.position = new Vector3(1000000, 10000, 10000);
         *  }
         */


        /// * //bad code we ran this before in  SetupLocalAircraft(localVehicle, pos, rot, UID);

        /*List<HPInfo> hpInfos = PlaneEquippableManager.generateLocalHpInfoList(UID);
         * CountermeasureManager cmManager = localVehicle.GetComponentInChildren<CountermeasureManager>();
         * List<int> cm = PlaneEquippableManager.generateCounterMeasuresFromCmManager(cmManager);
         * float fuel = PlaneEquippableManager.generateLocalFuelValue();
         *
         *
         *
         *
         * Debug.Log("Assembled our local vehicle");
         * if (!Networker.isHost || Multiplayer.SoloTesting)
         * {
         *  // Not host, so send host the spawn vehicle message
         *  Debug.Log($"Sending spawn vehicle message to: {Networker.hostID}");
         *  NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID,
         *      new Message_SpawnPlayerVehicle(currentVehicle,
         *          new Vector3D(pos),
         *          rot,
         *          SteamUser.GetSteamID().m_SteamID,
         *          UID,
         *          hpInfos.ToArray(),
         *          cm.ToArray(),
         *          fuel, PlayerManager.teamLeftie),
         *      EP2PSend.k_EP2PSendReliable);
         * }
         * else
         * {
         *  Debug.Log("I am host, no need to immediately forward my assembled vehicle");
         * }*/
    }
Ejemplo n.º 5
0
    public static void SetUpCarrier(GameObject carrier, ulong id, Teams team)
    {
        AirportManager airport = carrier.GetComponent <AirportManager>();

        if (airport != null)
        {
            airport.airportName = carrierNames[(int)id % carrierNames.Length] + " " + id;
            if (Networker.isClient)
            {
                VTMapManager.fetch.airports.Add(airport);
            }

            GameObject carrierPrefab = UnitCatalogue.GetUnitPrefab("AlliedCarrier");
            if (airport.voiceProfile == null)
            {
                if (carrierPrefab != null)
                {
                    airport.voiceProfile = carrierPrefab.GetComponent <AirportManager>().voiceProfile;
                    Debug.Log("Set ATC voice!");
                }
                else
                {
                    Debug.Log("Could not find carrier...");
                }
            }

            if (airport.vtolOnlyLanding == false)
            {//this stops inapropriate code from running on either the LHA or the Cruiser, and causing problems
                if (airport.carrierOlsTransform == null)
                {
                    GameObject olsTransform = new GameObject();
                    olsTransform.transform.parent        = carrier.transform;
                    olsTransform.transform.position      = airport.runways[0].transform.position + airport.runways[0].transform.forward * 30;
                    olsTransform.transform.localRotation = Quaternion.Euler(-3.5f, 180f, 0f);
                    airport.carrierOlsTransform          = olsTransform.transform;
                }

                if (airport.ols == null)
                {
                    if (carrierPrefab != null)
                    {
                        GameObject olsObject = GameObject.Instantiate(carrierPrefab.GetComponent <AirportManager>().ols.gameObject);
                        olsObject.transform.parent        = carrier.transform;
                        olsObject.transform.localPosition = new Vector3(-25f, 19.7f, 45f);
                        olsObject.transform.localRotation = Quaternion.Euler(-3.5f, 180, 0);

                        OpticalLandingSystem ols = olsObject.GetComponent <OpticalLandingSystem>();
                        airport.ols            = ols;
                        airport.runways[0].ols = ols;

                        Debug.Log("Stole the OLS!");
                    }
                    else
                    {
                        Debug.Log("Could not find carrier...");
                    }
                }

                Actor actor = carrier.GetComponent <Actor>();
                if (actor != null)
                {
                    actor.iconType              = UnitIconManager.MapIconTypes.Carrier;
                    actor.useIconRotation       = true;
                    actor.iconRotationReference = airport.runways[0].transform;
                }
            }
            else
            {
                Debug.Log("This is a cruiser or an LHA, no need to set up runways or landing systems");
            }

            if (airport.carrierCables.Length == 0)
            {
                airport.carrierCables = carrier.GetComponentsInChildren <CarrierCable>();
                Debug.Log("Assigned the carrier wires!");
            }

            int catCount = 1;
            foreach (CarrierCatapult catapult in carrier.GetComponentsInChildren <CarrierCatapult>())
            {
                if (catapult.catapultDesignation == 0)
                {
                    catapult.catapultDesignation = catCount;
                    catCount++;
                }
            }

            if (airport.surfaceColliders.Length == 0)
            {
                airport.surfaceColliders = carrier.GetComponentsInChildren <Collider>();
                Debug.Log("Assigned the surface colliders!");
            }

            airport.waveOffCheckDist = 400;
            airport.waveOffMinDist   = 200;
            airport.waveOffAoA.max   = 12;
            airport.waveOffAoA.min   = 7;

            if (carrier.GetComponentInChildren <ReArmingPoint>() == null)
            {
                Debug.Log("Carrier had no rearming points, adding my own!");
                foreach (AirportManager.ParkingSpace parkingSpace in airport.parkingSpaces)
                {
                    GameObject    rearmingGameObject = new GameObject();
                    ReArmingPoint rearmingPoint      = rearmingGameObject.AddComponent <ReArmingPoint>();
                    rearmingGameObject.transform.parent        = parkingSpace.transform;
                    rearmingGameObject.transform.localPosition = Vector3.zero;
                    rearmingGameObject.transform.localRotation = Quaternion.identity;
                    rearmingPoint.team      = team;
                    rearmingPoint.radius    = 18.93f;
                    rearmingPoint.canArm    = true;
                    rearmingPoint.canRefuel = true;
                }
            }
            else
            {
                Debug.Log("Carrier already had rearming points");
            }
        }
    }
Ejemplo n.º 6
0
    IEnumerator RespawnTimer()
    {
        Debug.Log("Starting respawn timer.");
        GameObject button = Multiplayer.CreateVehicleButton();

        yield return(new WaitForSeconds(respawnTimer));

        Destroy(button);

        Debug.Log("Finished respawn timer.");

        ReArmingPoint[] rearmPoints = GameObject.FindObjectsOfType <ReArmingPoint>();
        ReArmingPoint   rearmPoint  = rearmPoints[Random.Range(0, rearmPoints.Length - 1)];

        float lastRadius = 0;

        if (PlayerManager.carrierStart)
        {
            foreach (ReArmingPoint rep in rearmPoints)
            {
                if (rep.team == Teams.Allied)
                {
                    if (rep.radius > 17.8f && rep.radius < 19.0f)
                    {
                        rearmPoint = rep;
                    }
                }
            }
        }
        else
        {
            foreach (ReArmingPoint rep in rearmPoints)
            {
                Debug.Log("finding rearm pt");
                if (rep.team == Teams.Allied && rep.CheckIsClear(actor))
                {
                    if (rep.radius > lastRadius)
                    {
                        rearmPoint = rep;
                        lastRadius = rep.radius;
                    }
                }
            }
        }



        //UnEject();
        //PutPlayerBackInAircraft();
        //RepairAircraft();

        //foreach (GearAnimator gear in gears) {
        //    gear.ExtendImmediate();
        //}

        //GetComponent<Rigidbody>().velocity = Vector3.zero;
        //transform.position = rearmPoint.transform.position + Vector3.up * 10;
        //transform.rotation = rearmPoint.transform.rotation;

        Destroy(VTOLAPI.GetPlayersVehicleGameObject());
        Destroy(detacher.cameraRig);
        Destroy(detacher.gameObject);
        Destroy(ejection.gameObject);
        Destroy(BlackoutEffect.instance);
        Destroy(GetComponent <PlayerSpawn>());

        foreach (EngineEffects effect in effects)
        {
            Destroy(effect);
        }
        //as much stuff as im destroying, some stuff is most likely getting through, future people, look into this

        AudioController.instance.ClearAllOpenings();

        UnitIconManager.instance.UnregisterAll();
        TargetManager.instance.detectedByAllies.Clear();
        TargetManager.instance.detectedByEnemies.Clear();

        foreach (var actor in TargetManager.instance.allActors)
        {
            if (actor != null)
            {
                actor.discovered = false;
                actor.drawIcon   = true;
                //actor.DiscoverActor();


                actor.permanentDiscovery = true;

                Traverse.Create(actor).Field("detectedByAllied").SetValue(false);
                Traverse.Create(actor).Field("detectedByEnemy").SetValue(false);

                if (actor.team == Teams.Allied)
                {
                    actor.DetectActor(Teams.Allied);
                    actor.UpdateKnownPosition(actor.team);
                }

                //actor.DiscoverActor(); <----------------breaks and only works on every 2nd spawn
                // UnitIconManager.instance.RegisterIcon(actor, 0.07f * actor.iconScale, actor.iconOffset);
            }
        }

        if (PlayerManager.selectedVehicle == "FA-26B")
        {
            PlayerManager.selectedVehicle = "F/A-26B";
        }
        PilotSaveManager.currentVehicle = VTResources.GetPlayerVehicle(PlayerManager.selectedVehicle);
        string campID;

        if (PlayerManager.selectedVehicle == "AV-42C")
        {
            campID = "av42cQuickFlight";
        }
        else if (PlayerManager.selectedVehicle == "F/A-26B")
        {
            campID = "fa26bFreeFlight";
        }
        else
        {
            campID = "f45-quickFlight";
        }

        Campaign campref = VTResources.GetBuiltInCampaign(campID).ToIngameCampaign();

        PilotSaveManager.currentCampaign = campref;
        if (PilotSaveManager.currentVehicle == null)
        {
            Debug.LogError("current vehicle is null");
        }
        GameObject newPlayer = Instantiate(PilotSaveManager.currentVehicle.vehiclePrefab);

        if (newPlayer == null)
        {
            Debug.LogError("new vehicle is null");
        }
        newPlayer.GetComponent <Actor>().designation = FlightSceneManager.instance.playerActor.designation;//reassigning designation

        FlightSceneManager.instance.playerActor = newPlayer.GetComponent <Actor>();
        FlightSceneManager.instance.playerActor.flightInfo.PauseGCalculations();
        FlightSceneManager.instance.playerActor.flightInfo.OverrideRecordedAcceleration(Vector3.zero);

        rearmPoint.voiceProfile.PlayMessage(GroundCrewVoiceProfile.GroundCrewMessages.Success);
        PilotSaveManager.currentScenario.totalBudget       = 999999;
        PilotSaveManager.currentScenario.initialSpending   = 0;
        PilotSaveManager.currentScenario.inFlightSpending  = 0;
        PilotSaveManager.currentScenario.equipConfigurable = true;

        PlayerVehicleSetup pvSetup = newPlayer.GetComponent <PlayerVehicleSetup>();

        pvSetup.SetupForFlight();

        Rigidbody    rb       = newPlayer.GetComponent <Rigidbody>();
        GearAnimator gearAnim = newPlayer.GetComponent <GearAnimator>();

        if (gearAnim != null)
        {
            if (gearAnim.state != GearAnimator.GearStates.Extended)
            {
                gearAnim.ExtendImmediate();
            }
        }


        //  PlayerManager.StartRearm(rearmPoint);
        //rb.velocity = Vector3.zero;
        //rb.detectCollisions = true;
        PlayerManager.SpawnLocalVehicleAndInformOtherClients(newPlayer, newPlayer.transform.position, newPlayer.transform.rotation, networkUID);

        //PlayerManager.SetupLocalAircraft(newPlayer, newPlayer.transform.position, newPlayer.transform.rotation, networkUID);

        lastMessage.UID      = networkUID;
        lastMessage.isLeftie = PlayerManager.teamLeftie;
        lastMessage.tagName  = Steamworks.SteamFriends.GetPersonaName();
        lastMessage.vehicle  = VTOLAPI.GetPlayersVehicleEnum();
        if (Networker.isHost)
        {
            NetworkSenderThread.Instance.SendPacketAsHostToAllClients(lastMessage, Steamworks.EP2PSend.k_EP2PSendReliable);
        }
        else
        {
            NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendReliable);
        }
    }