public static void HandleLiquidateEvent(Item heldItem, int actualValue) { //if the player is holding only one item, don't let them transmute it to money unless they're holding shift. if (heldItem.Stack == 1 && !EquivalentExchange.IsShiftKeyPressed()) { return; } //placeholder for determining if the transmute occurs, so it knows to play a sound. bool didTransmuteOccur = false; //placeholder for determining if the transmute rebounds, so it knows to play a different sound. bool didTransmuteFail = false; //if the transmute did fail, this preserves the damage so we can apply it in one cycle, otherwise batches look weird af int reboundDamageTaken = 0; //needed for some profession effects bool isItemWorthLessThanOnePercentOfMoney = (Game1.player.money * 0.01F > actualValue); //stamina cost is overridden for conduits if money is > 100x the item's value. double staminaCost = (isItemWorthLessThanOnePercentOfMoney && Game1.player.professions.Contains(Professions.Conduit)) ? 0D : Alchemy.GetStaminaCostForTransmutation(actualValue); //if the player lacks the stamina to execute a transmute, abort if (Game1.player.Stamina <= staminaCost) { return; } //if we fail this check, it's because a rebound would kill the player. //if the rebound chance is zero, this check will automatically pass. if (!Alchemy.CanSurviveRebound(actualValue, isItemWorthLessThanOnePercentOfMoney, true)) { return; } //if we fail this check, transmutation will fail this cycle. //this is our "rebound check" if (Alchemy.DidPlayerFailReboundCheck(isItemWorthLessThanOnePercentOfMoney, true)) { reboundDamageTaken += Alchemy.GetReboundDamage(actualValue); didTransmuteFail = true; } //the conduit profession makes it so that the transmutation succeeds anyway, after taking damage. if (Game1.player.professions.Contains((int)Professions.Sage) || !didTransmuteFail) { //if we reached this point transmutation will succeed didTransmuteOccur = true; Alchemy.HandleStaminaDeduction(staminaCost, false); //we floor the math here because we don't want weirdly divergent values based on stack count - the rate is fixed regardless of quantity //this occurs at the expense of rounding - liquidation is lossy. int liquidationValue = (int)Math.Floor(Alchemy.GetLiquidationValuePercentage() * actualValue); int totalValue = liquidationValue; Game1.player.Money += totalValue; Game1.player.reduceActiveItemByOne(); //the percentage of experience you get is increased by the lossiness of the transmute //as you increase in levels, this amount diminishes to a minimum of 1. double experienceValueCoefficient = 1D - Alchemy.GetLiquidationValuePercentage(); int experienceValue = (int)Math.Floor(Math.Sqrt(experienceValueCoefficient * actualValue / 10 + 1)); Alchemy.AddAlchemyExperience(experienceValue); //a transmute (at least one) happened, play the cash money sound if (didTransmuteOccur && !didTransmuteFail) { SoundUtil.PlayMoneySound(); } } //a rebound occurred, apply the damage and also play the ouchy sound. if (didTransmuteFail) { Alchemy.TakeDamageFromRebound(reboundDamageTaken); SoundUtil.PlayReboundSound(); } }
public static void HandleTransmuteEvent(Item heldItem, int actualValue) { //cost of a single item, multiplied by the cost multiplier below int transmutationCost = (int)Math.Ceiling(Alchemy.GetTransmutationMarkupPercentage() * actualValue); //nor should totalCost of a single cycle int totalCost = transmutationCost; //placeholder for determining if the transmute occurs, so it knows to play a sound. bool didTransmuteOccur = false; //placeholder for determining if the transmute rebounds, so it knows to play a different sound. bool didTransmuteFail = false; //if the transmute did fail, this preserves the damage so we can apply it in one cycle, otherwise batches look weird af int reboundDamageTaken = 0; //needed for some profession effects bool isItemWorthLessThanOnePercentOfMoney = (Game1.player.money * 0.01F > actualValue); //stamina cost is overridden for conduits if money is > 100x the item's value. double staminaCost = (isItemWorthLessThanOnePercentOfMoney && Game1.player.professions.Contains(Professions.Conduit)) ? 0D : Alchemy.GetStaminaCostForTransmutation(actualValue); //loop for each transmute-cycle attempt if (Game1.player.money >= totalCost) { //if the player lacks the stamina to execute a transmute, abort if (Game1.player.Stamina <= staminaCost) { return; } //if we fail this check, it's because a rebound would kill the player. //if the rebound chance is zero, this check will automatically pass. if (!Alchemy.CanSurviveRebound(actualValue, isItemWorthLessThanOnePercentOfMoney, false)) { return; } //if we fail this check, transmutation will fail this cycle. //this is our "rebound check" if (Alchemy.DidPlayerFailReboundCheck(isItemWorthLessThanOnePercentOfMoney, false)) { reboundDamageTaken += Alchemy.GetReboundDamage(actualValue); didTransmuteFail = true; //the conduit profession makes it so that the transmutation succeeds anyway, after taking damage. } if (Game1.player.professions.Contains((int)Professions.Sage) || !didTransmuteFail) { didTransmuteOccur = true; Alchemy.HandleStaminaDeduction(staminaCost, true); Game1.player.Money -= totalCost; Item spawnedItem = heldItem.getOne(); Game1.createItemDebris(spawnedItem, Game1.player.getStandingPosition(), Game1.player.FacingDirection, (GameLocation)null); //the percentage of experience you get is increased by the lossiness of the transmute //as you increase in levels, this amount diminishes to a minimum of 1. double experienceValueCoefficient = Alchemy.GetTransmutationMarkupPercentage() - 1D; int experienceValue = (int)Math.Floor(Math.Sqrt(experienceValueCoefficient * actualValue / 10 + 1)); Alchemy.AddAlchemyExperience(experienceValue); } } //a transmute (at least one) happened, play the magicky sound if (didTransmuteOccur && !didTransmuteFail) { SoundUtil.PlayMagickySound(); } //a rebound occurred, apply the damage and also play the ouchy sound. if (didTransmuteFail) { Alchemy.TakeDamageFromRebound(reboundDamageTaken); SoundUtil.PlayReboundSound(); } }