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 bool ConsumeResources(TechType techType) { if (!IsCraftRecipeFulfilled(techType)) { ErrorMessage.AddWarning(Language.main.Get("DontHaveNeededIngredients")); return(false); } var itemsContainers = FindAllItemsContainersInRange(); ITechData techData = CraftData.Get(techType, false); if (techData == null) { return(false); } int i = 0; int ingredientCount = techData.ingredientCount; while (i < ingredientCount) { IIngredient ingredient = techData.GetIngredient(i); TechType techType2 = ingredient.techType; int j = 0; int amount = ingredient.amount; while (j < amount) { DestroyItemInContainers(techType2, itemsContainers); uGUI_IconNotifier.main.Play(techType2, uGUI_IconNotifier.AnimationType.To, null); j++; } i++; } return(true); }
private static void Postfix(uGUI_BlueprintEntry __instance, TechType techType) { var techData = CraftData.Get(techType); if (techData != null && techData.ingredientCount > 0) { __instance.gameObject.AddComponent <BlueprintTrackerPdaEntry>().techType = techType; } }
private static void LoadRecyclingTooltip(TechType recyclingTech) { TooltipFactoryWrapper.RegisterTech(recyclingTech); var lang = Language.main; if (lang == null) { return; } if (IsBlackListed(recyclingTech)) { var errorText = lang.Get(nonRecyclableTooltipID); LanguageWrapper.SetDefault("Tooltip_" + recyclingTech.AsString(), errorText); return; } var data = CraftData.Get(recyclingTech); if (data == null) { return; } var ings = new Dictionary <TechType, int>(); for (var i = 0; i < data.linkedItemCount; i++) { var item = data.GetLinkedItem(i); ings[item] = ings.ContainsKey(item) ? (ings[item] + 1) : 1; } var builder = new System.Text.StringBuilder(); foreach (var ing in ings) { builder.Append(lang.Get(ing.Key.AsString())); if (ing.Value > 1) { builder.Append(" (x"); builder.Append(ing.Value); builder.Append(')'); } builder.Append(", "); } if (builder.Length >= 2) { builder.Length -= 2; } var ingList = builder.ToString(); var tooltip = lang.Get(recycleTooltipID); var formated = StringUtil.FormatWithFallback(tooltip, recycleTooltip, ingList); LanguageWrapper.SetDefault("Tooltip_" + recyclingTech.AsString(), formated); }
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; } } } }
/// <summary> /// Safely accesses the crafting data from any item.<para/> /// WARNING: This method is highly dependent on mod load order. /// Make sure your mod is loading after the mod whose TechData you are trying to access. /// </summary> /// <param name="techType">The TechType whose TechData you want to access.</param> /// <returns>Returns TechData if it exists; Otherwise, returns <c>null</c>.</returns> TechData ICraftDataHandler.GetTechData(TechType techType) { if (CraftDataPatcher.CustomTechData.TryGetValue(techType, out ITechData iTechData)) { return(ConvertToTechData(iTechData)); } iTechData = CraftData.Get(techType, true); if (iTechData != null) { return(ConvertToTechData(iTechData)); } return(null); }
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; } } }
private static void LoadRecyclingData(TechType originTech, TechType recyclingTech) { if (IsBlackListed(recyclingTech)) { CraftDataWrapper.SetTechData(recyclingTech, new TechData(0, new Ingredient[0], new TechType[0])); return; } var originData = CraftData.Get(originTech); var ingredients = new Dictionary <TechType, int>(); if (originData.craftAmount > 0) { ingredients[originTech] = originData.craftAmount; } for (var i = 0; i < originData.linkedItemCount; i++) { var item = originData.GetLinkedItem(i); ingredients[item] = ingredients.ContainsKey(item) ? (ingredients[item] + 1) : 1; } var resIngs = new List <IIngredient>(); ingredients.ForEach(x => resIngs.Add(new Ingredient(x.Key, x.Value))); var linkedItems = new List <TechType>(); var isTool = IsPlayerToolWithEnergyMixin(originTech); for (var i = 0; i < originData.ingredientCount; i++) { var ing = originData.GetIngredient(i); if (isTool && IsBattery(ing.techType)) { continue; } var amount = UnityEngine.Mathf.FloorToInt(ing.amount * Config.GetYield(ing.techType)); for (var j = 0; j < amount; j++) { linkedItems.Add(ing.techType); } } CraftDataWrapper.SetTechData(recyclingTech, new TechData(0, resIngs, linkedItems)); }
private void SetTechType(TechType techType) { this.techType = techType; ITechData techData = CraftData.Get(techType, true); if (techData == null) { Logger.Error("Could not find tech data for techtype: " + techType); return; } if (Mod.Left) { mainIcon = BlueprintTrackerIcon.Create(contents.transform, null, SpriteManager.Get(techType), true, false); } else { removeButton = BlueprintTrackerRemoveButton.Create(contents.transform, techType, true, false); } icons.Clear(); for (int i = 0; i < techData.ingredientCount; ++i) { IIngredient ingredient = techData.GetIngredient(i); Atlas.Sprite sprite = SpriteManager.Get(ingredient.techType); var icon = BlueprintTrackerIcon.Create(contents.transform, ingredient, sprite, Mod.Left ? false : i == 0, Mod.Left ? i == techData.ingredientCount - 1 : false ); icons.Add(icon); } if (!Mod.Left) { mainIcon = BlueprintTrackerIcon.Create(contents.transform, null, SpriteManager.Get(techType), false, true); } else { removeButton = BlueprintTrackerRemoveButton.Create(contents.transform, techType, false, true); } }
public static bool TryGet(TechType originTech, out TechType recyclingTech) { recyclingTech = TechType.None; if (originTech == TechType.None) { return(false); } if (cache.TryGetValue(originTech, out recyclingTech)) { return(true); } var originData = CraftData.Get(originTech, true); if (originData == null) { Logger.Error($"Failed to load ITechData for TechType '{originTech}'."); return(false); } recyclingTech = techBase + cache.Count; cache[originTech] = recyclingTech; TechTypeExtensionsWrapper.Link(recyclingTech, techKeyPrefix + recyclingTech); if (Config.IsBlacklisted(originTech)) { blacklist.Add(recyclingTech); } KnownTechWrapper.AddDefault(recyclingTech); LoadRecyclingData(originTech, recyclingTech); LoadRecyclingSprite(originTech, recyclingTech); LoadRecyclingPrefab(originTech, recyclingTech); LoadRecyclingText(originTech, recyclingTech); LoadRecyclingTooltip(recyclingTech); return(true); }
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); } }
public static bool Prefix(Trashcan __instance) { if (__instance.biohazard) { return(true); } __instance.storageContainer.hoverText = "Recycling Bin"; __instance.storageContainer.storageLabel = "Recycling Bin"; __instance.storageContainer.container._label = "Recycling Bin"; inventoryItems = new List <InventoryItem>(); forcePickupItems = new List <Pickupable>(); foreach (Trashcan.Waste waste in __instance.wasteList) { InventoryItem item = waste.inventoryItem; if (item is null) { continue; } TechType techType = item.item.GetTechType(); ITechData techData = CraftData.Get(techType); bool inputcheck = GameInput.GetButtonHeld(GameInput.Button.Deconstruct); if (!inputcheck && techType != TechType.Titanium && Main.BatteryCheck(item.item) && techData != null) { if (CheckRequirements(__instance, item.item, techData)) { for (int i = 0; i < techData.ingredientCount; i++) { IIngredient ingredient = techData.GetIngredient(i); for (int j = 0; j < ingredient.amount; j++) { GameObject gameObject = CraftData.InstantiateFromPrefab(ingredient.techType, false); if (gameObject.GetComponent <LiveMixin>() != null) { GameObject.Destroy(gameObject); break; } gameObject.SetActive(true); Pickupable pickupable = gameObject.GetComponent <Pickupable>(); pickupable.Pickup(false); forcePickupItems.Add(pickupable); } } break; } } else { if (inputcheck) { inventoryItems.Add(item); } else { forcePickupItems.Add(item.item); } break; } } forcePickupItems.ForEach((rejectedItem) => Inventory.main.ForcePickup(rejectedItem)); inventoryItems.ForEach((item) => UnityEngine.Object.Destroy(item.item.gameObject)); return(false); }