Ejemplo n.º 1
0
        public static bool IsCraftRecipeFulfilled(TechType techType)
        {
            if (Inventory.main == null)
            {
                return(false);
            }
            if (!GameModeUtils.RequiresIngredients())
            {
                return(true);
            }

            var       itemContainers = FindAllItemsContainersInRange();
            ITechData techData       = CraftData.Get(techType, false);

            if (techData != null)
            {
                int i = 0;
                int ingredientCount = techData.ingredientCount;
                while (i < ingredientCount)
                {
                    IIngredient ingredient = techData.GetIngredient(i);
                    if (GetTotalPickupCount(ingredient.techType, itemContainers) < ingredient.amount)
                    {
                        return(false);
                    }
                    i++;
                }
                return(true);
            }
            return(false);
        }
        public static void CrafterLogic_IsCraftRecipeFulfilled_Postfix(TechType techType, ref bool __result)
        {
            if (__result && GameModeUtils.RequiresIngredients())
            {
                Inventory main = Inventory.main;
#if SN1
                ITechData techData = CraftData.Get(techType, true);
                if (techData != null)
                {
                    int i = 0;
                    int ingredientCount = techData.ingredientCount;
                    while (i < ingredientCount)
                    {
                        IIngredient ingredient = techData.GetIngredient(i);
#elif BZ
                IList <Ingredient> ingredients = TechData.GetIngredients(techType);
                if (ingredients != null)
                {
                    int i = 0;
                    int ingredientCount = ingredients.Count;
                    while (i < ingredientCount)
                    {
                        Ingredient ingredient = ingredients[i];
#endif
                        int count = 0;
                        IList <InventoryItem> inventoryItems = main.container.GetItems(ingredient.techType);
                        if (inventoryItems != null)
                        {
                            foreach (InventoryItem inventoryItem in inventoryItems)
                            {
                                if (Main.BatteryCheck(inventoryItem.item))
                                {
                                    count++;
                                }
                            }
                        }
                        if (count < ingredient.amount)
                        {
                            __result = false;
                            return;
                        }
                        i++;
                    }
                    __result = true;
                    return;
                }
                __result = false;
                return;
            }
        }
    }
}
        public static void CrafterLogic_IsCraftRecipeFulfilled_Postfix(TechType techType, ref bool __result)
        {
            if (!__result || !GameModeUtils.RequiresIngredients())
            {
                return;
            }
            var main = Inventory.main;

#if SN1
            var techData = CraftData.Get(techType, true);
            if (techData != null)
            {
                var i = 0;
                var ingredientCount = techData.ingredientCount;
                while (i < ingredientCount)
                {
                    var ingredient = techData.GetIngredient(i);
#elif BZ
            IList <Ingredient> ingredients = TechData.GetIngredients(techType);
            if (ingredients != null)
            {
                var i = 0;
                var ingredientCount = ingredients.Count;
                while (i < ingredientCount)
                {
                    var ingredient = ingredients[i];
#endif
                    var count          = 0;
                    var inventoryItems = main.container.GetItems(ingredient.techType);
                    if (inventoryItems != null)
                    {
                        count += inventoryItems.Count(inventoryItem => Main.BatteryCheck(inventoryItem.item));
                    }
                    if (count < ingredient.amount)
                    {
                        __result = false;
                        return;
                    }
                    i++;
                }
                __result = true;
                return;
            }
            __result = false;
        }
    }
}
Ejemplo n.º 4
0
        static int getMaxAmount(TechInfo techInfo)
        {
            int maxAmount = int.MaxValue;

            if (GameModeUtils.RequiresIngredients())
            {
                foreach (var ing in techInfo.ingredients)
                {
                    maxAmount = Math.Min(maxAmount, getCountAvailable(ing.techType) / ing.amount);
                }

                if (currentPowerRelay?.GetPower() > 5f)
                {
                    maxAmount = Math.Min(maxAmount, (int)(currentPowerRelay.GetPower() / 5f - 1f));
                }
            }

            return(maxAmount);
        }
