CompatibilityLayer framework

This commit is contained in:
nossr50
2020-04-24 20:21:21 -07:00
parent f82ad99c82
commit 5984230bf3
37 changed files with 1292 additions and 123 deletions

View File

@@ -14,7 +14,29 @@ public class RandomChanceSkill implements RandomChanceExecution {
protected final SubSkillType subSkillType;
protected final double probabilityCap;
protected final boolean isLucky;
private int skillLevel;
protected int skillLevel;
protected double resultModifier;
public RandomChanceSkill(Player player, SubSkillType subSkillType, double resultModifier)
{
this.primarySkillType = subSkillType.getParentSkill();
this.subSkillType = subSkillType;
this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (player != null && mcMMOPlayer != null) {
this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
} else {
this.skillLevel = 0;
}
if(player != null)
isLucky = Permissions.lucky(player, primarySkillType);
else
isLucky = false;
this.resultModifier = resultModifier;
}
public RandomChanceSkill(Player player, SubSkillType subSkillType)
{
@@ -33,6 +55,8 @@ public class RandomChanceSkill implements RandomChanceExecution {
isLucky = Permissions.lucky(player, primarySkillType);
else
isLucky = false;
this.resultModifier = 1.0D;
}
public RandomChanceSkill(Player player, SubSkillType subSkillType, boolean hasCap)
@@ -56,6 +80,33 @@ public class RandomChanceSkill implements RandomChanceExecution {
isLucky = Permissions.lucky(player, primarySkillType);
else
isLucky = false;
this.resultModifier = 1.0D;
}
public RandomChanceSkill(Player player, SubSkillType subSkillType, boolean hasCap, double resultModifier)
{
if(hasCap)
this.probabilityCap = AdvancedConfig.getInstance().getMaximumProbability(subSkillType);
else
this.probabilityCap = RandomChanceUtil.LINEAR_CURVE_VAR;
this.primarySkillType = subSkillType.getParentSkill();
this.subSkillType = subSkillType;
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (player != null && mcMMOPlayer != null) {
this.skillLevel = mcMMOPlayer.getSkillLevel(primarySkillType);
} else {
this.skillLevel = 0;
}
if(player != null)
isLucky = Permissions.lucky(player, primarySkillType);
else
isLucky = false;
this.resultModifier = resultModifier;
}
/**
@@ -118,4 +169,12 @@ public class RandomChanceSkill implements RandomChanceExecution {
public boolean isLucky() {
return isLucky;
}
public double getResultModifier() {
return resultModifier;
}
public void setResultModifier(double resultModifier) {
this.resultModifier = resultModifier;
}
}

View File

@@ -13,6 +13,13 @@ public class RandomChanceSkillStatic extends RandomChanceSkill {
this.xPos = xPos;
}
public RandomChanceSkillStatic(double xPos, Player player, SubSkillType subSkillType, double resultModifier)
{
super(player, subSkillType, resultModifier);
this.xPos = xPos;
}
/**
* Gets the XPos used in the formula for success
*

View File

@@ -46,6 +46,32 @@ public class RandomChanceUtil
}
}
/**
* This method is the final step in determining if a Sub-Skill / Secondary Skill in mcMMO successfully activates either from chance or otherwise
* Random skills check for success based on numbers and then fire a cancellable event, if that event is not cancelled they succeed
* 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
* @return returns true if all conditions are met and the event is not cancelled
*/
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player, double resultModifier)
{
switch(skillActivationType)
{
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
return checkRandomChanceExecutionSuccess(player, subSkillType, true);
case RANDOM_STATIC_CHANCE:
return checkRandomStaticChanceExecutionSuccess(player, subSkillType, resultModifier);
case ALWAYS_FIRES:
SubSkillEvent event = EventUtils.callSubSkillEvent(player, subSkillType);
return !event.isCancelled();
default:
return false;
}
}
public static double getActivationChance(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player)
{
switch(skillActivationType)
@@ -78,7 +104,24 @@ public class RandomChanceUtil
}
public static boolean rollDice(double chanceOfSuccess, int bound) {
return chanceOfSuccess > ThreadLocalRandom.current().nextInt(bound);
return rollDice(chanceOfSuccess, bound, 1.0F);
}
public static boolean rollDice(double chanceOfSuccess, int bound, double resultModifier) {
return chanceOfSuccess > (ThreadLocalRandom.current().nextInt(bound) * resultModifier);
}
/**
* Used for stuff like Excavation, Fishing, etc...
* @param randomChance
* @return
*/
public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkillStatic randomChance, double resultModifier)
{
double chanceOfSuccess = calculateChanceOfSuccess(randomChance);
//Check the odds
return rollDice(chanceOfSuccess, 100, resultModifier);
}
/**
@@ -88,10 +131,7 @@ public class RandomChanceUtil
*/
public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkillStatic randomChance)
{
double chanceOfSuccess = calculateChanceOfSuccess(randomChance);
//Check the odds
return rollDice(chanceOfSuccess, 100);
return checkRandomChanceExecutionSuccess(randomChance, 1.0F);
}
public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkill randomChance)
@@ -115,9 +155,7 @@ public class RandomChanceUtil
* @return
*/
public static double getRandomChanceExecutionChance(RandomChanceExecution randomChance) {
double chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), randomChance.getProbabilityCap(), LINEAR_CURVE_VAR);
return chanceOfSuccess;
return getChanceOfSuccess(randomChance.getXPos(), randomChance.getProbabilityCap(), LINEAR_CURVE_VAR);
}
public static double getRandomChanceExecutionChance(RandomChanceStatic randomChance) {
@@ -210,7 +248,18 @@ public class RandomChanceUtil
return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType));
}
public static boolean checkRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType)
public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, boolean hasCap, double resultModifier)
{
return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType, hasCap, resultModifier));
}
public static boolean checkRandomChanceExecutionSuccess(Player player, SubSkillType subSkillType, double resultModifier)
{
return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType, resultModifier));
}
public static boolean checkRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType, double resultModifier)
{
try {
return checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(getStaticRandomChance(subSkillType), player, subSkillType));
@@ -222,6 +271,11 @@ public class RandomChanceUtil
return false;
}
public static boolean checkRandomStaticChanceExecutionSuccess(Player player, SubSkillType subSkillType)
{
return checkRandomStaticChanceExecutionSuccess(player, subSkillType, 1.0F);
}
/**
* Grabs static activation rolls for Secondary Abilities
* @param subSkillType The secondary ability to grab properties of