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); } }
//Copied this from the Vehicle class public static bool TorpedoShot(ItemsContainer container, TorpedoType torpedoType, Transform muzzle, Vector3 forward, Quaternion rotation) { if (torpedoType != null && container.DestroyItem(torpedoType.techType)) { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(torpedoType.prefab); Transform component = gameObject.GetComponent <Transform>(); SeamothTorpedo component2 = gameObject.GetComponent <SeamothTorpedo>(); Vector3 zero = Vector3.zero; Rigidbody componentInParent = muzzle.GetComponentInParent <Rigidbody>(); Vector3 rhs = (!(componentInParent != null)) ? Vector3.zero : componentInParent.velocity; float speed = Vector3.Dot(forward, rhs); component2.Shoot(muzzle.position, rotation, speed, -1f); return(true); } return(false); }