/// <summary> /// build this at the indicated location. /// </summary> /// <param name="at"></param> /// <param name="buildingMaterial">object being used in hand to build this.</param> /// <returns>true game object if successful</returns> public GameObject ServerBuild(SpawnDestination at, BuildingMaterial buildingMaterial) { var stackable = buildingMaterial.GetComponent <Stackable>(); if (stackable != null) { if (stackable.Amount < cost) { Logger.LogWarningFormat("Server logic error. " + "Tried building {0} with insufficient materials in hand ({1})." + " Build will not be performed.", Category.Construction, name, buildingMaterial); return(null); } stackable.ServerConsume(cost); } else { if (cost > 1) { Logger.LogWarningFormat("Server logic error. " + "Tried building {0} with insufficient materials in hand ({1})." + " Build will not be performed.", Category.Construction, name, buildingMaterial); return(null); } Inventory.ServerDespawn(buildingMaterial.GetComponent <Pickupable>().ItemSlot); } return(Spawn.ServerPrefab(prefab, at, spawnAmount)?.GameObject); }
/// <summary> /// returns true iff this entry can be built with the buildingMaterial /// </summary> /// <param name="buildingMaterial"></param> /// <returns></returns> public bool CanBuildWith(BuildingMaterial buildingMaterial) { int heldAmount = 0; var stackable = buildingMaterial.GetComponent <Stackable>(); if (stackable != null) { heldAmount = stackable.Amount; } else { heldAmount = 1; } return(heldAmount >= Cost); }