protected override void UpdateTask()
    {
        base.UpdateTask();
        float maxDistance = AirTraffic.trafficRadius * 1.01f;

        if ((AirTraffic.instance.mpMode || AirTraffic.settings.mpTestMode) && AirTraffic.instance.akutan == false)
        {
            maxDistance = AirTraffic.mapRadius * 1.4f;
        }
        if (AirTraffic.DistanceFromOrigin(VTMapManager.WorldToGlobalPoint(transform.position)) > maxDistance)
        {
            if (aircraft.aiPilot.commandState == AIPilot.CommandStates.Orbit)
            {
                Debug.Log(gameObject.name + " went outta bounds, respawning elsewhere");
                Vector3D pos = AirTraffic.PointOnCruisingRadius();
                Vector3  dir = -pos.toVector3;
                dir.y = 0;
                Spawn(pos, dir);
            }
            else
            {
                if (health.normalizedHealth != 0)
                {
                    Debug.Log(gameObject.name + " went outta bounds untintentionally, destroying them for our saftey");
                    health.Kill();
                }
            }
        }
    }
示例#2
0
    private void FixedUpdate()
    {
        if (thisMissile == null)
        {
            Debug.LogError("thisMissile null.");
        }
        if (hasFired != thisMissile.fired)
        {
            Debug.Log("Missile fired " + thisMissile.name);
            hasFired = true;

            RigidbodyNetworker_Sender rbSender = gameObject.AddComponent <RigidbodyNetworker_Sender>();
            rbSender.networkUID = networkUID;
        }
        if (thisMissile != null && thisMissile.fired)
        {
            if (lastMessage == null)
            {
                Debug.LogError("lastMessage null");
            }
            lastMessage.networkUID   = networkUID;
            lastMessage.guidanceMode = thisMissile.guidanceMode;
            if (thisMissile.guidanceMode == Missile.GuidanceModes.Radar)
            {
                if (thisMissile.radarLock != null && thisMissile.radarLock.actor != null)
                {
                    lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.radarLock.actor.transform.position);
                    foreach (var AI in AIManager.AIVehicles)
                    {
                        if (AI.actor == thisMissile.radarLock.actor)
                        {
                            lastMessage.radarLock = AI.vehicleUID;
                            // Debug.Log($"Missile {gameObject.name} has found its lock {AI.actor.name} with an uID of {AI.vehicleUID} while trying to lock {thisMissile.radarLock.actor.name}");
                        }
                    }
                }
            }
            else if (thisMissile.guidanceMode == Missile.GuidanceModes.Optical)
            {
                lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.opticalTargetActor.transform.position);
                //lastMessage.seekerRotation = thisMissile.heatSeeker.transform.rotation;
            }
            else if (thisMissile.guidanceMode == Missile.GuidanceModes.Heat)
            {
                //lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.opticalTargetActor.transform.position);
                lastMessage.seekerRotation = thisMissile.heatSeeker.transform.rotation;
            }
            SendMessage(false);
        }

        /*if (thisMissile.guidanceMode == Missile.GuidanceModes.Radar)
         * {
         *  if (thisMissile.isPitbull)
         *  {
         *      Debug.Log(gameObject.name + " is now pitbull.");
         *  }
         * }*/
    }
 public static Vector3D GetPlayerPosition()
 {
     if ((instance.mpMode || settings.mpTestMode) && instance.akutan == false)
     {
         return(new Vector3D(mapRadius, 0, mapRadius));
     }
     else
     {
         return(VTMapManager.WorldToGlobalPoint(FlightSceneManager.instance.playerActor.gameObject.transform.position));
     }
 }
 void Update()
 {
     if (targetActor != null)
     {
         lastTargetPositon  = VTMapManager.WorldToGlobalPoint(targetActor.transform.position);
         lastTargetVelocity = targetActor.velocity;
     }
     else
     {
         lastTargetPositon += lastTargetVelocity * Time.deltaTime;
     }
 }
