public bool AddMaterials(float materialID, int amountToAdd) { if (amountToAdd <= 0) { Debug.LogError("Amount of materials to add cannot be 0 or less."); return(false); } else { if (MaterialIsAvailable(materialID)) { WoodshopMaterialCount w = AvailableMaterials.Find(x => x.MaterialID == materialID); int index = AvailableMaterials.IndexOf(w); w.Amount += amountToAdd; AvailableMaterials.Insert(index, w); } else { WoodshopMaterialCount newCount = new WoodshopMaterialCount { MaterialID = materialID, Amount = amountToAdd }; AvailableMaterials.Add(newCount); } return(true); } }
public bool RemoveMaterial(float materialID, int amountToRemove) { if (amountToRemove <= 0) { Debug.LogError("Amount of materials to remove cannot be 0 or less."); return(false); } else { if (MaterialIsAvailable(materialID)) { if (GetMaterialCount(materialID) - amountToRemove < 0) { throw new Exception("You don't have enough of this item (ID: " + materialID + ")"); } else { WoodshopMaterialCount w = AvailableMaterials.Find(x => x.MaterialID == materialID); w.Amount -= amountToRemove; if (w.Amount == 0) { AvailableMaterials.Remove(w); } return(true); } } else { throw new Exception("You don't have enough of this item (ID: " + materialID + ")"); } } }
public int GetMaterialCount(float materialID) { int count = 0; if (MaterialIsAvailable(materialID)) { WoodshopMaterialCount w = AvailableMaterials.Find(x => x.MaterialID == materialID); count = w.Amount; } return(count); }
public bool MaterialIsAvailable(float materialID) { WoodshopMaterialCount w = AvailableMaterials.Find(x => x.MaterialID == materialID); return(w != null); }