Exemplo n.º 1
0
        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);
            }
        }
 public static void Prefix(ExosuitTorpedoArm __instance, bool __result, TorpedoType torpedoType, Transform siloTransform)
 {
     if (torpedoType != null)
     {
         ExosuitArmAction action = ExosuitArmAction.START_USE_TOOL;
         if (siloTransform == __instance.siloSecond)
         {
             action = ExosuitArmAction.ALT_HIT;
         }
         if (siloTransform != __instance.siloFirst && siloTransform != __instance.siloSecond)
         {
             Log.Error("Exosuit torpedo arm siloTransform is not first or second silo " + NitroxEntity.GetId(__instance.gameObject));
         }
         NitroxServiceLocator.LocateService <ExosuitModuleEvent>().BroadcastArmAction(TechType.ExosuitTorpedoArmModule,
                                                                                      __instance,
                                                                                      action,
                                                                                      Player.main.camRoot.GetAimingTransform().forward,
                                                                                      Player.main.camRoot.GetAimingTransform().rotation
                                                                                      );
     }
 }
Exemplo n.º 3
0
 public static void Prefix(ExosuitTorpedoArm __instance, bool __result, TorpedoType torpedoType, Transform siloTransform)
 {
     if (torpedoType != null)
     {
         ExosuitArmAction action = ExosuitArmAction.startUseTool;
         if (siloTransform == __instance.siloSecond)
         {
             action = ExosuitArmAction.altHit;
         }
         if (siloTransform != __instance.siloFirst && siloTransform != __instance.siloSecond)
         {
             Log.Error("Exosuit torpedo arm siloTransform is not first or second silo " + NitroxIdentifier.GetId(__instance.gameObject));
         }
         NitroxServiceLocator.LocateService <ExosuitModuleEvent>().BroadcastArmAction(TechType.ExosuitTorpedoArmModule,
                                                                                      __instance,
                                                                                      action,
                                                                                      Optional <Vector3> .Of(Player.main.camRoot.GetAimingTransform().forward),
                                                                                      Optional <Quaternion> .Of(Player.main.camRoot.GetAimingTransform().rotation)
                                                                                      );
     }
 }
 public static void Prefix(ExosuitTorpedoArm __instance)
 {
     NitroxServiceLocator.LocateService <ExosuitModuleEvent>().BroadcastArmAction(TechType.ExosuitTorpedoArmModule, __instance, ExosuitArmAction.END_USE_TOOL);
 }