diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ReforgeOptions.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ReforgeOptions.java index 05b81ab3..4d5ec411 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ReforgeOptions.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/ReforgeOptions.java @@ -119,7 +119,8 @@ public class ReforgeOptions { } /** - * Keeps the display name of the item. + * If the item should be rerolled when updated. In the contrary, + * the previous RNG will be transferred onto the newest item. */ public boolean shouldReRoll() { return reRoll; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java index 36375eb0..dea5a911 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java @@ -1,6 +1,7 @@ package net.Indyuce.mmoitems.api; import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.player.modifier.ModifierSource; import net.Indyuce.mmoitems.MMOItems; @@ -298,10 +299,9 @@ public class Type { */ @Nullable public static Type get(@Nullable String id) { - if (id == null) { - return null; - } - String format = id.toUpperCase().replace("-", "_").replace(" ", "_"); + if (id == null) return null; + + String format = UtilityMethods.enumName(id); return MMOItems.plugin.getTypes().has(format) ? MMOItems.plugin.getTypes().get(format) : null; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/MMOItemReforger.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/MMOItemReforger.java index e913630b..d4b4d08c 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/MMOItemReforger.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/MMOItemReforger.java @@ -28,18 +28,13 @@ import java.util.ArrayList; import java.util.Objects; /** - * A class to manage modification of items with reference to what they used to be - * (and apparently also used to automatically apply SoulBounds): + * A class to manage modification of items with reference to what + * they used to be. Updating/reforging refers to changing the base + * stats of a MMOItem instance to what the template currently has, + * usually keeping gem stones and upgrade level. This won't reroll + * RNG stats unless the specific option is toggled on. * - *
updating
refers to changing the base stats
- * of a MMOItem instance to what the template currently has, usually
- * keeping gem stones and upgrade level. This wont reroll RNG stats.
reforging
same thing as updating, but rerolling
- * the RNG stats - basically transferring the data specified by the
- * {@link ReforgeOptions} into a new item of the same Type-ID
RANDOM.nextGaussian()
or whatever other
- * value that you actually want to pass.
- *
+ * @param random Result of RANDOM.nextGaussian()
or whatever other
+ * value that you actually want to pass.
* @return The calculated value
*/
public double calculate(double levelScalingFactor, double random) {
- if (useRelativeSpread) {
- //SPRD//if (spread > 0) MMOItems.log("\u00a7c༺\u00a77 Using \u00a7eRelative\u00a77 spread formula: \u00a76μ=" + (base + scale * levelScalingFactor) + "\u00a77, \u00a73σ=" + (spread * (base + scale * levelScalingFactor) + "\u00a7b=" + spread + "×" + (base + scale * levelScalingFactor)) + " \u00a7c@" + random + "\u00a7e = " + (base + scale * levelScalingFactor) * (1 + Math.min(Math.max(random * spread, -maxSpread), maxSpread)));
- return (base + scale * levelScalingFactor) * (1 + Math.min(Math.max(random * spread, -maxSpread), maxSpread));
- }
-
// The mean, the center of the distribution
- double actualBase = base + (scale * levelScalingFactor);
+ final double actualBase = base + (scale * levelScalingFactor);
/*
- * This is one pick from a gaussian distribution
- * at mean 0, and standard deviation 1, multiplied
- * by the spread chosen.
+ * This is one pick from a gaussian distribution at mean 0, and
+ * standard deviation 1, multiplied by the spread chosen.
+ * Does it exceed the max spread (positive or negative)? Not anymore!
*/
- double flatSpread = random * spread;
+ final double spreadCoef = Math.min(Math.max(random * spread, -maxSpread), maxSpread);
- // Does it exceed the max spread (positive or negative)? Not anymore!
- flatSpread = Math.min(Math.max(flatSpread, -maxSpread), maxSpread);
-
- // That's it
- //SPRD//if (spread > 0) MMOItems.log("\u00a7c༺\u00a77 Using \u00a7aAdditive\u00a77 spread formula, \u00a76μ=" + (base + scale * levelScalingFactor) + "\u00a77, \u00a73σ=" + (spread) + " \u00a7c@" + random + "\u00a7e = " + (actualBase + gaussSpread));
- return actualBase + flatSpread;
+ return useRelativeSpread ? actualBase * (1 + spreadCoef) : actualBase + spreadCoef;
}
@Override
@@ -235,43 +222,27 @@ public class NumericStatFormula implements RandomStatData* Example of unobtainable data: the current numeric stat value is now out * of the numeric formula bounds (defined by max-spread). - * + *
* This interface will tell the {@link net.Indyuce.mmoitems.api.util.MMOItemReforger} * if the current roll may be kept, or it is too extreme (under the updated metrics) * to be considered 'obtainable' and thus must be removed. - * + *
* If a RandomStatData does not implement this, it will never be kept when
* updating items (always be rerolled with latest settings).
*
* @author Gunging
*/
@FunctionalInterface
-public interface UpdatableRandomStatData {
+public interface UpdatableRandomStatData
* In contrast to reforging, in which it is expected its RNG to be rerolled, updating should not do it
* except in the most dire scenarios:
@@ -91,14 +31,41 @@ public class RFGKeepRNG implements Listener {
* + There is a new stat: The original data is null so this method cannot be called, will roll the
* new stat to actually add it for the first time.
*/
- @Nullable StatData shouldReRollRegardless(@NotNull ItemStat stat, @NotNull RandomStatData source, @NotNull StatData original, int determinedItemLevel) {
- // Not Mergeable, impossible to keep
- if (!(source instanceof UpdatableRandomStatData))
- //RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is not updatable!");
- return null;
+ @EventHandler
+ public void onReforge(MMOItemReforgeEvent event) {
+ // Rerolling stats? Nevermind
+ if (event.getOptions().shouldReRoll())
+// event.setCancelled(true);
+ //RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping new item (Complete RNG Reroll)");
+ return;
- // Just pass on
- return ((UpdatableRandomStatData) source).reroll(stat, original, determinedItemLevel);
+ //RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping old RNG Rolls");
+
+ event.getOldMMOItem().getStats()
+ .forEach(stat -> {
+
+ // Check if stat can be transferred over new item
+ final RandomStatData source = event.getReforger().getTemplate().getBaseItemData().get(stat);
+ if (source == null || !(source instanceof UpdatableRandomStatData))
+ return;
+
+ /*
+ * Decide if this data is too far from RNG to
+ * preserve its rolls, even if it should be
+ * preserving the rolls.
+ */
+ final StatHistory hist = StatHistory.from(event.getOldMMOItem(), stat);
+ final StatData keptData = ((UpdatableRandomStatData) source).reroll(stat, hist.getOriginalData(), event.getReforger().getGenerationItemLevel());
+
+ // Old roll is ridiculously low probability under the new parameters. Forget.
+ if (keptData == null)
+ return;
+
+ // Fetch History from the new item
+ final StatHistory clear = StatHistory.from(event.getNewMMOItem(), stat);
+
+ // Replace original data of the new one with the roll from the old one
+ clear.setOriginalData(keptData);
+ });
}
-
}
{
/**
- *
- * @param stat In case its relevant, the stat this Stat Data is linked to
- *
- * @param original The StatData currently in the item being reforged.
- *
+ * @param stat In case its relevant, the stat this Stat Data is linked to
+ * @param original The StatData currently in the item being reforged.
* @param determinedItemLevel The level of the item
- *
* @return The rerolled StatData if the original is unreasonable.
- *
- * If the original is reasonable, a clone of it, probably using {@link Mergeable#cloneData()}
+ *
+ * If the original is reasonable, a clone of it, probably using {@link Mergeable#cloneData()}
*/
- @NotNull