public static List <HPInfo> generateHpInfoListFromWeaponManager(WeaponManager weaponManager, HPInfoListGenerateNetworkType networkType, ulong networkID = 0) { List <HPInfo> hpInfos = new List <HPInfo>(); HPEquippable lastEquippable; bool playerFlag = weaponManager.actor.isPlayer; for (int i = 0; i < weaponManager.equipCount; i++) { //Debug.Log("Weapon Manager, Equip " + i); lastEquippable = weaponManager.GetEquip(i); if (lastEquippable == null) //If this is null, it means there isn't any weapon in that slot. { continue; } //Debug.Log("Last Equippable = " + lastEquippable.fullName); List <ulong> missileUIDS = new List <ulong>(); if (lastEquippable is HPEquipMissileLauncher HPml) { //Debug.Log("This last equip is a missile launcher"); if (HPml.ml == null) { Debug.LogError("The Missile Launcher was null on this Missile Launcher"); Debug.LogError("Type was = " + lastEquippable.weaponType); continue; } if (HPml.ml.missiles == null) { Debug.LogError("The missile list is null"); continue; } //Debug.Log($"This has {HPml.ml.missiles.Length} missiles"); for (int j = 0; j < HPml.ml.missiles.Length; j++) { //There shouldn't be any shot missiles, but if so this skips them as they are null. if (HPml.ml.missiles[j] == null) { missileUIDS.Add(0); //Debug.LogError("It seems there was a missile shot as it was null"); continue; } //Debug.Log("Adding Missle Networker to missile"); switch (networkType) { case HPInfoListGenerateNetworkType.generate: MissileNetworker_Sender mnSender = HPml.ml.missiles[j].gameObject.AddComponent <MissileNetworker_Sender>(); mnSender.networkUID = Networker.GenerateNetworkUID(); missileUIDS.Add(mnSender.networkUID); if (playerFlag) { HPml.ml.missiles[j].gameObject.name = Steamworks.SteamFriends.GetPersonaName() + "'s " + HPml.ml.missiles[j].gameObject.name; } break; case HPInfoListGenerateNetworkType.sender: MissileNetworker_Sender sender = HPml.ml.missiles[j].gameObject.GetComponent <MissileNetworker_Sender>(); if (playerFlag) { HPml.ml.missiles[j].gameObject.name = Steamworks.SteamFriends.GetPersonaName() + "'s " + HPml.ml.missiles[j].gameObject.name; } if (sender != null) { missileUIDS.Add(sender.networkUID); } else { Debug.LogError($"Failed to get NetworkUID for missile ({HPml.ml.missiles[j].gameObject.name})"); } break; case HPInfoListGenerateNetworkType.receiver: MissileNetworker_Receiver reciever = HPml.ml.missiles[j].gameObject.GetComponent <MissileNetworker_Receiver>(); if (reciever != null) { missileUIDS.Add(reciever.networkUID); } else { Debug.LogError($"Receiver null, Failed to get NetworkUID for missile ({HPml.ml.missiles[j].gameObject.name})"); } break; } } } else if (lastEquippable is HPEquipGunTurret HPm230 && networkID != 0) { switch (networkType) { case HPInfoListGenerateNetworkType.generate: Debug.Log("Added m230 turret sender"); TurretNetworker_Sender sender = HPm230.gameObject.AddComponent <TurretNetworker_Sender>(); sender.networkUID = networkID; sender.turret = HPm230.GetComponent <ModuleTurret>(); break; default: break; } } hpInfos.Add(new HPInfo( lastEquippable.gameObject.name.Replace("(Clone)", ""), lastEquippable.hardpointIdx, lastEquippable.weaponType, missileUIDS.ToArray())); } return(hpInfos); }
public static void setupAIAircraft(Actor actor) { if (actor.role == Actor.Roles.Missile || actor.isPlayer) { return; } if (actor.name.Contains("Rearm/Refuel")) { return; } foreach (AI ai in AIManager.AIVehicles) { if (ai.actor == actor) { return; } } if (actor.parentActor == null) { AIManager.AIVehicles.Add(new AIManager.AI(actor.gameObject, actor.unitSpawn.unitName, actor, Networker.networkUID + 1)); foreach (Actor child in actor.gameObject.GetComponentsInChildren <Actor>()) { ulong networkUID = Networker.GenerateNetworkUID(); Debug.Log("Adding UID senders to " + child.name + $", their uID will be {networkUID}."); if (!VTOLVR_Multiplayer.AIDictionaries.allActors.ContainsKey(networkUID)) { VTOLVR_Multiplayer.AIDictionaries.allActors.Add(networkUID, child); } if (!VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.ContainsKey(child)) { VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.Add(child, networkUID); } UIDNetworker_Sender uidSender = child.gameObject.AddComponent <UIDNetworker_Sender>(); uidSender.networkUID = networkUID; Debug.Log("Added UID sender!"); Debug.Log("Checking for locking radars"); foreach (LockingRadar radar in child.GetComponentsInChildren <LockingRadar>()) { if (radar.GetComponent <Actor>() == child) { Debug.Log($"Adding radar sender to object {child.name} as it is the same game object as this actor."); LockingRadarNetworker_Sender lastLockingSender = child.gameObject.AddComponent <LockingRadarNetworker_Sender>(); lastLockingSender.networkUID = networkUID; Debug.Log("Added locking radar!"); } else if (radar.GetComponentInParent <Actor>() == child) { Debug.Log($"Adding radar sender to object {child.name} as it is a child of this actor."); LockingRadarNetworker_Sender lastLockingSender = child.gameObject.AddComponent <LockingRadarNetworker_Sender>(); lastLockingSender.networkUID = networkUID; Debug.Log("Added locking radar!"); } else { Debug.Log("This radar is not direct child of this actor, ignoring"); } } Debug.Log("Checking for health"); if (child.gameObject.GetComponent <Health>() != null) { Debug.Log("adding health sender to ai"); HealthNetworker_Sender healthNetworker = child.gameObject.AddComponent <HealthNetworker_Sender>(); healthNetworker.networkUID = networkUID; Debug.Log("added health sender to ai!"); } else { Debug.Log(child.name + " has no health?"); } Debug.Log("checking for movement type"); if (child.gameObject.GetComponent <ShipMover>() != null) { Debug.Log("I am a ship!"); ShipNetworker_Sender shipNetworker = child.gameObject.AddComponent <ShipNetworker_Sender>(); shipNetworker.networkUID = networkUID; } else if (child.gameObject.GetComponent <GroundUnitMover>() != null) { Debug.Log("I am a ground mover!"); if (child.gameObject.GetComponent <Rigidbody>() != null) { GroundNetworker_Sender lastGroundSender = child.gameObject.AddComponent <GroundNetworker_Sender>(); lastGroundSender.networkUID = networkUID; } } else if (child.gameObject.GetComponent <Rigidbody>() != null) { Debug.Log("I am physicsy!"); RigidbodyNetworker_Sender lastRigidSender = child.gameObject.AddComponent <RigidbodyNetworker_Sender>(); lastRigidSender.networkUID = networkUID; //reduced tick rate for ground Units if (child.role == Actor.Roles.Ground) { lastRigidSender.tickRate = 0.01f; } if (child.role == Actor.Roles.GroundArmor) { lastRigidSender.tickRate = 1.0f; } } Debug.Log("checking if aircraft"); if (!child.isPlayer && child.role == Actor.Roles.Air) { if (child.weaponManager != null) { PlaneEquippableManager.generateHpInfoListFromWeaponManager(child.weaponManager, PlaneEquippableManager.HPInfoListGenerateNetworkType.generate, uidSender.networkUID); } PlaneNetworker_Sender lastPlaneSender = child.gameObject.AddComponent <PlaneNetworker_Sender>(); lastPlaneSender.networkUID = networkUID; } Debug.Log("checking ext lights"); if (child.gameObject.GetComponentInChildren <ExteriorLightsController>() != null) { //ExtNPCLight_Sender extLight = actor.gameObject.AddComponent<ExtNPCLight_Sender>(); //extLight.networkUID = networkUID; } Debug.Log("checking for guns"); if (child.gameObject.GetComponentsInChildren <Actor>().Count() <= 1) {//only run this code on units without subunits ulong turretCount = 0; foreach (ModuleTurret moduleTurret in child.gameObject.GetComponentsInChildren <ModuleTurret>()) { TurretNetworker_Sender tSender = moduleTurret.gameObject.AddComponent <TurretNetworker_Sender>(); tSender.networkUID = networkUID; tSender.turretID = turretCount; Debug.Log("Added turret " + turretCount + " to actor " + networkUID + " uid"); turretCount++; } ulong gunCount = 0; foreach (GunTurretAI moduleTurret in child.gameObject.GetComponentsInChildren <GunTurretAI>()) { AAANetworker_Sender gSender = moduleTurret.gameObject.AddComponent <AAANetworker_Sender>(); gSender.networkUID = networkUID; gSender.gunID = gunCount; Debug.Log("Added gun " + gunCount + " to actor " + networkUID + " uid"); gunCount++; } } Debug.Log("checking for IRSams"); IRSamLauncher ml = child.gameObject.GetComponentInChildren <IRSamLauncher>(); if (ml != null) { List <ulong> samIDS = new List <ulong>(); MissileNetworker_Sender lastSender; for (int i = 0; i < ml.ml.missiles.Length; i++) { lastSender = ml.ml.missiles[i].gameObject.AddComponent <MissileNetworker_Sender>(); lastSender.networkUID = Networker.GenerateNetworkUID(); samIDS.Add(lastSender.networkUID); } child.gameObject.AddComponent <IRSAMNetworker_Sender>().irIDs = samIDS.ToArray(); } Debug.Log("checking for soldier"); Soldier soldier = child.gameObject.GetComponentInChildren <Soldier>(); if (soldier != null) { if (soldier.soldierType == Soldier.SoldierTypes.IRMANPAD) { List <ulong> samIDS = new List <ulong>(); MissileNetworker_Sender lastSender; for (int i = 0; i < soldier.irMissileLauncher.missiles.Length; i++) { lastSender = soldier.irMissileLauncher.missiles[i].gameObject.AddComponent <MissileNetworker_Sender>(); lastSender.networkUID = Networker.GenerateNetworkUID(); samIDS.Add(lastSender.networkUID); } child.gameObject.AddComponent <IRSAMNetworker_Sender>().irIDs = samIDS.ToArray(); } } Debug.Log("checking for airport"); AirportManager airport = child.gameObject.GetComponent <AirportManager>(); if (airport != null) { AIManager.SetUpCarrier(child.gameObject, networkUID, child.team); } //if (!child.unitSpawn.unitSpawner.spawned) //{ // Debug.Log("Actor " + child.name + " isn't spawned yet, still sending."); //} } } else { Debug.Log(actor.name + " has a parent, not giving an uID sender."); } }