// RIP AZIR void AssignShopItems(DefaultItemBase.ItemTypes Type) { // Finds the refs XMLParser XML = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <XMLParser>(); ItemTypeFinder TypeFinder = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <ItemTypeFinder>(); // Loop through all the XML for (int i = 0; i < XML.items.Count; i++) { // if its a seed if (XML.items.ElementAt(i).Value.GetType() == Type) { // Generate a random number to see if that seed will be in the shop int RandomChance = UnityEngine.Random.Range(0, 100); if (Type == DefaultItemBase.ItemTypes.Tool || RandomChance > 50) { /*Wanna get the gameobject we will put the component on*/ GameObject childObject = Instantiate(ShopSlot) as GameObject; if (Type == DefaultItemBase.ItemTypes.Seed) { childObject.transform.parent = SeedParentShopSlot.transform; } else { childObject.transform.parent = ToolParentShopSlot.transform; } /******************************************/ /* Get the image so we can set the sprite to appear there */ Image Image = childObject.transform.Find("ImageSlot").transform.Find("ItemImage").GetComponent <Image>(); Image.sprite = XML.items.ElementAt(i).Value.GetSpriteImage(); /******************************************/ // Sets the title TextMeshProUGUI TitleText = childObject.transform.Find("Title").GetComponent <TextMeshProUGUI>(); TitleText.text = XML.items.ElementAt(i).Value.GetName(); // Sets the price TextMeshProUGUI PriceText = childObject.transform.Find("Price").GetComponent <TextMeshProUGUI>(); PriceText.text = "Price: " + XML.items.ElementAt(i).Value.GetSellPrice().ToString(); // Set the desctext TextMeshProUGUI DescText = childObject.transform.Find("Description").GetComponent <TextMeshProUGUI>(); DescText.text = XML.items.ElementAt(i).Value.GetDesc(); // Find what item we are wanting to use and set it up TypeFinder.TyepFinder(i, childObject).SetUpThisItem(XML.items.ElementAt(i).Value.bItemType, XML.items.ElementAt(i).Value.bName, XML.items.ElementAt(i).Value.bAmount, XML.items.ElementAt(i).Value.bStackable, XML.items.ElementAt(i).Value.bSrcImage, XML.items.ElementAt(i).Value.bSoundEffect, XML.items.ElementAt(i).Value.bTile, XML.items.ElementAt(i).Value.bPrefab, XML.items.ElementAt(i).Value.bSellPrice, XML.items.ElementAt(i).Value.bCustomData, XML.items.ElementAt(i).Value.GetDesc()); } } } }
// Start is called before the first frame update //private void Awake() //{ // GetCamera(); //} void Start() { // RIP AZIR Selected = new bool[10]; XML = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <XMLParser>(); GetCamera(); tool = new ItemBase(); GetCamera(); CoolDown = 0.0f; //for (int i = 0; i < 4; i++) {ItemBase BasicItem = gameObject.AddComponent<ItemBase>() as ItemBase; AddItem(BasicItem); } Debug.Log(ItemList.Length); cInventory = this.GetComponent <InventoryClass>(); cHotBar = this.GetComponent <HotBarClass>(); TypeFinder = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <ItemTypeFinder>(); if (SceneManager.GetActiveScene().name != "LoadSaveScene") { Resize(10); for (int i = 0; i < XML.items.Count; i++) { if (XML.items.ElementAt(i).Value.bName == "Hoe" || XML.items.ElementAt(i).Value.bName == "Water Bucket" || XML.items.ElementAt(i).Value.bName == "Scythe") { ItemBase BasicItem = new ItemBase(); // Get the object the component will be on and give it a name GameObject SubGameObject = new GameObject(XML.items.ElementAt(i).Value.bName); SubGameObject.transform.parent = ToolItems.transform; // Find the type of the item and set it up, after add it to the dictionary. BasicItem = TypeFinder.TyepFinder(i, SubGameObject); BasicItem.SetUpThisItem(XML.items.ElementAt(i).Value.bItemType, XML.items.ElementAt(i).Value.bName, XML.items.ElementAt(i).Value.bAmount, XML.items.ElementAt(i).Value.bStackable, XML.items.ElementAt(i).Value.bSrcImage, XML.items.ElementAt(i).Value.bSoundEffect, XML.items.ElementAt(i).Value.bTile, XML.items.ElementAt(i).Value.bPrefab, XML.items.ElementAt(i).Value.bSellPrice, XML.items.ElementAt(i).Value.bCustomData, XML.items.ElementAt(i).Value.GetDesc()); AddItem(BasicItem); } } } UpdateUI(); // }
/*RIP AZIR*/ public void BuyShopItem() { XMLParser XML = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <XMLParser>(); MoneyClass PlayerMoney = GameObject.FindGameObjectWithTag("Player").GetComponent <MoneyClass>(); InventoryClass cInventory = GameObject.FindGameObjectWithTag("InventoryManager").GetComponent <InventoryClass>(); ItemBase Item = new ItemBase(); ItemBase NewItem = gameObject.GetComponentInParent <ItemBase>(); ItemTypeFinder TypeFinder = GameObject.FindGameObjectWithTag("ItemManager").GetComponent <ItemTypeFinder>(); // Get the object the component will be on and give it a name GameObject SubGameObject = new GameObject(NewItem.bName); SubGameObject.transform.parent = cInventory.ToolItems.transform; // If the player has enough gold if (PlayerMoney.GetMoney() >= NewItem.GetSellPrice()) { // If it has the item and is stackable if (cInventory.HasItem(NewItem.GetName()) && NewItem.GetStackable()) { cInventory.AddAmount(NewItem.GetName(), NewItem.GetAmount()); PlayerMoney.SetMoney(PlayerMoney.GetMoney() - NewItem.GetSellPrice()); } else { // Find the type of the item and set it up, after add it to the dictionary. Item = TypeFinder.ItemTyepFinder(NewItem, SubGameObject); Item.SetUpThisItem(NewItem.bItemType, NewItem.bName, NewItem.bAmount, NewItem.bStackable, NewItem.bSrcImage, NewItem.bSoundEffect, NewItem.bTile, NewItem.bPrefab, NewItem.bSellPrice, NewItem.bCustomData, NewItem.GetDesc()); cInventory.AddItem(Item); PlayerMoney.SetMoney(PlayerMoney.GetMoney() - Item.GetSellPrice()); } } cInventory.UpdateUI(); }