// Updates the text fields and images to the information provided by the recipie public void updateInfo(GameObject caller) { ItemRecipie details = caller.GetComponent <ItemRecipie>(); for (int i = 0; i < list.Count; i = i + 4) { switch (i) { case 0: { if (details.item_ingredient1_sprite) { list[i].GetComponent <Text>().text = details.item_ingredient1_name; list[i + 1].GetComponent <Image>().enabled = true; list[i + 1].GetComponent <Image>().sprite = details.item_ingredient1_sprite; list[i + 2].GetComponent <Text>().text = "" + details.item_ingredient1_count; list[i + 3].GetComponent <Text>().text = "" + player.getResourceAmount((int)details.item_ingredient1); } break; } case 4: { if (details.item_ingredient2_sprite) { list[i].GetComponent <Text>().text = details.item_ingredient2_name; list[i + 1].GetComponent <Image>().enabled = true; list[i + 1].GetComponent <Image>().sprite = details.item_ingredient2_sprite; list[i + 2].GetComponent <Text>().text = "" + details.item_ingredient2_count; list[i + 3].GetComponent <Text>().text = "" + player.getResourceAmount((int)details.item_ingredient2); } break; } case 8: { if (details.item_ingredient3_sprite) { list[i].GetComponent <Text>().text = details.item_ingredient3_name; list[i + 1].GetComponent <Image>().enabled = true; list[i + 1].GetComponent <Image>().sprite = details.item_ingredient3_sprite; list[i + 2].GetComponent <Text>().text = "" + details.item_ingredient3_count; list[i + 3].GetComponent <Text>().text = "" + player.getResourceAmount((int)details.item_ingredient3); } break; } } } }
public static EnergyRecipe use(this Energy e, ItemRecipie ir) //TODO generalize Recipie { if (producing == null) { initList(); } EnergyRecipe longest = null; foreach (EnergyRecipe er in producing[(int)e]) { if (longest == null || er.timeLeft > longest.timeLeft) { longest = er; } } return(longest); }
// The crafting function public bool craft(ItemRecipie details, GameObject item) { PlayerController controller = player.GetComponent <PlayerController>(); // Get player resource counts and subtract from requirement amount int ingredient1 = controller.getResourceAmount((int)details.item_ingredient1) - details.item_ingredient1_count; int ingredient2 = controller.getResourceAmount((int)details.item_ingredient2) - details.item_ingredient2_count; int ingredient3 = controller.getResourceAmount((int)details.item_ingredient3) - details.item_ingredient3_count; // If any one of the counts is negative, crafting is not possible if (ingredient1 >= 0 && ingredient2 >= 0 && ingredient3 >= 0) { // Add the item to the inventory according to the yield amount for (int i = 0; i < details.item_yield_amount; i++) { controller.inventory.addItem(item.GetComponent <Item>()); } // Subtract the resources from the player counts controller.subtractResourceAmount((int)details.item_ingredient1, details.item_ingredient1_count); controller.subtractResourceAmount((int)details.item_ingredient2, details.item_ingredient2_count); controller.subtractResourceAmount((int)details.item_ingredient3, details.item_ingredient3_count); // If the item crafted is ammo and the same type as weapon held, update the HUD counter if (details.item_type == ItemType.AMMO && details.item.GetComponent <Item>().ammo_type == controller.getWeapon.GetComponentInChildren <Weapon>().getAmmoType) { Weapon weaponHeld = controller.getWeapon.GetComponentInChildren <Weapon>(); HudController hud = GameObject.FindGameObjectWithTag("HUD").GetComponent <HudController>(); weaponHeld.updateAmmoCounts(weaponHeld.RoundsInClip, weaponHeld.TotalRounds + details.item_yield_amount); hud.updateAmmoText(weaponHeld.RoundsInClip, weaponHeld.TotalRounds); } return(true); } else { return(false); } }
// Use this for initialization void Start() { List <VerticalLayoutGroup> cols = new List <VerticalLayoutGroup>(GetComponentsInChildren <VerticalLayoutGroup>()); tools = cols.Find((VerticalLayoutGroup obj) => { return(obj.gameObject.name.Equals("Tools")); }); energy = cols.Find((VerticalLayoutGroup obj) => { return(obj.gameObject.name.Equals("Energy")); }); refine = cols.Find((VerticalLayoutGroup obj) => { return(obj.gameObject.name.Equals("Refine")); }); raw = cols.Find((VerticalLayoutGroup obj) => { return(obj.gameObject.name.Equals("Raw")); }); ItemRecipie ax = Instantiate(temp, tools.transform).GetComponent <ItemRecipie>(); ax.name = "Axe"; ax.item = Item.Axe; ax.recipie = new Recipie(20, 10, new Item[] { Item.Wood, Item.Iron }, new int[] { 2, 8 }); //ax.init (); ItemRecipie pick = Instantiate(temp, tools.transform).GetComponent <ItemRecipie>(); pick.name = "Pickaxe"; pick.item = Item.Pickaxe; pick.recipie = new Recipie(20, 10, new Item[] { Item.Wood, Item.Iron }, new int[] { 2, 8 }); ItemRecipie shovel = Instantiate(temp, tools.transform).GetComponent <ItemRecipie>(); shovel.name = "shovel"; shovel.item = Item.Shovel; shovel.recipie = new Recipie(20, 10, new Item[] { Item.Wood, Item.Iron }, new int[] { 2, 8 }); ItemRecipie ir = Instantiate(temp, energy.transform).GetComponent <ItemRecipie>(); EnergyRecipe campfire = ir.gameObject.AddComponent <EnergyRecipe>(); GameObject.Destroy(ir); campfire.name = "Light Bonfire"; campfire.energy = Energy.Fire; campfire.recipie = new Recipie(0, 10, new Item[] { Item.Wood }, new int[] { 3 }); ItemRecipie wood = Instantiate(temp, raw.transform).GetComponent <ItemRecipie>(); wood.name = "Chop Tree"; wood.item = Item.Wood; wood.recipie = new Recipie(1, 1, new Item[] { Item.Axe }, new int[] { 1 }); ItemRecipie ore = Instantiate(temp, raw.transform).GetComponent <ItemRecipie>(); ore.name = "Mine Ore"; ore.item = Item.Ore; ore.recipie = new Recipie(1, 1, new Item[] { Item.Pickaxe }, new int[] { 1 }); ItemRecipie clay = Instantiate(temp, raw.transform).GetComponent <ItemRecipie>(); clay.name = "Dig Clay"; clay.item = Item.Shovel; clay.recipie = new Recipie(1, 1, new Item[] { Item.Shovel }, new int[] { 1 }); ItemRecipie charcoal = Instantiate(temp, refine.transform).GetComponent <ItemRecipie>(); charcoal.name = "Char Wood"; charcoal.item = Item.Charcoal; charcoal.recipie = new Recipie(1, 1.5f, new Item[] { Item.Wood }, new int[] { 1 }, new Energy[] { Energy.Fire }); ItemRecipie iron = Instantiate(temp, refine.transform).GetComponent <ItemRecipie>(); iron.name = "Smelt Ore"; iron.item = Item.Iron; iron.recipie = new Recipie(2, 3, new Item[] { Item.Ore }, new int[] { 2 }, new Energy[] { Energy.Fire }); ItemRecipie brick = Instantiate(temp, refine.transform).GetComponent <ItemRecipie>(); brick.name = "Bake Brick"; brick.item = Item.Brick; brick.recipie = new Recipie(1, 2, new Item[] { Item.Clay }, new int[] { 1 }, new Energy[] { Energy.Fire }); }