Refactor probability tests a little bit

This commit is contained in:
nossr50
2022-12-18 17:08:36 -08:00
parent 4a5e3542ef
commit 12fb4a3679
3 changed files with 37 additions and 36 deletions

View File

@ -33,6 +33,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;
import java.util.Locale;
@ -198,7 +199,8 @@ public class Roll extends AcrobaticsSubSkill {
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
private double rollCheck(Player player, McMMOPlayer mcMMOPlayer, double damage) {
@VisibleForTesting
public double rollCheck(Player player, McMMOPlayer mcMMOPlayer, double damage) {
int skillLevel = mcMMOPlayer.getSkillLevel(getPrimarySkill());
@ -246,8 +248,7 @@ public class Roll extends AcrobaticsSubSkill {
private double gracefulRollCheck(Player player, McMMOPlayer mcMMOPlayer, double damage, int skillLevel) {
double modifiedDamage = calculateModifiedRollDamage(damage, mcMMO.p.getAdvancedConfig().getRollDamageThreshold() * 2);
double gracefulOdds = ProbabilityUtil.getSubSkillProbability(subSkillType, player).getValue() * 2;
Probability gracefulProbability = Probability.ofPercent(gracefulOdds);
Probability gracefulProbability = getGracefulProbability(player);
if (!isFatal(player, modifiedDamage)
//TODO: Graceful isn't sending out an event
@ -271,6 +272,12 @@ public class Roll extends AcrobaticsSubSkill {
return damage;
}
@NotNull
public static Probability getGracefulProbability(Player player) {
double gracefulOdds = ProbabilityUtil.getSubSkillProbability(SubSkillType.ACROBATICS_ROLL, player).getValue() * 2;
return Probability.ofPercent(gracefulOdds);
}
/**
* Check if the player is "farming" Acrobatics XP using
* exploits in the game.