Add some tests for com.gmail.nossr50.util.random classes

This commit is contained in:
nossr50
2021-01-03 12:21:32 -08:00
parent 867d222062
commit 7931a095fe
27 changed files with 195 additions and 87 deletions

View File

@@ -1,8 +1,6 @@
package com.gmail.nossr50.util.random;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
@@ -11,109 +9,92 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class RandomChanceSkill implements RandomChanceExecution {
protected final @NotNull PrimarySkillType primarySkillType;
protected final @NotNull SubSkillType subSkillType;
protected final double probabilityCap;
protected final boolean isLucky;
protected int skillLevel;
protected double resultModifier;
protected final double resultModifier;
protected final double maximumBonusLevelCap;
public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, double resultModifier) {
this.primarySkillType = subSkillType.getParentSkill();
this.subSkillType = subSkillType;
this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (player != null && mcMMOPlayer != null) {
this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
this.skillLevel = mcMMOPlayer.getSkillLevel(subSkillType.getParentSkill());
} else {
this.skillLevel = 0;
}
if (player != null)
isLucky = Permissions.lucky(player, primarySkillType);
isLucky = Permissions.lucky(player, subSkillType.getParentSkill());
else
isLucky = false;
this.resultModifier = resultModifier;
this.maximumBonusLevelCap = RandomChanceUtil.getMaxBonusLevelCap(subSkillType);
}
public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType) {
this.primarySkillType = subSkillType.getParentSkill();
this.subSkillType = subSkillType;
this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (player != null && mcMMOPlayer != null) {
this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
this.skillLevel = mcMMOPlayer.getSkillLevel(subSkillType.getParentSkill());
} else {
this.skillLevel = 0;
}
if (player != null)
isLucky = Permissions.lucky(player, primarySkillType);
isLucky = Permissions.lucky(player, subSkillType.getParentSkill());
else
isLucky = false;
this.resultModifier = 1.0D;
this.maximumBonusLevelCap = RandomChanceUtil.getMaxBonusLevelCap(subSkillType);
}
public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap) {
if (hasCap)
this.probabilityCap = AdvancedConfig.getInstance().getMaximumProbability(subSkillType);
this.probabilityCap = RandomChanceUtil.getMaximumProbability(subSkillType);
else
this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
this.primarySkillType = subSkillType.getParentSkill();
this.subSkillType = subSkillType;
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (player != null && mcMMOPlayer != null) {
this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
this.skillLevel = mcMMOPlayer.getSkillLevel(subSkillType.getParentSkill());
} else {
this.skillLevel = 0;
}
if (player != null)
isLucky = Permissions.lucky(player, primarySkillType);
isLucky = Permissions.lucky(player, subSkillType.getParentSkill());
else
isLucky = false;
this.resultModifier = 1.0D;
this.maximumBonusLevelCap = RandomChanceUtil.getMaxBonusLevelCap(subSkillType);
}
public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap, double resultModifier) {
if (hasCap)
this.probabilityCap = AdvancedConfig.getInstance().getMaximumProbability(subSkillType);
this.probabilityCap = RandomChanceUtil.getMaximumProbability(subSkillType);
else
this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
this.primarySkillType = subSkillType.getParentSkill();
this.subSkillType = subSkillType;
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (player != null && mcMMOPlayer != null) {
this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
this.skillLevel = mcMMOPlayer.getSkillLevel(subSkillType.getParentSkill());
} else {
this.skillLevel = 0;
}
if (player != null)
isLucky = Permissions.lucky(player, primarySkillType);
isLucky = Permissions.lucky(player, subSkillType.getParentSkill());
else
isLucky = false;
this.resultModifier = resultModifier;
}
/**
* The subskill corresponding to this RandomChanceSkill
*
* @return this subskill
*/
public @NotNull SubSkillType getSubSkill() {
return subSkillType;
this.maximumBonusLevelCap = RandomChanceUtil.getMaxBonusLevelCap(subSkillType);
}
/**
@@ -142,7 +123,7 @@ public class RandomChanceSkill implements RandomChanceExecution {
* @return the maximum bonus from skill level for this skill
*/
public double getMaximumBonusLevelCap() {
return AdvancedConfig.getInstance().getMaxBonusLevel(subSkillType);
return maximumBonusLevelCap;
}
/**
@@ -173,8 +154,4 @@ public class RandomChanceSkill implements RandomChanceExecution {
public double getResultModifier() {
return resultModifier;
}
public void setResultModifier(double resultModifier) {
this.resultModifier = resultModifier;
}
}

View File

@@ -3,7 +3,6 @@ package com.gmail.nossr50.util.random;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillRandomCheckEvent;
import com.gmail.nossr50.util.EventUtils;
@@ -20,6 +19,7 @@ public class RandomChanceUtil {
public static final @NotNull DecimalFormat percent = new DecimalFormat("##0.00%");
//public static final DecimalFormat decimal = new DecimalFormat("##0.00");
public static final double LINEAR_CURVE_VAR = 100.0D;
public static final double LUCKY_MODIFIER = 1.333D;
/**
* This method is the final step in determining if a Sub-Skill / Secondary Skill in mcMMO successfully activates either from chance or otherwise
@@ -142,7 +142,7 @@ public class RandomChanceUtil {
return chanceOfSuccess;
}*/
private static double calculateChanceOfSuccess(@NotNull RandomChanceSkill randomChance) {
public static double calculateChanceOfSuccess(@NotNull RandomChanceSkill randomChance) {
double skillLevel = randomChance.getSkillLevel();
double maximumProbability = randomChance.getProbabilityCap();
double maximumBonusLevel = randomChance.getMaximumBonusLevelCap();
@@ -163,7 +163,7 @@ public class RandomChanceUtil {
return chanceOfSuccess;
}
private static double calculateChanceOfSuccess(@NotNull RandomChanceSkillStatic randomChance) {
public static double calculateChanceOfSuccess(@NotNull RandomChanceSkillStatic randomChance) {
double chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), 100, 100);
//Add Luck
@@ -304,15 +304,23 @@ public class RandomChanceUtil {
public static double addLuck(@NotNull Player player, @NotNull PrimarySkillType primarySkillType, double chance) {
if (Permissions.lucky(player, primarySkillType))
return chance * 1.333D;
return chance * LUCKY_MODIFIER;
else
return chance;
}
public static double addLuck(boolean isLucky, double chance) {
if (isLucky)
return chance * 1.333D;
return chance * LUCKY_MODIFIER;
else
return chance;
}
public static double getMaximumProbability(@NotNull SubSkillType subSkillType) {
return AdvancedConfig.getInstance().getMaximumProbability(subSkillType);
}
public static double getMaxBonusLevelCap(@NotNull SubSkillType subSkillType) {
return AdvancedConfig.getInstance().getMaxBonusLevel(subSkillType);
}
}