Working on inventory and crafting system. Translated Excel-Itemlist to .json.
This commit is contained in:
@@ -1,5 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
|
||||
public class Item
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user