Skip to content

Commit

Permalink
Going to eep with bf pawesome
Browse files Browse the repository at this point in the history
  • Loading branch information
SammySemicolon committed Jan 12, 2024
1 parent cfe166e commit 5a0f299
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void render(SpiritCrucibleCoreBlockEntity blockEntityIn, float partialTic
poseStack.mulPose(Axis.YP.rotationDegrees(180f));
for (int i = 0; i < validValues.size(); i++) {
CrucibleTuning.CrucibleTuningType tuningType = validValues.get(i);
String dataPrint = tuningType.statDisplayFunction.apply(blockEntityIn);
String dataPrint = tuningType.statDisplayFunction.apply(blockEntityIn.getAccelerationData());
boolean important = tuningType.equals(blockEntityIn.tuningType);
MutableComponent dataText = Component.literal(" <" + dataPrint + ">");
MutableComponent text = Component.translatable(tuningType.translation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ public class CrucibleAccelerationData {
public final List<BlockPos> positions = new ArrayList<>();
public final List<ICrucibleAccelerator> accelerators = new ArrayList<>();

public final float processingSpeed;
public final float damageChance;
public final TunedValue processingSpeed;
public final TunedValue damageChance;

public final float bonusYieldChance;
public final float fuelUsageRate;
public final float chainFocusingChance;
public final float damageAbsorptionChance;
public final float restorationChance;
public final TunedValue bonusYieldChance;
public final TunedValue fuelUsageRate;
public final TunedValue chainFocusingChance;
public final TunedValue damageAbsorptionChance;
public final TunedValue restorationChance;

public float globalAttributeModifier;

public static CrucibleAccelerationData createData(ICatalyzerAccelerationTarget target, int lookupRange, Level level, BlockPos pos) {
Collection<ICrucibleAccelerator> nearbyAccelerators = BlockHelper.getBlockEntities(ICrucibleAccelerator.class, level, pos, lookupRange);
Expand All @@ -46,33 +48,42 @@ public static CrucibleAccelerationData createData(ICatalyzerAccelerationTarget t
}
}
}
return new CrucibleAccelerationData(target, typeCount, validAccelerators);
final CrucibleAccelerationData data = new CrucibleAccelerationData(target, typeCount, validAccelerators);
data.globalAttributeModifier = target.getAccelerationData() != null ? target.getAccelerationData().globalAttributeModifier : 0;
return data;
}

public CrucibleAccelerationData(ICatalyzerAccelerationTarget target, Map<ICrucibleAccelerator.CrucibleAcceleratorType, Integer> typeCount, Collection<ICrucibleAccelerator> accelerators) {
final List<AbstractAugmentItem> augments = Stream.concat(accelerators.stream().map(ICrucibleAccelerator::getAugmentType), target.getAugmentTypes().stream()).filter(Optional::isPresent).map(Optional::get).toList();
CrucibleTuning tuning = new CrucibleTuning(target.getTuningType());
this.processingSpeed = (1 + typeCount.entrySet().stream().map((entry) -> entry.getKey().getAcceleration(entry.getValue())).reduce(Float::sum).orElse(0f)
+ augments.stream().map(AbstractAugmentItem::getSpeedIncrease).reduce(Float::sum).orElse(0f)) * tuning.speedIncreaseMultiplier.getMultiplier();
this.damageChance = Mth.clamp((typeCount.entrySet().stream().map((entry) -> entry.getKey().getExtraDamageRollChance(entry.getValue())).reduce(Float::sum).orElse(0f)
+ augments.stream().map(AbstractAugmentItem::getDamageChanceIncrease).reduce(Float::sum).orElse(0f)) * tuning.damageChanceMultiplier.getMultiplier(), 0, 0.99f);

this.bonusYieldChance = augments.stream().map(AbstractAugmentItem::getBonusYieldChanceIncrease).reduce(Float::sum).orElse(0f) * tuning.bonusYieldChanceMultiplier.getMultiplier();
this.fuelUsageRate = (1 + augments.stream().map(AbstractAugmentItem::getFuelUsageRateIncrease).reduce(Float::sum).orElse(0f)) * tuning.fuelEfficiencyIncreaseMultiplier.getMultiplier();
this.chainFocusingChance = augments.stream().map(AbstractAugmentItem::getInstantCompletionChance).reduce(Float::sum).orElse(0f) * tuning.chainFocusingChanceMultiplier.getMultiplier();
this.damageAbsorptionChance = augments.stream().map(AbstractAugmentItem::getCompleteDamageNegationChance).reduce(Float::sum).orElse(0f) * tuning.damageAbsorptionChanceMultiplier.getMultiplier();
this.restorationChance = augments.stream().map(AbstractAugmentItem::getRestorationChance).reduce(Float::sum).orElse(0f) * tuning.restorationChanceMultiplier.getMultiplier();
CrucibleTuning tuning = new CrucibleTuning(target);
this.processingSpeed = tuning.processingSpeedMultiplier.createTunedValue(
(1 + typeCount.entrySet().stream().map((entry) -> entry.getKey().getAcceleration(entry.getValue())).reduce(Float::sum).orElse(0f)
+ augments.stream().map(AbstractAugmentItem::getSpeedIncrease).reduce(Float::sum).orElse(0f)) * tuning.processingSpeedMultiplier.getMultiplier());
this.damageChance = tuning.damageChanceMultiplier.createTunedValue(
Mth.clamp((typeCount.entrySet().stream().map((entry) -> entry.getKey().getExtraDamageRollChance(entry.getValue())).reduce(Float::sum).orElse(0f)
+ augments.stream().map(AbstractAugmentItem::getDamageChanceIncrease).reduce(Float::sum).orElse(0f)) * tuning.damageChanceMultiplier.getMultiplier(), 0, 0.99f));

this.bonusYieldChance = tuning.bonusYieldChanceMultiplier.createTunedValue(
augments.stream().map(AbstractAugmentItem::getBonusYieldChanceIncrease).reduce(Float::sum).orElse(0f) * tuning.bonusYieldChanceMultiplier.getMultiplier());
this.fuelUsageRate = tuning.fuelUsageRate.createTunedValue(
1 + augments.stream().map(AbstractAugmentItem::getFuelUsageRateIncrease).reduce(Float::sum).orElse(0f) * tuning.fuelUsageRate.getMultiplier());
this.chainFocusingChance = tuning.chainFocusingChanceMultiplier.createTunedValue(
augments.stream().map(AbstractAugmentItem::getInstantCompletionChance).reduce(Float::sum).orElse(0f) * tuning.chainFocusingChanceMultiplier.getMultiplier());
this.damageAbsorptionChance = tuning.damageAbsorptionChanceMultiplier.createTunedValue(
augments.stream().map(AbstractAugmentItem::getCompleteDamageNegationChance).reduce(Float::sum).orElse(0f) * tuning.damageAbsorptionChanceMultiplier.getMultiplier());
this.restorationChance = tuning.restorationChanceMultiplier.createTunedValue(
augments.stream().map(AbstractAugmentItem::getRestorationChance).reduce(Float::sum).orElse(0f) * tuning.restorationChanceMultiplier.getMultiplier());
accelerators.forEach(this::addAccelerator);
}

public CrucibleAccelerationData() {
this.processingSpeed = 1;
this.damageChance = 0;
this.bonusYieldChance = 0;
this.fuelUsageRate = 1;
this.chainFocusingChance = 0;
this.damageAbsorptionChance = 0;
this.restorationChance = 0;
this.processingSpeed = new DefaultedTunedValue(1);
this.damageChance = new DefaultedTunedValue(0);
this.bonusYieldChance = new DefaultedTunedValue(0);
this.fuelUsageRate = new DefaultedTunedValue(1);
this.chainFocusingChance = new DefaultedTunedValue(0);
this.damageAbsorptionChance = new DefaultedTunedValue(0);
this.restorationChance = new DefaultedTunedValue(0);
}

private void addAccelerator(ICrucibleAccelerator crucibleAccelerator) {
Expand All @@ -89,6 +100,7 @@ public void save(CompoundTag compound) {
BlockHelper.saveBlockPos(acceleratorTag, position, "accelerator_" + i + "_");
}
}
acceleratorTag.putFloat("globalAttributeModifier", globalAttributeModifier);
compound.put("acceleratorData", acceleratorTag);
}

Expand All @@ -110,10 +122,39 @@ public static CrucibleAccelerationData load(Level level, ICatalyzerAccelerationT
BlockHelper.updateState(level, pos);
}
}
return new CrucibleAccelerationData(target, typeCount, accelerators);
final CrucibleAccelerationData data = new CrucibleAccelerationData(target, typeCount, accelerators);
data.globalAttributeModifier = acceleratorTag.getFloat("globalAttributeModifier");
return data;
}
else {
return DEFAULT;
}
}

