From be9aeacd707ff049ff039a9aaff0333af8bb7c35 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 27 Jan 2019 19:00:48 -0800 Subject: [PATCH] Fixing lucky displays --- .../util/random/RandomChanceStatic.java | 8 +++++++- .../nossr50/util/random/RandomChanceUtil.java | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/random/RandomChanceStatic.java b/src/main/java/com/gmail/nossr50/util/random/RandomChanceStatic.java index 3df0ae390..30f84cfbf 100644 --- a/src/main/java/com/gmail/nossr50/util/random/RandomChanceStatic.java +++ b/src/main/java/com/gmail/nossr50/util/random/RandomChanceStatic.java @@ -3,11 +3,13 @@ package com.gmail.nossr50.util.random; public class RandomChanceStatic implements RandomChanceExecution { private final double xPos; private final double probabilityCap; + private final boolean isLucky; - public RandomChanceStatic(double xPos) + public RandomChanceStatic(double xPos, boolean isLucky) { this.xPos = xPos; this.probabilityCap = xPos; + this.isLucky = isLucky; } /** @@ -30,4 +32,8 @@ public class RandomChanceStatic implements RandomChanceExecution { public double getProbabilityCap() { return probabilityCap; } + + public boolean isLucky() { + return isLucky; + } } diff --git a/src/main/java/com/gmail/nossr50/util/random/RandomChanceUtil.java b/src/main/java/com/gmail/nossr50/util/random/RandomChanceUtil.java index 7bb5f011d..9c1d76c8b 100644 --- a/src/main/java/com/gmail/nossr50/util/random/RandomChanceUtil.java +++ b/src/main/java/com/gmail/nossr50/util/random/RandomChanceUtil.java @@ -123,6 +123,15 @@ public class RandomChanceUtil */ public static double getRandomChanceExecutionChance(RandomChanceExecution randomChance) { double chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), randomChance.getProbabilityCap(), LINEAR_CURVE_VAR); + + return chanceOfSuccess; + } + + public static double getRandomChanceExecutionChance(RandomChanceStatic randomChance) { + double chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), randomChance.getProbabilityCap(), LINEAR_CURVE_VAR); + + chanceOfSuccess = addLuck(randomChance.isLucky(), chanceOfSuccess); + return chanceOfSuccess; } @@ -262,15 +271,18 @@ public class RandomChanceUtil } public static String[] calculateAbilityDisplayValuesStatic(Player player, PrimarySkillType primarySkillType, double chance) { - RandomChanceStatic rcs = new RandomChanceStatic(chance); + RandomChanceStatic rcs = new RandomChanceStatic(chance, false); double successChance = getRandomChanceExecutionChance(rcs); + RandomChanceStatic rcs_lucky = new RandomChanceStatic(chance, true); + double successChance_lucky = getRandomChanceExecutionChance(rcs_lucky); + String[] displayValues = new String[2]; boolean isLucky = Permissions.lucky(player, primarySkillType); displayValues[0] = percent.format(Math.min(successChance, 100.0D) / 100.0D); - displayValues[1] = isLucky ? percent.format(Math.min(successChance * 1.3333D, 100.0D) / 100.0D) : null; + displayValues[1] = isLucky ? percent.format(Math.min(successChance_lucky, 100.0D) / 100.0D) : null; return displayValues; } @@ -280,6 +292,8 @@ public class RandomChanceUtil successChance *= multiplier; //Currently only used for graceful roll String[] displayValues = new String[2]; + //TODO: Account for lucky in this + boolean isLucky = Permissions.lucky(player, subSkillType.getParentSkill()); displayValues[0] = percent.format(Math.min(successChance, 100.0D) / 100.0D);