コード例 #1
0
    /// <summary>
    /// Create a specific ingredient from 3 specific part IDs
    /// </summary>
    /// <param name="colourId">The ID of the colour part</param>
    /// <param name="descId">The ID of the descriptor part</param>
    /// <param name="typeId">The ID of the</param>
    /// <returns>An ingredient built from the supplied parts</returns>
    public Ingredient GenerateIngredientFromIDs(int colourId, int descId, int typeId)
    {
        Ingredient ingredient = ScriptableObject.CreateInstance <Ingredient>();

        // Grab the parts from the JSON data
        PartList.Part colourPart = partList.Data[colourId];
        PartList.Part descPart   = partList.Data[descId];
        PartList.Part typePart   = partList.Data[typeId];

        // Build the ingredient
        ingredient = BuildIngredient(colourPart, descPart, typePart);

        // Return the ingredient
        return(ingredient);
    }
コード例 #2
0
    /// <summary>
    /// Builds the ingredient data from 3 giving parts
    /// </summary>
    /// <param name="colourPart">The desired colour part</param>
    /// <param name="descPart">The desired descriptor part</param>
    /// <param name="typePart">The desired type part</param>
    /// <returns></returns>
    private Ingredient BuildIngredient(PartList.Part colourPart, PartList.Part descPart, PartList.Part typePart)
    {
        Ingredient ingredient = ScriptableObject.CreateInstance <Ingredient>();

        // Populate the ingredient's ID array with its part ids
        ingredient.ids[0] = colourPart.id;
        ingredient.ids[1] = descPart.id;
        ingredient.ids[2] = typePart.id;

        // Build the ingredient's name from the part names
        ingredient.ingredient_name = colourPart.part_name + " " + descPart.part_name + " " + typePart.part_name;

        // The ingredient's cost is the sum of the parts'
        ingredient.cost = colourPart.cost + descPart.cost + typePart.cost;

        ingredient.effectsDict = new Dictionary <string, float[]>();

        // The ingredient's effects are all the part modifiers added together, and all the multipliers added together
        // Multipliers are kept separate at this point. They are applied when the potion is brewed
        ingredient.effectsDict.Add("str", new float[2] {
            (colourPart.effectsDict["str"][0] + descPart.effectsDict["str"][0] + typePart.effectsDict["str"][0]), (colourPart.effectsDict["str"][1] * descPart.effectsDict["str"][1] * typePart.effectsDict["str"][1])
        });
        ingredient.effectsDict.Add("int", new float[2] {
            (colourPart.effectsDict["int"][0] + descPart.effectsDict["int"][0] + typePart.effectsDict["int"][0]), (colourPart.effectsDict["int"][1] * descPart.effectsDict["int"][1] * typePart.effectsDict["int"][1])
        });
        ingredient.effectsDict.Add("dex", new float[2] {
            (colourPart.effectsDict["dex"][0] + descPart.effectsDict["dex"][0] + typePart.effectsDict["dex"][0]), (colourPart.effectsDict["dex"][1] * descPart.effectsDict["dex"][1] * typePart.effectsDict["dex"][1])
        });

        // Add the part tags to the ingredient
        ingredient.tags.AddRange(colourPart.tags);
        ingredient.tags.AddRange(descPart.tags);
        ingredient.tags.AddRange(typePart.tags);

        // Build the ingredients new sprite
        ingredient.sprite = CombineSprites(colourPart.sprite, descPart.sprite, typePart.sprite);

        // Combine the part flavour text
        ingredient.desc_string = colourPart.desc_string + typePart.desc_string + descPart.desc_string;

        // Build the effect string
        ingredient.effect_string = BuildEffectString(ingredient.effectsDict);

        // Return the ingredient
        return(ingredient);
    }
コード例 #3
0
    /// <summary>
    /// Generates an ingredient of a specified tag type
    /// </summary>
    public List <Ingredient> GenerateIngredients(int numberOfIngredients, PartList.Part.Tags targetTag, int shopTier)
    {
        // Create the list we will return
        List <Ingredient> Ingredients = new List <Ingredient>();


        for (int i = 0; i < numberOfIngredients; i++)
        {
            int loopCounter = 0;
            int MAX_LOOPS   = 50;

            // Create the new ingredient
            Ingredient ingredient = ScriptableObject.CreateInstance <Ingredient>();

            // Keep generating the ingredient ----
            do
            {
                PartList.Part colourPart = null;
                PartList.Part descPart   = null;
                PartList.Part typePart   = null;

                // Get a random Colour of the targetted tag, or with the "any" tag at a particular tier or below
                do
                {
                    int randIndex = Random.Range(0, Colours.Count);
                    if ((Colours[randIndex].tags.Contains(PartList.Part.Tags.any) || Colours[randIndex].tags.Contains(targetTag)) && Colours[randIndex].tier <= shopTier)
                    {
                        colourPart = Colours[randIndex];
                    }
                } while (colourPart == null);

                // Get a random Descriptor, or with the "any" tag at a particular tier or below
                do
                {
                    int randIndex = Random.Range(0, Descriptors.Count);
                    if ((Descriptors[randIndex].tags.Contains(PartList.Part.Tags.any) || Descriptors[randIndex].tags.Contains(targetTag)) && Descriptors[randIndex].tier <= shopTier)
                    {
                        descPart = Descriptors[randIndex];
                    }
                } while (descPart == null);

                // Get a random Type, or with the "any" tag at a particular tier or below
                do
                {
                    int randIndex = Random.Range(0, Types.Count);
                    if ((Types[randIndex].tags.Contains(PartList.Part.Tags.any) || Types[randIndex].tags.Contains(targetTag)) && Types[randIndex].tier <= shopTier)
                    {
                        typePart = Types[randIndex];
                    }
                } while (typePart == null);

                // Build that ingredient
                ingredient = BuildIngredient(colourPart, descPart, typePart);

                // Keep track of how many times we've tried this, do not infinite loop
                loopCounter++;
            } while (Ingredients.Contains(ingredient) && loopCounter < MAX_LOOPS); // --- Until the ingredient is unique, or the we've tried the maximum number of times

            // Add the ingredient to the list
            Ingredients.Add(ingredient);
        }

        // Only allow the shops to generate an inventory once per day!
        switch (targetTag)
        {
        case PartList.Part.Tags.plant:
            if (plantShopInv.Count == 0)
            {
                plantShopInv = Ingredients;
            }
            else
            {
                return(plantShopInv);
            }
            break;

        case PartList.Part.Tags.meat:
            if (meatShopInv.Count == 0)
            {
                meatShopInv = Ingredients;
            }
            else
            {
                return(meatShopInv);
            }
            break;

        case PartList.Part.Tags.mineral:
            if (mineralShopInv.Count == 0)
            {
                mineralShopInv = Ingredients;
            }
            else
            {
                return(mineralShopInv);
            }
            break;

        default:
            break;
        }


        // Return the list
        return(Ingredients);
    }