Ejemplo n.º 5
0
        public static void WriteIngredients(ITechData data, List <TooltipIcon> icons)
        {
            int ingredientCount = data.ingredientCount;

            ItemsContainer[] itemContainers = FindAllItemsContainersInRange();
            StringBuilder    stringBuilder  = new StringBuilder();

            for (int i = 0; i < ingredientCount; i++)
            {
                stringBuilder.Length = 0;
                IIngredient  ingredient       = data.GetIngredient(i);
                TechType     techType         = ingredient.techType;
                int          totalPickupCount = GetTotalPickupCount(techType, itemContainers);
                int          amount           = ingredient.amount;
                bool         flag             = totalPickupCount >= amount || !GameModeUtils.RequiresIngredients();
                Atlas.Sprite sprite           = SpriteManager.Get(techType);
                if (flag)
                {
                    stringBuilder.Append("<color=#94DE00FF>");
                }
                else
                {
                    stringBuilder.Append("<color=#DF4026FF>");
                }
                string orFallback = Language.main.GetOrFallback(TooltipFactory.techTypeIngredientStrings.Get(techType), techType);
                stringBuilder.Append(orFallback);
                if (amount > 1)
                {
                    stringBuilder.Append(" x");
                    stringBuilder.Append(amount);
                }
                if (totalPickupCount > 0 && totalPickupCount < amount)
                {
                    stringBuilder.Append(" (");
                    stringBuilder.Append(totalPickupCount);
                    stringBuilder.Append(")");
                }
                stringBuilder.Append("</color>");
                icons.Add(new TooltipIcon(sprite, stringBuilder.ToString()));
            }
        }
Ejemplo n.º 6
0
        // Static reproduction of Constructable.Construct to replace the body of the existing method
        public static bool Construct(Constructable constructable)
        {
            if (constructable._constructed)
            {
                return(false);
            }

            var resourceMap = ConstructableResourceMap.GetValue(constructable) as List <TechType>;

            var count = resourceMap.Count;

            var resourceID = (int)ConstructableGetResourceId.Invoke(constructable, new object[] { });

            constructable.constructedAmount += Time.deltaTime / ((float)count * (float)ConstructableGetConstructInterval.Invoke(constructable, new object[] { }));
            constructable.constructedAmount  = Mathf.Clamp01(constructable.constructedAmount);

            var resourceID2 = (int)ConstructableGetResourceId.Invoke(constructable, new object[] { });

            if (resourceID != resourceID2)
            {
                var techType = resourceMap[resourceID2 - 1];
                if (!CrafterLogicHelper.DestroyItemInLocalContainers(techType) && GameModeUtils.RequiresIngredients())
                {
                    constructable.constructedAmount = (float)resourceID / (float)count;
                    return(false);
                }
            }

            ConstructableUpdateMaterial.Invoke(constructable, new object[] { });
            if (constructable.constructedAmount >= 1f)
            {
                constructable.SetState(true, true);
            }

            return(true);
        }