示例#5
0
 private void Update()
 {
     if (receivedGlobalUID && thisMissile != null && thisMissile.fired)
     {
         lastMessage.networkUID = networkUID;
         lastMessage.position   = VTMapManager.WorldToGlobalPoint(rigidbody.position);
         lastMessage.rotation   = new Vector3D(rigidbody.rotation.eulerAngles);
         if (thisMissile.radarLock != null && thisMissile.radarLock.actor != null)
         {
             lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.radarLock.actor.transform.position);
         }
         SendMessage(false);
     }
 }
示例#6
0
    private void FixedUpdate()
    {
        globalLastPosition += new Vector3D(lastVelocity * Time.fixedDeltaTime);
        localLastPosition   = VTMapManager.GlobalToWorldPoint(globalLastPosition);
        Quaternion quatVel = Quaternion.Euler(lastAngularVelocity * Time.fixedDeltaTime);

        lastRotation *= quatVel;

        lastUp      = lastRotation * Vector3.up;
        lastForward = lastRotation * Vector3.forward;
        tick       += Time.fixedDeltaTime;
        if (tick > 1.0f / tickRate || Vector3.Distance(localLastPosition, transform.TransformPoint(originOffset)) > threshold || Vector3.Angle(lastUp, transform.up) > angleThreshold || Vector3.Angle(lastForward, transform.forward) > angleThreshold)
        {
            tick        = 0.0f;
            lastUp      = transform.up;
            lastForward = transform.forward;

            globalLastPosition = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset));
            lastVelocity       = rb.velocity;

            lastRotation        = transform.rotation;
            lastAngularVelocity = rb.angularVelocity * Mathf.Rad2Deg;

            lastMessage.position = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset));
            lastMessage.rotation = transform.rotation;
            if (Multiplayer.SoloTesting)
            {
                lastMessage.position += new Vector3D(-30, 0, 0);
            }
            lastMessage.velocity        = new Vector3D(rb.velocity);
            lastMessage.angularVelocity = new Vector3D(rb.angularVelocity * Mathf.Rad2Deg);
            lastMessage.networkUID      = networkUID;
            lastMessage.sequenceNumber  = ++updateNumber;
            if (Networker.isHost)
            {
                NetworkSenderThread.Instance.SendPacketAsHostToAllClients(lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
            }
            else
            {
                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
            }
        }
        // Temperz STOP KILLING PERFORMANCE AND HARD DRIVES!
        //Debug.Log($"{actor.name} is not outside of the threshold {Threshold}, the distance is {Vector3.Distance(lastPos, gameObject.transform.position)} not updating it.");
    }
