Example #1
0
        public static bool HandleTransmuteEvent(Item heldItem, int actualValue)
        {
            // if the recipes list doesn't contain the item you're holding, you can't transmute that.
            var recipes = EquivalentExchange.GetTransmutationFormulas();

            // sorted recipe list
            var validRecipes = recipes.GetRecipesForOutput(heldItem.parentSheetIndex);

            if (validRecipes.Count == 0)
            {
                return(true);
            }

            // use more sorting magic to find a potential recipe from the player's inventory
            // prioritize the recipes by their input costs (cheapest inputs are prioritized by the function GetRecipesForOutput)
            var optimalRecipe = validRecipes.FindBestRecipe(Game1.player);

            // something has stopped us from finding a valid recipe. The player either doesn't have the necessary items
            // or doesn't have the energy to do the transmutation.
            if (optimalRecipe == null)
            {
                return(true);
            }

            var breakRepeaterLoop = false;

            Alchemy.HandleAlchemyEnergyDeduction(optimalRecipe.GetEnergyCost(), false);

            if (optimalRecipe.GetEnergyCost() > EquivalentExchange.CurrentEnergy)
            {
                breakRepeaterLoop = true;
            }

            Alchemy.IncreaseTotalTransmuteValue((int)Math.Floor(Math.Max(1D, optimalRecipe.GetEnergyCost())));

            Util.TakeItemFromPlayer(optimalRecipe.InputId, optimalRecipe.GetInputCost(), Game1.player);

            Item spawnedItem = heldItem.getOne();

            spawnedItem.Stack = optimalRecipe.GetOutputQuantity();

            Util.GiveItemToPlayer((StardewValley.Object)spawnedItem, Game1.player);

            SoundUtil.PlayMagickySound();

            return(breakRepeaterLoop);
        }
Example #2
0
 private static void HandleToolTransmuteConsequence(float cost)
 {
     Alchemy.HandleAlchemyEnergyDeduction(GetToolTransmutationEnergyCost(EquivalentExchange.AlchemyLevel, cost), false);
     Alchemy.HandleAlchemyEnergyDeduction(GetToolTransmutationStaminaCost(EquivalentExchange.AlchemyLevel, cost), true);
     Alchemy.IncreaseTotalTransmuteValue((int)Math.Floor(cost));
 }