Ejemplo n.º 7
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null)
            {
                var thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(false);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    TechType destroyTechType = __instance.resourceMap[resourceID2 - 1];
                    if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                    {
                        var storageContainer = ((Exosuit)thisVehicle).storageContainer;

                        if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                        {
                            storageContainer.container.DestroyItem(destroyTechType);
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                    else
                    {
                        var  seamoth      = (SeaMoth)thisVehicle;
                        bool storageCheck = false;
                        for (int i = 0; i < 12; i++)
                        {
                            try
                            {
                                var storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                if (storage != null && storage.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                                {
                                    storage.DestroyItem(destroyTechType);
                                    storageCheck = true;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount >= 1f)
                {
                    __instance.SetState(true, true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 8
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null)
            {
                var thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(true);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount -= Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID && GameModeUtils.RequiresIngredients())
                {
                    TechType   techType   = __instance.resourceMap[resourceID2];
                    GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false);
                    Pickupable component  = gameObject.GetComponent <Pickupable>();

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

                        if (storageContainer.container.HasRoomFor(component) && GameModeUtils.RequiresIngredients())
                        {
                            var name = Language.main.Get(component.GetTechName());
                            ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                            uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

                            component = component.Initialize();

                            var item = new InventoryItem(component);
                            storageContainer.container.UnsafeAdd(item);
                            component.PlayPickupSound();
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                    else
                    {
                        var  seamoth      = (SeaMoth)thisVehicle;
                        bool storageCheck = false;
                        for (int i = 0; i < 12; i++)
                        {
                            try
                            {
                                var storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                if (storage != null && storage.HasRoomFor(component) && GameModeUtils.RequiresIngredients())
                                {
                                    var name = Language.main.Get(component.GetTechName());
                                    ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                                    uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

                                    component = component.Initialize();

                                    var item = new InventoryItem(component);
                                    storage.UnsafeAdd(item);
                                    component.PlayPickupSound();
                                    storageCheck = true;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount <= 0f)
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 10
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null || Player.main.GetComponentInParent <SeaTruckSegment>() != null)
            {
                var thisVehicle  = Player.main.GetVehicle();
                var thisSeatruck = Player.main.GetComponentInParent <SeaTruckSegment>();

                if (__instance._constructed)
                {
                    return(false);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID)
                {
                    bool     storageCheck    = false;
                    TechType destroyTechType = __instance.resourceMap[resourceID2 - 1];
                    if (thisVehicle != null)
                    {
                        if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                        {
                            StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer;

                            if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                            {
                                storageContainer.container.DestroyItem(destroyTechType);
                                storageCheck = true;
                            }
                        }
                    }
                    else if (thisSeatruck != null)
                    {
                        SeaTruckSegment[]         seaTruckSegments = thisSeatruck.GetComponents <SeaTruckSegment>();
                        List <StorageContainer[]> containers       = new List <StorageContainer[]>();
                        foreach (SeaTruckSegment seaTruckSegment in seaTruckSegments)
                        {
                            containers.Add(seaTruckSegment.GetComponentsInChildren <StorageContainer>());
                        }
                        foreach (StorageContainer[] storageContainers in containers)
                        {
                            foreach (StorageContainer storageContainer in storageContainers)
                            {
                                if (storageContainer.container.Contains(destroyTechType) && GameModeUtils.RequiresIngredients())
                                {
                                    storageContainer.container.DestroyItem(destroyTechType);
                                    storageCheck = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!storageCheck)
                    {
                        __instance.constructedAmount = backupConstructedAmount;
                        return(true);
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount >= 1f)
                {
                    __instance.SetState(true, true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 11
0
        static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null || Player.main.GetComponentInParent <SeaTruckSegment>() != null)
            {
                var thisVehicle  = Player.main.GetVehicle();
                var thisSeatruck = Player.main.GetComponentInParent <SeaTruckSegment>();
                if (__instance._constructed)
                {
                    return(true);
                }
                int count      = __instance.resourceMap.Count;
                int resourceID = __instance.GetResourceID();
                var backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount -= Time.deltaTime / ((float)count * Constructable.GetConstructInterval());
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = __instance.GetResourceID();
                if (resourceID2 != resourceID && GameModeUtils.RequiresIngredients())
                {
                    bool       storageCheck = false;
                    TechType   techType     = __instance.resourceMap[resourceID2];
                    GameObject gameObject   = CraftData.InstantiateFromPrefab(techType, false);
                    Pickupable component    = gameObject.GetComponent <Pickupable>();

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

                            if (storageContainer.container.HasRoomFor(component) && GameModeUtils.RequiresIngredients())
                            {
                                var name = Language.main.Get(component.GetTechName());
                                ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                                uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

                                component.Initialize();

                                var item = new InventoryItem(component);
                                storageContainer.container.UnsafeAdd(item);
                                component.PlayPickupSound();
                                storageCheck = true;
                            }
                        }
                    }
                    else
                    {
                        SeaTruckSegment[]         seaTruckSegments = thisSeatruck.GetComponents <SeaTruckSegment>();
                        List <StorageContainer[]> containers       = new List <StorageContainer[]>();
                        foreach (SeaTruckSegment seaTruckSegment in seaTruckSegments)
                        {
                            containers.Add(seaTruckSegment.GetComponentsInChildren <StorageContainer>());
                        }
                        foreach (StorageContainer[] storageContainers in containers)
                        {
                            foreach (StorageContainer storageContainer in storageContainers)
                            {
                                if (storageContainer.container.HasRoomFor(component) && GameModeUtils.RequiresIngredients())
                                {
                                    var name = Language.main.Get(component.GetTechName());
                                    ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                                    uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

                                    component.Initialize();

                                    var item = new InventoryItem(component);
                                    storageContainer.container.UnsafeAdd(item);
                                    component.PlayPickupSound();
                                    storageCheck = true;
                                    break;
                                }
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount <= 0f)
                {
                    return(true);
                }

                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        public static bool Prefix(Constructable __instance)
        {
            var player = Player.main;

            if (player.isPiloting && GameModeUtils.RequiresIngredients())
            {
                if (__instance._constructed)
                {
                    return(false);
                }
#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 destroyTechType = __instance.resourceMap[resourceID2 - 1];
                    var thisVehicle     = player.GetVehicle();
                    var storageCheck    = false;
                    if (thisVehicle != null)
                    {
                        switch (thisVehicle)
                        {
                        case Exosuit exosuit:
                            if (exosuit.storageContainer.container.Contains(destroyTechType) &&
                                exosuit.storageContainer.container.DestroyItem(destroyTechType))
                            {
                                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.Contains(destroyTechType))
                                    {
                                        continue;
                                    }
                                    if (!storage.DestroyItem(destroyTechType))
                                    {
                                        continue;
                                    }
                                    storageCheck = true;
                                    break;
                                }
                                catch
                                {
                                    // ignored
                                }
                            }
                            break;
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
#if BZ
                    var seaTruck = player.GetComponentInParent <SeaTruckUpgrades>();
                    if (seaTruck != null)
                    {
                        foreach (var storageContainer in seaTruck.GetComponentsInChildren <StorageContainer>() ?? new StorageContainer[0])
                        {
                            try
                            {
                                if (!storageContainer.container.DestroyItem(destroyTechType))
                                {
                                    continue;
                                }
                                storageCheck = true;
                                break;
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                    }
                    if (!storageCheck)
                    {
                        __instance.constructedAmount = backupConstructedAmount;
                        return(true);
                    }
#endif
                }
                __instance.UpdateMaterial();
                if (__instance.constructedAmount >= 1f)
                {
                    _ = __instance.SetState(true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 14
0
        public static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null && GameModeUtils.RequiresIngredients())
            {
                Type            ConstructableType          = typeof(Constructable);
                List <TechType> resourceMapField           = (List <TechType>)AccessTools.Field(ConstructableType, "resourceMap").GetValue(__instance);
                MethodInfo      getResourceIDMethod        = AccessTools.Method(ConstructableType, "GetResourceID");
                MethodInfo      GetConstructIntervalMethod = AccessTools.Method(ConstructableType, "GetConstructInterval");
                MethodInfo      updateMaterialMethod       = AccessTools.Method(ConstructableType, "UpdateMaterial");

                Vehicle thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(true);
                }
                int count = resourceMapField.Count;

                int   resourceID = (int)getResourceIDMethod.Invoke(__instance, null);
                float backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount -= Time.deltaTime / (count * (float)GetConstructIntervalMethod.Invoke(__instance, null));
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = (int)getResourceIDMethod.Invoke(__instance, null);
                if (resourceID2 != resourceID)
                {
                    TechType   techType   = resourceMapField[resourceID2];
                    GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false);
                    Pickupable component  = gameObject.GetComponent <Pickupable>();

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

                        if (storageContainer.container.HasRoomFor(component))
                        {
                            string name = Language.main.Get(component.GetTechName());
                            ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                            uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);
#if SUBNAUTICA
                            component = component.Initialize();
#elif BELOWZERO
                            component.Initialize();
#endif
                            var item = new InventoryItem(component);
                            storageContainer.container.UnsafeAdd(item);
                            component.PlayPickupSound();
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                    else
                    {
                        var  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(component))
                                {
                                    string name = Language.main.Get(component.GetTechName());
                                    ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                                    uGUI_IconNotifier.main.Play(component.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

#if SUBNAUTICA
                                    component = component.Initialize();
#elif BELOWZERO
                                    component.Initialize();
#endif
                                    var item = new InventoryItem(component);
                                    storage.UnsafeAdd(item);
                                    component.PlayPickupSound();
                                    storageCheck = true;
                                    break;
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                updateMaterialMethod.Invoke(__instance, null);
                return(__instance.constructedAmount <= 0f);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 15
0
        public static bool Prefix(Constructable __instance)
        {
            if (Player.main.GetVehicle() != null && GameModeUtils.RequiresIngredients())
            {
                Type            ConstructableType          = typeof(Constructable);
                List <TechType> resourceMapField           = (List <TechType>)AccessTools.Field(ConstructableType, "resourceMap").GetValue(__instance);
                MethodInfo      getResourceIDMethod        = AccessTools.Method(ConstructableType, "GetResourceID");
                MethodInfo      GetConstructIntervalMethod = AccessTools.Method(ConstructableType, "GetConstructInterval");
                MethodInfo      updateMaterialMethod       = AccessTools.Method(ConstructableType, "UpdateMaterial");


                Vehicle thisVehicle = Player.main.GetVehicle();
                if (__instance._constructed)
                {
                    return(false);
                }
                int   count      = resourceMapField.Count;
                int   resourceID = (int)getResourceIDMethod.Invoke(__instance, null);
                float backupConstructedAmount = __instance.constructedAmount;
                __instance.constructedAmount += Time.deltaTime / (count * (float)GetConstructIntervalMethod.Invoke(__instance, null));
                __instance.constructedAmount  = Mathf.Clamp01(__instance.constructedAmount);
                int resourceID2 = (int)getResourceIDMethod.Invoke(__instance, null);
                if (resourceID2 != resourceID)
                {
                    TechType destroyTechType = resourceMapField[resourceID2 - 1];
                    if (thisVehicle.GetType().Equals(typeof(Exosuit)))
                    {
                        StorageContainer storageContainer = ((Exosuit)thisVehicle).storageContainer;

                        if (storageContainer.container.Contains(destroyTechType))
                        {
                            _ = storageContainer.container.DestroyItem(destroyTechType);
                        }
                        else
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                    else
                    {
                        var  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.Contains(destroyTechType))
                                {
                                    if (storage.DestroyItem(destroyTechType))
                                    {
                                        storageCheck = true;
                                        break;
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                        if (!storageCheck)
                        {
                            __instance.constructedAmount = backupConstructedAmount;
                            return(true);
                        }
                    }
                }
                _ = updateMaterialMethod.Invoke(__instance, null);
                if (__instance.constructedAmount >= 1f)
                {
                    _ = __instance.SetState(true, true);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }