コード例 #1
0
    public void WeaponSet_Result(Packet packet)
    {
        Message_WeaponSet_Result message = (Message_WeaponSet_Result)((PacketSingle)packet).message;

        if (message.UID != networkUID)
        {
            return;
        }

        List <string> hpLoadoutNames = new List <string>();

        for (int i = 0; i < message.hpLoadout.Length; i++)
        {
            hpLoadoutNames.Add(message.hpLoadout[i].hpName);
        }


        Loadout loadout = new Loadout();

        loadout.hpLoadout      = hpLoadoutNames.ToArray();
        loadout.cmLoadout      = message.cmLoadout;
        loadout.normalizedFuel = message.normalizedFuel;
        weaponManager.EquipWeapons(loadout);

        for (int i = 0; i < cmManager.countermeasures.Count; i++)
        {
            //There should only ever be two counter measures.
            //So the second array in message should be fine.
            cmManager.countermeasures[i].count = message.cmLoadout[i];
        }

        fuelTank.startingFuel = loadout.normalizedFuel;
        fuelTank.SetNormFuel(loadout.normalizedFuel);
    }
    public override void Spawn(Vector3D pos, Vector3 dir)
    {
        base.Spawn(pos, dir);
        rb.velocity = aircraft.transform.forward * pilot.navSpeed;

        pilot.CommandCancelOverride();

        gearAnimator?.RetractImmediate();
        tailHook?.RetractHook();
        catHook?.SetState(0);
        wingRotator?.SetDefault();
        refuelPort?.Close();

        kPlane?.SetToKinematic();

        fuelTank?.SetNormFuel(1);
    }
コード例 #3
0
    public static void SetLoadout(GameObject vehicle, ulong networkID, float fuel, HPInfo[] hpLoadout, int[] cmLoadout)
    {
        int    playerIDX  = PlayerManager.GetPlayerIDFromCSteamID(new CSteamID(networkID));
        bool   playerFlag = false;
        string playerName = "";

        if (playerIDX != -1)
        {
            playerFlag = true;
        }
        if (playerFlag)
        {
            playerName = PlayerManager.players[playerIDX].nameTag + "'s ";
        }

        WeaponManager weaponManager = vehicle.GetComponent <WeaponManager>();

        if (weaponManager == null)
        {
            Debug.LogError("Failed to get weapon manager on " + vehicle.name);
        }
        string[] hpLoadoutNames = new string[30];
        //Debug.Log("foreach var equip in message.hpLoadout");
        int debugInteger = 0;

        foreach (var equip in hpLoadout)
        {
            Debug.Log(debugInteger);
            hpLoadoutNames[equip.hpIdx] = equip.hpName;
            debugInteger++;
        }

        Loadout loadout = new Loadout();

        loadout.normalizedFuel = fuel;
        loadout.hpLoadout      = hpLoadoutNames;
        loadout.cmLoadout      = cmLoadout;
        weaponManager.EquipWeapons(loadout);
        weaponManager.RefreshWeapon();
        //Debug.Log("Refreshed this weapon manager's weapons.");
        MissileNetworker_Receiver lastReciever;

        for (int i = 0; i < 30; i++)
        {
            int          uIDidx = 0;
            HPEquippable equip  = weaponManager.GetEquip(i);
            if (equip is HPEquipMissileLauncher)
            {
                //Debug.Log(equip.name + " is a missile launcher");
                HPEquipMissileLauncher hpML = equip as HPEquipMissileLauncher;
                //Debug.Log("This missile launcher has " + hpML.ml.missiles.Length + " missiles.");
                for (int j = 0; j < hpML.ml.missiles.Length; j++)
                {
                    //Debug.Log("Adding missile reciever");
                    lastReciever             = hpML.ml.missiles[j].gameObject.AddComponent <MissileNetworker_Receiver>();
                    lastReciever.thisMissile = hpML.ml.missiles[j];
                    foreach (var thingy in hpLoadout) // it's a loop... because f**k you!
                    {
                        //Debug.Log("Try adding missile reciever uID");
                        if (equip.hardpointIdx == thingy.hpIdx)
                        {
                            if (uIDidx < thingy.missileUIDS.Length)
                            {
                                lastReciever.networkUID = thingy.missileUIDS[uIDidx];
                                Debug.Log($"Missile ({lastReciever.gameObject.name}) has received their UID from the host. \n Missiles UID = {lastReciever.networkUID}");
                                lastReciever.thisML = hpML.ml;
                                if (playerFlag)
                                {
                                    lastReciever.gameObject.name = playerName + lastReciever.gameObject.name;
                                }
                                lastReciever.idx = j;
                                uIDidx++;
                            }
                        }
                    }
                }
            }
            else if (equip is HPEquipGunTurret)
            {
                TurretNetworker_Receiver reciever = equip.gameObject.AddComponent <TurretNetworker_Receiver>();
                reciever.networkUID = networkID;
                reciever.turret     = equip.GetComponent <ModuleTurret>();
                equip.enabled       = false;
                Debug.Log("Added m230 turret reciever");
            }
        }
        FuelTank fuelTank = vehicle.GetComponent <FuelTank>();

        if (fuelTank == null)
        {
            Debug.LogError("Failed to get fuel tank on " + vehicle.name);
        }
        fuelTank.startingFuel = loadout.normalizedFuel * fuelTank.maxFuel;
        fuelTank.SetNormFuel(loadout.normalizedFuel);
    }
