4 days of work and I'm still not done ;_;

This commit is contained in:
nossr50
2019-01-08 19:52:52 -08:00
parent ee765a0d30
commit 362d036b16
95 changed files with 2781 additions and 908 deletions

View File

@@ -1,66 +1,118 @@
package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.skills.SubSkill;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.entity.Player;
import java.util.HashMap;
public class RankUtils {
public static HashMap<SubSkill, HashMap<Integer, Integer>> subSkillRanks;
/**
* Adds ranks to subSkillRanks for target SubSkill
* @param subSkill Target SubSkill
*/
private static void addRanks(SubSkill subSkill) {
int numRanks = subSkill.getNumRanks();
public static HashMap<String, HashMap<Integer, Integer>> subSkillRanks;
/* NEW SYSTEM */
private static void addRanks(AbstractSubSkill abstractSubSkill)
{
//Fill out the rank array
for(int i = 0; i < numRanks; i++)
for(int i = 0; i < abstractSubSkill.getNumRanks(); i++)
{
//This adds the highest ranks first
addRank(subSkill, numRanks-i);
addRank(abstractSubSkill, abstractSubSkill.getNumRanks()-i);
//TODO: Remove debug code
/*System.out.println("DEBUG: Adding rank "+(numRanks-i)+" to "+subSkill.toString());*/
/*System.out.println("DEBUG: Adding rank "+(numRanks-i)+" to "+subSkillType.toString());*/
}
}
private static void addRanks(SubSkillType subSkillType)
{
//Fill out the rank array
for(int i = 0; i < subSkillType.getNumRanks(); i++)
{
//This adds the highest ranks first
addRank(subSkillType, subSkillType.getNumRanks()-i);
//TODO: Remove debug code
/*System.out.println("DEBUG: Adding rank "+(numRanks-i)+" to "+subSkillType.toString());*/
}
}
/**
* Gets the current rank of the subskill for the player
* @param player The player in question
* @param subSkill Target subskill
* @param subSkillType Target subskill
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
*/
public static int getRank(Player player, SubSkill subSkill)
public static int getRank(Player player, SubSkillType subSkillType)
{
String skillName = subSkillType.toString();
int numRanks = subSkillType.getNumRanks();
if(subSkillRanks == null)
subSkillRanks = new HashMap<>();
if(subSkill.getNumRanks() == 0)
if(numRanks == 0)
return -1; //-1 Means the skill doesn't have ranks
if(subSkillRanks.get(subSkill) == null && subSkill.getNumRanks() > 0)
addRanks(subSkill);
if(subSkillRanks.get(skillName) == null && numRanks > 0)
addRanks(subSkillType);
//Get our rank map
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkill);
HashMap<Integer, Integer> rankMap = subSkillRanks.get(skillName);
//Skill level of parent skill
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(subSkill.getParentSkill());
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(subSkillType.getParentSkill());
for(int i = 0; i < subSkill.getNumRanks(); i++)
for(int i = 0; i < numRanks; i++)
{
//Compare against the highest to lowest rank in that order
int rank = subSkill.getNumRanks()-i;
int unlockLevel = getUnlockLevel(subSkill, rank);
int rank = numRanks-i;
int unlockLevel = getUnlockLevel(subSkillType, rank);
//TODO: Remove this debug code
/*System.out.println("[DEBUG RANKCHECK] Checking rank "+rank+" of "+subSkill.getNumRanks());
System.out.println("[DEBUG RANKCHECK] Rank "+rank+" -- Unlock level: "+unlockLevel);
System.out.println("[DEBUG RANKCHECK] Rank" +rank+" -- Player Skill Level: "+currentSkillLevel);*/
//If we check all ranks and still cannot unlock the skill, we return rank 0
if(rank == 0)
return 0;
//True if our skill level can unlock the current rank
if(currentSkillLevel >= unlockLevel)
return rank;
}
return 0; //We should never reach this
}
/**
* Gets the current rank of the subskill for the player
* @param player The player in question
* @param abstractSubSkill Target subskill
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
*/
public static int getRank(Player player, AbstractSubSkill abstractSubSkill)
{
String skillName = abstractSubSkill.getConfigKeyName();
int numRanks = abstractSubSkill.getNumRanks();
if(subSkillRanks == null)
subSkillRanks = new HashMap<>();
if(numRanks == 0)
return -1; //-1 Means the skill doesn't have ranks
if(subSkillRanks.get(skillName) == null && numRanks > 0)
addRanks(abstractSubSkill);
//Get our rank map
HashMap<Integer, Integer> rankMap = subSkillRanks.get(skillName);
//Skill level of parent skill
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(abstractSubSkill.getPrimarySkill());
for(int i = 0; i < numRanks; i++)
{
//Compare against the highest to lowest rank in that order
int rank = numRanks-i;
int unlockLevel = getUnlockLevel(abstractSubSkill, rank);
//If we check all ranks and still cannot unlock the skill, we return rank 0
if(rank == 0)
@@ -76,32 +128,54 @@ public class RankUtils {
/**
* Adds ranks to our map
* @param subSkill The subskill to add ranks for
* @param abstractSubSkill The subskill to add ranks for
* @param rank The rank to add
*/
private static void addRank(SubSkill subSkill, int rank)
private static void addRank(AbstractSubSkill abstractSubSkill, int rank)
{
if(subSkillRanks == null)
subSkillRanks = new HashMap<>();
initMaps(abstractSubSkill.getConfigKeyName());
if(subSkillRanks.get(subSkill) == null)
subSkillRanks.put(subSkill, new HashMap<>());
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkill);
HashMap<Integer, Integer> rankMap = subSkillRanks.get(abstractSubSkill.getConfigKeyName());
//TODO: Remove this debug code
//System.out.println("[DEBUG]: Rank "+rank+" for "+subSkill.toString()+" requires skill level "+getUnlockLevel(subSkill, rank));
rankMap.put(rank, getUnlockLevel(subSkill, rank));
//System.out.println("[DEBUG]: Rank "+rank+" for "+subSkillName.toString()+" requires skill level "+getUnlockLevel(subSkillType, rank));
rankMap.put(rank, getUnlockLevel(abstractSubSkill, rank));
}
@Deprecated
private static void addRank(SubSkillType subSkillType, int rank)
{
initMaps(subSkillType.toString());
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkillType.toString());
//TODO: Remove this debug code
//System.out.println("[DEBUG]: Rank "+rank+" for "+subSkillName.toString()+" requires skill level "+getUnlockLevel(subSkillType, rank));
rankMap.put(rank, getUnlockLevel(subSkillType, rank));
}
private static void initMaps(String s) {
if (subSkillRanks == null)
subSkillRanks = new HashMap<>();
if (subSkillRanks.get(s) == null)
subSkillRanks.put(s, new HashMap<>());
}
/**
* Gets the unlock level for a specific rank in a subskill
* @param subSkill The target subskill
* @param subSkillType The target subskill
* @param rank The target rank
* @return The level at which this rank unlocks
*/
private static int getUnlockLevel(SubSkill subSkill, int rank)
@Deprecated
private static int getUnlockLevel(SubSkillType subSkillType, int rank)
{
return AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkill, rank);
return AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkillType, rank);
}
private static int getUnlockLevel(AbstractSubSkill abstractSubSkill, int rank)
{
return AdvancedConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, rank);
}
}

