public Ingredient(string name, int startingLevel, int baseCost, EffectTree[] effectTrees, int[] currentEffectlevels = null, IngredientOperations operations = null) { if (effectTrees.Length != 4) { throw new ArgumentException("Needs to have exactly 4 effect trees.", nameof(effectTrees)); } Level = startingLevel; BaseCost = baseCost; Name = name; Operations = operations ?? new IngredientOperations(null); EffectTreesPossible = effectTrees; for (int i = 0; i < effectTrees.Length; i++) { EffectTreesPossible[i].SetSlot(i); } // Current effects are the actual effects which this ingredient has right now. // At start it has the first effects from all trees. CurrentEffectLevels = currentEffectlevels ?? new[] { 0, 0, 0, 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)); } } } } }