public void WeaponSet(Packet packet) { //This message has only been sent to us so no need to check UID List <HPInfo> hpInfos = new List <HPInfo>(); List <int> cm = new List <int>(); float fuel = 0.65f; HPEquippable lastEquippable = null; for (int i = 0; i < weaponManager.equipCount; i++) { lastEquippable = weaponManager.GetEquip(i); List <ulong> missileUIDS = new List <ulong>(); if (lastEquippable.weaponType != HPEquippable.WeaponTypes.Gun && lastEquippable.weaponType != HPEquippable.WeaponTypes.Rocket) { HPEquipMissileLauncher HPml = lastEquippable as HPEquipMissileLauncher; if (HPml.ml == null) //I think this could be null. { break; } for (int j = 0; j < HPml.ml.missiles.Length; j++) { //If they are null, they have been shot. if (HPml.ml.missiles[i] == null) { missileUIDS.Add(0); continue; } MissileNetworker_Sender sender = HPml.ml.missiles[i].gameObject.GetComponent <MissileNetworker_Sender>(); if (sender != null) { missileUIDS.Add(sender.networkUID); } else { Debug.LogError($"Failed to get NetworkUID for missile ({HPml.ml.missiles[i].gameObject.name})"); } } } hpInfos.Add(new HPInfo( lastEquippable.gameObject.name.Replace("(Clone)", ""), lastEquippable.weaponType, missileUIDS.ToArray())); } for (int i = 0; i < cmManager.countermeasures.Count; i++) { cm.Add(cmManager.countermeasures[i].count); } fuel = fuelTank.fuel / fuelTank.totalFuel; Networker.SendP2P(Networker.hostID, new Message_WeaponSet_Result(hpInfos.ToArray(), cm.ToArray(), fuel, networkUID), Steamworks.EP2PSend.k_EP2PSendReliable); }
public HPInfo[] GenerateHPInfo() { if (!Networker.isHost) { Debug.LogError("Generate HPInfo was ran from a player which isn't the host."); return(null); } List <HPInfo> hpInfos = new List <HPInfo>(); HPEquippable lastEquippable = null; for (int i = 0; i < weaponManager.equipCount; i++) { lastEquippable = weaponManager.GetEquip(i); List <ulong> missileUIDS = new List <ulong>(); if (lastEquippable.weaponType != HPEquippable.WeaponTypes.Gun && lastEquippable.weaponType != HPEquippable.WeaponTypes.Rocket) { HPEquipMissileLauncher HPml = lastEquippable as HPEquipMissileLauncher; if (HPml.ml == null) //I think this could be null. { break; } for (int j = 0; j < HPml.ml.missiles.Length; j++) { //If they are null, they have been shot. if (HPml.ml.missiles[i] == null) { missileUIDS.Add(0); continue; } MissileNetworker_Receiver reciever = HPml.ml.missiles[i].gameObject.GetComponent <MissileNetworker_Receiver>(); if (reciever != null) { missileUIDS.Add(reciever.networkUID); } else { Debug.LogError($"Failed to get NetworkUID for missile ({HPml.ml.missiles[i].gameObject.name})"); } } } hpInfos.Add(new HPInfo( lastEquippable.gameObject.name.Replace("(Clone)", ""), lastEquippable.weaponType, missileUIDS.ToArray())); } return(hpInfos.ToArray()); }
private void Update() { if (weaponManager != null) { if (weaponManager.isFiring != previousFiringState || lastIdx != (int)traverse.Field("weaponIdx").GetValue()) { previousFiringState = weaponManager.isFiring; lastFiringMessage.weaponIdx = (int)traverse.Field("weaponIdx").GetValue(); lastIdx = lastFiringMessage.weaponIdx; Debug.Log("combinedWeaponIdx = " + lastFiringMessage.weaponIdx); lastFiringMessage.UID = networkUID; // lastStoppedFiringMessage.UID = networkUID; lastFiringMessage.isFiring = weaponManager.isFiring; if (weaponManager.currentEquip is HPEquipGun || weaponManager.currentEquip is VTOLCannon) { lastFiringMessage.noAmmo = weaponManager.currentEquip.GetCount() == 0; } else { lastFiringMessage.noAmmo = false; } if (weaponManager.isFiring && weaponManager.currentEquip is HPEquipMissileLauncher) { lastml = weaponManager.currentEquip as HPEquipMissileLauncher; lastFiringMessage.missileIdx = (int)Traverse.Create(lastml.ml).Field("missileIdx").GetValue(); } if (Networker.isHost) { NetworkSenderThread.Instance.SendPacketAsHostToAllClients(lastFiringMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay); } else { NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastFiringMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay); } } } }
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); }
public void WeaponFiring(Packet packet) { Message_WeaponFiring message = ((PacketSingle)packet).message as Message_WeaponFiring; if (message.UID != networkUID) { return; } if (weaponManager.isMasterArmed == false) { weaponManager.ToggleMasterArmed(); } idx = (int)traverse.Field("weaponIdx").GetValue(); /*while (message.weaponIdx != idx && i < 60) * { * if (weaponManager.isMasterArmed == false) * { * weaponManager.ToggleMasterArmed(); * } * // Debug.Log(idx + " " + message.weaponIdx); * i++; * } * if (i > 59) * { * Debug.Log("couldn't change weapon idx to right weapon for aircraft " + gameObject.name); * }*/ weaponManager.SetWeapon(message.weaponIdx); idx = (int)traverse.Field("weaponIdx").GetValue(); if (idx != message.weaponIdx) { Debug.LogWarning("Couldn't change weapon idx to the right weapon for aircraft " + gameObject.name); } if (message.isFiring != weaponManager.isFiring) { if (message.isFiring) { if (weaponManager.currentEquip is HPEquipMissileLauncher) { lastml = weaponManager.currentEquip as HPEquipMissileLauncher; //Traverse.Create(lastml.ml).Field("missileIdx").SetValue(message.missileIdx); Debug.Log("Single firing this missile " + weaponManager.currentEquip.shortName); //weaponManager.SingleFire(); } else if (weaponManager.currentEquip is RocketLauncher) { weaponManager.SingleFire(); } else { Debug.Log("try start fire for vehicle" + gameObject.name + " on current equip " + weaponManager.currentEquip); if (message.noAmmo && noAmmo == false) { if (weaponManager.currentEquip is HPEquipGun) { ((HPEquipGun)weaponManager.currentEquip).gun.currentAmmo = 0; noAmmo = true; } else if (weaponManager.currentEquip is HPEquipGunTurret) { ((HPEquipGunTurret)weaponManager.currentEquip).gun.currentAmmo = 0; noAmmo = true; } } else { if (weaponManager.currentEquip is HPEquipGun) { ((HPEquipGun)weaponManager.currentEquip).gun.currentAmmo = ((HPEquipGun)weaponManager.currentEquip).gun.maxAmmo; noAmmo = false; } else if (weaponManager.currentEquip is HPEquipGunTurret) { ((HPEquipGun)weaponManager.currentEquip).gun.currentAmmo = ((HPEquipGun)weaponManager.currentEquip).gun.maxAmmo; noAmmo = false; } } weaponManager.StartFire(); } } else { if (!(weaponManager.currentEquip is HPEquipMissileLauncher || weaponManager.currentEquip is RocketLauncher)) { weaponManager.EndFire(); } } } }
/// <summary> /// Sends the message to other clients to spawn their vehicles /// </summary> /// <param name="localVehicle">The local clients gameobject</param> public static void SendSpawnVehicle(GameObject localVehicle, Vector3 pos, Vector3 rot, ulong UID) //Both { Debug.Log("Sending our location to spawn our vehicle"); VTOLVehicles currentVehicle = VTOLAPI.GetPlayersVehicleEnum(); players.Add(new Player(SteamUser.GetSteamID(), localVehicle, currentVehicle, UID)); RigidbodyNetworker_Sender rbSender = localVehicle.AddComponent <RigidbodyNetworker_Sender>(); rbSender.networkUID = UID; rbSender.spawnPos = pos; rbSender.spawnRot = rot; rbSender.SetSpawn(); Debug.Log("Adding Plane Sender"); PlaneNetworker_Sender planeSender = localVehicle.AddComponent <PlaneNetworker_Sender>(); planeSender.networkUID = UID; if (currentVehicle == VTOLVehicles.AV42C || currentVehicle == VTOLVehicles.F45A) { Debug.Log("Added Tilt Updater to our vehicle"); EngineTiltNetworker_Sender tiltSender = localVehicle.AddComponent <EngineTiltNetworker_Sender>(); tiltSender.networkUID = UID; } if (Multiplayer.SoloTesting) { pos += new Vector3(20, 0, 0); } List <int> cm = new List <int>(); float fuel = 0.65f; //Setting up missiles with MissileUpdate Scripts Debug.Log("Setting up missiles"); WeaponManager weaponManager = localVehicle.GetComponent <WeaponManager>(); List <HPInfo> hpInfos = new List <HPInfo>(); HPEquippable lastEquippable = null; 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.weaponType != HPEquippable.WeaponTypes.Gun && lastEquippable.weaponType != HPEquippable.WeaponTypes.Rocket) { Debug.Log("This last equip is a missile launcher"); HPEquipMissileLauncher HPml = lastEquippable as HPEquipMissileLauncher; 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 wa sa missile shot as it was null"); continue; } Debug.Log("Adding Missle Networker to missile"); MissileNetworker_Sender sender = HPml.ml.missiles[j].gameObject.AddComponent <MissileNetworker_Sender>(); sender.networkUID = Networker.GenerateNetworkUID(); missileUIDS.Add(sender.networkUID); } } hpInfos.Add(new HPInfo( lastEquippable.gameObject.name.Replace("(Clone)", ""), lastEquippable.weaponType, missileUIDS.ToArray())); } //Getting Counter Measure flares. Debug.Log("Setting up Counter Measure"); CountermeasureManager cmManager = localVehicle.GetComponentInChildren <CountermeasureManager>(); for (int i = 0; i < cmManager.countermeasures.Count; i++) { cm.Add(cmManager.countermeasures[i].count); } //Getting Fuel if (VehicleEquipper.loadoutSet) { fuel = VehicleEquipper.loadout.normalizedFuel; } if (!Networker.isHost || Multiplayer.SoloTesting) { Networker.SendP2P(Networker.hostID, new Message_SpawnVehicle(currentVehicle, new Vector3D(pos), new Vector3D(rot), SteamUser.GetSteamID().m_SteamID, UID, hpInfos.ToArray(), cm.ToArray(), fuel), EP2PSend.k_EP2PSendReliable); } }