public static bool Prefix(PlayerSpawn __instance)
    {
        if (PlayerManager.selectedVehicle == "")
        {
            Debug.LogError("selected vehicle is empty");
        }
        if (PlayerManager.selectedVehicle == "FA-26B")
        {
            PlayerManager.selectedVehicle = "F/A-26B";
        }
        VTScenario.current.vehicle      = VTResources.GetPlayerVehicle(PlayerManager.selectedVehicle);
        PilotSaveManager.currentVehicle = VTResources.GetPlayerVehicle(PlayerManager.selectedVehicle);
        VTCampaignInfo[] list   = VTResources.GetBuiltInCampaigns().ToArray();
        string           campID = " ";

        if (PlayerManager.selectedVehicle == "AV-42C")
        {
            campID = "av42cQuickFlight";
        }
        else if (PlayerManager.selectedVehicle == "FA-26B")
        {
            campID = "fa26bFreeFlight";
        }
        else
        {
            campID = "f45-quickFlight";
        }
        Campaign campref = VTResources.GetBuiltInCampaign(campID).ToIngameCampaign();

        PilotSaveManager.currentCampaign = campref;
        Multiplayer._instance.buttonMade = false;
        return(true);
    }
Exemple #2
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);
        }
    }
 public static GameObject CreateVehicleButton()
 {
     foreach (var controller in GameObject.FindObjectsOfType <VRHandController>())
     {
         GameObject button;
         if (canvasButtonPrefab == null)
         {
             button = GameObject.Instantiate(GameObject.Find("RecenterCanvas"));
         }
         else
         {
             button = GameObject.Instantiate(canvasButtonPrefab);
             button.SetActive(true);
         }
         if (!controller.isLeft)
         {
             Debug.Log("Current vehicle name is " + PilotSaveManager.currentVehicle.name);
             button.transform.SetParent(controller.transform);
             button.transform.localPosition = new Vector3(0.101411f, 0.02100047f, -0.128024f);
             button.transform.localRotation = Quaternion.Euler(-5.834f, 283.583f, 328.957f);
             button.transform.localScale    = new Vector3(button.transform.localScale.x * -1, button.transform.localScale.y * -1, button.transform.localScale.z);
             VRInteractable bInteractable = button.GetComponentInChildren <VRInteractable>();
             Text           text          = button.GetComponentInChildren <Text>();
             text.transform.localScale = text.transform.localScale * 0.75f;
             text.text = PilotSaveManager.currentVehicle.name;
             bInteractable.interactableName = "Switch Vehicles.";
             bInteractable.OnInteract       = new UnityEvent();
             PlayerManager.selectedVehicle  = PilotSaveManager.currentVehicle.name;
             foreach (var vehicle in VTResources.GetPlayerVehicles())
             {
                 Debug.Log(vehicle.name);
                 Debug.Log(vehicle.vehicleName);
             }
             bInteractable.OnInteract.AddListener(delegate
             {
                 if (PilotSaveManager.currentVehicle.name == "AV-42C")
                 {
                     PilotSaveManager.currentVehicle = VTResources.GetPlayerVehicle("F/A-26B");
                 }
                 else if (PilotSaveManager.currentVehicle.name == "FA-26B")
                 {
                     PilotSaveManager.currentVehicle = VTResources.GetPlayerVehicle("F-45A");
                 }
                 else
                 {
                     PilotSaveManager.currentVehicle = VTResources.GetPlayerVehicle("AV-42C");
                 }
                 text.text = PilotSaveManager.currentVehicle.name;
                 PlayerManager.selectedVehicle = text.text;
                 if (VTOLAPI.currentScene == VTOLScenes.VehicleConfiguration)
                 {
                     // BPilotSaveManager.currentVehicle = VTResources.GetPlayerVehicle(PlayerManager.selectedVehicle);
                     string campID;
                     if (PlayerManager.selectedVehicle == "AV-42C")
                     {
                         campID = "av42cQuickFlight";
                     }
                     else if (PlayerManager.selectedVehicle == "FA-26B")
                     {
                         campID = "fa26bFreeFlight";
                     }
                     else
                     {
                         campID = "f45-quickFlight";
                     }
                     Campaign campref = VTResources.GetBuiltInCampaign(campID).ToIngameCampaign();
                     PilotSaveManager.currentCampaign = campref;
                     Multiplayer._instance.buttonMade = false;
                     SceneManager.LoadScene("VehicleConfiguration");
                 }
             });
         }
         if (canvasButtonPrefab == null)
         {
             canvasButtonPrefab = Instantiate(GameObject.Find("RecenterCanvas"));
             canvasButtonPrefab.SetActive(false);
             DontDestroyOnLoad(canvasButtonPrefab);
         }
         Multiplayer._instance.buttonMade = true;
         return(button);
     }
     return(null);
 }