From 2dd6ab8c6f151eaf2c65064300cb8ed7e4e9c1ef Mon Sep 17 00:00:00 2001 From: Noogear <123232885+Noogear@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:43:52 +0800 Subject: [PATCH] Add max health and damage options, scaling changes (#12) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 <63976867+Archy-X@users.noreply.github.com> --- .../auramobs/entities/AureliumMob.java | 24 ++++++++++++++++++ .../auramobs/entities/ScaleManager.java | 25 +++++++++++++------ src/main/resources/config.yml | 8 +++++- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/main/java/dev/aurelium/auramobs/entities/AureliumMob.java b/src/main/java/dev/aurelium/auramobs/entities/AureliumMob.java index 3f4e562..514554b 100644 --- a/src/main/java/dev/aurelium/auramobs/entities/AureliumMob.java +++ b/src/main/java/dev/aurelium/auramobs/entities/AureliumMob.java @@ -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(); diff --git a/src/main/java/dev/aurelium/auramobs/entities/ScaleManager.java b/src/main/java/dev/aurelium/auramobs/entities/ScaleManager.java index 28fb24c..a49278c 100644 --- a/src/main/java/dev/aurelium/auramobs/entities/ScaleManager.java +++ b/src/main/java/dev/aurelium/auramobs/entities/ScaleManager.java @@ -15,8 +15,9 @@ public class ScaleManager { private final List entries = new ArrayList<>(); - private Attribute scaleAttribute; private final AuraMobs plugin; + private boolean override; + private Attribute scaleAttribute; public ScaleManager(AuraMobs plugin) { this.plugin = plugin; @@ -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) { @@ -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))); } } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 69f4d00..d1c56f6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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' @@ -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' @@ -85,4 +89,6 @@ spawn_reasons: - 'COMMAND' - 'CUSTOM' - 'DEFAULT' -scales: \ No newline at end of file +scaling: + override: false + levels: {}