示例#1
0
    private RecipeData.Flavors GetMajorityFlavor(RecipeData.Flavors ignore)
    {
        int  highest        = 0;
        int  lastCount      = 0;
        int  majorityFlavor = 0;
        bool tied           = false;

        for (int f = 1; f <= 64; f = f << 1)
        {
            if (f != (int)ignore && flavorCountDictionary[(RecipeData.Flavors)f] > highest)
            {
                highest = flavorCountDictionary[(RecipeData.Flavors)f];
                if (highest == lastCount)
                {
                    tied = true;
                }
                else
                {
                    tied = false;
                }
                lastCount      = highest;
                majorityFlavor = f;
            }
        }
        if (tied)
        {
            return(RecipeData.Flavors.None);
        }
        else
        {
            return((RecipeData.Flavors)majorityFlavor);
        }
    }
示例#2
0
    public IngredientData PopIngredient()
    {
        IngredientData poppedIngredient = ingredientStack.Pop();

        ingredientCountDictionary[poppedIngredient.displayName] = ingredientCountDictionary[poppedIngredient.displayName] - 1;

        for (int f = 1; f <= 64; f = f << 1)
        {
            if ((f & (int)poppedIngredient.flavors) > 0)
            {
                RecipeData.Flavors foundFlavor = (RecipeData.Flavors)f;
                flavorCountDictionary[foundFlavor] = flavorCountDictionary[foundFlavor] - 1;
            }
        }

        return(poppedIngredient);
    }
示例#3
0
    public void PushIngredient(IngredientData ingredient)
    {
        ingredientStack.Push(ingredient);

        // Sweet = 1, Acquired = 64
        for (int f = 1; f <= 64; f = f << 1)
        {
            if ((f & (int)ingredient.flavors) > 0)
            {
                RecipeData.Flavors foundFlavor = (RecipeData.Flavors)f;
                flavorCountDictionary[foundFlavor] = flavorCountDictionary[foundFlavor] + 1;
            }
        }
        if (!ingredientCountDictionary.ContainsKey(ingredient.displayName))
        {
            ingredientCountDictionary.Add(ingredient.displayName, 1);
        }
        else
        {
            ingredientCountDictionary[ingredient.displayName] = ingredientCountDictionary[ingredient.displayName] + 1;
        }
    }
    private void UpdateFlavorIcons(IngredientData[] ingredientData, Image[] flavorIconImg)
    {
        // check each ingredient of the active skewer
        for (int i = 0; i < 3; i++)
        {
            // failsafe to update all three slots even if there aren't three ingredients
            if (i >= ingredientData.Length)
            {
                flavorIconImg[i].sprite = emptySprite;
                continue;
            }

            RecipeData.Flavors flavor1 = RecipeData.Flavors.None;

            int            flavorsFound      = 0;
            IngredientData currentIngredient = ingredientData[i];

            // check for the presence of each flavor,
            for (int f = 1; f <= 64; f = f << 1)
            {
                if ((f & (int)currentIngredient.flavors) > 0)
                {
                    flavorsFound++;

                    if (flavorsFound == 1)
                    {
                        flavor1 = (RecipeData.Flavors)f;
                    }
                }
                if (flavorsFound >= 1)
                {
                    break;
                }
            }

            flavorIconImg[i].sprite = iconDictionary[flavor1];
        }
    }
示例#5
0
    public virtual void Feed(IngredientData[] ingredientArray, bool fedByPlayer)
    {
        //Debug.Log("Skewer of size " + ingredientArray.Length);
        for (int i = 0; i < ingredientArray.Length; i++)
        {
            IngredientData ingredient = ingredientArray[i];
            if (ingredientCountDictionary.ContainsKey(ingredient.displayName))
            {
                ingredientCountDictionary[ingredient.displayName] = ingredientCountDictionary[ingredient.displayName] + 1;
                //Debug.Log("Ate one " + ingredient.displayName);
            }
            else
            {
                ingredientCountDictionary.Add(ingredient.displayName, 1);
                //Debug.Log("Ate one " + ingredient.displayName);
            }

            // mod hunger
            if (characterData != null)
            {
                characterData.InstantiateSignal(0.5f, "Hunger", -0.5f, false, true);
            }


            for (int f = 1; f <= 64; f = f << 1)
            {
                if ((f & (int)ingredient.flavors) > 0)
                {
                    RecipeData.Flavors foundFlavor = (RecipeData.Flavors)f;
                    flavorCountDictionary[foundFlavor] = flavorCountDictionary[foundFlavor] + 1;
                    Debug.Log(ingredient.displayName + " has flavor " + foundFlavor);
                }
            }
        }

        RespondToIngredients(fedByPlayer);
        SpawnReward(ingredientArray, fedByPlayer);
    }
示例#6
0
    /// <summary>
    /// Returns the majority flavor on either the active skewer or all skewers.
    /// Can return either Acquired or None if there is a tie
    /// </summary>
    public RecipeData.Flavors GetMajorityFlavor(bool checkAllSkewers, bool acquiredTies)
    {
        RecipeData.Flavors majorityFlavor = RecipeData.Flavors.None;
        bool tie = true;

        if (!checkAllSkewers)
        {
            if (ActiveSkewerEmpty())
            {
                //Debug.Log("Warning: Cannot find majority flavor on empty skewer");
                return(RecipeData.Flavors.None);
            }

            int highestNumber = 0;
            int lastNumber    = 0;
            //iterate over all possible flavors
            for (int f = 1; f <= 64; f = f << 1)
            {
                if (quiver[activeSkewer].flavorCountDictionary[(RecipeData.Flavors)f] >= highestNumber)
                {
                    highestNumber = quiver[activeSkewer].flavorCountDictionary[(RecipeData.Flavors)f];

                    if (lastNumber == highestNumber)
                    {
                        tie = true;
                    }
                    else
                    {
                        tie = false;
                    }

                    lastNumber     = highestNumber;
                    majorityFlavor = (RecipeData.Flavors)f;
                }
            }
            if (!tie)
            {
                return(majorityFlavor);
            }
            else
            {
                return(acquiredTies ? RecipeData.Flavors.Acquired : RecipeData.Flavors.None);
            }
        }
        else
        {
            if (AllSkewersEmpty())
            {
                //Debug.Log("Warning: Cannot find majority flavor on empty skewers");
                return(RecipeData.Flavors.None);
            }

            int highestNumber = 0;
            int lastNumber    = 0;
            //iterate over all possible flavors
            for (int s = 0; s < numberOfSkewers; s++)
            {
                for (int f = 1; f <= 64; f = f << 1)
                {
                    if (quiver[s].flavorCountDictionary[(RecipeData.Flavors)f] > highestNumber)
                    {
                        highestNumber = quiver[s].flavorCountDictionary[(RecipeData.Flavors)f];

                        if (lastNumber == highestNumber)
                        {
                            tie = true;
                        }
                        else
                        {
                            tie = false;
                        }

                        lastNumber     = highestNumber;
                        majorityFlavor = (RecipeData.Flavors)f;
                    }
                }
            }
            if (!tie)
            {
                return(majorityFlavor);
            }
            else
            {
                return(acquiredTies ? RecipeData.Flavors.Acquired : RecipeData.Flavors.None);
            }
        }
    }