Skip to content

Commit

Permalink
Merge pull request #438 from ArcanePlugins/3.9-dev
Browse files Browse the repository at this point in the history
3.9 dev
  • Loading branch information
lokka30 authored Dec 20, 2022
2 parents 82a59e3 + d93c208 commit d23233c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.lokka30</groupId>
<artifactId>LevelledMobs</artifactId>
<version>3.9.0 b727</version>
<version>3.9.1 b730</version>
<packaging>jar</packaging>
<name>LevelledMobs</name>
<description>The Ultimate RPG Mob Levelling Plugin</description>
Expand Down
60 changes: 34 additions & 26 deletions src/main/java/me/lokka30/levelledmobs/managers/MobDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

package me.lokka30.levelledmobs.managers;

import static me.lokka30.levelledmobs.misc.DebugType.ATTRIBUTE_MULTIPLIERS;
import static me.lokka30.levelledmobs.util.Utils.debugLog;

import java.util.Collections;
import java.util.Enumeration;
import java.util.Map;
Expand Down Expand Up @@ -95,9 +98,9 @@ void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity,
(float) Objects.requireNonNull(getAttributeDefaultValue(lmEntity, attribute)) :
(float) Objects.requireNonNull(lmEntity.getLivingEntity().getAttribute(attribute))
.getBaseValue();
final double additionValue = getAdditionsForLevel(lmEntity, addition, defaultValue);
final float additionValue = getAdditionsForLevel(lmEntity, addition, defaultValue);

if (additionValue == 0.0) {
if (additionValue == 0.0f) {
return;
}

Expand Down Expand Up @@ -135,7 +138,7 @@ void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity,
}

