mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-31 11:35:28 +02:00
Update code style
This commit is contained in:
@@ -3,6 +3,7 @@ package com.gmail.nossr50.util.random;
|
||||
public interface RandomChanceExecution {
|
||||
/**
|
||||
* Gets the XPos used in the formula for success
|
||||
*
|
||||
* @return value of x for our success probability graph
|
||||
*/
|
||||
double getXPos();
|
||||
@@ -10,6 +11,7 @@ public interface RandomChanceExecution {
|
||||
/**
|
||||
* The maximum odds for this RandomChanceExecution
|
||||
* For example, if this value is 10, then 10% odds would be the maximum and would be achieved only when xPos equaled the LinearCurvePeak
|
||||
*
|
||||
* @return maximum probability odds from 0.00 (no chance of ever happened) to 100.0 (probability can be guaranteed)
|
||||
*/
|
||||
double getProbabilityCap();
|
||||
|
@@ -15,26 +15,24 @@ public class RandomChanceSkill implements RandomChanceExecution {
|
||||
protected final boolean isLucky;
|
||||
private int skillLevel;
|
||||
|
||||
public RandomChanceSkill(Player player, SubSkillType subSkillType)
|
||||
{
|
||||
public RandomChanceSkill(Player player, SubSkillType subSkillType) {
|
||||
this.primarySkillType = subSkillType.getParentSkill();
|
||||
this.subSkillType = subSkillType;
|
||||
this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
|
||||
|
||||
if(player != null)
|
||||
if (player != null)
|
||||
this.skillLevel = UserManager.getPlayer(player).getSkillLevel(primarySkillType);
|
||||
else
|
||||
this.skillLevel = 0;
|
||||
|
||||
if(player != null)
|
||||
if (player != null)
|
||||
isLucky = Permissions.lucky(player, primarySkillType);
|
||||
else
|
||||
isLucky = false;
|
||||
}
|
||||
|
||||
public RandomChanceSkill(Player player, SubSkillType subSkillType, boolean hasCap)
|
||||
{
|
||||
if(hasCap)
|
||||
public RandomChanceSkill(Player player, SubSkillType subSkillType, boolean hasCap) {
|
||||
if (hasCap)
|
||||
this.probabilityCap = mcMMO.getConfigManager().getSkillMaxChance(subSkillType);
|
||||
else
|
||||
this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
|
||||
@@ -42,12 +40,12 @@ public class RandomChanceSkill implements RandomChanceExecution {
|
||||
this.primarySkillType = subSkillType.getParentSkill();
|
||||
this.subSkillType = subSkillType;
|
||||
|
||||
if(player != null)
|
||||
if (player != null)
|
||||
this.skillLevel = UserManager.getPlayer(player).getSkillLevel(primarySkillType);
|
||||
else
|
||||
this.skillLevel = 0;
|
||||
|
||||
if(player != null)
|
||||
if (player != null)
|
||||
isLucky = Permissions.lucky(player, primarySkillType);
|
||||
else
|
||||
isLucky = false;
|
||||
@@ -55,6 +53,7 @@ public class RandomChanceSkill implements RandomChanceExecution {
|
||||
|
||||
/**
|
||||
* The subskill corresponding to this RandomChanceSkill
|
||||
*
|
||||
* @return this subskill
|
||||
*/
|
||||
public SubSkillType getSubSkill() {
|
||||
@@ -63,15 +62,16 @@ public class RandomChanceSkill implements RandomChanceExecution {
|
||||
|
||||
/**
|
||||
* Gets the skill level of the player who owns this RandomChanceSkill
|
||||
*
|
||||
* @return the current skill level relating to this RandomChanceSkill
|
||||
*/
|
||||
public int getSkillLevel()
|
||||
{
|
||||
public int getSkillLevel() {
|
||||
return skillLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the skill level used for this skill's RNG calculations
|
||||
*
|
||||
* @param newSkillLevel new skill level
|
||||
*/
|
||||
public void setSkillLevel(int newSkillLevel) {
|
||||
|
@@ -6,8 +6,7 @@ import org.bukkit.entity.Player;
|
||||
public class RandomChanceSkillStatic extends RandomChanceSkill {
|
||||
private final double xPos;
|
||||
|
||||
public RandomChanceSkillStatic(double xPos, Player player, SubSkillType subSkillType)
|
||||
{
|
||||
public RandomChanceSkillStatic(double xPos, Player player, SubSkillType subSkillType) {
|
||||
super(player, subSkillType);
|
||||
|
||||
this.xPos = xPos;
|
||||
|
@@ -5,8 +5,7 @@ public class RandomChanceStatic implements RandomChanceExecution {
|
||||
private final double probabilityCap;
|
||||
private final boolean isLucky;
|
||||
|
||||
public RandomChanceStatic(double xPos, boolean isLucky)
|
||||
{
|
||||
public RandomChanceStatic(double xPos, boolean isLucky) {
|
||||
this.xPos = xPos;
|
||||
this.probabilityCap = xPos;
|
||||
this.isLucky = isLucky;
|
||||
|
@@ -14,8 +14,7 @@ import org.bukkit.entity.Player;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomChanceUtil
|
||||
{
|
||||
public class RandomChanceUtil {
|
||||
public static final DecimalFormat percent = new DecimalFormat("##0.00%");
|
||||
//public static final DecimalFormat decimal = new DecimalFormat("##0.00");
|
||||
public static final double LINEAR_CURVE_VAR = 100.0D;
|
||||
@@ -26,14 +25,12 @@ public class RandomChanceUtil
|
||||
* non-RNG skills just fire the cancellable event and succeed if they go uncancelled
|
||||
*
|
||||
* @param skillActivationType this value represents what kind of activation procedures this sub-skill uses
|
||||
* @param subSkillType The identifier for this specific sub-skill
|
||||
* @param player The owner of this sub-skill
|
||||
* @param subSkillType The identifier for this specific sub-skill
|
||||
* @param player The owner of this sub-skill
|
||||
* @return returns true if all conditions are met and they event is not cancelled
|
||||
*/
|
||||
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player)
|
||||
{
|
||||
switch(skillActivationType)
|
||||
{
|
||||
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player) {
|
||||
switch (skillActivationType) {
|
||||
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
|
||||
return checkRandomChanceExecutionSuccess(player, subSkillType, true);
|
||||
case RANDOM_STATIC_CHANCE:
|
||||
@@ -46,10 +43,8 @@ public class RandomChanceUtil
|
||||
}
|
||||
}
|
||||
|
||||
public static double getActivationChance(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player)
|
||||
{
|
||||
switch(skillActivationType)
|
||||
{
|
||||
public static double getActivationChance(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player) {
|
||||
switch (skillActivationType) {
|
||||
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
|
||||
return getRandomChanceExecutionSuccess(player, subSkillType, true);
|
||||
case RANDOM_STATIC_CHANCE:
|
||||
@@ -61,10 +56,10 @@ public class RandomChanceUtil
|
||||
|
||||
/**
|
||||
* Checks whether or not the random chance succeeds
|
||||
*
|
||||
* @return true if the random chance succeeds
|
||||
*/
|
||||
public static boolean checkRandomChanceExecutionSuccess(Player player, PrimarySkillType primarySkillType, double chance)
|
||||
{
|
||||
public static boolean checkRandomChanceExecutionSuccess(Player player, PrimarySkillType primarySkillType, double chance) {
|
||||
//Check the odds
|
||||
chance *= 100;
|
||||
|
||||
@@ -88,19 +83,18 @@ public class RandomChanceUtil
|
||||
|
||||
/**
|
||||
* Used for stuff like Excavation, Fishing, etc...
|
||||
*
|
||||
* @param randomChance
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkillStatic randomChance)
|
||||
{
|
||||
public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkillStatic randomChance) {
|
||||
double chanceOfSuccess = calculateChanceOfSuccess(randomChance);
|
||||
|
||||
//Check the odds
|
||||
return rollDice(chanceOfSuccess, 100);
|
||||
}
|
||||
|
||||
public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkill randomChance)
|
||||
{
|
||||
public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkill randomChance) {
|
||||
double chanceOfSuccess = calculateChanceOfSuccess(randomChance);
|
||||
|
||||
Random random = new Random();
|
||||
@@ -118,6 +112,7 @@ public class RandomChanceUtil
|
||||
|
||||
/**
|
||||
* Gets the Static Chance for something to activate
|
||||
*
|
||||
* @param randomChance
|
||||
* @return
|
||||
*/
|
||||
@@ -176,27 +171,23 @@ public class RandomChanceUtil
|
||||
*
|
||||
* @return the chance of success from 0-100 (100 = guaranteed)
|
||||
*/
|
||||
private static int getChanceOfSuccess(double skillLevel, double maxProbability, double maxLevel)
|
||||
{
|
||||
private static int getChanceOfSuccess(double skillLevel, double maxProbability, double maxLevel) {
|
||||
//return (int) (x / (y / LINEAR_CURVE_VAR));
|
||||
return (int) (maxProbability * (skillLevel/maxLevel));
|
||||
return (int) (maxProbability * (skillLevel / maxLevel));
|
||||
// max probability * (weight/maxlevel) = chance of success
|
||||
}
|
||||
|
||||
private static int getChanceOfSuccess(double x, double y)
|
||||
{
|
||||
private static int getChanceOfSuccess(double x, double y) {
|
||||
return (int) (x / (y / LINEAR_CURVE_VAR));
|
||||
// max probability * (weight/maxlevel) = chance of success
|
||||
}
|
||||
|
||||
public static double getRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, boolean hasCap)
|
||||
{
|
||||
public static double getRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, boolean hasCap) {
|
||||
RandomChanceSkill rcs = new RandomChanceSkill(player, subSkillType, hasCap);
|
||||
return calculateChanceOfSuccess(rcs);
|
||||
}
|
||||
|
||||
public static double getRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType)
|
||||
{
|
||||
public static double getRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType) {
|
||||
try {
|
||||
return getRandomChanceExecutionChance(new RandomChanceSkillStatic(getStaticRandomChance(subSkillType), player, subSkillType));
|
||||
} catch (InvalidStaticChance invalidStaticChance) {
|
||||
@@ -207,18 +198,15 @@ public class RandomChanceUtil
|
||||
return 0.1337; //Puts on shades
|
||||
}
|
||||
|
||||
public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, boolean hasCap)
|
||||
{
|
||||
public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, boolean hasCap) {
|
||||
return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType, hasCap));
|
||||
}
|
||||
|
||||
public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType)
|
||||
{
|
||||
public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType) {
|
||||
return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType));
|
||||
}
|
||||
|
||||
public static boolean checkRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType)
|
||||
{
|
||||
public static boolean checkRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType) {
|
||||
try {
|
||||
return checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getStaticRandomChance(subSkillType), player, subSkillType));
|
||||
} catch (InvalidStaticChance invalidStaticChance) {
|
||||
@@ -231,14 +219,13 @@ public class RandomChanceUtil
|
||||
|
||||
/**
|
||||
* Grabs static activation rolls for Secondary Abilities
|
||||
*
|
||||
* @param subSkillType The secondary ability to grab properties of
|
||||
* @throws InvalidStaticChance if the skill has no defined static chance this exception will be thrown and you should know you're a naughty boy
|
||||
* @return The static activation roll involved in the RNG calculation
|
||||
* @throws InvalidStaticChance if the skill has no defined static chance this exception will be thrown and you should know you're a naughty boy
|
||||
*/
|
||||
public static double getStaticRandomChance(SubSkillType subSkillType) throws InvalidStaticChance
|
||||
{
|
||||
switch(subSkillType)
|
||||
{
|
||||
public static double getStaticRandomChance(SubSkillType subSkillType) throws InvalidStaticChance {
|
||||
switch (subSkillType) {
|
||||
case AXES_ARMOR_IMPACT:
|
||||
return AdvancedConfig.getInstance().getImpactChance();
|
||||
case AXES_GREATER_IMPACT:
|
||||
@@ -250,8 +237,7 @@ public class RandomChanceUtil
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean sendSkillEvent(Player player, SubSkillType subSkillType, double activationChance)
|
||||
{
|
||||
public static boolean sendSkillEvent(Player player, SubSkillType subSkillType, double activationChance) {
|
||||
SubSkillRandomCheckEvent event = new SubSkillRandomCheckEvent(player, subSkillType, activationChance);
|
||||
return !event.isCancelled();
|
||||
}
|
||||
@@ -262,8 +248,7 @@ public class RandomChanceUtil
|
||||
return (event.getChance() * activationChance) > (Misc.getRandom().nextDouble() * activationChance) && !event.isCancelled();
|
||||
}*/
|
||||
|
||||
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, AbstractSubSkill abstractSubSkill, Player player)
|
||||
{
|
||||
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, AbstractSubSkill abstractSubSkill, Player player) {
|
||||
return isActivationSuccessful(skillActivationType, abstractSubSkill.getSubSkillType(), player);
|
||||
}
|
||||
|
||||
@@ -311,17 +296,15 @@ public class RandomChanceUtil
|
||||
return displayValues;
|
||||
}
|
||||
|
||||
public static double addLuck(Player player, PrimarySkillType primarySkillType, double chance)
|
||||
{
|
||||
if(Permissions.lucky(player, primarySkillType))
|
||||
public static double addLuck(Player player, PrimarySkillType primarySkillType, double chance) {
|
||||
if (Permissions.lucky(player, primarySkillType))
|
||||
return chance * 1.333D;
|
||||
else
|
||||
return chance;
|
||||
}
|
||||
|
||||
public static double addLuck(boolean isLucky, double chance)
|
||||
{
|
||||
if(isLucky)
|
||||
public static double addLuck(boolean isLucky, double chance) {
|
||||
if (isLucky)
|
||||
return chance * 1.333D;
|
||||
else
|
||||
return chance;
|
||||
|
Reference in New Issue
Block a user