Пример #1
0
    private static void CreateRecipeFromStrings(string[] ingsS, string[] ingAmountS, string stationS, string resultS, string amountS)
    {
        Item.Type ing1 = (Item.Type)Enum.Parse(typeof(Item.Type), ingsS[0]);
        Item.Type ing2 = (Item.Type)Enum.Parse(typeof(Item.Type), ingsS[1]);
        Item.Type ing3 = (Item.Type)Enum.Parse(typeof(Item.Type), ingsS[2]);
        Item.Type ing4 = (Item.Type)Enum.Parse(typeof(Item.Type), ingsS[3]);
        int[]     ingAmount;
        if (ingAmountS == null)
        {
            ingAmount = null;
        }
        else
        {
            ingAmount = new int[4];
            for (int i = 0; i < ingAmountS.Length; i++)
            {
                ingAmount[i] = 0;
                Int32.TryParse(ingAmountS[i], out ingAmount[i]);
            }
        }
        CraftingStationType station = (CraftingStationType)Enum.Parse(typeof(CraftingStationType), stationS);

        Item.Type result = (Item.Type)Enum.Parse(typeof(Item.Type), resultS);
        int       amount = 0;

        Int32.TryParse(amountS, out amount);

        Recipe recipe = new Recipe(new Item.Type[] { ing1, ing2, ing3, ing4 }, ingAmount, station, result, amount);

        insertRecipe(recipe);
    }
Пример #2
0
 public Recipe(Item.Type[] ing, int[] ingAmount, CraftingStationType station, Item.Type res, int resAmount)
 {
     ingredients = ing;
     if (ingAmount == null)
     {
         amount = new int[] { 1, 1, 1, 1 };
     }
     else
     {
         amount = ingAmount;
     }
     craftingstation = station;
     result          = res;
     resultAmount    = resAmount;
 }
Пример #3
0
    public static ItemBehavior craft(ItemBehavior[] input, CraftingStationType station)
    {
        if (input.Length != 4)
        {
            return(null);
        }
        for (int i = 0; i < input.Length; i++)
        {
            if (input[i] == null)
            {
                input[i] = Item.createItem(Item.Type.UNDEF, 100, new Vector3(0, 0, 0));
            }
        }
        for (int i = 0; i < input.Length; i++)
        {
            int pos = i - 1;
            while (pos >= 0)
            {
                if ((int)input[pos].type <= (int)input[i].type)
                {
                    break;
                }
                pos--;
            }
            if (pos + 1 != i)
            {
                ItemBehavior temp = input[i];
                for (int p = i; p > pos + 1; p--)
                {
                    input[p] = input[p - 1];
                }
                input[pos + 1] = temp;
            }
        }
        int recipe = 0;

        while (recipe < recipes.Length)
        {
            if (input[0].type == recipes[recipe].ingredients[0] &&
                input[1].type == recipes[recipe].ingredients[1] &&
                input[2].type == recipes[recipe].ingredients[2] &&
                input[3].type == recipes[recipe].ingredients[3] &&
                station == recipes[recipe].craftingstation)
            {
                if (input[0].amount >= recipes[recipe].amount[0] &&
                    input[1].amount >= recipes[recipe].amount[1] &&
                    input[2].amount >= recipes[recipe].amount[2] &&
                    input[3].amount >= recipes[recipe].amount[3])
                {
                    input[0].amount -= recipes[recipe].amount[0];
                    input[1].amount -= recipes[recipe].amount[1];
                    input[2].amount -= recipes[recipe].amount[2];
                    input[3].amount -= recipes[recipe].amount[3];
                    ItemBehavior result = Item.createItem(recipes[recipe].result, recipes[recipe].resultAmount, new Vector3(0, 0, 0));
                    for (int i = 0; i < input.Length; i++)
                    {
                        if (input[i].type == Item.Type.UNDEF)
                        {
                            GameObject.Destroy(input[i].gameObject);
                        }
                    }
                    return(result);
                }
                else
                {
                    for (int i = 0; i < input.Length; i++)
                    {
                        if (input[i].type == Item.Type.UNDEF)
                        {
                            GameObject.Destroy(input[i].gameObject);
                        }
                    }
                    return(null);
                }
            }
            else
            {
                recipe++;
            }
        }
        for (int i = 0; i < input.Length; i++)
        {
            if (input[i].type == Item.Type.UNDEF)
            {
                GameObject.Destroy(input[i].gameObject);
            }
        }
        return(null);
    }