示例#7
0
 private void LateUpdate()
 {
     lastMessage.position = VTMapManager.WorldToGlobalPoint(transform.position);
     lastMessage.rotation = new Vector3D(transform.rotation.eulerAngles);
     if (Multiplayer.SoloTesting)
     {
         lastMessage.position += new Vector3D(-30, 0, 0);
     }
     lastMessage.velocity        = new Vector3D(rb.velocity);
     lastMessage.angularVelocity = new Vector3D(rb.angularVelocity);
     lastMessage.networkUID      = networkUID;
     if (Networker.isHost)
     {
         Networker.SendGlobalP2P(lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
     }
     else
     {
         Networker.SendP2P(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
     }
 }
示例#8
0
    private void FixedUpdate()
    {
        globalLastPosition += new Vector3D(lastVelocity * Time.fixedDeltaTime);
        localLastPosition   = VTMapManager.GlobalToWorldPoint(globalLastPosition);
        Quaternion quatVel = Quaternion.Euler(lastAngularVelocity * Time.fixedDeltaTime);

        lastRotation *= quatVel;

        lastUp      = lastRotation * Vector3.up;
        lastForward = lastRotation * Vector3.forward;
        tick       += Time.fixedDeltaTime;
        if (tick > 1.0f / tickRate || Vector3.Distance(localLastPosition, transform.TransformPoint(originOffset)) > threshold || Vector3.Angle(lastUp, transform.up) > angleThreshold || Vector3.Angle(lastForward, transform.forward) > angleThreshold)
        {
            tick        = 0.0f;
            lastUp      = transform.up;
            lastForward = transform.forward;

            globalLastPosition = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset));
            lastVelocity       = rb.velocity;

            lastRotation        = transform.rotation;
            lastAngularVelocity = rb.angularVelocity * Mathf.Rad2Deg;

            lastMessage.position = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset));
            lastMessage.rotation = transform.rotation;

            lastMessage.velocity        = new Vector3D(rb.velocity);
            lastMessage.angularVelocity = new Vector3D(rb.angularVelocity * Mathf.Rad2Deg);
            lastMessage.networkUID      = networkUID;
            lastMessage.sequenceNumber  = ++updateNumber;
            if (Networker.isHost)
            {
                Networker.addToUnreliableSendBuffer(lastMessage);
            }
            else
            {
                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliable);
            }
        }
    }
    void FixedUpdate()
    {
        timer += Time.fixedDeltaTime;
        if (timer > 1)
        {
            timer = 0;

            lastMessage.position = VTMapManager.WorldToGlobalPoint(ship.transform.position);
            lastMessage.rotation = ship.transform.rotation;
            lastMessage.velocity = new Vector3D(ship.velocity);

            lastMessage.UID = networkUID;
            if (Networker.isHost)
            {
                NetworkSenderThread.Instance.SendPacketAsHostToAllClients(lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
            }
            else
            {
                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
            }
        }
    }
    static bool Prefix(GPSTargetSystem __instance, Vector3 worldPosition, string prefix)
    {
        Vector3 pos  = worldPosition;
        string  msgp = prefix;

        Debug.Log("sending GPS");


        Message_GPSData gpsm = new Message_GPSData(PlayerManager.localUID, VTMapManager.WorldToGlobalPoint(pos), "MP", PlayerManager.teamLeftie, __instance.currentGroup.groupName);

        if (PlayerManager.sendGPS)
        {
            if (Networker.isHost)
            {
                NetworkSenderThread.Instance.SendPacketAsHostToAllClients(gpsm, Steamworks.EP2PSend.k_EP2PSendReliable);
            }
            else
            {
                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, gpsm, Steamworks.EP2PSend.k_EP2PSendReliable);
            }
        }
        return(true);
    }
示例#11
0
        public static Vector3D WorldPositionToGPSCoords(Vector3 worldPoint)
        {
            VTMap map = VTMapManager.fetch.map;

            Vector3D vector3D = VTMapManager.WorldToGlobalPoint(worldPoint);
            double   z        = (double)(worldPoint.y - WaterPhysics.instance.height);
            double   num      = vector3D.z / 111319.9;
            double   num2     = Math.Abs(Math.Cos(num * 0.01745329238474369) * 111319.9);
            double   num3     = 0.0;

            if (num2 > 0.0)
            {
                num3 = vector3D.x / num2;
            }
            double num4 = num3;

            if (map)
            {
                num  += (double)map.mapLatitude;
                num4 += (double)map.mapLongitude;
            }
            return(new Vector3D(num, num4, z));
        }
示例#12
0
    void FixedUpdate()
    {
        timer += Time.fixedDeltaTime;
        if (timer > 0.5f)
        {
            timer = 0;

            lastMessage.position = VTMapManager.WorldToGlobalPoint(groundUnitMover.transform.position);
            lastMessage.rotation = groundUnitMover.transform.rotation.normalized;
            lastMessage.velocity = new Vector3D(groundUnitMover.velocity);

            ///Debug.Log("Ground sender rotation is: " + lastMessage.rotation.ToString());

            lastMessage.UID = networkUID;
            if (Networker.isHost)
            {
                Networker.addToUnreliableSendBuffer(lastMessage);
            }
            else
            {
                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliable);
            }
        }
    }
