//Buy item private void BuyItem(GameObject item) { int itemId = item.GetComponent <IDScript>().id; int itemType = -1; ShopItem shopItem = null; if (item.tag == "Computer") { shopItem = ComputerList.FindItem(itemId); itemType = 0; } else if (item.tag == "GraphicCard") { shopItem = GraphicCardList.FindItem(itemId); itemType = 1; } else if (item.tag == "Asic") { shopItem = AsicList.FindItem(itemId); itemType = 2; } if (shopItem != null) { if (gameStatManager.IsEnoughCash(shopItem.GetPrice())) { gameStatManager.DeductCash(shopItem.GetPrice()); gameStatManager.AddSpeed(shopItem.GetSpeed()); gameStatManager.AddWatt(shopItem.GetWatt()); if (itemType == 0) { gameStatManager.AddComputer(itemId); } else if (itemType == 1) { gameStatManager.AddGrahpicCard(itemId); } else if (itemType == 2) { gameStatManager.AddAsic(itemId); } else { Debug.Log("Error: [ItemContainerManager][BuyItem][Cannot get itemType]"); } statusText.color = Color.green; statusText.text = "Model [" + shopItem.GetModel() + "] purchase successful!"; } else { statusText.color = Color.red; statusText.text = "Not enough cash to buy model [" + shopItem.GetModel() + "]"; } } }
private void ProcessItemList() { computerList = gameStatManager.GetComputerList(); graphicCardList = gameStatManager.GetGraphicCardList(); asicList = gameStatManager.GetAsicList(); //Initialize computerCount = new Dictionary <ShopItem, int>(); graphicCardCount = new Dictionary <ShopItem, int>(); asicCount = new Dictionary <ShopItem, int>(); //Computer foreach (int item in computerList) { Computer computer = ComputerList.FindItem(item); if (computerCount.ContainsKey(computer)) { //Already contains model computerCount[computer]++; } else { //No current model computerCount.Add(computer, 1); } } //Graphic card foreach (int item in graphicCardList) { GraphicCard graphicCard = GraphicCardList.FindItem(item); if (graphicCardCount.ContainsKey(graphicCard)) { //Already contains model graphicCardCount[graphicCard]++; } else { //No current model graphicCardCount.Add(graphicCard, 1); } } //Asic foreach (int item in asicList) { Asic asic = AsicList.FindItem(item); if (asicCount.ContainsKey(asic)) { //Already contains model asicCount[asic]++; } else { //No current model asicCount.Add(asic, 1); } } }