Files
RuinAdventurer/Scripts/Crafting/Item.cs
T

43 lines
1.2 KiB
C#

using System.Collections.Generic;
using Godot;
public class Item : Ingredient
{
public Dictionary<Ingredient, int> ingredients;
public double craftTime;
public double elapsedCraftTime;
public int amountCrafted;
public Item(string name, Dictionary<Ingredient, int> ingredients, int stackSize, double craftTime)
{
this.name = name;
this.ingredients = ingredients;
currentAmount = 0;
this.stackSize = stackSize;
this.craftTime = craftTime;
amountCrafted = 0;
}
public CraftingResult Craft(int amount, double delta)
{
if (GameData.inventory.CanCraft(ingredients, amount-amountCrafted))
{
elapsedCraftTime += delta;
if (elapsedCraftTime >= craftTime)
{
elapsedCraftTime -= craftTime;
currentAmount += 1;
amountCrafted++;
if (amountCrafted >= amount)
{
amountCrafted = 0;
elapsedCraftTime = 0;
return CraftingResult.FINISHED;
}
}
return CraftingResult.CRAFTING;
}
return CraftingResult.FAILED;
}
}