public void UseTorpedo(ExosuitTorpedoArm torpedoArm, ExosuitArmAction armAction, Optional <Vector3> opVector, Optional <Quaternion> opRotation) { if (armAction == ExosuitArmAction.startUseTool || armAction == ExosuitArmAction.altHit) { if (opVector.IsEmpty() || opRotation.IsEmpty()) { Log.Error("Torpedo arm action shoot: no vector or rotation present"); return; } Vector3 forward = opVector.Get(); Quaternion rotation = opRotation.Get(); Transform silo = default(Transform); if (armAction == ExosuitArmAction.startUseTool) { silo = torpedoArm.siloFirst; } else { silo = torpedoArm.siloSecond; } ItemsContainer container = (ItemsContainer)torpedoArm.ReflectionGet("container"); Exosuit exosuit = torpedoArm.GetComponentInParent <Exosuit>(); TorpedoType[] torpedoTypes = exosuit.torpedoTypes; TorpedoType torpedoType = null; for (int i = 0; i < torpedoTypes.Length; i++) { if (container.Contains(torpedoTypes[i].techType)) { torpedoType = torpedoTypes[i]; break; } } // Copied from SeamothModuleActionProcessor. We need to synchronize both methods GameObject gameObject = UnityEngine.Object.Instantiate(torpedoType.prefab); Transform component = gameObject.GetComponent <Transform>(); SeamothTorpedo component2 = gameObject.GetComponent <SeamothTorpedo>(); Vector3 zero = Vector3.zero; Rigidbody componentInParent = silo.GetComponentInParent <Rigidbody>(); Vector3 rhs = (!(componentInParent != null)) ? Vector3.zero : componentInParent.velocity; float speed = Vector3.Dot(forward, rhs); component2.Shoot(silo.position, rotation, speed, -1f); torpedoArm.animator.SetBool("use_tool", true); if (container.count == 0) { Utils.PlayFMODAsset(torpedoArm.torpedoDisarmed, torpedoArm.transform, 1f); } } else if (armAction == ExosuitArmAction.endUseTool) { torpedoArm.animator.SetBool("use_tool", false); } else { Log.Error("Torpedo arm got an arm action he should not get: " + armAction); } }
private bool TryShoot(out float cooldownDuration, bool verbose) { TorpedoType[] torpedoTypes = ThisSeamoth.torpedoTypes; TorpedoType torpedoType = null; for (int i = 0; i < torpedoTypes.Length; i++) { if (container.Contains(torpedoTypes[i].techType)) { torpedoType = torpedoTypes[i]; break; } } float num = Mathf.Clamp(Time.time - timeFirstShot, 0f, 5f); float num2 = Mathf.Clamp(Time.time - timeSecondShot, 0f, 5f); float b = 5f - num; float b2 = 5f - num2; float num3 = Mathf.Min(num, num2); if (num3 < 1f) { cooldownDuration = 0f; return(false); } if (num >= 5f) { if (Shoot(torpedoType, siloFirst, verbose)) { timeFirstShot = Time.time; cooldownDuration = Mathf.Max(1f, b2); return(true); } } else { if (num2 < 5f) { cooldownDuration = 0f; return(false); } if (Shoot(torpedoType, siloSecond, verbose)) { timeSecondShot = Time.time; cooldownDuration = Mathf.Max(1f, b); return(true); } } animator.SetBool("use_tool", false); cooldownDuration = 0f; return(false); }
private static bool Prefix(SeaMoth __instance, TechType techType, int slotID) { if (techType == TechType.SeamothTorpedoModule) { Transform[] muzzles = { __instance.transform.Find("TorpedoSiloLeft"), __instance.transform.Find("TorpedoSiloRight"), __instance.transform.Find("TorpedoSiloUpperLeft"), __instance.transform.Find("TorpedoSiloUpperRight"), }; Transform muzzle = muzzles[slotID]; ItemsContainer storageInSlot = __instance.GetStorageInSlot(slotID, TechType.SeamothTorpedoModule); if (storageInSlot.count == 0) { ErrorMessage.AddError(Language.main.Get("VehicleTorpedoNoAmmo")); } TorpedoType torpedoType = null; var primaryType = __instance.GetComponent <PrimaryTorpedo>().PrimaryTorpedoType; List <TorpedoType> torpedoTypes = __instance.torpedoTypes.ToList(); torpedoTypes.Sort((a, b) => { return(a.techType == b.techType ? 0 : (a.techType == primaryType ? -1 : 1)); }); foreach (var t in torpedoTypes) { if (storageInSlot.Contains(t.techType)) { torpedoType = t; break; } } var firedTorpedo = Vehicle.TorpedoShot(storageInSlot, torpedoType, muzzle); if (firedTorpedo && storageInSlot.count == 0) { Utils.PlayFMODAsset(__instance.torpedoDisarmed, __instance.transform, 1f); } if (firedTorpedo) { var quickSlotTimeUsed = (float[])Vehicle_quickSlotTimeUsed.GetValue(__instance); var quickSlotCooldown = (float[])Vehicle_quickSlotCooldown.GetValue(__instance); quickSlotTimeUsed[slotID] = Time.time; quickSlotCooldown[slotID] = Mod.config.TorpedoShotCooldown; } return(false); } return(true); }
public override void Process(SeamothModulesAction packet) { using (packetSender.Suppress <SeamothModulesAction>()) using (packetSender.Suppress <ItemContainerRemove>()) { GameObject _gameObject = NitroxEntity.RequireObjectFrom(packet.Id); SeaMoth seamoth = _gameObject.GetComponent <SeaMoth>(); if (seamoth != null) { TechType techType = packet.TechType.ToUnity(); if (techType == TechType.SeamothElectricalDefense) { float[] chargearray = (float[])seamoth.ReflectionGet("quickSlotCharge"); float charge = chargearray[packet.SlotID]; float slotCharge = seamoth.GetSlotCharge(packet.SlotID); GameObject gameObject = global::Utils.SpawnZeroedAt(seamoth.seamothElectricalDefensePrefab, seamoth.transform, false); ElectricalDefense component = gameObject.GetComponent <ElectricalDefense>(); component.charge = charge; component.chargeScalar = slotCharge; } if (techType == TechType.SeamothTorpedoModule) { Transform muzzle = (packet.SlotID != seamoth.GetSlotIndex("SeamothModule1") && packet.SlotID != seamoth.GetSlotIndex("SeamothModule3")) ? seamoth.torpedoTubeRight : seamoth.torpedoTubeLeft; ItemsContainer storageInSlot = seamoth.GetStorageInSlot(packet.SlotID, TechType.SeamothTorpedoModule); TorpedoType torpedoType = null; for (int i = 0; i < seamoth.torpedoTypes.Length; i++) { if (storageInSlot.Contains(seamoth.torpedoTypes[i].techType)) { torpedoType = seamoth.torpedoTypes[i]; break; } } //Original Function use Player Camera need parse owner camera values TorpedoShot(storageInSlot, torpedoType, muzzle, packet.Forward.ToUnity(), packet.Rotation.ToUnity()); } } } }
public void BroadcastTorpedoLaunch(TechType techType, int slotID, SeaMoth instance) { string Guid = GuidHelper.GetGuid(instance.gameObject); TorpedoType torpedoType = null; ItemsContainer storageInSlot = instance.GetStorageInSlot(slotID, TechType.SeamothTorpedoModule); for (int i = 0; i < instance.torpedoTypes.Length; i++) { if (storageInSlot.Contains(instance.torpedoTypes[i].techType)) { torpedoType = instance.torpedoTypes[i]; break; } } if (torpedoType != null) // Dont send packet if torpedo storage is empty { SeamothModulesAction Changed = new SeamothModulesAction(techType, slotID, Guid, Player.main.camRoot.GetAimingTransform().forward, Player.main.camRoot.GetAimingTransform().rotation); packetSender.Send(Changed); } }
public void BroadcastTorpedoLaunch(TechType techType, int slotID, SeaMoth instance) { NitroxId id = NitroxEntity.GetId(instance.gameObject); TorpedoType torpedoType = null; ItemsContainer storageInSlot = instance.GetStorageInSlot(slotID, TechType.SeamothTorpedoModule); for (int i = 0; i < instance.torpedoTypes.Length; i++) { if (storageInSlot.Contains(instance.torpedoTypes[i].techType)) { torpedoType = instance.torpedoTypes[i]; break; } } if (torpedoType != null) // Dont send packet if torpedo storage is empty { Transform aimingTransform = Player.main.camRoot.GetAimingTransform(); SeamothModulesAction changed = new SeamothModulesAction(techType.ToDto(), slotID, id, aimingTransform.forward.ToDto(), aimingTransform.rotation.ToDto()); packetSender.Send(changed); } }
public static bool Prefix(Constructable __instance) { if (Player.main.GetVehicle() != null) { Vehicle thisVehicle = Player.main.GetVehicle(); if (__instance._constructed) { return(false); } int count = __instance.resourceMap.Count; int resourceID = __instance.GetResourceID(); float backupConstructedAmount = __instance.constructedAmount; __instance.constructedAmount += Time.deltaTime / (count * Constructable.GetConstructInterval()); __instance.constructedAmount = Mathf.Clamp01(__instance.constructedAmount); int resourceID2 = __instance.GetResourceID(); if (resourceID2 != resourceID) { TechType destroyTechType = __instance.resourceMap[resourceID2 - 1]; if (thisVehicle.GetType().Equals(typeof(Exosuit))) { StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer; if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients()) { storageContainer.container.DestroyItem(destroyTechType); } else { __instance.constructedAmount = backupConstructedAmount; return(true); } } else { var seamoth = (SeaMoth)thisVehicle; bool storageCheck = false; for (int i = 0; i < 12; i++) { try { ItemsContainer storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule); if (storage != null && storage.Contains(destroyTechType) && GameModeUtils.RequiresIngredients()) { storage.DestroyItem(destroyTechType); storageCheck = true; break; } } catch (Exception) { continue; } } if (!storageCheck) { __instance.constructedAmount = backupConstructedAmount; return(true); } } } __instance.UpdateMaterial(); if (__instance.constructedAmount >= 1f) { __instance.SetState(true, true); } return(false); } else { return(true); } }
public static bool Prefix(Constructable __instance) { if (Player.main.GetVehicle() != null && GameModeUtils.RequiresIngredients()) { Type ConstructableType = typeof(Constructable); List <TechType> resourceMapField = (List <TechType>)AccessTools.Field(ConstructableType, "resourceMap").GetValue(__instance); MethodInfo getResourceIDMethod = AccessTools.Method(ConstructableType, "GetResourceID"); MethodInfo GetConstructIntervalMethod = AccessTools.Method(ConstructableType, "GetConstructInterval"); MethodInfo updateMaterialMethod = AccessTools.Method(ConstructableType, "UpdateMaterial"); Vehicle thisVehicle = Player.main.GetVehicle(); if (__instance._constructed) { return(false); } int count = resourceMapField.Count; int resourceID = (int)getResourceIDMethod.Invoke(__instance, null); float backupConstructedAmount = __instance.constructedAmount; __instance.constructedAmount += Time.deltaTime / (count * (float)GetConstructIntervalMethod.Invoke(__instance, null)); __instance.constructedAmount = Mathf.Clamp01(__instance.constructedAmount); int resourceID2 = (int)getResourceIDMethod.Invoke(__instance, null); if (resourceID2 != resourceID) { TechType destroyTechType = resourceMapField[resourceID2 - 1]; if (thisVehicle.GetType().Equals(typeof(Exosuit))) { StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer; if (storageContainer.container.Contains(destroyTechType)) { _ = storageContainer.container.DestroyItem(destroyTechType); } else { __instance.constructedAmount = backupConstructedAmount; return(true); } } else { var seamoth = (SeaMoth)thisVehicle; bool storageCheck = false; for (int i = 0; i < 12; i++) { try { ItemsContainer storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule); if (storage != null && storage.Contains(destroyTechType)) { if (storage.DestroyItem(destroyTechType)) { storageCheck = true; break; } } } catch (Exception) { continue; } } if (!storageCheck) { __instance.constructedAmount = backupConstructedAmount; return(true); } } } _ = updateMaterialMethod.Invoke(__instance, null); if (__instance.constructedAmount >= 1f) { _ = __instance.SetState(true, true); } return(false); } else { return(true); } }