public static List <ItemRecipe> GetUsages(this Item item) { List <ItemRecipe> result = new List <ItemRecipe>(); foreach (Terraria.Recipe recipe in Main.recipe.Where(x => x.requiredItem.Select(y => y.type).Contains(item.type))) { ItemRecipe itemRecipe = new ItemRecipe(); foreach (Item ingredient in recipe.requiredItem) { if (!ingredient.IsAir) { itemRecipe.AddIngredient(ingredient.type, ingredient.stack); } } foreach (int tile in recipe.requiredTile) { if (tile > 0) { itemRecipe.AddTile(tile); } } itemRecipe.createItems.Add(recipe.createItem); itemRecipe.anyIronBar = recipe.anyIronBar; itemRecipe.anyFragment = recipe.anyFragment; itemRecipe.anyWood = recipe.anyWood; itemRecipe.anySand = recipe.anySand; itemRecipe.anyPressurePlate = recipe.anyPressurePlate; result.Add(itemRecipe); } result.AddRange(TheOneLibrary.Instance.recipes.Where(x => x.requiredItem.Contains(item))); return(result); }
public void DisplayRecipe(ItemType item, ItemRecipe recipe) { if (itemIcon != null) { itemIcon.sprite = item.Icon; } if (itemName != null) { itemName.text = item.Name; } myItem = item; myRecipe = recipe; // Clean ingredients area foreach (Transform child in ingredientsArea) { Destroy(child.gameObject); } foreach (ItemStack stack in recipe.GetRequiredItems()) { var stackDisplay = GameObject.Instantiate(itemStackDisplayerPrefab, ingredientsArea) as ItemStackDisplayer; stackDisplay.DisplayStack(stack); } }
public override void AddRecipes() { ItemRecipe recipe = new ItemRecipe(); recipe.AddIngredient(ItemID.CopperBar, 5); recipe.AddIngredient(ItemID.StoneBlock, 100); recipe.SetResult(ItemID.Abeemination); recipe.AddRecipe(); }
private void UseRecipe(ItemRecipe pItem, InventoryItemStack pStack) { if (CraftingManager.Instance.TeachRecipe(pItem.Recipe.UniqueName)) { if (pItem.Consumable == true) { PlayerInventory.RemoveFromStack(pStack, 1); } } }
void OnEnable() { for (int i = 0; i < playerInventoryDefaults.itemRecipes.Count; i++) { // Add default items to inventory ItemRecipe itemRecipe = playerInventoryDefaults.itemRecipes[i]; int itemCount = playerInventoryDefaults.itemCounts[i]; Item newItem = new Item(itemRecipe, itemCount); consumables.Add(newItem); } }
public static GameObject Create(string name) { ItemRecipe recipe = Resources.Load <ItemRecipe>("Recipes/ItemRecipes/" + name); if (recipe == null) { Debug.LogError("No Unit Recipe for name: " + name); return(null); } return(Create(recipe)); }
//BaseResource CreateItem(BaseResource finalItem) //{ // BaseResource newItem = finalItem; // //Do thing with item, add to inventory? // cartComponent.GetComponent<InventoryComponent>().AddtoInventroy(newItem, cartComponent.GetComponent<InventoryComponent>()); // return newItem; //} public bool CanCraft(ItemRecipe currentRecipe) { for (int i = 0; i < recipeList.Count; i++) { if (recipeList[i].finalItem == currentRecipe.finalItem) { //return CraftFromRecipe(allRecipes[i]); return(true); } } return(false); }
public static GameObject Create(ItemRecipe recipe) { GameObject obj = InstantiatePrefab("Prefabs/Equipment/" + recipe.Name); obj.name = recipe.name; obj.AddComponent <Equippable>(); Equippable item = obj.GetComponent <Equippable>(); item.defaultSlots = recipe.defaultSlots; item.secondarySlots = recipe.secondarySlots; return(obj); }
public ItemRecipe GetCopy(int index) { ItemRecipe ir = new ItemRecipe(); ir.outcome = new ItemShort(this.recipe[index].outcome.GetData(new Hashtable())); ir.useFormula = this.recipe[index].useFormula; ir.formulaID = this.recipe[index].formulaID; ir.ingredient = new ItemShort[this.recipe[index].ingredient.Length]; for(int i=0; i<this.recipe[index].ingredient.Length; i++) { ir.ingredient[i] = new ItemShort(this.recipe[index].ingredient[i].GetData(new Hashtable())); } return ir; }
public bool BuyItem(ItemRecipe item, int buyAmount) { int itemCost = item.ItemCost(buyAmount); if (money >= itemCost) { money -= itemCost; UpdateCount(item, buyAmount); return(true); } else { return(false); } }
public void CraftItem(long playerid, Item[] ingredients) { ItemRecipe recipe = context.GetModule <ItemModule>().GetRecipe(ingredients.Select(i => i.ID).ToArray()); if (recipe != null) { foreach (RecipeIngredient item in recipe.Ingredients.Where(i => i.Consumed)) { RemoveItem(playerid, item.Item, 1); } } else { foreach (Item item in ingredients) { RemoveItem(playerid, item.ID, 1); } } User user = context.GetModule <UserModule>().GetUser(playerid); Item targetitem = recipe != null?context.GetModule <ItemModule>().GetItem(recipe.ItemID) : context.GetModule <ItemModule>().GetItem("Garbage"); if (targetitem != null) { AddItem(playerid, targetitem.ID, 1, true); RPGMessageBuilder message = context.GetModule <RPGMessageModule>().Create(); message.User(user).Text(" has created ").Item(targetitem).Text(" out of "); for (int i = 0; i < ingredients.Length; ++i) { if (i == ingredients.Length - 1) { message.Text(" and "); } else if (i > 0) { message.Text(", "); } message.Item(ingredients[i]); } message.Text(".").Send(); } }
public List <Item> GetAvailableItems(ItemRecipe recipe) { var result = new List <Item>(); var tmpRecipe = recipe.GetItems().ToList(); foreach (var item in _inventory.Items) { if (item == null) { continue; } if (!tmpRecipe.Contains(item.ItemType)) { continue; } result.Add(item); tmpRecipe.Remove(item.ItemType); } return(result); }
public int UpdateCount(ItemRecipe item, int itemAmount) { for (int i = 0; i < consumables.Count; i++) { Item consumable = consumables[i]; if (item.itemName == consumable.itemName) { consumable.UpdateCount(itemAmount); return(consumable.count); } } //usually, item.itemcountrange.minvalue will be 0. if (itemAmount > item.itemCountRange.minValue) { //the "item" in New Item("item", itemAmount), is a reference to "ItemRecipe item" Item newItem = new Item(item, itemAmount); consumables.Add(newItem); } return(-1); }
public void PopulateRecipe() { gridIngredients.Clear(); gridResults.Clear(); ItemRecipe currentRecipe = allRecipes.Any() ? allRecipes.Where(x => x.requiredTiles.IsEqual(tiles[currentTileIndex])).ToList()[currentRecipeIndex] : null; if (currentRecipe != null) { textRecipe.SetText($"{currentRecipeIndex + 1}/{allRecipes.Count(x => x.requiredTiles.IsEqual(tiles[currentTileIndex]))}"); for (int i = 0; i < currentRecipe.requiredItem.Count; i++) { UIIngredient ing = new UIIngredient(i, currentRecipe.requiredItem[i]); gridIngredients.Add(ing); } for (int i = 0; i < currentRecipe.createItems.Count; i++) { UIIngredient ing = new UIIngredient(i, currentRecipe.createItems[i]); gridResults.Add(ing); } } }
public static ItemRecipe[] Add(ItemRecipe n, ItemRecipe[] list) { ArrayList tmp = new ArrayList(); foreach(ItemRecipe str in list) tmp.Add(str); tmp.Add(n); return tmp.ToArray(typeof(ItemRecipe)) as ItemRecipe[]; }
public RecipeTag(ItemRecipe recipe) { Internal = recipe; }
// -1 is the default value, and if it is at -1, that means no count was passed in. public Item(ItemRecipe recipe, int count = -1) { this.recipe = recipe; this.count = count == -1 ? recipe.itemCountRange.defaultValue : count; }
public static ItemRecipe[] Remove(int index, ItemRecipe[] list) { ArrayList tmp = new ArrayList(); foreach(ItemRecipe str in list) tmp.Add(str); tmp.RemoveAt(index); return tmp.ToArray(typeof(ItemRecipe)) as ItemRecipe[]; }
public void LoadData() { ArrayList data = XMLHandler.LoadXML(dir+filename); if(data.Count > 0) { foreach(Hashtable entry in data) { if(entry[XMLHandler.NODE_NAME] as string == ItemRecipeData.ITEMRECIPES) { if(entry.ContainsKey(XMLHandler.NODES)) { ArrayList subs = entry[XMLHandler.NODES] as ArrayList; icon = new string[subs.Count]; recipe = new ItemRecipe[subs.Count]; foreach(Hashtable val in subs) { if(val[XMLHandler.NODE_NAME] as string == ItemRecipeData.ITEMRECIPE) { int i = int.Parse((string)val["id"]); icon[i] = ""; recipe[i] = new ItemRecipe(); recipe[i].outcome.SetData(val); recipe[i].ingredient = new ItemShort[int.Parse((string)val["ingredients"])]; if(val.ContainsKey("formula")) { recipe[i].useFormula = true; recipe[i].formulaID = int.Parse((string)val["formula"]); } ArrayList s = val[XMLHandler.NODES] as ArrayList; foreach(Hashtable ht in s) { this.LoadLanguages(ht, i, subs.Count); if(ht[XMLHandler.NODE_NAME] as string == ItemRecipeData.INGREDIENT) { recipe[i].ingredient[int.Parse((string)ht["id"])] = new ItemShort(ht); } } } } } } } } }