mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 11:03:43 +01:00 
			
		
		
		
	Fixed Luck permission showing incorrect percentages to players using commands
Fixed #4405
This commit is contained in:
		@@ -75,6 +75,25 @@ public class RandomChanceSkill implements RandomChanceExecution {
 | 
			
		||||
        this.maximumBonusLevelCap = RandomChanceUtil.getMaxBonusLevelCap(subSkillType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RandomChanceSkill(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap, boolean luckyOverride) {
 | 
			
		||||
        if (hasCap)
 | 
			
		||||
            this.probabilityCap = RandomChanceUtil.getMaximumProbability(subSkillType);
 | 
			
		||||
        else
 | 
			
		||||
            this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
 | 
			
		||||
 | 
			
		||||
        final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
 | 
			
		||||
        if (player != null && mcMMOPlayer != null) {
 | 
			
		||||
            this.skillLevel = mcMMOPlayer.getSkillLevel(subSkillType.getParentSkill());
 | 
			
		||||
        } else {
 | 
			
		||||
            this.skillLevel = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        isLucky = luckyOverride;
 | 
			
		||||
 | 
			
		||||
        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 = RandomChanceUtil.getMaximumProbability(subSkillType);
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,12 @@ public class RandomChanceSkillStatic extends RandomChanceSkill {
 | 
			
		||||
        this.xPos = xPos;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RandomChanceSkillStatic(double xPos, @Nullable Player player, @NotNull SubSkillType subSkillType, boolean luckyOverride) {
 | 
			
		||||
        super(player, subSkillType, false, luckyOverride);
 | 
			
		||||
 | 
			
		||||
        this.xPos = xPos;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RandomChanceSkillStatic(double xPos, @Nullable Player player, @NotNull SubSkillType subSkillType, double resultModifier) {
 | 
			
		||||
        super(player, subSkillType, resultModifier);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -45,12 +45,12 @@ public class RandomChanceUtil {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double getActivationChance(@NotNull SkillActivationType skillActivationType, @NotNull SubSkillType subSkillType, @Nullable Player player) {
 | 
			
		||||
    public static double getActivationChance(@NotNull SkillActivationType skillActivationType, @NotNull SubSkillType subSkillType, @Nullable Player player, boolean luckyOverride) {
 | 
			
		||||
        switch (skillActivationType) {
 | 
			
		||||
            case RANDOM_LINEAR_100_SCALE_WITH_CAP:
 | 
			
		||||
                return getRandomChanceExecutionSuccess(player, subSkillType, true);
 | 
			
		||||
                return getRandomChanceExecutionSuccess(player, subSkillType, true, luckyOverride);
 | 
			
		||||
            case RANDOM_STATIC_CHANCE:
 | 
			
		||||
                return getRandomStaticChanceExecutionSuccess(player, subSkillType);
 | 
			
		||||
                return getRandomStaticChanceExecutionSuccess(player, subSkillType, luckyOverride);
 | 
			
		||||
            default:
 | 
			
		||||
                return 0.1337;
 | 
			
		||||
        }
 | 
			
		||||
@@ -129,6 +129,10 @@ public class RandomChanceUtil {
 | 
			
		||||
        return getChanceOfSuccess(randomChance.getXPos(), randomChance.getProbabilityCap(), LINEAR_CURVE_VAR);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double getRandomChanceExecutionChance(@NotNull RandomChanceExecution randomChance, boolean luckyOverride) {
 | 
			
		||||
        return getChanceOfSuccess(randomChance.getXPos(), randomChance.getProbabilityCap(), LINEAR_CURVE_VAR);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double getRandomChanceExecutionChance(@NotNull RandomChanceStatic randomChance) {
 | 
			
		||||
        double chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), randomChance.getProbabilityCap(), LINEAR_CURVE_VAR);
 | 
			
		||||
 | 
			
		||||
@@ -194,9 +198,14 @@ public class RandomChanceUtil {
 | 
			
		||||
        return calculateChanceOfSuccess(rcs);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double getRandomStaticChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType) {
 | 
			
		||||
    public static double getRandomChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean hasCap, boolean luckyOverride) {
 | 
			
		||||
        RandomChanceSkill rcs = new RandomChanceSkill(player, subSkillType, hasCap, luckyOverride);
 | 
			
		||||
        return calculateChanceOfSuccess(rcs);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static double getRandomStaticChanceExecutionSuccess(@Nullable Player player, @NotNull SubSkillType subSkillType, boolean luckyOverride) {
 | 
			
		||||
        try {
 | 
			
		||||
            return getRandomChanceExecutionChance(new RandomChanceSkillStatic(getStaticRandomChance(subSkillType), player, subSkillType));
 | 
			
		||||
            return getRandomChanceExecutionChance(new RandomChanceSkillStatic(getStaticRandomChance(subSkillType), player, subSkillType, luckyOverride));
 | 
			
		||||
        } catch (InvalidStaticChance invalidStaticChance) {
 | 
			
		||||
            //Catch invalid static skills
 | 
			
		||||
            invalidStaticChance.printStackTrace();
 | 
			
		||||
@@ -259,13 +268,15 @@ public class RandomChanceUtil {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String @NotNull [] calculateAbilityDisplayValues(@NotNull SkillActivationType skillActivationType, @NotNull Player player, @NotNull SubSkillType subSkillType) {
 | 
			
		||||
        double successChance = getActivationChance(skillActivationType, subSkillType, player);
 | 
			
		||||
        double successChance = getActivationChance(skillActivationType, subSkillType, player, false);
 | 
			
		||||
        double successChanceLucky = getActivationChance(skillActivationType, subSkillType, player, true);
 | 
			
		||||
 | 
			
		||||
        String[] displayValues = new String[2];
 | 
			
		||||
 | 
			
		||||
        boolean isLucky = Permissions.lucky(player, subSkillType.getParentSkill());
 | 
			
		||||
 | 
			
		||||
        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(successChanceLucky, 100.0D) / 100.0D) : null;
 | 
			
		||||
 | 
			
		||||
        return displayValues;
 | 
			
		||||
    }
 | 
			
		||||
@@ -288,16 +299,16 @@ public class RandomChanceUtil {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String @NotNull [] calculateAbilityDisplayValuesCustom(@NotNull SkillActivationType skillActivationType, @NotNull Player player, @NotNull SubSkillType subSkillType, double multiplier) {
 | 
			
		||||
        double successChance = getActivationChance(skillActivationType, subSkillType, player);
 | 
			
		||||
        double successChance = getActivationChance(skillActivationType, subSkillType, player, false);
 | 
			
		||||
        double successChanceLucky = getActivationChance(skillActivationType, subSkillType, player, true);
 | 
			
		||||
        //TODO: Most likely incorrectly displays the value for graceful roll but gonna ignore for now...
 | 
			
		||||
        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);
 | 
			
		||||
        displayValues[1] = isLucky ? percent.format(Math.min(successChance * 1.3333D, 100.0D) / 100.0D) : null;
 | 
			
		||||
        displayValues[1] = isLucky ? percent.format(Math.min(successChanceLucky, 100.0D) / 100.0D) : null;
 | 
			
		||||
 | 
			
		||||
        return displayValues;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user