Fixed Luck permission showing incorrect percentages to players using commands

Fixed #4405
This commit is contained in:
nossr50 2021-01-25 14:37:23 -08:00
parent bf9bb6ffd8
commit c6d700c5a7
5 changed files with 53 additions and 12 deletions

View File

@ -1,3 +1,8 @@
Version 2.1.173
Fixed a visual bug where players who had lucky perk were shown incorrect odds when using skill commands (such as /axes)
Updated ja_JP locale (thanks ViaSnake)
Fixed a bug where scoreboards were torn down inappropriately when moving to or from blacklisted worlds (thanks steve4744)
Version 2.1.172
Updated german locale (thanks TheBusyBiscuit)
Added 'mcmmo.broadcast.levelup' permission node, if a player lacks this node they will not have their level up milestones broadcast to chat, this is a default permission node

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.172</version>
<version>2.1.173-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>

View File

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

View File

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

View File

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