소스 검색

Fixed divide by zero bug impacting tridents XP when missing from config

nossr50 2 년 전
부모
커밋
d30b2f7bf6

+ 1 - 0
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

+ 1 - 1
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 */

+ 1 - 1
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());

+ 7 - 7
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);
         }
     }

+ 4 - 2
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