public void AssignBuilding(IBuildable newBuilding) { assignedBuilding = newBuilding; GetComponent<Image>().sprite = assignedBuilding.GetIcon(); if (!newBuilding.IsBuilt()) { bool canBuild = false; List<InventoryItem> usedLocalItems = new List<InventoryItem>(); //if (currentSelectedMember.CheckEnoughFatigue(totalBuildFatigueCost)) { //Prep used item list and required item count dict Dictionary<CraftRecipe.CraftableItems, int> availableIngredients = new Dictionary<CraftRecipe.CraftableItems, int>(assignedBuilding.GetMaterials()); //Run a check through local inventory and member personal inventory, to see if foreach (CraftRecipe.CraftableItems ingredientKey in assignedBuilding.GetMaterials().Keys) { foreach (InventoryItem localItem in MapManager.main.GetTown().GetStashedItems())//InventoryScreenHandler.mainISHandler.selectedMember.currentRegion.GetStashedItems()) { if (localItem.GetType() == CraftRecipe.GetItemInstance(ingredientKey).GetType()) { availableIngredients[ingredientKey] = availableIngredients[ingredientKey] - 1; usedLocalItems.Add(localItem); if (availableIngredients[ingredientKey] == 0) break; } } } bool enoughIngredients = true; foreach (int remainingRequiredCount in availableIngredients.Values) { if (remainingRequiredCount > 0) { enoughIngredients = false; break; } } canBuild = (enoughIngredients && TownManager.main.money >= assignedBuilding.GetBuildCost()); } //Refresh button if (canBuild) { GetComponent<Button>().interactable = true; //Add button effect GetComponent<Button>().onClick.RemoveAllListeners(); GetComponent<Button>().onClick.AddListener( () => ButtonClicked(usedLocalItems)); } else GetComponent<Button>().interactable = false; } else { GetComponent<Button>().onClick.RemoveAllListeners(); GetComponent<Button>().interactable = true; } }