Exemple #1
0
        public void DumpToPlayer()
        {
            for (int i = _currentAmount - 1; i > -1; i--)
            {
#if SUBNAUTICA
                var itemSize = CraftData.GetItemSize(TechType.GasPod);
#elif BELOWZERO
                var itemSize = TechData.GetItemSize(techType);
#endif
                if (Inventory.main.HasRoomFor(itemSize.x, itemSize.y))
                {
                    if (_currentAmount > 0)
                    {
                        _currentAmount -= 1;
                        var pickup = CraftData.InstantiateFromPrefab(TechType.GasPod).GetComponent <Pickupable>();
                        Inventory.main.Pickup(pickup);
                    }
                }
                else
                {
                    break;
                }

                OnAmountChanged?.Invoke(_currentAmount);
            }
        }
        private void PerformTakeOperation(TechType techType)
        {
            QuickLogger.Debug("Perform Take Operation", true);
            foreach (DSSRackController baseUnit in BaseRacks)
            {
                if (baseUnit.HasItem(techType))
                {
                    var data = baseUnit.GetItemDataFromServer(techType);
                    QuickLogger.Debug("Calling Take", true);
                    var result = baseUnit.GivePlayerItem(techType, data);
                    if (!result)
                    {
                        return;
                        //TODO Add Message
                    }
                    return;
                }
            }

            //Check connectables
            foreach (KeyValuePair <string, FCSConnectableDevice> fcsConnectable in FCSConnectables)
            {
                Vector2int itemSize = CraftData.GetItemSize(techType);
                if (fcsConnectable.Value.ContainsItem(techType) && Inventory.main.HasRoomFor(itemSize.x, itemSize.y))
                {
                    var item = fcsConnectable.Value.RemoveItemFromContainer(techType, 1);
                    if (item == null)
                    {
                        continue;
                    }
                    DSSHelpers.GivePlayerItem(item);
                    break;
                }
            }
        }
        internal void AttemptToTakeItem(TechType techType)
        {
            var amount = _container.container.GetCount(techType);

            QuickLogger.Debug($"Container returned {amount} item/s for TechType {techType}");
#if SUBNAUTICA
            var itemSize = CraftData.GetItemSize(techType);
#elif BELOWZERO
            var itemSize = TechData.GetItemSize(techType);
#endif
            if (Inventory.main.HasRoomFor(itemSize.x, itemSize.y))
            {
                if (amount > 0)
                {
                    QuickLogger.Debug($"Attempting to take {_multiplier} item/s");

                    for (int i = 0; i < _multiplier; i++)
                    {
                        Pickupable pickup = _container.container.RemoveItem(techType);

                        if (pickup == null)
                        {
                            QuickLogger.Debug($"There are 0 {techType} in the container while using first or default Current Amount of {techType} is: {_container.container.GetCount(techType)}", true);
                            return;
                        }

                        Inventory.main.Pickup(pickup);
                    }
                }
                else
                {
                    QuickLogger.Debug($"There are 0 {techType} in the container.", true);
                }
            }
        }
Exemple #4
0
        public static bool TryOverflowIntoCyclopsBioreactors(SubRoot subRoot, TechType fishType, ref int breedCount)
        {
            CyBioReactorMono[] cyBioReactors = subRoot.GetComponentsInChildren <CyBioReactorMono>() ?? new CyBioReactorMono[0];

            if (cyBioReactors.Length == 0)
            {
                return(breedCount > 0);
            }

            Vector2int sizePerFish = CraftData.GetItemSize(fishType);
            int        failCount   = 0;

            while (failCount < cyBioReactors.Length && breedCount > 0)
            {
                foreach (CyBioReactorMono reactor in cyBioReactors)
                {
                    if (breedCount > 0 && reactor.container.HasRoomFor(sizePerFish.x, sizePerFish.y))
                    {
                        CoroutineHost.StartCoroutine(AddToReactor(subRoot, fishType, sizePerFish, reactor));
                        breedCount--;
                    }
                    else
                    {
                        failCount++;
                    }
                }
                if (failCount < cyBioReactors.Length)
                {
                    failCount = 0;
                }
            }
            return(breedCount > 0);
        }
