Esempio n. 1
0
        private static bool CheckRequirements(Trashcan __instance, Pickupable item, ITechData techData)
        {
            bool check            = true;
            int  craftCountNeeded = techData.craftAmount;
            IList <InventoryItem> inventoryItems = __instance.storageContainer.container.GetItems(item.GetTechType());

            if (inventoryItems != null && inventoryItems.Count >= craftCountNeeded)
            {
                while (craftCountNeeded > 0)
                {
                    Trashcan_Update.inventoryItems.Add(inventoryItems[craftCountNeeded - 1]);
                    craftCountNeeded--;
                }

                List <TechType> linkedItems = new List <TechType>();
                for (int i = 0; i < techData.linkedItemCount; i++)
                {
                    linkedItems.Add(techData.GetLinkedItem(i));
                }

                foreach (TechType techType in linkedItems)
                {
                    int linkedCountNeeded = linkedItems.FindAll((TechType tt) => tt == techType).Count;
                    IList <InventoryItem> inventoryItems2 = __instance.storageContainer.container.GetItems(techType);
                    IList <InventoryItem> inventoryItems3 = Inventory.main.container.GetItems(techType);
                    int count = (inventoryItems2?.Count ?? 0) + (inventoryItems3?.Count ?? 0);
                    if (count < linkedCountNeeded)
                    {
                        ErrorMessage.AddMessage($"Missing {linkedCountNeeded - (inventoryItems2?.Count + inventoryItems3?.Count)} {techType}");
                        Inventory.main.ForcePickup(item);
                        Trashcan_Update.inventoryItems.Clear();
                        return(false);
                    }

                    int count1 = inventoryItems2?.Count ?? 0;
                    int count2 = inventoryItems3?.Count ?? 0;
                    while (linkedCountNeeded > 0)
                    {
                        if (count1 > 0)
                        {
                            Trashcan_Update.inventoryItems.Add(inventoryItems2[count1 - 1]);
                            count1--;
                        }
                        else if (count2 > 0)
                        {
                            Trashcan_Update.inventoryItems.Add(inventoryItems3[count2 - 1]);
                            count2--;
                        }
                        linkedCountNeeded--;
                    }
                }
            }
            else
            {
                check = false;
            }

            return(check);
        }
Esempio n. 2
0
        public static void Postfix(ref ITechData __result)
        {
            var patchedTech = new TechData()
            {
                craftAmount = __result.craftAmount
            };

            for (int i = 0; i < __result.ingredientCount; i++)
            {
                IIngredient ingredient        = __result.GetIngredient(i);
                Ingredient  patchedIngredient = new Ingredient(ingredient.techType, ingredient.amount * HCPSettings.Instance.CraftingCostMultiplier);
                patchedTech.Ingredients.Add(patchedIngredient);
            }

            for (int i = 0; i < __result.ingredientCount; i++)
            {
                patchedTech.LinkedItems.Add(__result.GetLinkedItem(i));
            }

            __result = patchedTech;
        }
Esempio n. 3
0
        private static TechData ConvertToTechData(ITechData iTechData)
        {
            var techData = new TechData()
            {
                craftAmount = iTechData.craftAmount
            };

            for (int i = 0; i < iTechData.ingredientCount; i++)
            {
                IIngredient ingredient    = iTechData.GetIngredient(i);
                var         smlingredient = new Ingredient(ingredient.techType, ingredient.amount);
                techData.Ingredients.Add(smlingredient);
            }

            for (int i = 0; i < iTechData.linkedItemCount; i++)
            {
                techData.LinkedItems.Add(iTechData.GetLinkedItem(i));
            }

            return(techData);
        }
        private static void PatchCustomTechData()
        {
            short added    = 0;
            short replaced = 0;

            foreach (TechType techType in CustomTechData.Keys)
            {
                bool      techExists  = CraftData.techData.TryGetValue(techType, out CraftData.TechData techData);
                ITechData smlTechData = CustomTechData[techType];
                bool      sameData    = false;

                if (techExists)
                {
                    sameData = smlTechData.craftAmount == techData.craftAmount &&
                               smlTechData.ingredientCount == techData.ingredientCount &&
                               smlTechData.linkedItemCount == techData.linkedItemCount;

                    if (sameData)
                    {
                        for (int i = 0; i < smlTechData.ingredientCount; i++)
                        {
                            if (smlTechData.GetIngredient(i).techType != techData.GetIngredient(i).techType)
                            {
                                sameData = false;
                                break;
                            }
                            if (smlTechData.GetIngredient(i).amount != techData.GetIngredient(i).amount)
                            {
                                sameData = false;
                                break;
                            }
                        }
                    }

                    if (sameData)
                    {
                        for (int i = 0; i < smlTechData.linkedItemCount; i++)
                        {
                            if (smlTechData.GetLinkedItem(i) != techData.GetLinkedItem(i))
                            {
                                sameData = false;
                                break;
                            }
                        }
                    }
                }

                if (!techExists || !sameData)
                {
                    var techDataInstance = new CraftData.TechData
                    {
                        _techType    = techType,
                        _craftAmount = smlTechData.craftAmount
                    };

                    var ingredientsList = new CraftData.Ingredients();

                    if (smlTechData.ingredientCount > 0)
                    {
                        for (int i = 0; i < smlTechData.ingredientCount; i++)
                        {
                            IIngredient smlIngredient = smlTechData.GetIngredient(i);

                            var ingredient = new CraftData.Ingredient(smlIngredient.techType, smlIngredient.amount);
                            ingredientsList.Add(smlIngredient.techType, smlIngredient.amount);
                        }
                        techDataInstance._ingredients = ingredientsList;
                    }

                    if (smlTechData.linkedItemCount > 0)
                    {
                        var linkedItems = new List <TechType>();
                        for (int l = 0; l < smlTechData.linkedItemCount; l++)
                        {
                            linkedItems.Add(smlTechData.GetLinkedItem(l));
                        }
                        techDataInstance._linkedItems = linkedItems;
                    }

                    if (techExists)
                    {
                        CraftData.techData.Remove(techType);
                        Logger.Log($"{techType} TechType already existed in the CraftData.techData dictionary. Original value was replaced.", LogLevel.Warn);
                        replaced++;
                    }
                    else
                    {
                        added++;
                    }
                    CraftData.techData.Add(techType, techDataInstance);
                }
            }

            if (added > 0)
            {
                Logger.Log($"Added {added} new entries to the CraftData.techData dictionary.", LogLevel.Info);
            }

            if (replaced > 0)
            {
                Logger.Log($"Replaced {replaced} existing entries to the CraftData.techData dictionary.", LogLevel.Info);
            }
        }
