mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-02 20:45:28 +02:00

committed by
GitHub

parent
02c732bdf2
commit
971e5da0ad
@@ -94,4 +94,17 @@ public interface Probability {
|
||||
double probabilityValue = getValue() * probabilityMultiplier;
|
||||
return isSuccessfulRoll(probabilityValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify and then Simulate an outcome on a probability and return true or false for the result of that outcome.
|
||||
*
|
||||
* @param probabilityMultiplier probability will be multiplied by this before success is checked
|
||||
* @param finalProbabilityMultiplier probability will be multiplied by this after the first multiplier,
|
||||
* should be between 0 and 1
|
||||
* @return true if the probability succeeded, false if it failed
|
||||
*/
|
||||
default boolean evaluate(double probabilityMultiplier, double finalProbabilityMultiplier) {
|
||||
double probabilityValue = getValue() * probabilityMultiplier;
|
||||
return isSuccessfulRoll(probabilityValue * finalProbabilityMultiplier);
|
||||
}
|
||||
}
|
||||
|
@@ -188,6 +188,45 @@ public class ProbabilityUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is one of several Skill RNG evaluation methods.
|
||||
* This one specifically allows for a probability multiplier to be passed in.
|
||||
* This probability multiplier is applied after any lucky modifiers, affecting the final result.
|
||||
* <p>
|
||||
* This helper method is for specific {@link SubSkillType},
|
||||
* which help mcMMO understand where the RNG values used in our calculations come from this {@link SubSkillType}
|
||||
* <p>
|
||||
* 1) Determine where the RNG values come from for the passed {@link SubSkillType}
|
||||
* NOTE: In the config file, there are values which are static and which are more dynamic,
|
||||
* this is currently a bit hardcoded and will need to be updated manually
|
||||
* <p>
|
||||
* 2) Determine whether to use Lucky multiplier and influence the outcome
|
||||
* <p>
|
||||
* 3)
|
||||
* Creates a {@link Probability} and pipes it to {@link ProbabilityUtil} which processes the result and returns it
|
||||
* <p>
|
||||
* This also calls a {@link SubSkillEvent} which can be cancelled, if it is cancelled this will return false
|
||||
* The outcome of the probability can also be modified by this event that is called
|
||||
*
|
||||
* @param subSkillType target subskill
|
||||
* @param mmoPlayer target player
|
||||
* can be null (null players are given odds equivalent to a player with no levels or luck)
|
||||
* @return true if the Skill RNG succeeds, false if it fails
|
||||
*/
|
||||
public static boolean isSkillRNGSuccessful(@NotNull SubSkillType subSkillType, @Nullable McMMOPlayer mmoPlayer,
|
||||
double probabilityMultiplier) {
|
||||
final Probability probability = getSkillProbability(subSkillType, mmoPlayer);
|
||||
|
||||
//Luck
|
||||
boolean isLucky = mmoPlayer != null && Permissions.lucky(mmoPlayer.getPlayer(), subSkillType.getParentSkill());
|
||||
|
||||
if (isLucky) {
|
||||
return probability.evaluate(LUCKY_MODIFIER, probabilityMultiplier);
|
||||
} else {
|
||||
return probability.evaluate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Probability} for a specific {@link SubSkillType} for a specific {@link Player}.
|
||||
* This does not take into account perks such as lucky for the player.
|
||||
|
Reference in New Issue
Block a user