Exemple #5
0
        public static bool TryOverflowIntoBioreactors(SubRoot subRoot, TechType fishType, ref int breedCount)
        {
            BaseBioReactor[] bioReactors = subRoot?.gameObject?.GetComponentsInChildren <BaseBioReactor>() ?? new BaseBioReactor[0];

            if (bioReactors.Length == 0)
            {
                return(breedCount > 0);
            }

            Vector2int sizePerFish = CraftData.GetItemSize(fishType);
            int        failCount   = 0;

            while (failCount < bioReactors.Length && breedCount > 0)
            {
                foreach (BaseBioReactor reactor in bioReactors)
                {
                    if (breedCount > 0 && reactor.container.HasRoomFor(sizePerFish.x, sizePerFish.y))
                    {
                        CoroutineHost.StartCoroutine(AddToReactor(subRoot, fishType, sizePerFish, reactor));
                        breedCount--;
                    }
                    else
                    {
                        failCount++;
                    }
                }
                if (failCount < bioReactors.Length)
                {
                    failCount = 0;
                }
            }
            return(breedCount > 0);
        }
Exemple #6
0
        public static int getItemSize(TechType techType)
        {
#if GAME_SN
            var size = CraftData.GetItemSize(techType);
#elif GAME_BZ
            var size = TechData.GetItemSize(techType);
#endif
            return(size.x * size.y);
        }
