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);
            }
Пример #2
0
        public ItemsContainer GetStorageContainer(Pickupable pickupable)
        {
            for (int i = 0; i < 4; i++)
            {
                var storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                if (storage != null && storage.HasRoomFor(pickupable))
                {
                    return(storage);
                }
            }

            return(null);
        }
        public static void OpenTorpedoStorageEx(this SeaMoth seamoth, int slotID, Transform useTransform)
        {
            bool hasTorpedoModules = seamoth.modules.GetCount(TechType.SeamothTorpedoModule) > 0;

            if (hasTorpedoModules)
            {
                ItemsContainer storageInSlot = seamoth.GetStorageInSlot(slotID, TechType.SeamothTorpedoModule);
                if (storageInSlot != null)
                {
                    Inventory.main.ClearUsedStorage();
                    storageInSlot.isAllowedToRemove = new IsAllowedToRemove(AllowTorpedoRemoval);
                    storageInSlot.Resize(Mod.config.TorpedoStorageWidth, Mod.config.TorpedoStorageHeight);
                    Inventory.main.SetUsedStorage(storageInSlot, false);
                    Player.main.GetPDA().Open(PDATab.Inventory, useTransform, null, -1f);
                }
            }
        }
        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());
                        }
                    }
                }
        }
            private static bool Prefix(SeaMoth __instance, int slotID, TechType techType, bool added)
            {
                if (techType == TechType.SeamothTorpedoModule)
                {
                    if (added)
                    {
                        var torpedoStorage = __instance.GetStorageInSlot(slotID, techType);
                        torpedoStorage.SetAllowedTechTypes(__instance.torpedoTypes.Select((t) => t.techType).ToArray());
                        torpedoStorage.Resize(Mod.config.TorpedoStorageWidth, Mod.config.TorpedoStorageHeight);
                    }

                    if (slotID == 2 || slotID == 3)
                    {
                        GameObject gameObject = __instance.transform.Find(slotID == 2 ? "TorpedoSiloUpperLeft" : "TorpedoSiloUpperRight")?.gameObject;
                        gameObject?.SetActive(added);
                    }
                }
                return(true);
            }
Пример #6
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);
            }
        }
Пример #7
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);
            }
        }
        public static void OnHoverTorpedoStorageEx(this SeaMoth seamoth, int slotID, Transform useTransform)
        {
            var torpedoStorage = seamoth.GetStorageInSlot(slotID, TechType.SeamothTorpedoModule);

            if (torpedoStorage != null)
            {
                var interactText = $"{Language.main.Get("SeamothTorpedoStorage")} {slotID + 1}";

                List <string> countText = new List <string>();
                foreach (var torpedoType in seamoth.torpedoTypes)
                {
                    var typeName = Language.main.Get(torpedoType.techType);
                    var count    = torpedoStorage.GetCount(torpedoType.techType);
                    if (count > 0)
                    {
                        countText.Add($"{typeName} x{count}");
                    }
                }

                HandReticle.main.SetInteractTextRaw(interactText, countText.Count > 0 ? string.Join("\n", countText.ToArray()) : "empty");
                HandReticle.main.SetIcon(HandReticle.IconType.Hand, 1f);
            }
        }
Пример #9
0
        public static bool Prefix(Constructable __instance)
        {
#endif
            if (Player.main.GetVehicle() != null && GameModeUtils.RequiresIngredients())
            {
                Vehicle thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(true);
                }
                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 techType = __instance.resourceMap[resourceID2];

                    Vector2int size =
#if SN1
                        CraftData.GetItemSize(techType);
#elif BZ
                        TechData.GetItemSize(techType);
#endif

                    if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                    {
                        StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer;

                        if (storageContainer.container.HasRoomFor(size.x, size.y))
                        {
                            CoroutineHost.StartCoroutine(AddToVehicle(techType, storageContainer.container));
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
#if SN1
                    else
                    {
                        SeaMoth 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.HasRoomFor(size.x, size.y))
                                {
                                    CoroutineHost.StartCoroutine(AddToVehicle(techType, storage));
                                    storageCheck = true;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
#endif
                }
                __instance.UpdateMaterial();
#if SUBNAUTICA_EXP || BZ
                result.Set(__instance.constructedAmount <= 0f);
                return(false);
#elif SUBNAUTICA_STABLE
                return(__instance.constructedAmount <= 0f);
#endif
            }
            return(true);
        }