if (!existingMod.getName().startsWith("GENERIC_")) {
Utils.debugLog(main, DebugType.MULTIPLIER_REMOVED, String.format(
debugLog(main, DebugType.MULTIPLIER_REMOVED, String.format(
"Removing %s from (lvl %s) %s at %s,%s,%s", existingMod.getName(), lmEntity.getMobLevel(), lmEntity.getNameIfBaby(),
lmEntity.getLocation().getBlockX(), lmEntity.getLocation().getBlockY(), lmEntity.getLocation().getBlockZ()));
}
Expand All @@ -144,13 +147,13 @@ void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity,
}

if (useStaticValues) {
Utils.debugLog(main, DebugType.ATTRIBUTE_MULTIPLIERS,
debugLog(main, ATTRIBUTE_MULTIPLIERS,
String.format("%s (%s): attrib: %s, base: %s, new base value: %s",
lmEntity.getNameIfBaby(), lmEntity.getMobLevel(), attribute.name(),
Utils.round(attrib.getBaseValue(), 3), Utils.round(defaultValue, 3)));
attrib.setBaseValue(defaultValue);
} else {
Utils.debugLog(main, DebugType.ATTRIBUTE_MULTIPLIERS,
debugLog(main, ATTRIBUTE_MULTIPLIERS,
String.format("%s (%s): attrib: %s, base: %s, addtion: %s",
lmEntity.getNameIfBaby(), lmEntity.getMobLevel(), attribute.name(),
Utils.round(attrib.getBaseValue(), 3), Utils.round(additionValue, 3)));
Expand All @@ -159,25 +162,25 @@ void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity,

// MAX_HEALTH specific: set health to max health
if (attribute == Attribute.GENERIC_MAX_HEALTH) {
double newHealth = attrib.getValue() - existingDamage;
if (newHealth < 0.0) {
newHealth = 0.0;
}
try {
if (lmEntity.getLivingEntity().getHealth() <= 0.0) {
return;
}
lmEntity.getLivingEntity().setHealth(newHealth);
} catch (final IllegalArgumentException ignored) {
}
if (lmEntity.getLivingEntity().getHealth() <= 0.0) return;
lmEntity.getLivingEntity().setHealth(
Math.max(
0.0d,
attrib.getValue() - existingDamage
)
);
} catch (final IllegalArgumentException ignored) {}
}
}

public final float getAdditionsForLevel(final LivingEntityWrapper lmEntity,
final Addition addition, final float defaultValue) {
public final float getAdditionsForLevel(
final LivingEntityWrapper lmEntity,
final Addition addition,
final float defaultValue
) {
final float maxLevel = main.rulesManager.getRuleMobMaxLevel(lmEntity);

//double attributeValue = 0;
final FineTuningAttributes fineTuning = lmEntity.getFineTuningAttributes();
FineTuningAttributes.Multiplier multiplier = null;
float attributeMax = 0;
Expand All @@ -193,22 +196,27 @@ public final float getAdditionsForLevel(final LivingEntityWrapper lmEntity,
}
}

if (maxLevel == 0 || multiplier == null) {
if (maxLevel == 0 || multiplier == null || multiplier.value() == 0.0f) {
debugLog(main, ATTRIBUTE_MULTIPLIERS, lmEntity.getNameIfBaby() +
", maxLevel=0 / multiplier=null; returning 0 for " + addition);
return 0.0f;
}

final float multiplierValue = multiplier.value();

if (fineTuning.useStacked || multiplier.useStacked()){
if (fineTuning.useStacked != null && fineTuning.useStacked || multiplier.useStacked()) {
debugLog(main, ATTRIBUTE_MULTIPLIERS, multiplier +
", using stacked formula");
return (float) lmEntity.getMobLevel() * multiplierValue;
}
else {
// only used for 5 specific attributes
} else {
debugLog(main, ATTRIBUTE_MULTIPLIERS, multiplier +
", using standard formula");

if (attributeMax > 0.0) {
// only used for 5 specific attributes
return (lmEntity.getMobLevel() / maxLevel) * (attributeMax * multiplierValue);
} else
// normal formula for most attributes
{
} else {
// normal formula for most attributes
return (defaultValue * multiplierValue) * ((lmEntity.getMobLevel()) / maxLevel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public FineTuningAttributes(){
this.multipliers = new LinkedHashMap<>();
}

private final Map<Addition, Multiplier> multipliers;
private Map<Addition, Multiplier> multipliers;
public boolean doNotMerge;
public Boolean useStacked;

Expand All @@ -36,7 +36,7 @@ void mergeAttributes(final @Nullable FineTuningAttributes attributes) {
return;
}

this.multipliers.putAll(attributes.multipliers);
this.multipliers.putAll(attributes.copyMultipliers());
}

public void addItem(final Addition addition, final Multiplier multiplier){
Expand Down Expand Up @@ -92,7 +92,6 @@ public void addItem(final Addition addition, final Multiplier multiplier){
}

public record Multiplier(Addition addition, boolean useStacked, float value){

@Contract(pure = true)
public @NotNull String toString(){
final StringBuilder sb = new StringBuilder();
Expand All @@ -109,13 +108,31 @@ public FineTuningAttributes cloneItem() {
FineTuningAttributes copy = null;
try {
copy = (FineTuningAttributes) super.clone();
copy.cloneMultipliers();
} catch (final Exception e) {
e.printStackTrace();
}

return copy;
}

private void cloneMultipliers(){
final Map<Addition, Multiplier> copy = copyMultipliers();
this.multipliers = new LinkedHashMap<>(copy.size());
this.multipliers.putAll(copy);
}

private @NotNull Map<Addition, Multiplier> copyMultipliers(){
final Map<Addition, Multiplier> copy = new LinkedHashMap<>(this.multipliers.size());

for (final Addition addition : this.multipliers.keySet()){
final Multiplier old = this.multipliers.get(addition);
copy.put(addition, new Multiplier(addition, old.useStacked, old.value));
}

return copy;
}

public String toString() {
if (this.isEmpty())
return "No items";
Expand All @@ -131,7 +148,7 @@ public String toString() {
}
sb.append(getShortName(item.addition()));
sb.append(": ");
sb.append(item.value);
sb.append(item.value());
if (item.useStacked()){
sb.append(" (");
sb.append("stk)");
Expand All @@ -140,4 +157,5 @@ public String toString() {

return sb.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1386,23 +1386,24 @@ private void parseFineTuning(final @Nullable ConfigurationSection cs) {
for (final String item : cs.getKeys(false)){
switch (item.toLowerCase()) {
case "use-stacked" ->
attribs.useStacked = ymlHelper.getBoolean2(cs, item, attribs.useStacked);
attribs.useStacked = ymlHelper.getBoolean2(cs, item, attribs.useStacked);
case "do-not-merge" ->
attribs.doNotMerge = ymlHelper.getBoolean(cs, item, false);
attribs.doNotMerge = ymlHelper.getBoolean(cs, item, false);
case "vanilla-bonus", "custom-mob-level" -> { }
default -> {
LMMultiplier lmMultiplier;
try{
lmMultiplier = LMMultiplier.valueOf(item.replace("-", "_").toUpperCase());
}
catch (Exception ignored){
try {
lmMultiplier = LMMultiplier
.valueOf(item.replace("-", "_")
.toUpperCase());
} catch (Exception ignored){
Utils.logger.warning("Invalid multiplier: " + item);
continue;
}

final Addition addition = attribs.getAdditionFromLMMultiplier(lmMultiplier);
FineTuningAttributes.Multiplier multiplier = parseFineTuningValues2(
cs, addition, item);
FineTuningAttributes.Multiplier multiplier =
parseFineTuningValues2(cs, addition, item);
if (multiplier != null) {
attribs.addItem(addition, multiplier);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ presets:
# Special Multipliers (0.0 Min - 1.0 Max)
armor-bonus: 0.2
armor-toughness: 0.15
## optional: use the stacker multiplier instead
## optional: use the stacked multiplier instead
# max-health: [ '4.25', 'STACKED' ]
# movement-speed: [ '0.002', 'STACKED' ]
# attack-damage: [ '0.25', 'STACKED' ]
Expand Down

0 comments on commit d23233c

Please sign in to comment.