Exemple #7
0
        public static bool testContainer(ItemsContainer container)
        {
            List <TechType> techTypes = container.GetItemTypes();

            if (techTypes.Count() == 1)
            {
                Vector2int itemSize = CraftData.GetItemSize(techTypes[0]);
                if (itemSize.x == 1 && itemSize.y == 1 && container.count <= (container.sizeX * container.sizeY * DW_Tweaks_Settings.Instance.ContainerOverstuff))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #8
0
        public static bool Prefix(ItemsContainer __instance, Pickupable pickupable, ref bool __result)
        {
            Vector2int itemSize = CraftData.GetItemSize(pickupable.GetTechType());

            if (itemSize.x == 1 && itemSize.y == 1)
            {
                List <TechType> techTypes = __instance.GetItemTypes();
                if (techTypes.Count() == 1 && techTypes[0] == pickupable.GetTechType() && __instance.count < (__instance.sizeX * __instance.sizeY * DW_Tweaks_Settings.Instance.ContainerOverstuff))
                {
                    __result = true;
                    return(false);
                }
            }
            return(true);
        }
        /// <summary>
        /// A method that takes the tank from holder and gives it to the player.
        /// </summary>
        private void TakeTank()
        {
            var size = CraftData.GetItemSize(TechType.FireExtinguisher);

            if (!Inventory.main.HasRoomFor(size.x, size.y))
            {
                QuickLogger.Message(Language.main.Get("InventoryFull"));
                return;
            }

            CraftData.AddToInventory(TechType.FireExtinguisher, 1, false, false);

            _hasTank = false;
            _tankMesh.SetActive(false);
            gameObject.GetComponent <FireExtinguisher>().fuel = _fuel;
        }
        internal int GetUsedSpace()
        {
            var items  = _container.ToList();
            int amount = 0;

            foreach (InventoryItem item in items)
            {
#if SUBNAUTICA
                var itemSize = CraftData.GetItemSize(item.item.GetTechType());
#elif BELOWZERO
                var itemSize = TechData.GetItemSize(item.item.GetTechType());
#endif
                amount += itemSize.x * itemSize.y;
            }

            return(amount);
        }
Exemple #11
0
 public static void Patch()
 {
     try
     {
         Config.Load();
         foreach (TechType techType in Enum.GetValues(typeof(TechType)))
         {
             var name          = techType.ToString();
             var x             = CraftData.GetItemSize(techType).x;
             var y             = CraftData.GetItemSize(techType).y;
             var configChanged =
                 Config.TryGet(ref x, name, "X")
                 | Config.TryGet(ref y, name, "Y");
             if (configChanged)
             {
                 Config.Save();
             }
             if (x < 1)
             {
                 Logger.Warning("[" + name + "] X can't be less than 1. It was set to the default value");
                 x = CraftData.GetItemSize(techType).x;
             }
             if (x > 6)
             {
                 Logger.Warning("[" + name + "] X can't be greater than 1. It was set to the default value");
                 x = CraftData.GetItemSize(techType).x;
             }
             if (y < 1)
             {
                 Logger.Warning("[" + name + "] Y can't be less than 1. It was set to the default value");
                 y = CraftData.GetItemSize(techType).x;
             }
             if (y > 8)
             {
                 Logger.Warning("[" + name + "] Y can't be greater than 8. It was set to the default value");
                 y = CraftData.GetItemSize(techType).x;
             }
             CraftDataPatcher.customItemSizes[techType] = new Vector2int(x, y);
         }
     }
     catch (Exception e)
     {
         e.Log(LogType.Console);
     }
 }
Exemple #12
0
        internal void RemoveGaspod()
        {
#if SUBNAUTICA
            var itemSize = CraftData.GetItemSize(TechType.GasPod);
#elif BELOWZERO
            var itemSize = TechData.GetItemSize(TechType.GasPod);
#endif
            if (Inventory.main.HasRoomFor(itemSize.x, itemSize.y))
            {
                if (_currentAmount > 0)
                {
                    _currentAmount -= 1;
                    var pickup = CraftData.InstantiateFromPrefab(TechType.GasPod).GetComponent <Pickupable>();
                    Inventory.main.Pickup(pickup);
                }
            }


            OnAmountChanged?.Invoke(_currentAmount);
        }
Exemple #13
0
        internal void RemoveItemFromContainer(TechType item)
        {
            QuickLogger.Debug("Taking From Container", true);
            if (Items.ContainsKey(item))
            {
#if SUBNAUTICA
                var itemSize = CraftData.GetItemSize(item);
#elif BELOWZERO
                var itemSize = TechData.GetItemSize(item);
#endif
                if (!Inventory.main.HasRoomFor(itemSize.x, itemSize.y) || Items[item] < 1)
                {
                    return;
                }

                Items[item] -= 1;
                var pickup = CraftData.InstantiateFromPrefab(item).GetComponent <Pickupable>();
                Inventory.main.Pickup(pickup);
                OnContainerUpdate?.Invoke(GetTotal(), StorageLimit);
                _mono?.Producer?.TryStartingNextClone();
            }
        }
Exemple #14
0
        internal void AttemptToTakeItem(TechType techType)
        {
            var amount = GetItemCount(techType);

            QuickLogger.Debug($"Container returned {amount} item/s for TechType {techType}");
#if SUBNAUTICA
            var itemSize = CraftData.GetItemSize(techType);
#elif BELOWZERO
            var itemSize = TechData.GetItemSize(techType);
#endif
            if (Inventory.main.HasRoomFor(itemSize.x, itemSize.y))
            {
                if (amount > 0)
                {
                    QuickLogger.Debug($"Attempting to take {_multiplier} item/s");

                    for (int i = 0; i < _multiplier; i++)
                    {
                        var        itemData = ContainerItems.FirstOrDefault(x => x.TechType == techType);
                        Pickupable pickup   = InventoryHelpers.ConvertToPickupable(itemData);

                        if (pickup == null)
                        {
                            QuickLogger.Debug($"There are 0 {techType} in the container while using first or default Current Amount of {techType} is: {GetItemCount(techType)}", true);
                            return;
                        }

                        Inventory.main.Pickup(pickup);
                        ContainerItems.Remove(itemData);
                        //OnContainerUpdate?.Invoke(GetTotalCount(),_maxItems);
                    }
                }
                else
                {
                    QuickLogger.Debug($"There are 0 {techType} in the container.", true);
                }
            }
        }
Exemple #15
0
        internal static bool GivePlayerItem(TechType techType, ObjectDataTransferData itemData,
                                            Func <ObjectData, RackSlot> getServerWithObjectData)
        {
            QuickLogger.Debug($"Give Player Item: {techType}", true);

            bool isSuccessful = false;

#if SUBNAUTICA
            var itemSize = CraftData.GetItemSize(techType);
#elif BELOWZERO
            var itemSize = TechData.GetItemSize(techType);
#endif
            if (Inventory.main.HasRoomFor(itemSize.x, itemSize.y))
            {
                //TODO handle null playerToolData
                if (itemData.Vehicle == null)
                {
                    var pickup = CheckIfEggAnExtractPickable(techType);

                    if (!itemData.IsServer)
                    {
                        var data = (ObjectData)itemData.data;

                        if (data != null)
                        {
                            DetectDataObjectTypeAndPerformConversion(data, pickup);

                            var result = getServerWithObjectData?.Invoke(data);
                            result?.Remove(data);
                            isSuccessful = true;
                        }
                    }
                    else
                    {
                        var data       = (HashSet <ObjectData>)itemData.data;
                        var controller = pickup.gameObject.GetComponent <DSSServerController>();
                        controller.Initialize();
                        controller.FCSFilteredStorage.Items   = new HashSet <ObjectData>(data);
                        controller.FCSFilteredStorage.Filters = new List <Filter>(itemData.Filters);
                        controller.DisplayManager.UpdateDisplay();
                        isSuccessful = true;
                    }

                    Inventory.main.Pickup(pickup);
                }
                else if (itemData.Vehicle != null)
                {
                    QuickLogger.Debug("Is Vehicle Item");

                    var vehicleContainers = itemData.Vehicle.gameObject.GetComponentsInChildren <StorageContainer>()
                                            .Select((x) => x.container).ToList();
                    vehicleContainers.AddRange(GetSeamothStorage(itemData.Vehicle));

                    for (var index = 0; index < vehicleContainers.Count; index++)
                    {
                        for (var i = 0; i < vehicleContainers[index].ToList().Count; i++)
                        {
                            var item = vehicleContainers[index].ToList()[i];

                            if (item.item.GetTechType() == techType)
                            {
                                var passedItem = vehicleContainers[index].RemoveItem(item.item);
                                if (passedItem)
                                {
                                    if (Inventory.main.Pickup(item.item))
                                    {
                                        CrafterLogic.NotifyCraftEnd(Player.main.gameObject, item.item.GetTechType());

                                        goto _end;
                                    }
                                }
                            }
                        }
                    }

_end:
                    isSuccessful = true;
                }
            }

            Mod.OnBaseUpdate?.Invoke();
            return(isSuccessful);
        }
Exemple #16
0
        internal static bool GivePlayerItem(TechType techType, ObjectDataTransferData itemData,
                                            Func <ObjectData, RackSlot> getServerWithObjectData)
        {
            QuickLogger.Debug($"Give Player Item: {techType}", true);

            bool isSuccessful = false;

#if SUBNAUTICA
            var itemSize = CraftData.GetItemSize(techType);
#elif BELOWZERO
            var itemSize = TechData.GetItemSize(techType);
#endif
            if (Inventory.main.HasRoomFor(itemSize.x, itemSize.y))
            {
                //TODO handle null playerToolData
                Pickupable pickup;
                if (itemData.Vehicle == null)
                {
                    if (EggHandler.GetDiscoveredEgg(techType, out TechType value))
                    {
                        pickup = CraftData.InstantiateFromPrefab(value).EnsureComponent <Pickupable>();
                    }
                    else
                    {
                        pickup = CraftData.InstantiateFromPrefab(techType).EnsureComponent <Pickupable>();
                    }
                    if (!itemData.IsServer)
                    {
                        var data = (ObjectData)itemData.data;

                        if (data != null)
                        {
                            switch (data.DataObjectType)
                            {
                            case SaveDataObjectType.PlayerTool:

                                if (data.PlayToolData.HasBattery)
                                {
                                    var batteryTechType = data.PlayToolData.BatteryInfo.TechType;
                                    var tempBattery     = CraftData.GetPrefabForTechType(batteryTechType);
                                    var capacity        = tempBattery?.gameObject.GetComponent <IBattery>()?.capacity;

                                    if (data.PlayToolData.HasBattery && capacity != null && capacity > 0)
                                    {
                                        var energyMixin      = pickup.gameObject.GetComponent <EnergyMixin>();
                                        var normalizedCharge = data.PlayToolData.BatteryInfo.BatteryCharge / capacity;
                                        if (energyMixin.GetBattery() != null)
                                        {
                                            QuickLogger.Debug("Battery was already in device destroying");
                                        }

                                        if (!energyMixin.compatibleBatteries.Contains(batteryTechType))
                                        {
                                            energyMixin.compatibleBatteries.Add(batteryTechType);
                                        }

                                        energyMixin.SetBattery(data.PlayToolData.BatteryInfo.TechType,
                                                               (float)normalizedCharge);
                                        QuickLogger.Info(
                                            $"Gave Player Player tool {data.PlayToolData.TechType} with battery {batteryTechType}");
                                    }
                                    else
                                    {
                                        QuickLogger.Error <DSSServerController>(
                                            "While trying to get the batter capacity of the battery it returned null or 0.");
                                    }
                                }

                                break;



                            case SaveDataObjectType.Eatable:
                                //We are not handling decaying items so I dont need to set anything
                                break;

                            case SaveDataObjectType.Server:
                                var server = pickup.gameObject.GetComponent <DSSServerController>();
                                server.FCSFilteredStorage.Items = new HashSet <ObjectData>(data.ServerData);
                                server.Initialize();
                                server.DisplayManager.UpdateDisplay();
                                break;

                            case SaveDataObjectType.Battery:
                                var battery = pickup.gameObject.GetComponent <Battery>();
                                battery.charge = data.PlayToolData.BatteryInfo.BatteryCharge;
                                break;
                            }
                        }

                        var result = getServerWithObjectData?.Invoke(data);
                        result?.Remove(data);
                        isSuccessful = true;
                    }
                    else
                    {
                        var data       = (HashSet <ObjectData>)itemData.data;
                        var controller = pickup.gameObject.GetComponent <DSSServerController>();
                        controller.Initialize();
                        controller.FCSFilteredStorage.Items   = new HashSet <ObjectData>(data);
                        controller.FCSFilteredStorage.Filters = new List <Filter>(itemData.Filters);
                        controller.DisplayManager.UpdateDisplay();
                        isSuccessful = true;
                    }

                    Inventory.main.Pickup(pickup);
                }
                else if (itemData.Vehicle != null)
                {
                    QuickLogger.Debug("Is Vehicle Item");

                    var vehicleContainers = itemData.Vehicle.gameObject.GetComponentsInChildren <StorageContainer>()
                                            .Select((x) => x.container).ToList();
                    vehicleContainers.AddRange(GetSeamothStorage(itemData.Vehicle));

                    for (var index = 0; index < vehicleContainers.Count; index++)
                    {
                        for (var i = 0; i < vehicleContainers[index].ToList().Count; i++)
                        {
                            var item = vehicleContainers[index].ToList()[i];

                            if (item.item.GetTechType() == techType)
                            {
                                var passedItem = vehicleContainers[index].RemoveItem(item.item);
                                if (passedItem)
                                {
                                    if (Inventory.main.Pickup(item.item))
                                    {
                                        CrafterLogic.NotifyCraftEnd(Player.main.gameObject, item.item.GetTechType());

                                        goto _end;
                                    }
                                }
                            }
                        }
                    }

_end:
                    isSuccessful = true;
                }
            }

            Mod.OnBaseUpdate?.Invoke();
            return(isSuccessful);
        }
        private static void BreakIntoResources_Patch(BreakableResource __instance)
        {
            __instance.SendMessage("OnBreakResource", null, SendMessageOptions.DontRequireReceiver);
            if (__instance.gameObject.GetComponent <VFXBurstModel>())
            {
                __instance.gameObject.BroadcastMessage("OnKill");
            }
            else
            {
                UnityEngine.Object.Destroy(__instance.gameObject);
            }
            if (__instance.customGoalText != "")
            {
                GoalManager.main.OnCustomGoalEvent(__instance.customGoalText);
            }
            bool flag = false;

            for (int i = 0; i < __instance.numChances; i++)
            {
                GameObject gameObject = __instance.ChooseRandomResource();
                if (gameObject)
                {
                    QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "1 - Random Resouce is called");
                    if (Player.main.GetVehicle() is Exosuit exosuit)
                    {
                        QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "2 - Start AddToPrawn over randomress");
                        AddtoPrawn(__instance, exosuit, gameObject);
                    }
                    else
                    {
                        if ((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands.MetalHandsMK2TechType) | (MetalHands.Config.Config_fastcollect == true))
                        {
                            QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "3 - Player has glove - randomress");
                            Vector2int size      = CraftData.GetItemSize(CraftData.GetTechType(gameObject));
                            Inventory  inventory = Inventory.Get();
                            if (inventory.HasRoomFor(size.x, size.y))
                            {
                                CraftData.AddToInventory(CraftData.GetTechType(gameObject));
                            }
                            else
                            {
                                __instance.SpawnResourceFromPrefab(gameObject);
                            }
                        }
                        else
                        {
                            __instance.SpawnResourceFromPrefab(gameObject);
                        }
                    }
                    flag = true;
                }
            }
            if (!flag)
            {
                QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "5 - default resouce is called");
                if (Player.main.GetVehicle() is Exosuit exosuit)
                {
                    QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "6 - Start AddToPrawn over defaultress");
                    AddtoPrawn(__instance, exosuit, __instance.defaultPrefab);
                }
                else if ((Inventory.main.equipment.GetTechTypeInSlot("Gloves") == MetalHands.MetalHandsMK2TechType) | (MetalHands.Config.Config_fastcollect == true))
                {
                    QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "7 - Player has glove - defaultress");
                    Vector2int size      = CraftData.GetItemSize(CraftData.GetTechType(__instance.defaultPrefab));
                    Inventory  inventory = Inventory.Get();
                    if (inventory.HasRoomFor(size.x, size.y))
                    {
                        CraftData.AddToInventory(CraftData.GetTechType(__instance.defaultPrefab));
                    }
                    else
                    {
                        __instance.SpawnResourceFromPrefab(__instance.defaultPrefab);
                    }
                }
                else
                {
                    __instance.SpawnResourceFromPrefab(__instance.defaultPrefab);
                }
            }
            FMODUWE.PlayOneShot(__instance.breakSound, __instance.transform.position, 1f);
            if (__instance.hitFX)
            {
                Utils.PlayOneShotPS(__instance.breakFX, __instance.transform.position, Quaternion.Euler(new Vector3(270f, 0f, 0f)), null);
            }

            QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, "9 - Original Methode ending");
        }
        private Pickupable PerformTakeOperation(TechType techType)
        {
            QuickLogger.Debug("Perform Take Operation", true);
            foreach (DSSRackController baseUnit in BaseRacks)
            {
                if (baseUnit.HasItem(techType))
                {
                    var data = baseUnit.GetItemDataFromServer(techType, out RackSlot slot);
                    QuickLogger.Debug("Calling Take", true);

                    if (GivePlayerItem)
                    {
                        var result = baseUnit.GivePlayerItem(techType, data);
                        if (!result)
                        {
                            return(null);
                            //TODO Add Message
                        }
                    }
                    else
                    {
                        slot.Remove((ObjectData)data.data);
                        GivePlayerItem = true;
                    }

                    return(data.ToPickable(techType));
                }
            }

            if (!TakeFromConnectables)
            {
                TakeFromConnectables = true;
                return(null);
            }
            //Check connectables
            foreach (KeyValuePair <string, FCSConnectableDevice> fcsConnectable in FCSConnectables)
            {
                Vector2int itemSize = CraftData.GetItemSize(techType);
                if (fcsConnectable.Value.ContainsItem(techType) && fcsConnectable.Value.IsVisible && !fcsConnectable.Value.IsBase() &&
                    fcsConnectable.Value.IsOperational())
                {
                    var item = fcsConnectable.Value.RemoveItemFromContainer(techType, 1);

                    if (item == null)
                    {
                        continue;
                    }

                    if (GivePlayerItem)
                    {
                        DSSHelpers.GivePlayerItem(item);
                    }

                    GivePlayerItem = true;
                    Mod.OnBaseUpdate?.Invoke();
                    return(item);
                }
            }

            return(null);
        }
