41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Text.Json.Serialization;
|
|
using Godot;
|
|
|
|
public class Item
|
|
{
|
|
public ItemData data;
|
|
public int currentAmount = 0;
|
|
public double elapsedCraftTime = 0;
|
|
public int amountCrafted = 0;
|
|
|
|
public CraftingResult Craft(int amount, double delta)
|
|
{
|
|
if (GameData.inventory.CanCraft(data.Inputs, amount - amountCrafted))
|
|
{
|
|
elapsedCraftTime += delta;
|
|
if (elapsedCraftTime >= data.CraftTime)
|
|
{
|
|
elapsedCraftTime -= data.CraftTime;
|
|
currentAmount += 1;
|
|
amountCrafted++;
|
|
if (amountCrafted >= amount)
|
|
{
|
|
amountCrafted = 0;
|
|
elapsedCraftTime = 0;
|
|
return CraftingResult.FINISHED;
|
|
}
|
|
}
|
|
return CraftingResult.CRAFTING;
|
|
}
|
|
return CraftingResult.FAILED;
|
|
}
|
|
|
|
public string GetReadableName()
|
|
{
|
|
string noUnderscore = data.Id.Replace("_", " ").ToLower();
|
|
return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1);
|
|
}
|
|
}
|
|
|