コード例 #1
0
 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));
     }
 }
コード例 #2
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");
                    }
                }
            }
        }
    }