Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change upgrade modifiers to BiFunctions instead of UpgradeOperations. #203

Open
wants to merge 1 commit into
base: 1.21.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class StatConfigData {
MULTIPLY_BASE: x + ((x * y) * z),
MULTIPLY_TOTAL: x * (y + 1)^z,
ADD: x + (y * z).
CUSTOM: logic is overwritten in code, can't be changed via configs

...where x - Base stat value, y - Value of [upgradeModifier], z - Current relic level
""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static it.hurts.sskirillss.relics.items.relics.base.data.leveling.misc.UpgradeOperation.*;


public interface IRelicItem {
@Nullable
default Item getItem() {
Expand Down Expand Up @@ -886,13 +889,7 @@ default double getRelativeStatValue(String ability, String stat, double value, i
if (data == null)
return result;

var step = data.getUpgradeModifier().getValue();

switch (data.getUpgradeModifier().getKey()) {
case ADD -> result = value + (points * step);
case MULTIPLY_BASE -> result = value + ((value * step) * points);
case MULTIPLY_TOTAL -> result = value * Math.pow(step + 1, points);
}
result = data.getNewUpgradeModifier().apply(value, points);

var threshold = data.getThresholdValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import lombok.Data;
import org.apache.commons.lang3.tuple.Pair;

import java.util.function.BiFunction;
import java.util.function.Function;

import static it.hurts.sskirillss.relics.items.relics.base.data.leveling.misc.UpgradeOperation.CUSTOM;

@Data
@Builder
public class StatData {
Expand All @@ -24,19 +27,30 @@ public static StatDataBuilder builder(String id) {
@Builder.Default
private Pair<UpgradeOperation, Double> upgradeModifier;
@Builder.Default
private BiFunction<Double, Integer, Double> newUpgradeModifier;
@Builder.Default
private Pair<Double, Double> initialValue;
@Builder.Default
private Pair<Double, Double> thresholdValue;

@Builder.Default
private Function<Double, ? extends Number> formatValue = Double::doubleValue;

public StatConfigData toConfigData() {
return new StatConfigData(initialValue.getKey(), initialValue.getValue(), thresholdValue.getKey(), thresholdValue.getValue(), upgradeModifier.getKey(), upgradeModifier.getValue());
}

public void setUpgradeModifier(Pair<UpgradeOperation, Double> upgradeModifier) {
this.upgradeModifier = upgradeModifier;
switch (upgradeModifier.getKey()) {
case ADD -> newUpgradeModifier = (current, points) -> current + points * upgradeModifier.getValue();
case MULTIPLY_BASE -> newUpgradeModifier = (current, points) -> current + ((current * upgradeModifier.getValue()) * points);
case MULTIPLY_TOTAL -> newUpgradeModifier = (current, points) -> current * Math.pow(upgradeModifier.getValue() + 1, points);
}
}

public static class StatDataBuilder {
private Pair<UpgradeOperation, Double> upgradeModifier = Pair.of(UpgradeOperation.ADD, 0D);
private Pair<UpgradeOperation, Double> upgradeModifier = Pair.of(CUSTOM, 0D);
private BiFunction<Double, Integer, Double> newUpgradeModifier = null;
private Pair<Double, Double> initialValue = Pair.of(0D, 0D);
private Pair<Double, Double> thresholdValue = Pair.of(Double.MIN_VALUE, Double.MAX_VALUE);

Expand All @@ -58,9 +72,27 @@ public StatDataBuilder thresholdValue(double min, double max) {
return this;
}

private StatDataBuilder newUpgradeModifier(BiFunction<Double, Integer, Double> function) {
return this;
}

/**
* @deprecated Use {@code upgradeModifier(BiFunction<Double, Integer, Double> function)} instead
*/
@Deprecated
public StatDataBuilder upgradeModifier(UpgradeOperation operation, double step) {
upgradeModifier = Pair.of(operation, step);
switch (operation) {
case ADD -> newUpgradeModifier = (current, points) -> current + points * step;
case MULTIPLY_BASE -> newUpgradeModifier = (current, points) -> current + ((current * step) * points);
case MULTIPLY_TOTAL -> newUpgradeModifier = (current, points) -> current * Math.pow(step + 1, points);
}

return this;
}

public StatDataBuilder upgradeModifier(BiFunction<Double, Integer, Double> function) {
newUpgradeModifier = function;
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package it.hurts.sskirillss.relics.items.relics.base.data.leveling.misc;

import lombok.AllArgsConstructor;

/**
* @deprecated Use BiFunctions instead
*/
@Deprecated
@AllArgsConstructor
public enum UpgradeOperation {
ADD,
MULTIPLY_BASE,
MULTIPLY_TOTAL
MULTIPLY_TOTAL,
CUSTOM;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public RelicData constructDefaultRelicData() {
.requiredPoints(2)
.stat(StatData.builder("charm")
.initialValue(1D, 3D)
.upgradeModifier(UpgradeOperation.ADD, 1D)
//.upgradeModifier(UpgradeOperation.ADD, 1D) // Deprecated
.upgradeModifier(Double::sum)
.formatValue(value -> (int) (MathUtils.round(value, 1)))
.build())
.build())
Expand Down