Exemple #19
0
        public static bool Prefix(Constructable __instance)
        {
#endif
            var player = Player.main;
            if (player.isPiloting && GameModeUtils.RequiresIngredients())
            {
                if (__instance._constructed)
                {
                    return(true);
                }
#if BZ
                if (player.GetComponentInParent <Hoverbike>() is not null)
                {
                    return(true);
                }
#endif
                var count = __instance.resourceMap.Count;

                var resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount -= Time.deltaTime / (count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                var resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    var techType = __instance.resourceMap[resourceID2];

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

                    var storageCheck = false;
                    var thisVehicle  = Player.main.GetVehicle();
                    if (thisVehicle != null)
                    {
                        switch (thisVehicle)
                        {
                        case Exosuit exosuit:
                        {
                            var storageContainer = exosuit.storageContainer;

                            if (storageContainer.container.HasRoomFor(size.x, size.y))
                            {
                                CoroutineHost.StartCoroutine(AddToVehicle(techType, storageContainer.container));
                                storageCheck = true;
                            }
                            break;
                        }

                        case SeaMoth seaMoth:
                        {
                            for (var i = 0; i < 12; i++)
                            {
                                try
                                {
                                    var storage = seaMoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                    if (storage == null || !storage.HasRoomFor(size.x, size.y))
                                    {
                                        continue;
                                    }
                                    CoroutineHost.StartCoroutine(AddToVehicle(techType, storage));
                                    storageCheck = true;
                                    break;
                                }
                                catch
                                {
                                    // ignored
                                }
                            }

                            break;
                        }
                        }
                    }
#if BZ
                    var seaTruck = player.GetComponentInParent <SeaTruckUpgrades>();
                    if (seaTruck != null)
                    {
                        foreach (var storageContainer in seaTruck.GetComponentsInChildren <StorageContainer>() ?? new StorageContainer[0])
                        {
                            try
                            {
                                var storage = storageContainer.container;
                                if (storage == null || !storage.HasRoomFor(size.x, size.y))
                                {
                                    continue;
                                }
                                CoroutineHost.StartCoroutine(AddToVehicle(techType, storage));
                                storageCheck = true;
                                break;
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                    }
#endif

                    if (!storageCheck)
                    {
                        __instance.constructedAmount = backupConstructedAmount;
                        return(true);
                    }
                }
                __instance.UpdateMaterial();
#if SUBNAUTICA_EXP || BZ
                result.Set(__instance.constructedAmount <= 0f);
                return(false);
#elif SUBNAUTICA_STABLE
                return(__instance.constructedAmount <= 0f);
#endif
            }
            return(true);
        }
Exemple #20
0
        internal static bool CanPlayerHold(TechType techType)
        {
            var size = CraftData.GetItemSize(techType);

            return(Inventory.main.HasRoomFor(size.x, size.y));
        }
Exemple #21
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);
        }