Cleaned up project with better structure.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
public class GameResource
|
||||
{
|
||||
public string name;
|
||||
public ItemData item;
|
||||
|
||||
private int currentAmount;
|
||||
private int maxAmount;
|
||||
private bool isEndless;
|
||||
private float extractionSpeed;
|
||||
private double timeSinceLastExtraction;
|
||||
|
||||
public GameResource(string name)
|
||||
{
|
||||
this.name = name;
|
||||
maxAmount = GameData.rand.Next(1000, 10000);
|
||||
currentAmount = maxAmount;
|
||||
isEndless = false;
|
||||
extractionSpeed = 1f;
|
||||
item = GameData.availableItems[name];
|
||||
}
|
||||
|
||||
public bool Extract(double delta)
|
||||
{
|
||||
timeSinceLastExtraction += delta;
|
||||
if (timeSinceLastExtraction < extractionSpeed) return false;
|
||||
|
||||
timeSinceLastExtraction = 0;
|
||||
if (isEndless) return true;
|
||||
|
||||
if (currentAmount > 0)
|
||||
{
|
||||
currentAmount--;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanExtract()
|
||||
{
|
||||
return (isEndless || currentAmount > 0) && GameData.availableResearch[item.Research].state == ResearchState.RESEARCHED;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user