View File

@@ -3,7 +3,7 @@ package com.gmail.nossr50.util.skills;
/**
* Defines the type of random calculations to use with a given skill
*/
public enum SubSkillActivationType {
public enum SkillActivationType {
RANDOM_LINEAR_100_SCALE_NO_CAP, //A skill level of 100 would guarantee the proc with this
RANDOM_LINEAR_100_SCALE_WITH_CAP, //This one is based on a scale of 1-100 but with a specified cap for max bonus
RANDOM_STATIC_CHANCE, //The skill always has a SPECIFIC chance to succeed

View File

@@ -4,9 +4,12 @@ import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbility;
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
import com.gmail.nossr50.datatypes.skills.SubSkill;
import com.gmail.nossr50.datatypes.skills.XPGainReason;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
import com.gmail.nossr50.datatypes.skills.subskills.interfaces.RandomChance;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent;
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillWeightedActivationCheckEvent;
import com.gmail.nossr50.locale.LocaleLoader;
@@ -28,10 +31,54 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
public class SkillUtils {
public static final DecimalFormat percent = new DecimalFormat("##0.00%");
public static final DecimalFormat decimal = new DecimalFormat("##0.00");
public static void applyXpGain(McMMOPlayer mcMMOPlayer, PrimarySkill skill, float xp, XPGainReason xpGainReason) {
mcMMOPlayer.beginXpGain(skill, xp, xpGainReason);
}
/*
* Skill Stat Calculations
*/
public static String[] calculateAbilityDisplayValues(double chance, boolean isLucky) {
String[] displayValues = new String[2];
displayValues[0] = percent.format(Math.min(chance, 100.0D) / 100.0D);
displayValues[1] = isLucky ? percent.format(Math.min(chance * 1.3333D, 100.0D) / 100.0D) : null;
return displayValues;
}
public static String[] calculateAbilityDisplayValues(float skillValue, SubSkillType subSkillType, boolean isLucky) {
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(subSkillType);
return calculateAbilityDisplayValues((AdvancedConfig.getInstance().getMaxChance(subSkillType) / maxBonusLevel) * Math.min(skillValue, maxBonusLevel), isLucky);
}
public static String[] calculateLengthDisplayValues(Player player, float skillValue, PrimarySkill skill) {
int maxLength = skill.getAbility().getMaxLength();
int length = 2 + (int) (skillValue / AdvancedConfig.getInstance().getAbilityLength());
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength);
if (maxLength != 0) {
length = Math.min(length, maxLength);
}
return new String[] { String.valueOf(length), String.valueOf(enduranceLength) };
}
/*
* Others
*/
public static int handleFoodSkills(Player player, PrimarySkill skill, int eventFoodLevel, int baseLevel, int maxLevel, int rankChange) {
int skillLevel = UserManager.getPlayer(player).getSkillLevel(skill);
@@ -199,7 +246,7 @@ public class SkillUtils {
/**
* Checks whether or not the given skill succeeds
* @param subSkill The ability corresponding to this check
* @param subSkillType The ability corresponding to this check
* @param player The player whose skill levels we are checking against
* @param skillLevel The skill level of the corresponding skill
* @param activationChance used to determine activation chance
@@ -207,9 +254,15 @@ public class SkillUtils {
* @param maxLevel maximum skill level bonus
* @return true if random chance succeeds and the event isn't cancelled
*/
private static boolean performRandomSkillCheck(SubSkill subSkill, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
private static boolean performRandomSkillCheck(SubSkillType subSkillType, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel) / activationChance;
return performRandomSkillCheckStatic(subSkill, player, activationChance, chance);
return performRandomSkillCheckStatic(subSkillType, player, activationChance, chance);
}
/* NEW VERSION */
private static boolean performRandomSkillCheck(AbstractSubSkill abstractSubSkill, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel) / activationChance;
return performRandomSkillCheckStatic(abstractSubSkill, player, activationChance, chance);
}
/**
@@ -224,48 +277,107 @@ public class SkillUtils {
* Random skills check for success based on numbers and then fire a cancellable event, if that event is not cancelled they succeed
* All other skills just fire the cancellable event and succeed if it is not cancelled
*
* @param subSkill The identifier for this specific sub-skill
* @param subSkillType The identifier for this specific sub-skill
* @param player The owner of this sub-skill
* @param skill The identifier for the parent of our sub-skill
* @param activationChance This is the value that we roll against, 100 is normal, and 75 is for lucky perk
* @param subskillActivationType this value represents what kind of activation procedures this sub-skill uses
* @return returns true if all conditions are met and they event is not cancelled
*/
public static boolean isActivationSuccessful(SubSkillActivationType subskillActivationType, SubSkill subSkill, Player player,
public static boolean isActivationSuccessful(SkillActivationType subskillActivationType, SubSkillType subSkillType, Player player,
PrimarySkill skill, int skillLevel, int activationChance)
{
//Maximum chance to succeed
double maxChance = AdvancedConfig.getInstance().getMaxChance(subSkill);
double maxChance = AdvancedConfig.getInstance().getMaxChance(subSkillType);
//Maximum roll we can make
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(subSkill);
int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(subSkillType);
switch(subskillActivationType)
{
//100 Skill = Guaranteed
case RANDOM_LINEAR_100_SCALE_NO_CAP:
return performRandomSkillCheck(subSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
return performRandomSkillCheck(subSkillType, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
return performRandomSkillCheck(subSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), AdvancedConfig.getInstance().getMaxChance(subSkill), AdvancedConfig.getInstance().getMaxBonusLevel(subSkill));
return performRandomSkillCheck(subSkillType, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), maxChance, maxBonusLevel);
case RANDOM_STATIC_CHANCE:
//Grab the static activation chance of this skill
double staticRoll = getSecondaryAbilityStaticChance(subSkill) / activationChance;
return performRandomSkillCheckStatic(subSkill, player, activationChance, staticRoll);
double staticRoll = getSecondaryAbilityStaticChance(subSkillType) / activationChance;
return performRandomSkillCheckStatic(subSkillType, player, activationChance, staticRoll);
case ALWAYS_FIRES:
SubSkillEvent event = EventUtils.callSubSkillEvent(player, subSkill);
SubSkillEvent event = EventUtils.callSubSkillEvent(player, subSkillType);
return !event.isCancelled();
default:
return false;
}
}
/* NEW VERSION */
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, AbstractSubSkill abstractSubSkill, Player player, double maxChance, int maxBonusLevel)
{
int skillLevel = UserManager.getPlayer(player).getSkillLevel(abstractSubSkill.getPrimarySkill());
PrimarySkill skill = abstractSubSkill.getPrimarySkill();
switch(skillActivationType)
{
//100 Skill = Guaranteed
case RANDOM_LINEAR_100_SCALE_NO_CAP:
return performRandomSkillCheck(abstractSubSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
return performRandomSkillCheck(abstractSubSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), maxChance, maxBonusLevel);
case RANDOM_STATIC_CHANCE:
//TODO: Add this in for the new system
//Grab the static activation chance of this skill
//double staticRoll = getSecondaryAbilityStaticChance(subSkillType) / activationChance;
//return performRandomSkillCheckStatic(subSkillType, player, activationChance, staticRoll);
return false;
case ALWAYS_FIRES:
SubSkillEvent event = EventUtils.callSubSkillEvent(player, abstractSubSkill);
return !event.isCancelled();
default:
return false;
}
}
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, AbstractSubSkill abstractSubSkill, Player player)
{
//Maximum chance to succeed
RandomChance randomChance = (RandomChance) abstractSubSkill;
double maxChance = randomChance.getRandomChanceMaxChance();
//Maximum roll we can make
int maxBonusLevel = randomChance.getRandomChanceMaxBonus();
int skillLevel = UserManager.getPlayer(player).getSkillLevel(abstractSubSkill.getPrimarySkill());
PrimarySkill skill = abstractSubSkill.getPrimarySkill();
switch(skillActivationType)
{
//100 Skill = Guaranteed
case RANDOM_LINEAR_100_SCALE_NO_CAP:
return performRandomSkillCheck(abstractSubSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
return performRandomSkillCheck(abstractSubSkill, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), maxChance, maxBonusLevel);
case RANDOM_STATIC_CHANCE:
//TODO: Add this in for the new system
//Grab the static activation chance of this skill
//double staticRoll = getSecondaryAbilityStaticChance(subSkillType) / activationChance;
//return performRandomSkillCheckStatic(subSkillType, player, activationChance, staticRoll);
return false;
case ALWAYS_FIRES:
SubSkillEvent event = EventUtils.callSubSkillEvent(player, abstractSubSkill);
return !event.isCancelled();
default:
return false;
}
}
/**
* Grabs static activation rolls for Secondary Abilities
* @param subSkill The secondary ability to grab properties of
* @param subSkillType The secondary ability to grab properties of
* @return The static activation roll involved in the RNG calculation
*/
public static double getSecondaryAbilityStaticChance(SubSkill subSkill)
public static double getSecondaryAbilityStaticChance(SubSkillType subSkillType)
{
switch(subSkill)
switch(subSkillType)
{
case AXES_ARMOR_IMPACT:
return AdvancedConfig.getInstance().getImpactChance();
@@ -280,20 +392,27 @@ public class SkillUtils {
/**
* Used to determine whether or not a sub-skill activates from random chance (using static values)
* @param subSkill The identifier for this specific sub-skill
* @param subSkillType The identifier for this specific sub-skill
* @param player The owner of this sub-skill
* @param activationChance This is the value that we roll against, 100 is normal, and 75 is for lucky perk
* @param chance This is the static modifier for our random calculations
* @return true if random chance was successful and the event wasn't cancelled
*/
private static boolean performRandomSkillCheckStatic(SubSkill subSkill, Player player, int activationChance, double chance) {
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, subSkill, chance);
private static boolean performRandomSkillCheckStatic(SubSkillType subSkillType, Player player, int activationChance, double chance) {
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, subSkillType, chance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return (event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance) && !event.isCancelled();
}
/* NEW VERSION */
private static boolean performRandomSkillCheckStatic(AbstractSubSkill abstractSubSkill, Player player, int activationChance, double chance) {
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, abstractSubSkill, chance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return (event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance) && !event.isCancelled();
}
public static boolean treasureDropSuccessful(Player player, double dropChance, int activationChance) {
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, SubSkill.EXCAVATION_TREASURE_HUNTER, dropChance / activationChance);
SubSkillWeightedActivationCheckEvent event = new SubSkillWeightedActivationCheckEvent(player, SubSkillType.EXCAVATION_TREASURE_HUNTER, dropChance / activationChance);
mcMMO.p.getServer().getPluginManager().callEvent(event);
return (event.getChance() * activationChance) > (Misc.getRandom().nextDouble() * activationChance) && !event.isCancelled();
}