Skip to content

Commit

Permalink
Add max health and damage options, scaling changes (#12)
Browse files Browse the repository at this point in the history
- Add health.max and damage.max options under mob_defaults and bosses
- Rename mobs scaling config options, move user-defined config under levels section
- Mobs are scaled proportionately based on existing scale, can be disable by setting override to true
 
Co-authored-by: Archy-X <[email protected]>
  • Loading branch information
Noogear authored Sep 27, 2024
1 parent 49a73bd commit 2dd6ab8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
24 changes: 24 additions & 0 deletions src/main/java/dev/aurelium/auramobs/entities/AureliumMob.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ public AureliumMob(LivingEntity mob, int level, AuraMobs plugin) {
Expression resHealth = new ExpressionBuilder(healthFormula).build();
double damage = BigDecimal.valueOf(resDamage.evaluate()).setScale(2, RoundingMode.CEILING).doubleValue();
double health = resHealth.evaluate();

String optDamageMax = plugin.optionString(prefix + "damage.max");
if (optDamageMax != null && !optDamageMax.isEmpty()) {
String damageMax = MessageUtils.setPlaceholders(null, optDamageMax
.replace("{mob_damage}", String.valueOf(startDamage))
.replace("{level}", String.valueOf(level1))
.replace("{distance}", Double.toString(distance))
);
Expression resMaxDamage = new ExpressionBuilder(damageMax).build();
double maxDamage = BigDecimal.valueOf(resMaxDamage.evaluate()).setScale(2, RoundingMode.CEILING).doubleValue();
damage = Math.min(maxDamage, damage);
}
String optHealthMax = plugin.optionString(prefix + "health.max");
if (optHealthMax != null && !optHealthMax.isEmpty()) {
String healthMax = MessageUtils.setPlaceholders(null, optHealthMax
.replace("{mob_health}", String.valueOf(startHealth))
.replace("{level}", String.valueOf(level1))
.replace("{distance}", Double.toString(distance))
);
Expression resMaxHealth = new ExpressionBuilder(healthMax).build();
double maxHealth = resMaxHealth.evaluate();
health = Math.min(maxHealth, health);
}

String formattedHealth = plugin.getFormatter().format(health);
if (health > plugin.getMaxHealth()) {
health = plugin.getMaxHealth();
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/dev/aurelium/auramobs/entities/ScaleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
public class ScaleManager {

private final List<EntityScale> entries = new ArrayList<>();
private Attribute scaleAttribute;
private final AuraMobs plugin;
private boolean override;
private Attribute scaleAttribute;

public ScaleManager(AuraMobs plugin) {
this.plugin = plugin;
Expand All @@ -35,11 +36,16 @@ public void loadConfiguration() {

if (scaleAttribute == null) return;

ConfigurationSection section = plugin.getConfig().getConfigurationSection("scales");
ConfigurationSection section = plugin.getConfig().getConfigurationSection("scaling");
if (section == null) return;

for (String entry : section.getKeys(false)) {
ConfigurationSection entrySection = section.getConfigurationSection(entry);
ConfigurationSection levelSection = section.getConfigurationSection("levels");
if (levelSection == null) return;

override = plugin.optionBoolean("scaling.override");

for (String entry : levelSection.getKeys(false)) {
ConfigurationSection entrySection = levelSection.getConfigurationSection(entry);
if (entrySection == null) continue;

if (entry.split("-").length < 2) {
Expand Down Expand Up @@ -105,13 +111,16 @@ public void applyScale(LivingEntity entity, int level) {
}

if (Math.random() < entry.getChance()) {
double random;
if (entry.getFixed().length > 0) {
double random = entry.getFixed()[ThreadLocalRandom.current().nextInt(entry.getFixed().length)];
ai.setBaseValue(Math.max(.00625, Math.min(16, random)));
random = entry.getFixed()[ThreadLocalRandom.current().nextInt(entry.getFixed().length)];
} else {
double random = entry.getIntervalStart() + (entry.getIntervalEnd() - entry.getIntervalStart()) * Math.random();
ai.setBaseValue(Math.max(.00625, Math.min(16, random)));
random = entry.getIntervalStart() + (entry.getIntervalEnd() - entry.getIntervalStart()) * Math.random();
}
if (!override) {
random = random * ai.getValue();
}
ai.setBaseValue(Math.max(.00625, Math.min(16, random)));
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ language: en
mob_defaults:
damage:
formula: '{mob_damage} + ({mob_damage} * ({level} - 1) / 25)'
max: ''
health:
formula: '{mob_health} * (1 + ({level} - 1) / 25)'
max: ''
mob_level:
formula: '{sumlevel}/{playercount}'
backup_formula: '{distance}*0.01'
Expand All @@ -20,8 +22,10 @@ bosses:
enabled: false
health:
formula: '{mob_health} * (1 + ({level} - 1) / 25)'
max: ''
damage:
formula: '{mob_damage} + ({mob_damage} * ({level} - 1) / 25)'
max: ''
level:
formula: '{sumlevel}/{playercount}'
backup_formula: '{distance}*0.01'
Expand Down Expand Up @@ -85,4 +89,6 @@ spawn_reasons:
- 'COMMAND'
- 'CUSTOM'
- 'DEFAULT'
scales:
scaling:
override: false
levels: {}

0 comments on commit 2dd6ab8

Please sign in to comment.