Example #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);
            }
        }
Example #2
0
        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);
            }
 //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);
 }
        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());
                        }
                    }
                }
        }
Example #6
0
        private bool Shoot(TorpedoType torpedoType, Transform siloTransform, bool verbose)
        {
            if (Vehicle.TorpedoShot(container, torpedoType, siloTransform))
            {
                Utils.PlayFMODAsset(fireSound, siloTransform, 20f);
                animator.SetBool("use_tool", true);

                if (container.count == 0)
                {
                    Utils.PlayFMODAsset(torpedoDisarmed, transform, 1f);
                }
                return(true);
            }
            if (verbose)
            {
                ErrorMessage.AddError(Language.main.Get("VehicleTorpedoNoAmmo"));
            }
            return(false);
        }
Example #7
0
        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 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
                                                                                      );
     }
 }
Example #9
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)
                                                                                      );
     }
 }
Example #10
0
        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);
            }
        }
Example #11
0
        public static void initPrefab(GameObject gasTorpedoPrefab)
        {
            if (torpedoType != null)
            {
                return;
            }

            if (!gasTorpedoPrefab)
            {
                "StasisTorpedo.initPrefab: invalid prefab for GasTorpedo!".logError();
                return;
            }

            var explosionPrefab = new GameObject("StasisExplosion", typeof(StasisExplosion));

            SMLHelper.V2.Assets.ModPrefabCache.AddPrefab(explosionPrefab, false);

            var torpedoPrefab = PrefabUtils.storePrefabCopy(gasTorpedoPrefab);

            torpedoPrefab.GetComponent <SeamothTorpedo>().explosionPrefab = explosionPrefab;

            torpedoType = new() { techType = TechType, prefab = torpedoPrefab };
        }
    }