示例#13
0
    /// <summary>
    /// When the user has received a message of spawn player vehicle,
    /// this creates the player vehicle and removes any thing which shouldn't
    /// be on it.
    /// </summary>
    /// <param name="packet">The message</param>
    public static void SpawnPlayerVehicle(Packet packet, CSteamID sender) //Both, but never spawns the local vehicle, only executes spawn vehicle messages from other clients
    {
        // We don't actually need the "sender" id, unless we're a client and want to check that the packet came from the host
        // which we're not doing right now.
        Message_SpawnPlayerVehicle message = (Message_SpawnPlayerVehicle)((PacketSingle)packet).message;

        if (message.networkID == PlayerManager.localUID)
        {
            return;
        }

        Debug.Log($"Recived a Spawn Vehicle Message from: {message.csteamID}");
        CSteamID spawnerSteamId = new CSteamID(message.csteamID);

        if (!gameLoaded)
        {
            Debug.LogWarning("Our game isn't loaded, adding spawn vehicle to queue");
            playersToSpawnQueue.Enqueue(packet);
            playersToSpawnIdQueue.Enqueue(sender);
            return;
        }
        //foreach (ulong id in spawnedVehicles)
        //{
        //    if (id == message.csteamID)
        //    {
        //        Debug.Log("Got a spawnedVehicle message for a vehicle we have already added! Returning....");
        //        return;
        //    }
        //}
        //spawnedVehicles.Add(message.csteamID);
        Debug.Log("Got a new spawnVehicle uID.");
        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
                        NetworkSenderThread.Instance.SendPacketToSpecificPlayer(spawnerSteamId,
                                                                                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");
                    //Send the host player to the new player.
                    //Debug.Log($"Running host code to tell new player about host vehicle.");

                    GameObject    localVehicle       = VTOLAPI.GetPlayersVehicleGameObject();
                    WeaponManager localWeaponManager = localVehicle.GetComponent <WeaponManager>();

                    List <HPInfo> hpInfos = PlaneEquippableManager.generateHpInfoListFromWeaponManager(localWeaponManager,
                                                                                                       PlaneEquippableManager.HPInfoListGenerateNetworkType.sender);
                    CountermeasureManager cmManager = localVehicle.GetComponentInChildren <CountermeasureManager>();
                    List <int>            cm        = PlaneEquippableManager.generateCounterMeasuresFromCmManager(cmManager);
                    float fuel = PlaneEquippableManager.generateLocalFuelValue();

                    NetworkSenderThread.Instance.SendPacketToSpecificPlayer(spawnerSteamId,
                                                                            new Message_SpawnPlayerVehicle(
                                                                                players[i].vehicleType,
                                                                                VTMapManager.WorldToGlobalPoint(players[i].vehicle.transform.position),
                                                                                players[i].vehicle.transform.rotation,
                                                                                players[i].cSteamID.m_SteamID,
                                                                                players[i].vehicleUID,
                                                                                hpInfos.ToArray(),
                                                                                cm.ToArray(),
                                                                                fuel, players[i].leftie),
                                                                            EP2PSend.k_EP2PSendReliable);

                    //Debug.Log($"We have told the new player about the host and NOT the other way around.");
                    //Debug.Log($"We don't need to resync the host weapons, that's guaranteed to already be up to date.");
                    continue;
                }

                if (players[i].vehicle != null)
                {
                    PlaneNetworker_Receiver existingPlayersPR = players[i].vehicle.GetComponent <PlaneNetworker_Receiver>();
                    //We first send the new player to an existing spawned in player
                    NetworkSenderThread.Instance.SendPacketToSpecificPlayer(players[i].cSteamID, message, EP2PSend.k_EP2PSendReliable);
                    //Then we send this current player to the new player.
                    NetworkSenderThread.Instance.SendPacketToSpecificPlayer(spawnerSteamId,
                                                                            new Message_SpawnPlayerVehicle(
                                                                                players[i].vehicleType,
                                                                                VTMapManager.WorldToGlobalPoint(players[i].vehicle.transform.position),
                                                                                players[i].vehicle.transform.rotation,
                                                                                players[i].cSteamID.m_SteamID,
                                                                                players[i].vehicleUID,
                                                                                existingPlayersPR.GenerateHPInfo(),
                                                                                existingPlayersPR.GetCMS(),
                                                                                existingPlayersPR.GetFuel(), players[i].leftie),
                                                                            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.
                    NetworkSenderThread.Instance.SendPacketToSpecificPlayer(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."); // marsh typo response lmao
                }
                else
                {
                    Debug.Log("players[" + i + "].vehicle is null");
                }
            }
        }

        if (Networker.isHost)
        {
            Debug.Log("Telling connected client about AI units");
            AIManager.TellClientAboutAI(spawnerSteamId);
        }
        AddToPlayerList(new Player(spawnerSteamId, null, message.vehicle, message.networkID, message.leftie));

        GameObject puppet = SpawnRepresentation(message.networkID, message.position, message.rotation, message.leftie);

        if (puppet != null)
        {
            PlaneEquippableManager.SetLoadout(puppet, message.networkID, message.normalizedFuel, message.hpLoadout, message.cmLoadout);
        }
    }
    static bool Prefix(Bullet __instance)
    {
        Vector3 pos = Traverse.Create(__instance).Field("hitPoint").GetValue <Vector3>();
        Vector3 vel = Traverse.Create(__instance).Field("velocity").GetValue <Vector3>();
        Vector3 a   = pos;

        a += -vel * Time.deltaTime;
        float  damage      = Traverse.Create(__instance).Field("damage").GetValue <float>();
        Actor  sourceActor = Traverse.Create(__instance).Field("sourceActor").GetValue <Actor>();
        Hitbox hitbox      = null;



        Collider[] ColliderHits;
        ColliderHits = Physics.OverlapSphere(pos, 5.0f, 1025);
        for (int i = 0; i < ColliderHits.Length; i++)
        {
            Collider coll = ColliderHits[i];
            hitbox = coll.GetComponent <Hitbox>();
            if ((bool)hitbox && (bool)hitbox.actor)
            {
                PlayerManager.lastBulletHit = hitbox;
                Debug.Log("hit box bullet hit");
                ulong lastID; ulong sourceID;
                if (VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.TryGetValue(hitbox.actor, out lastID))
                {
                    if (VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.TryGetValue(sourceActor, out sourceID))
                    {
                    }

                    Debug.Log("hit player sending bullet packet");
                    Message_BulletHit hitmsg = new Message_BulletHit(PlayerManager.localUID, lastID, sourceID, VTMapManager.WorldToGlobalPoint(pos), new Vector3D(vel), damage);
                    NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, hitmsg, Steamworks.EP2PSend.k_EP2PSendReliable);
                }
            }
        }

        return(true);
    }
