Cleaned up project with better structure.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
public class Research
|
||||
{
|
||||
public ResearchData data;
|
||||
public double elapsedResearchTime = 0;
|
||||
public bool paidResources = false;
|
||||
public ResearchState state;
|
||||
|
||||
public Research(ResearchData data)
|
||||
{
|
||||
this.data = data;
|
||||
state = ResearchState.UNDEFINED;
|
||||
}
|
||||
|
||||
public ResearchResult Execute(double delta)
|
||||
{
|
||||
if (!paidResources)
|
||||
{
|
||||
foreach (Ingredient ingredient in data.Inputs)
|
||||
{
|
||||
GameData.inventory.RemoveItem(ingredient.Item, ingredient.Amount);
|
||||
}
|
||||
paidResources = true;
|
||||
}
|
||||
|
||||
elapsedResearchTime += delta;
|
||||
if (elapsedResearchTime >= data.CraftTime)
|
||||
{
|
||||
state = ResearchState.RESEARCHED;
|
||||
return ResearchResult.FINISHED;
|
||||
}
|
||||
|
||||
return ResearchResult.RESEARCHING;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dj2epbu26v1nv
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public class ResearchData
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonPropertyName("inputs")]
|
||||
public List<Ingredient> Inputs { get; set; }
|
||||
|
||||
[JsonPropertyName("research")]
|
||||
public string Research { get; set; }
|
||||
|
||||
[JsonPropertyName("crafttime")]
|
||||
public double CraftTime { get; set; }
|
||||
|
||||
[JsonPropertyName("texture")]
|
||||
public string Texture { get; set; }
|
||||
|
||||
public string GetReadableName()
|
||||
{
|
||||
string noUnderscore = Id.Replace("_", " ").ToLower();
|
||||
return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
|
||||
}
|
||||
|
||||
public static string GetIndex(string readable)
|
||||
{
|
||||
return readable.ToLower().Replace(" ", "_");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://duwl6bhiry6uh
|
||||
@@ -0,0 +1,6 @@
|
||||
public enum ResearchResult
|
||||
{
|
||||
FAILED,
|
||||
RESEARCHING,
|
||||
FINISHED
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cuav7j7m1td2h
|
||||
@@ -0,0 +1,7 @@
|
||||
public enum ResearchState
|
||||
{
|
||||
UNDEFINED,
|
||||
RESEARCHED,
|
||||
AVAILABLE,
|
||||
LOCKED
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b57yhucbav37c
|
||||
Reference in New Issue
Block a user