From d30b2f7bf67ae91697cb9afcd8e2e74f05a0f0bc Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 23 Apr 2023 13:23:18 -0700 Subject: [PATCH] Fixed divide by zero bug impacting tridents XP when missing from config --- Changelog.txt | 1 + .../config/experience/ExperienceConfig.java | 2 +- .../nossr50/datatypes/player/McMMOPlayer.java | 2 +- .../com/gmail/nossr50/util/skills/CombatUtils.java | 14 +++++++------- src/main/resources/experience.yml | 6 ++++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 0eec68e12..e61407c9a 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -5,6 +5,7 @@ Version 2.2.000 TODO: Add unit test to determine crossbow or bow skill TODO: Add unit test for trident xp processing TODO: Add missing entries to changelog + Replaced 'Experience_Formula.Modifier' in experience.yml with 'Experience_Formula.Skill_Multiplier' which is easier to understand and less prone to divide by zero bugs (API) Many skills with RNG elements now send out a SubSkillEvent (which can be used to modify probability or cancel the results), some skills without RNG still send out this event when activated, this event is cancellable so it can be used to make a skill fail Treasure drop rate from Shake, Fishing, Hylian, and Excavation now benefit from the Luck perk Added 'Send_To_Console' settings to chat.yml to toggle sending party or admin chat messages to console diff --git a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java index 6863c0e55..bb7541828 100644 --- a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java +++ b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java @@ -256,7 +256,7 @@ public class ExperienceConfig extends BukkitConfig { /* Skill modifiers */ public double getFormulaSkillModifier(PrimarySkillType skill) { - return config.getDouble("Experience_Formula.Modifier." + StringUtils.getCapitalized(skill.toString())); + return config.getDouble("Experience_Formula.Modifier." + StringUtils.getCapitalized(skill.toString()), 1); } /* Custom XP perk */ diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 1e62dee8d..71bdbccb5 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -846,7 +846,7 @@ public class McMMOPlayer implements Identified { return 0; } - xp = (float) (xp / ExperienceConfig.getInstance().getFormulaSkillModifier(primarySkillType) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); + xp = (float) (xp * ExperienceConfig.getInstance().getFormulaSkillModifier(primarySkillType) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); if (mcMMO.p.getGeneralConfig().getToolModsEnabled()) { CustomTool tool = mcMMO.getModManager().getTool(player.getInventory().getItemInMainHand()); diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 6923c32be..45f30203b 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -137,8 +137,7 @@ public final class CombatUtils { mcMMOPlayer.checkAbilityActivation(PrimarySkillType.TRIDENTS); } - if(canUseLimitBreak(player, target, SubSkillType.TRIDENTS_TRIDENTS_LIMIT_BREAK)) - { + if(canUseLimitBreak(player, target, SubSkillType.TRIDENTS_TRIDENTS_LIMIT_BREAK)) { boostedDamage+=(getLimitBreakDamage(player, target, SubSkillType.TRIDENTS_TRIDENTS_LIMIT_BREAK) * mcMMOPlayer.getAttackStrength()); } @@ -821,13 +820,15 @@ public final class CombatUtils { XPGainReason xpGainReason; if (target instanceof Player defender) { - if (!ExperienceConfig.getInstance().getExperienceGainsPlayerVersusPlayerEnabled() || PartyManager.inSameParty(mcMMOPlayer.getPlayer(), (Player) target)) { + if (!ExperienceConfig.getInstance().getExperienceGainsPlayerVersusPlayerEnabled() + || PartyManager.inSameParty(mcMMOPlayer.getPlayer(), (Player) target)) { return; } xpGainReason = XPGainReason.PVP; - if (defender.isOnline() && SkillUtils.cooldownExpired(mcMMOPlayer.getRespawnATS(), Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS)) { + if (defender.isOnline() + && SkillUtils.cooldownExpired(mcMMOPlayer.getRespawnATS(), Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS)) { baseXP = 20 * ExperienceConfig.getInstance().getPlayerVersusPlayerXP(); } } @@ -839,8 +840,7 @@ public final class CombatUtils { EntityType type = target.getType(); baseXP = ExperienceConfig.getInstance().getAnimalsXP(type); } - else if (target instanceof Monster) - { + else if (target instanceof Monster) { EntityType type = target.getType(); baseXP = ExperienceConfig.getInstance().getCombatXP(type); } @@ -886,7 +886,7 @@ public final class CombatUtils { baseXP *= multiplier; - if (baseXP != 0) { + if (baseXP > 0) { new AwardCombatXpTask(mcMMOPlayer, primarySkillType, baseXP, target, xpGainReason).runTaskLater(mcMMO.p, 0); } } diff --git a/src/main/resources/experience.yml b/src/main/resources/experience.yml index 25e5383de..fffceb4a3 100644 --- a/src/main/resources/experience.yml +++ b/src/main/resources/experience.yml @@ -167,8 +167,10 @@ Experience_Formula: Breeding: Multiplier: 1.0 - # Experience gained will get divided by these values. 1.0 by default, 2.0 means two times less XP gained. - Modifier: + # Experience gained will get multiplied by these values. 1.0 by default, 0.5 means half XP gained. This happens right before multiplying the XP by the global multiplier. + Skill_Multiplier: + Crossbows: 1.0 + Tridents: 1.0 Swords: 1.0 Taming: 1.0 Acrobatics: 1.0