Esempio n. 5
0
        private static void HandleModifiedRecipe(IModifiedRecipe modifiedRecipe)
        {
            bool overrideRecipe = false;

            ITechData original = CraftData.Get(modifiedRecipe.ItemID);

            var replacement = new TechData();

            // Amount
            if (modifiedRecipe.AmountCrafted.HasValue)
            {
                overrideRecipe         |= true;
                replacement.craftAmount = modifiedRecipe.AmountCrafted.Value;
            }
            else
            {
                replacement.craftAmount = original.craftAmount;
            }

            // Ingredients
            if (modifiedRecipe.IngredientsCount.HasValue)
            {
                overrideRecipe |= true;
                foreach (EmIngredient ingredient in modifiedRecipe.Ingredients)
                {
                    replacement.Ingredients.Add(
                        new Ingredient(
                            ingredient.ItemID,
                            ingredient.Required));
                }
            }
            else
            {
                for (int i = 0; i < original.ingredientCount; i++)
                {
                    replacement.Ingredients.Add(
                        new Ingredient(
                            original.GetIngredient(i).techType,
                            original.GetIngredient(i).amount));
                }
            }

            // Linked Items
            if (modifiedRecipe.LinkedItemsCount.HasValue)
            {
                overrideRecipe |= true;
                foreach (TechType linkedItem in modifiedRecipe.LinkedItems)
                {
                    replacement.LinkedItems.Add(linkedItem);
                }
            }
            else
            {
                for (int i = 0; i < original.linkedItemCount; i++)
                {
                    replacement.LinkedItems.Add(original.GetLinkedItem(i));
                }
            }

            if (overrideRecipe)
            {
                CraftDataHandler.SetTechData(modifiedRecipe.ItemID, replacement);
            }
        }
Esempio n. 6
0
        private static void AddCustomTechDataToOriginalDictionary()
        {
            short added    = 0;
            short replaced = 0;

            foreach (TechType techType in CustomTechData.Keys)
            {
                ITechData smlTechData = CustomTechData[techType];

                var techDataInstance = new CraftData.TechData
                {
                    _techType    = techType,
                    _craftAmount = smlTechData.craftAmount
                };

                var ingredientsList = new CraftData.Ingredients();

                if (smlTechData.ingredientCount > 0)
                {
                    for (int i = 0; i < smlTechData.ingredientCount; i++)
                    {
                        IIngredient smlIngredient = smlTechData.GetIngredient(i);

                        var ingredient = new CraftData.Ingredient(smlIngredient.techType, smlIngredient.amount);
                        ingredientsList.Add(smlIngredient.techType, smlIngredient.amount);
                    }
                    techDataInstance._ingredients = ingredientsList;
                }

                if (smlTechData.linkedItemCount > 0)
                {
                    var linkedItems = new List <TechType>();
                    for (int l = 0; l < smlTechData.linkedItemCount; l++)
                    {
                        linkedItems.Add(smlTechData.GetLinkedItem(l));
                    }
                    techDataInstance._linkedItems = linkedItems;
                }

                bool techDataExists = CraftData.techData.ContainsKey(techType);

                if (techDataExists)
                {
                    CraftData.techData.Remove(techType);
                    Logger.Log($"{techType} TechType already existed in the CraftData.techData dictionary. Original value was replaced.", LogLevel.Warn);
                    replaced++;
                }
                else
                {
                    added++;
                }

                CraftData.techData.Add(techType, techDataInstance);
            }

            if (added > 0)
            {
                Logger.Log($"Added {added} new entries to the CraftData.techData dictionary.", LogLevel.Info);
            }

            if (replaced > 0)
            {
                Logger.Log($"Replaced {replaced} existing entries to the CraftData.techData dictionary.", LogLevel.Info);
            }
        }