public bool addMaterial(MaterialId id, int count) { if (materialHolded == null) { materialHolded = new MaterialHolder(id, count); } else if (materialHolded.getMaterialId() == id) { materialHolded.Add(count); return(true); } return(false); }
public MaterialHolder takeMaterial(MaterialHolder holded, int grabCount) { if (materialHolded != null && (holded == null || holded.getMaterialId() == materialHolded.getMaterialId())) { int maxPossible = materialHolded.Substract(grabCount); MaterialId mid = materialHolded.getMaterialId(); if (maxPossible != grabCount) { materialHolded = null; } return(new MaterialHolder(mid, maxPossible)); } return(null); }
public MaterialHolder(MaterialId materialId, int count) { this.materialId = materialId; this.count = count; }