Beispiel #1
0
 public Ingredient Clone(IngredientOperation operation, int newLevel)
 {
     return(new Ingredient(
                Name,
                newLevel,
                BaseCost,
                EffectTreesPossible.ToArray(),
                CurrentEffectLevels.ToArray(),
                new IngredientOperations(Operations, operation)));
 }
Beispiel #2
0
        public IEnumerable <Ingredient> GetPossibleImmediateUpgrades()
        {
            // ONLY POSITIVE EFFECTS CAN BE TRANSFORMED (UPGRADED)
            for (int i = 0; i < EffectTreesPossible.Length; i++)
            {
                Effect currentEffect = CurrentEffects[i];

                Effect possibleEffect =
                    EffectTreesPossible[i].GetEffects().Skip(CurrentEffectLevels[i] + 1).FirstOrDefault();
                // Are there any options to improve at this index?
                if (possibleEffect != null)
                {
                    var newOperations = new IngredientOperations(Operations);

                    PositiveEffect currentPositive = currentEffect as PositiveEffect;
                    if (currentPositive != null)
                    {
                        EffectUpgradeRequirement requirement = currentPositive.Requirement;

                        // It is not known how to update this (yet).
                        if (requirement == EffectUpgradeRequirement.Unknown)
                        {
                            continue;
                        }

                        // We don't have the required catalyst?
                        if (requirement.Catalyst != Catalyst.None && !HasCatalyst(requirement.Catalyst))
                        {
                            continue;
                        }

                        int currentLevel = Level;

                        // The concentration might need a change in order to be upgraded.
                        int levelChangeUno = GetLevelChangeToAttain(currentLevel, requirement.Concentration);
                        if (levelChangeUno != 0)
                        {
                            newOperations.Add(IngredientOperation.GetLevelChange(levelChangeUno));
                        }

                        currentLevel += levelChangeUno;

                        // The upgrade process changes the concentration.
                        int levelAfterUpgrade = requirement.Machine.ChangeLevel(currentLevel);
                        int levelChangeDos    = levelAfterUpgrade - currentLevel;
                        currentLevel = levelAfterUpgrade;
                        if (levelChangeDos != 0)
                        {
                            newOperations.Add(IngredientOperation.GetLevelChange(levelChangeDos, requirement.Machine));
                        }

                        // Update the new effect level (of the selected effect)
                        int[] newEffectLevels = CurrentEffectLevels.ToArray();
                        newEffectLevels[i]++;

                        // UPGRADE DONE.

                        // This is an iupdated ingredient which might not have the proper concentration
                        // for the upgraded effect to be active.
                        yield return
                            (new Ingredient(Name, currentLevel, BaseCost, EffectTreesPossible,
                                            newEffectLevels, newOperations));

                        // Change the concentration to acctivate the upgraded effect.
                        int levelChangeTres = GetLevelChangeToAttain(currentLevel, possibleEffect.ActiveRange);
                        if (levelChangeTres != 0)
                        {
                            newOperations.Add(IngredientOperation.GetLevelChange(levelChangeTres));
                            currentLevel += levelChangeTres;

                            yield return
                                (new Ingredient(Name, currentLevel, BaseCost,
                                                EffectTreesPossible, newEffectLevels, newOperations));
                        }
                    }
                }
            }
        }