68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
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 static GameResource FromSaveData(ResourceSaveData saveData)
|
|
{
|
|
GameResource resource = new GameResource(saveData.Name);
|
|
resource.currentAmount = saveData.CurrentAmount;
|
|
resource.maxAmount = saveData.MaxAmount;
|
|
resource.isEndless = saveData.IsEndless;
|
|
resource.extractionSpeed = saveData.ExtractionSpeed;
|
|
resource.timeSinceLastExtraction = saveData.TimeSinceLastExtraction;
|
|
return resource;
|
|
}
|
|
|
|
public ResourceSaveData CreateSaveData()
|
|
{
|
|
return new ResourceSaveData
|
|
{
|
|
Name = name,
|
|
CurrentAmount = currentAmount,
|
|
MaxAmount = maxAmount,
|
|
IsEndless = isEndless,
|
|
ExtractionSpeed = extractionSpeed,
|
|
TimeSinceLastExtraction = timeSinceLastExtraction
|
|
};
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|