示例#15
0
 public TrafficTask_LandTemp(string newName, Transform helipad, Vector3 localOffset) : base(newName)
 {
     point      = VTMapManager.WorldToGlobalPoint(helipad.TransformPoint(localOffset));
     maxPerTask = 1;
 }
示例#16
0
 public override void Start(FlybyCameraMFDPage mfdPage)
 {
     SCamPlus.position = VTMapManager.WorldToGlobalPoint(mfdPage.flybyCam.transform.position);
 }
    /// <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));
    }
示例#18
0
    /// <summary>
    /// Tell the connected clients about all the vehicles the host has. This code should never be run on a client.
    /// </summary>
    /// <param name="steamID">Pass 0 to tell it to every client.</param>
    public static void TellClientAboutAI(CSteamID steamID)
    {
        if (!Networker.isHost)
        {
            Debug.LogWarning("The client shouldn't be trying to tell everyone about AI");
            return;
        }
        Debug.Log("Trying sending AI's to client " + steamID);
        foreach (var actor in TargetManager.instance.allActors)
        {
            if (actor == null)
            {
                continue;
            }
            if (actor.parentActor != null)
            {
                continue;
            }
            Debug.Log("Trying sending new stage 1");
            if (!actor.isPlayer)
            {
                if (actor.name.Contains("Client [") == false)
                {
                    Debug.Log("Trying sending new stage 2");
                    bool Aggresion = false;
                    if (actor.gameObject.GetComponent <UIDNetworker_Sender>() != null)
                    {
                        Debug.Log("Try sending ai " + actor.name + " to client.");
                        HPInfo[]            hPInfos2  = null;
                        int[]               cmLoadout = null;
                        UIDNetworker_Sender uidSender = actor.gameObject.GetComponent <UIDNetworker_Sender>();
                        List <ulong>        subUIDs   = new List <ulong>();
                        foreach (UIDNetworker_Sender subActor in actor.gameObject.GetComponentsInChildren <UIDNetworker_Sender>())
                        {
                            subUIDs.Add(subActor.networkUID);
                            Debug.Log("Found ID sender with ID " + subActor.networkUID);
                        }

                        if (actor.role == Actor.Roles.Air)
                        {
                            WeaponManager wm = actor.gameObject.GetComponent <WeaponManager>();
                            if (wm != null)
                            {
                                hPInfos2 = PlaneEquippableManager.generateHpInfoListFromWeaponManager(actor.weaponManager, PlaneEquippableManager.HPInfoListGenerateNetworkType.sender, uidSender.networkUID).ToArray();
                            }
                        }
                        AIUnitSpawn aIUnitSpawn = actor.gameObject.GetComponent <AIUnitSpawn>();
                        if (aIUnitSpawn == null)
                        {
                            Debug.LogWarning("AI unit spawn is null on ai " + actor.name);
                        }
                        else
                        {
                            Aggresion = aIUnitSpawn.engageEnemies;
                        }
                        bool            canBreak = false;
                        PhoneticLetters letters  = new PhoneticLetters();
                        foreach (var Group in VTScenario.current.groups.GetExistingGroups(actor.team))
                        {
                            foreach (var ID in Group.unitIDs)
                            {
                                if (aIUnitSpawn != null)
                                {
                                    if (ID == actor.unitSpawn.unitID)
                                    {
                                        letters  = Group.groupID;
                                        canBreak = true;
                                        break;
                                    }
                                }
                            }
                            if (canBreak)
                            {
                                break;
                            }
                        }

                        Debug.LogWarning("passed group stuff");
                        List <ulong> ids = new List <ulong>();
                        ulong        lastID;
                        SAMLauncher  launcher = actor.gameObject.GetComponentInChildren <SAMLauncher>();
                        if (launcher != null)
                        {
                            foreach (var radar in launcher.lockingRadars)
                            {
                                if (radar.myActor == null)
                                {
                                    Debug.LogError("Locking radar on one of the SAM's is literally null.");
                                }
                                if (VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.TryGetValue(radar.myActor, out lastID))
                                {
                                    ids.Add(lastID);
                                    // Debug.Log("Aded a radar ID");
                                }
                                else
                                {
                                    Debug.LogError("Couldn't get a locking radar on one of the SAM's, probably a dictionary problem.");
                                }
                            }
                        }
                        ulong[] irIDS             = new ulong[0];
                        IRSAMNetworker_Sender irs = actor.gameObject.GetComponentInChildren <IRSAMNetworker_Sender>();
                        if (irs != null)
                        {
                            irIDS = irs.irIDs;
                        }
                        bool redfor = false;

                        if (actor.team == Teams.Enemy)
                        {
                            redfor = true;
                        }
                        if (steamID != new CSteamID(0))
                        {
                            Debug.Log("Finally sending AI " + actor.name + " to client " + steamID);
                            Debug.Log("This unit is made from " + subUIDs.Count + " actors! ");
                            if (canBreak)
                            {
                                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(steamID, new Message_SpawnAIVehicle(actor.name, GetUnitNameFromCatalog(actor.unitSpawn.unitName), redfor,
                                                                                                                            VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                                                            actor.gameObject.transform.rotation, uidSender.networkUID, subUIDs.ToArray(), hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, letters, ids.ToArray(), irIDS),
                                                                                        EP2PSend.k_EP2PSendReliableWithBuffering);
                            }
                            else
                            {
                                // Debug.Log("It seems that " + actor.name + " is not in a unit group, sending anyways.");
                                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(steamID, new Message_SpawnAIVehicle(actor.name, GetUnitNameFromCatalog(actor.unitSpawn.unitName), redfor,
                                                                                                                            VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                                                            actor.gameObject.transform.rotation, uidSender.networkUID, subUIDs.ToArray(), hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, ids.ToArray(), irIDS),
                                                                                        EP2PSend.k_EP2PSendReliableWithBuffering);
                            }
                        }
                        else
                        {
                            Debug.Log("Finally sending AI " + actor.name + " to client all clients.");
                            Debug.Log("This unit is made from " + subUIDs.Count + " actors! ");
                            if (canBreak)
                            {
                                Networker.addToReliableSendBuffer(new Message_SpawnAIVehicle(actor.name, GetUnitNameFromCatalog(actor.unitSpawn.unitName), redfor,
                                                                                             VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                             actor.gameObject.transform.rotation, uidSender.networkUID, subUIDs.ToArray(), hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, letters, ids.ToArray(), irIDS));
                            }
                            else
                            {
                                // Debug.Log("It seems that " + actor.name + " is not in a unit group, sending anyways.");
                                Networker.addToReliableSendBuffer(new Message_SpawnAIVehicle(actor.name, GetUnitNameFromCatalog(actor.unitSpawn.unitName), redfor,
                                                                                             VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                             actor.gameObject.transform.rotation, uidSender.networkUID, subUIDs.ToArray(), hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, ids.ToArray(), irIDS));
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("Could not find the UIDNetworker_Sender");
                    }
                }
            }
        }
    }
示例#19
0
    /*private bool sendRateLimiter()
     * {
     *  tick += Time.fixedDeltaTime;
     *
     *  if (tick > tickRate)
     *  {
     *      tick = 0.0f;
     *      return true;
     *  }
     *  return false;
     * }*/
    private void FixedUpdate()
    {
        if (thisMissile == null)
        {
            Debug.LogError("thisMissile null.");
        }
        if (hasFired != thisMissile.fired)
        {
            Debug.Log("Missile fired " + thisMissile.name);
            hasFired = true;

            RigidbodyNetworker_Sender rbSender = gameObject.AddComponent <RigidbodyNetworker_Sender>();
            rbSender.networkUID = networkUID;
        }
        if (thisMissile != null && thisMissile.fired)
        {
            if (lastMessage == null)
            {
                Debug.LogError("lastMessage null");
            }
            lastMessage.networkUID   = networkUID;
            lastMessage.guidanceMode = thisMissile.guidanceMode;
            if (thisMissile.guidanceMode == Missile.GuidanceModes.Radar)
            {
                if (thisMissile.radarLock != null && thisMissile.radarLock.actor != null)
                {
                    lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.radarLock.actor.transform.position);

                    if (VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.ContainsKey(thisMissile.radarLock.actor))
                    {
                        lastMessage.radarLock = VTOLVR_Multiplayer.AIDictionaries.reverseAllActors[thisMissile.radarLock.actor];
                    }
                }
            }
            else if (thisMissile.guidanceMode == Missile.GuidanceModes.Optical)
            {
                if (thisMissile.opticalTargetActor != null)
                {
                    lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.opticalTargetActor.transform.position);
                }
                else
                {
                    lastMessage.targetPosition = Traverse.Create(thisMissile).Field("staticOpticalTargetLock").GetValue <FixedPoint>().globalPoint;
                }


                //lastMessage.seekerRotation = thisMissile.heatSeeker.transform.rotation;
            }
            else if (thisMissile.guidanceMode == Missile.GuidanceModes.Heat)
            {
                //lastMessage.targetPosition = VTMapManager.WorldToGlobalPoint(thisMissile.opticalTargetActor.transform.position);
                lastMessage.seekerRotation = thisMissile.heatSeeker.transform.rotation;
            }
            SendMessage(false);
        }

        /*if (thisMissile.guidanceMode == Missile.GuidanceModes.Radar)
         * {
         *  if (thisMissile.isPitbull)
         *  {
         *      Debug.Log(gameObject.name + " is now pitbull.");
         *  }
         * }*/
    }
 static void Postfix(AIUnitSpawn __instance)
 {
     if (Networker.isHost)
     {
         Debug.Log("Setting up new AI.");
         AIManager.setupAIAircraft(__instance.actor);
         Debug.Log("Telling client about newly spawned AI.");
         Actor actor = __instance.actor;
         if (!actor.isPlayer)
         {
             if (actor.name.Contains("Client"))
             {
                 return;
             }
             bool Aggresion = false;
             if (actor.gameObject.GetComponent <UIDNetworker_Sender>() != null)
             {
                 Debug.Log("Try sending ai " + actor.name + " to client.");
                 HPInfo[]            hPInfos2  = null;
                 int[]               cmLoadout = null;
                 UIDNetworker_Sender uidSender = actor.gameObject.GetComponent <UIDNetworker_Sender>();
                 if (actor.role == Actor.Roles.Air)
                 {
                     WeaponManager wm = actor.gameObject.GetComponent <WeaponManager>();
                     if (wm != null)
                     {
                         hPInfos2 = PlaneEquippableManager.generateHpInfoListFromWeaponManager(actor.weaponManager, PlaneEquippableManager.HPInfoListGenerateNetworkType.sender, uidSender.networkUID).ToArray();
                     }
                 }
                 AIUnitSpawn aIUnitSpawn = actor.gameObject.GetComponent <AIUnitSpawn>();
                 if (aIUnitSpawn == null)
                 {
                     Debug.LogWarning("AI unit spawn is null on ai " + actor.name);
                 }
                 else
                 {
                     Aggresion = aIUnitSpawn.engageEnemies;
                 }
                 bool            canBreak = false;
                 PhoneticLetters letters  = new PhoneticLetters();
                 foreach (var Group in VTScenario.current.groups.GetExistingGroups(actor.team))
                 {
                     foreach (var ID in Group.unitIDs)
                     {
                         if (ID == actor.unitSpawn.unitID)
                         {
                             letters  = Group.groupID;
                             canBreak = true;
                             break;
                         }
                     }
                     if (canBreak)
                     {
                         break;
                     }
                 }
                 List <ulong> ids = new List <ulong>();
                 ulong        lastID;
                 SAMLauncher  launcher = actor.gameObject.GetComponentInChildren <SAMLauncher>();
                 if (launcher != null)
                 {
                     foreach (var radar in launcher.lockingRadars)
                     {
                         if (radar.myActor == null)
                         {
                             Debug.LogError("Locking radar on one of the SAM's is literally null.");
                         }
                         if (VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.TryGetValue(radar.myActor, out lastID))
                         {
                             ids.Add(lastID);
                             // Debug.Log("Aded a radar ID");
                         }
                         else
                         {
                             Debug.LogError("Couldn't get a locking radar on one of the SAM's, probably a dictionary problem.");
                         }
                     }
                 }
                 ulong[] irIDS             = new ulong[0];
                 IRSAMNetworker_Sender irs = actor.gameObject.GetComponentInChildren <IRSAMNetworker_Sender>();
                 if (irs != null)
                 {
                     irIDS = irs.irIDs;
                 }
                 Debug.Log("Finally sending AI " + actor.name + " to client all clients.");
                 if (canBreak)
                 {
                     NetworkSenderThread.Instance.SendPacketAsHostToAllClients(new Message_SpawnAIVehicle(actor.name, AIManager.GetUnitNameFromCatalog(actor.unitSpawn.unitName),
                                                                                                          VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                                          new Vector3D(actor.gameObject.transform.rotation.eulerAngles), uidSender.networkUID, hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, letters, ids.ToArray(), irIDS),
                                                                               EP2PSend.k_EP2PSendReliable);
                 }
                 else
                 {
                     // Debug.Log("It seems that " + actor.name + " is not in a unit group, sending anyways.");
                     NetworkSenderThread.Instance.SendPacketAsHostToAllClients(new Message_SpawnAIVehicle(actor.name, AIManager.GetUnitNameFromCatalog(actor.unitSpawn.unitName),
                                                                                                          VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                                          new Vector3D(actor.gameObject.transform.rotation.eulerAngles), uidSender.networkUID, hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, ids.ToArray(), irIDS),
                                                                               EP2PSend.k_EP2PSendReliable);
                 }
             }
             else
             {
                 Debug.Log("Could not find the UIDNetworker_Sender");
             }
         }
         AIManager.TellClientAboutAI(new Steamworks.CSteamID(0));
     }
 }