8170b700b2
Features: Sacrifice-Node, Maintain-Node, Options for screen type, lightcolor and soundvolume, tied in sound effects, game pause when menu is open, visibly open up gate when opening it.
93 lines
2.4 KiB
C#
93 lines
2.4 KiB
C#
public class GameResource
|
|
{
|
|
private const float NormalExtractionSpeed = 1f;
|
|
private const float EndlessExtractionSpeed = 4f;
|
|
|
|
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 = NormalExtractionSpeed;
|
|
item = GameData.availableItems[name];
|
|
}
|
|
|
|
public static GameResource FromSaveData(ResourceSaveData saveData)
|
|
{
|
|
GameResource resource = new GameResource(saveData.Name)
|
|
{
|
|
currentAmount = saveData.CurrentAmount,
|
|
maxAmount = saveData.MaxAmount,
|
|
isEndless = saveData.IsEndless,
|
|
extractionSpeed = saveData.ExtractionSpeed
|
|
};
|
|
if (resource.isEndless && resource.extractionSpeed <= NormalExtractionSpeed)
|
|
{
|
|
resource.extractionSpeed = EndlessExtractionSpeed;
|
|
}
|
|
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;
|
|
}
|
|
|
|
public void MakeEndless()
|
|
{
|
|
isEndless = true;
|
|
extractionSpeed = EndlessExtractionSpeed;
|
|
}
|
|
|
|
public bool IsEndless()
|
|
{
|
|
return isEndless;
|
|
}
|
|
|
|
public float GetExtractionSpeed()
|
|
{
|
|
return extractionSpeed;
|
|
}
|
|
}
|