public static class TunedValue {
public final CrucibleTuning.TuningModifier tuning;
protected final float baseValue;

public TunedValue(CrucibleTuning.TuningModifier tuning, float baseValue) {
this.tuning = tuning;
this.baseValue = baseValue;
}

public float getValue(CrucibleAccelerationData accelerationData) {
if (tuning.tuningType.equals(CrucibleTuning.CrucibleTuningType.CHAIN_FOCUSING_CHANCE)) {
return baseValue;
}
return baseValue * tuning.getMultiplierScalar(accelerationData.globalAttributeModifier);
}
}
public static class DefaultedTunedValue extends TunedValue {
public DefaultedTunedValue(float baseValue) {
super(null, baseValue);
}

@Override
public float getValue(CrucibleAccelerationData accelerationData) {
return baseValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,47 @@
public class CrucibleTuning {

public final CrucibleTuningType buffedStat;
public final TunedValue speedIncreaseMultiplier;
public final InverseTunedValue fuelEfficiencyIncreaseMultiplier;
public final InverseTunedValue damageChanceMultiplier;
public final TunedValue bonusYieldChanceMultiplier;
public final TunedValue chainFocusingChanceMultiplier;
public final TunedValue damageAbsorptionChanceMultiplier;
public final TunedValue restorationChanceMultiplier;

public CrucibleTuning(CrucibleTuningType buffedStat) {
this.buffedStat = buffedStat;
this.speedIncreaseMultiplier = new TunedValue(CrucibleTuningType.PROCESSING_SPEED, buffedStat);
this.fuelEfficiencyIncreaseMultiplier = new InverseTunedValue(CrucibleTuningType.FUEL_USAGE_RATE, buffedStat);
this.damageChanceMultiplier = new InverseTunedValue(CrucibleTuningType.INSTABILITY, buffedStat);
this.bonusYieldChanceMultiplier = new TunedValue(CrucibleTuningType.FORTUNE_CHANCE, buffedStat);
this.chainFocusingChanceMultiplier = new TunedValue(CrucibleTuningType.CHAIN_FOCUSING_CHANCE, buffedStat);
this.damageAbsorptionChanceMultiplier = new TunedValue(CrucibleTuningType.SHIELDING_CHANCE, buffedStat);
this.restorationChanceMultiplier = new TunedValue(CrucibleTuningType.RESTORATION_CHANCE, buffedStat);
public final Map<CrucibleTuningType, ? extends TuningModifier> values = new HashMap<>();

public final TuningModifier processingSpeedMultiplier;
public final InverseTuningModifier fuelUsageRate;
public final InverseTuningModifier damageChanceMultiplier;
public final TuningModifier bonusYieldChanceMultiplier;
public final TuningModifier chainFocusingChanceMultiplier;
public final TuningModifier damageAbsorptionChanceMultiplier;
public final TuningModifier restorationChanceMultiplier;

public CrucibleTuning(ICatalyzerAccelerationTarget target) {
this.buffedStat = target.getTuningType();
this.processingSpeedMultiplier = new TuningModifier(CrucibleTuningType.PROCESSING_SPEED, target);
this.fuelUsageRate = new InverseTuningModifier(CrucibleTuningType.FUEL_USAGE_RATE, target);
this.damageChanceMultiplier = new InverseTuningModifier(CrucibleTuningType.INSTABILITY, target);
this.bonusYieldChanceMultiplier = new TuningModifier(CrucibleTuningType.FORTUNE_CHANCE, target);
this.chainFocusingChanceMultiplier = new TuningModifier(CrucibleTuningType.CHAIN_FOCUSING_CHANCE, target);
this.damageAbsorptionChanceMultiplier = new TuningModifier(CrucibleTuningType.SHIELDING_CHANCE, target);
this.restorationChanceMultiplier = new TuningModifier(CrucibleTuningType.RESTORATION_CHANCE, target);
}

public enum CrucibleTuningType {
NONE(null, null),
PROCESSING_SPEED(d -> d.processingSpeed),
FUEL_USAGE_RATE(d -> d.fuelUsageRate),
INSTABILITY(d -> d.damageChance > 0, d -> String.format("%.2f", d.getAccelerationData().damageChance - d.getWexingEngineInfluence() * 0.15f)),
INSTABILITY(d -> d.damageChance),
FORTUNE_CHANCE(d -> d.bonusYieldChance),
CHAIN_FOCUSING_CHANCE(d -> d.chainFocusingChance),
SHIELDING_CHANCE(d -> d.damageAbsorptionChance),
RESTORATION_CHANCE(d -> d.restorationChance);

public final Predicate<CrucibleAccelerationData> isValueValid;
public final Function<ICatalyzerAccelerationTarget, String> statDisplayFunction;
public final Function<CrucibleAccelerationData, String> statDisplayFunction;

CrucibleTuningType(Predicate<CrucibleAccelerationData> isValueValid, Function<ICatalyzerAccelerationTarget, String> statDisplayFunction) {
CrucibleTuningType(Function<CrucibleAccelerationData, CrucibleAccelerationData.TunedValue> valueGetter) {
this(d -> valueGetter.apply(d).getValue(d) > 0, d -> String.format("%.2f", valueGetter.apply(d).getValue(d)));
}
CrucibleTuningType(Predicate<CrucibleAccelerationData> isValueValid, Function<CrucibleAccelerationData, String> statDisplayFunction) {
this.isValueValid = isValueValid;
this.statDisplayFunction = statDisplayFunction;
}
CrucibleTuningType(Function<CrucibleAccelerationData, Float> valueGetter) {
this(d -> valueGetter.apply(d) > 0, d -> String.format("%.2f", valueGetter.apply(d.getAccelerationData())));
}

public static List<CrucibleTuningType> getValidValues(CrucibleAccelerationData data) {
List<CrucibleTuningType> validValues = new ArrayList<>();
Expand All @@ -71,76 +73,83 @@ public String translation() {
}
}

public enum AppliedTuning {
BUFF(TunedValue::getPositiveMultiplier),
DEBUFF(TunedValue::getNegativeMultiplier),
NONE(TunedValue::getBaseValue);
public enum AppliedTuningType {
BUFF(TuningModifier::getPositiveMultiplier),
DEBUFF(TuningModifier::getNegativeMultiplier),
NONE(TuningModifier::getDefaultMultiplier);

public final Function<TunedValue, Float> multiplierGetter;
public final Function<TuningModifier, Float> multiplierGetter;

AppliedTuning(Function<TunedValue, Float> multiplierGetter) {
AppliedTuningType(Function<TuningModifier, Float> multiplierGetter) {
this.multiplierGetter = multiplierGetter;
}
}

public static class TunedValue {
public static class TuningModifier {
public final CrucibleTuningType tuningType;
public final AppliedTuning appliedTuning;
public final AppliedTuningType appliedTuningType;

public TunedValue(CrucibleTuningType tuningType, AppliedTuning appliedTuning) {
public TuningModifier(CrucibleTuningType tuningType, AppliedTuningType appliedTuningType) {
this.tuningType = tuningType;
this.appliedTuning = appliedTuning;
this.appliedTuningType = appliedTuningType;
}

public TunedValue(CrucibleTuningType tuningType, CrucibleTuningType buffedStat) {
public TuningModifier(CrucibleTuningType tuningType, ICatalyzerAccelerationTarget target) {
this.tuningType = tuningType;
this.appliedTuning = buffedStat.equals(CrucibleTuningType.NONE) ? AppliedTuning.NONE : tuningType.equals(buffedStat) ? AppliedTuning.BUFF : AppliedTuning.DEBUFF;
this.appliedTuningType = target.getTuningType().equals(CrucibleTuningType.NONE) ? AppliedTuningType.NONE : tuningType.equals(target.getTuningType()) ? AppliedTuningType.BUFF : AppliedTuningType.DEBUFF;
}

public CrucibleAccelerationData.TunedValue createTunedValue(float value) {
return new CrucibleAccelerationData.TunedValue(this, value);
}

public float getMultiplier() {
switch (appliedTuning) {
case NONE -> {
return getBaseValue();
}
case BUFF -> {
return getPositiveMultiplier();
}
case DEBUFF -> {
return getNegativeMultiplier();
}
default -> throw new NullPointerException("Tuned Value Tuning Type is somehow null.");
float value = getDefaultMultiplier();
switch (appliedTuningType) {
case BUFF -> value = getPositiveMultiplier();
case DEBUFF -> value = getNegativeMultiplier();
}
return value;
}

protected float getMultiplierScalar(float attributeMultiplier) {
return 1+attributeMultiplier;
}

protected float getBaseValue() {
private float getDefaultMultiplier() {
return 1f;
}

protected float getPositiveMultiplier() {
float getPositiveMultiplier() {
return 1.2f;
}

protected float getNegativeMultiplier() {
float getNegativeMultiplier() {
return 0.9f;
}
}

public static class InverseTunedValue extends TunedValue {
public InverseTunedValue(CrucibleTuningType tuningType, AppliedTuning appliedTuning) {
super(tuningType, appliedTuning);
public static class InverseTuningModifier extends TuningModifier {
public InverseTuningModifier(CrucibleTuningType tuningType, AppliedTuningType appliedTuningType) {
super(tuningType, appliedTuningType);
}

public InverseTunedValue(CrucibleTuningType tuningType, CrucibleTuningType buffedStat) {
super(tuningType, buffedStat);
public InverseTuningModifier(CrucibleTuningType tuningType, ICatalyzerAccelerationTarget target) {
super(tuningType, target);
}

@Override
protected float getMultiplierScalar(float attributeMultiplier) {
return 1-attributeMultiplier;
}

@Override
protected float getPositiveMultiplier() {
float getPositiveMultiplier() {
return 0.8f;
}

@Override
protected float getNegativeMultiplier() {
float getNegativeMultiplier() {
return 1.1f;
}
}
Expand Down
Loading

0 comments on commit 5a0f299

Please sign in to comment.