private void findAndSellShopItem(SellShopItem item, string Name) { money.GetComponent <Money>().addMoney(item.cost * item.quantity); int numberDeleted = 0; List <GameObject> playerInventory = FindObjectOfType <Inventory>().slots; foreach (GameObject playerInventorySlot in playerInventory) { if (playerInventorySlot.GetComponent <InventorySlot>().item != null) { if (playerInventorySlot.GetComponent <InventorySlot>().item.GetComponent <rsrce>().nameOfResource == Name) { var child = playerInventorySlot.transform.GetChild(0); child.GetComponent <DragDrop>().destroy(); playerInventorySlot.GetComponent <InventorySlot>().RemoveItem(); numberDeleted++; if (numberDeleted == item.quantity) { return; } } } } List <Planet> homePlanets = FindObjectOfType <Home>().homePlanets; foreach (Planet planet in homePlanets) { if (planet != null) { for (int i = 0; i < 3; i++) { if (planet.GetComponent <HomePlanet>().items[i].resource != null) { if (planet.GetComponent <HomePlanet>().items[i].resource.GetComponent <rsrce>().nameOfResource == Name) { if (planet.GetComponent <HomePlanet>().items[i].quantity > (item.quantity - numberDeleted)) { planet.GetComponent <HomePlanet>().removeItem(i, item.quantity - numberDeleted); numberDeleted += item.quantity; } else { numberDeleted += planet.GetComponent <HomePlanet>().items[i].quantity; planet.GetComponent <HomePlanet>().removeItem(i, planet.GetComponent <HomePlanet>().items[i].quantity); } if (numberDeleted == item.quantity) { return; } home.GetComponent <Home>().UpdatePlanetHud(); } } } } } }
public void sellShopResultOf(SellShopItem item, bool isTrader) { if (FindObjectOfType <ResourceInventory>().checkForItemAndRemove(item.name, item.quantity) && !isTrader) { findAndSellShopItem(item, item.name); return; } //if friendly trader List <GameObject> playerInventory = FindObjectOfType <Inventory>().slots; int numberFound = 0; foreach (GameObject playerInventorySlot in playerInventory) { if (playerInventorySlot.GetComponent <InventorySlot>().item != null) { if (playerInventorySlot.GetComponent <InventorySlot>().item.GetComponent <rsrce>().nameOfResource == item.name) { numberFound++; } } } if (numberFound >= item.quantity) { int numberDeleted = 0; foreach (GameObject playerInventorySlot in playerInventory) { if (playerInventorySlot.GetComponent <InventorySlot>().item != null) { if (playerInventorySlot.GetComponent <InventorySlot>().item.GetComponent <rsrce>().nameOfResource == item.name) { var child = playerInventorySlot.transform.GetChild(0); child.GetComponent <DragDrop>().destroy(); playerInventorySlot.GetComponent <InventorySlot>().RemoveItem(); numberDeleted++; if (numberDeleted == item.quantity) { return; } } } } } }
public void ItemSold(SellShopItem item) { ShopManager.GetComponent <ShopManager>().sellShopResultOf(item, isTrader); }