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

This commit is contained in:
nossr50 2023-04-23 13:23:18 -07:00
parent 72957c3d31
commit d30b2f7bf6
5 changed files with 14 additions and 11 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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());

View File

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

View File

@ -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