コード例 #4
0
    /// <summary>
    /// When the user has received a message of spawn vehicle,
    /// this creates the vehilc and removes any thing which shouldn't
    /// be on it.
    /// </summary>
    /// <param name="packet">The message</param>
    public static void SpawnVehicle(Packet packet)
    {
        Debug.Log("Recived a Spawn Vehicle Message");

        if (!gameLoaded)
        {
            Debug.LogWarning("Our game isn't loaded, adding spawn vehicle to queue");
            playersToSpawnQueue.Enqueue(packet);
            return;
        }

        Message_SpawnVehicle message = (Message_SpawnVehicle)((PacketSingle)packet).message;

        if (Networker.isHost)
        {
            Debug.Log("Generating UIDS for any missiles the new vehicle has");
            for (int i = 0; i < message.hpLoadout.Length; i++)
            {
                for (int j = 0; j < message.hpLoadout[i].missileUIDS.Length; j++)
                {
                    if (message.hpLoadout[i].missileUIDS[j] != 0)
                    {
                        //Storing the old one
                        ulong clientsUID = message.hpLoadout[i].missileUIDS[j];
                        //Generating a new global UID for that missile
                        message.hpLoadout[i].missileUIDS[j] = Networker.GenerateNetworkUID();
                        //Sending it back to that client
                        Networker.SendP2P(new CSteamID(message.csteamID),
                                          new Message_RequestNetworkUID(clientsUID, message.hpLoadout[i].missileUIDS[j]),
                                          EP2PSend.k_EP2PSendReliable);
                    }
                }
            }

            Debug.Log("Telling other clients about new player and new player about other clients. Player count = " + players.Count);
            for (int i = 0; i < players.Count; i++)
            {
                if (players[i].cSteamID == SteamUser.GetSteamID())
                {
                    Debug.LogWarning("Skiping this one as it's the host");
                    continue;
                }
                PlaneNetworker_Receiver existingPlayersPR = players[i].vehicle.GetComponent <PlaneNetworker_Receiver>();
                //We first send the new player to an existing spawned in player
                Networker.SendP2P(players[i].cSteamID, message, EP2PSend.k_EP2PSendReliable);
                //Then we send this current player to the new player.
                Networker.SendP2P(new CSteamID(message.csteamID),
                                  new Message_SpawnVehicle(
                                      players[i].vehicleName,
                                      VTMapManager.WorldToGlobalPoint(players[i].vehicle.transform.position),
                                      new Vector3D(players[i].vehicle.transform.rotation.eulerAngles),
                                      players[i].cSteamID.m_SteamID,
                                      players[i].vehicleUID,
                                      existingPlayersPR.GenerateHPInfo(),
                                      existingPlayersPR.GetCMS(),
                                      existingPlayersPR.GetFuel()),
                                  EP2PSend.k_EP2PSendReliable);
                Debug.Log($"We have told {players[i].cSteamID.m_SteamID} about the new player ({message.csteamID}) and the other way round");

                //We ask the existing player what their load out just incase the host's player receiver was out of sync.
                Networker.SendP2P(players[i].cSteamID,
                                  new Message(MessageType.WeaponsSet),
                                  EP2PSend.k_EP2PSendReliable);
                Debug.Log($"We have asked {players[i].cSteamID.m_SteamID} what their current weapons are, and now waiting for a responce.");
            }
        }

        GameObject newVehicle = null;

        switch (message.vehicle)
        {
        case VTOLVehicles.None:
            Debug.LogError("Vehcile Enum seems to be none, couldn't spawn player vehicle");
            return;

        case VTOLVehicles.AV42C:
            newVehicle = GameObject.Instantiate(av42cPrefab, message.position.toVector3, Quaternion.Euler(message.rotation.toVector3));
            break;

        case VTOLVehicles.FA26B:
            newVehicle = GameObject.Instantiate(fa26bPrefab, message.position.toVector3, Quaternion.Euler(message.rotation.toVector3));
            break;

        case VTOLVehicles.F45A:
            newVehicle = GameObject.Instantiate(f45Prefab, message.position.toVector3, Quaternion.Euler(message.rotation.toVector3));
            break;
        }
        Debug.Log("Setting vehicle name");
        newVehicle.name = $"Client [{message.csteamID}]";
        Debug.Log($"Spawned new vehicle at {newVehicle.transform.position}");

        RigidbodyNetworker_Receiver rbNetworker = newVehicle.AddComponent <RigidbodyNetworker_Receiver>();

        rbNetworker.networkUID = message.networkID;

        PlaneNetworker_Receiver planeReceiver = newVehicle.AddComponent <PlaneNetworker_Receiver>();

        planeReceiver.networkUID = message.networkID;

        if (message.vehicle == VTOLVehicles.AV42C || message.vehicle == VTOLVehicles.F45A)
        {
            Debug.Log("Adding Tilt Controller to this vehicle " + message.networkID);
            EngineTiltNetworker_Receiver tiltReceiver = newVehicle.AddComponent <EngineTiltNetworker_Receiver>();
            tiltReceiver.networkUID = message.networkID;
        }


        Rigidbody rb      = newVehicle.GetComponent <Rigidbody>();
        AIPilot   aIPilot = newVehicle.GetComponent <AIPilot>();

        Debug.Log($"Changing {newVehicle.name}'s position and rotation\nPos:{rb.position} Rotation:{rb.rotation.eulerAngles}");
        aIPilot.kPlane.SetToKinematic();
        aIPilot.kPlane.enabled = false;
        rb.interpolation       = RigidbodyInterpolation.None;
        aIPilot.commandState   = AIPilot.CommandStates.Override;


        rb.position            = message.position.toVector3;
        rb.rotation            = Quaternion.Euler(message.rotation.toVector3);
        aIPilot.kPlane.enabled = true;
        aIPilot.kPlane.SetVelocity(Vector3.zero);
        aIPilot.kPlane.SetToDynamic();
        rb.interpolation = RigidbodyInterpolation.Interpolate;

        Debug.Log($"Finished changing {newVehicle.name}\n Pos:{rb.position} Rotation:{rb.rotation.eulerAngles}");

        GameObject parent  = new GameObject("Name Tag Holder");
        GameObject nameTag = new GameObject("Name Tag");

        parent.transform.SetParent(newVehicle.transform);
        parent.transform.localRotation = Quaternion.Euler(0, 180, 0);
        nameTag.transform.SetParent(parent.transform);
        nameTag.AddComponent <Nametag>().SetText(
            SteamFriends.GetFriendPersonaName(new CSteamID(message.csteamID)),
            newVehicle.transform, VRHead.instance.transform);

        WeaponManager weaponManager = newVehicle.GetComponent <WeaponManager>();

        if (weaponManager == null)
        {
            Debug.LogError("Failed to get weapon manager on " + newVehicle.name);
        }

        List <string> hpLoadoutNames = new List <string>();

        for (int i = 0; i < message.hpLoadout.Length; i++)
        {
            hpLoadoutNames.Add(message.hpLoadout[i].hpName);
        }

        Debug.Log("Setting Loadout on this new vehicle spawned");
        for (int i = 0; i < hpLoadoutNames.Count; i++)
        {
            Debug.Log("HP " + i + " Name: " + hpLoadoutNames[i]);
        }
        Loadout loadout = new Loadout();

        loadout.normalizedFuel = message.normalizedFuel;
        loadout.hpLoadout      = hpLoadoutNames.ToArray();
        loadout.cmLoadout      = message.cmLoadout;
        weaponManager.EquipWeapons(loadout);

        FuelTank fuelTank = newVehicle.GetComponent <FuelTank>();

        if (fuelTank == null)
        {
            Debug.LogError("Failed to get fuel tank on " + newVehicle.name);
        }
        fuelTank.startingFuel = loadout.normalizedFuel * fuelTank.maxFuel;
        fuelTank.SetNormFuel(loadout.normalizedFuel);

        players.Add(new Player(new CSteamID(message.csteamID), newVehicle, message.vehicle, message.networkID));
    }