mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 10:14:43 +02:00
Merge branch 'master' of github.com:mcMMO-Dev/mcMMO into configurable
This commit is contained in:
@ -629,11 +629,28 @@ public final class ExperienceAPI {
|
||||
* @param skillType The skill to get the level for
|
||||
* @return the level of a given skill
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @deprecated Use getLevel(Player player, PrimarySkillType skillType) instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getLevel(Player player, String skillType) {
|
||||
return getPlayer(player).getSkillLevel(getSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level a player has in a specific skill.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param player The player to get the level for
|
||||
* @param skillType The skill to get the level for
|
||||
* @return the level of a given skill
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
*/
|
||||
public static int getLevel(Player player, PrimarySkillType skillType) {
|
||||
return getPlayer(player).getSkillLevel(skillType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level an offline player has in a specific skill.
|
||||
* </br>
|
||||
@ -975,7 +992,7 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidFormulaTypeException if the given formulaType is not valid
|
||||
*/
|
||||
public static int getXpNeededToLevel(int level) {
|
||||
return mcMMO.getFormulaManager().getCachedXpToLevel(level, mcMMO.getConfigManager().getConfigLeveling().getFormulaType());
|
||||
return mcMMO.getFormulaManager().getXPtoNextLevel(level, mcMMO.getConfigManager().getConfigLeveling().getFormulaType());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -988,7 +1005,7 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidFormulaTypeException if the given formulaType is not valid
|
||||
*/
|
||||
public static int getXpNeededToLevel(int level, String formulaType) {
|
||||
return mcMMO.getFormulaManager().getCachedXpToLevel(level, getFormulaType(formulaType));
|
||||
return mcMMO.getFormulaManager().getXPtoNextLevel(level, getFormulaType(formulaType));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -12,6 +13,7 @@ import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class McremoveCommand implements TabExecutor {
|
||||
@Override
|
||||
@ -24,7 +26,13 @@ public class McremoveCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mcMMO.getDatabaseManager().removeUser(playerName)) {
|
||||
UUID uuid = null;
|
||||
|
||||
if(Bukkit.getPlayer(playerName) != null) {
|
||||
uuid = Bukkit.getPlayer(playerName).getUniqueId();
|
||||
}
|
||||
|
||||
if (mcMMO.getDatabaseManager().removeUser(playerName, uuid)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName));
|
||||
} else {
|
||||
sender.sendMessage(playerName + " could not be removed from the database."); // Pretty sure this should NEVER happen.
|
||||
|
@ -267,22 +267,6 @@ public class AdvancedConfig extends ConfigValidated {
|
||||
reason.add(SKILLS + "." + AXES + "." + GREATER_IMPACT + "." + BONUS_DAMAGE + " should be at least 1!");
|
||||
}
|
||||
|
||||
if (getArmorImpactIncreaseLevel() < 1) {
|
||||
reason.add(SKILLS + "." + AXES + "." + ARMOR_IMPACT + "." + INCREASE_LEVEL + " should be at least 1!");
|
||||
}
|
||||
|
||||
if (getImpactChance() < 1) {
|
||||
reason.add(SKILLS + "." + AXES + "." + ARMOR_IMPACT + "." + CHANCE + " should be at least 1!");
|
||||
}
|
||||
|
||||
if (getArmorImpactMaxDurabilityDamage() < 1) {
|
||||
reason.add(SKILLS + "." + AXES + "." + ARMOR_IMPACT + "." + MAX_PERCENTAGE_DURABILITY_DAMAGE + " should be at least 1!");
|
||||
}
|
||||
|
||||
if (getSkullSplitterModifier() < 1) {
|
||||
reason.add(SKILLS + "." + AXES + "." + SKULL_SPLITTER + DAMAGE_MODIFIER + " should be at least 1!");
|
||||
}
|
||||
|
||||
/*if (getFishermanDietRankChange() < 1) {
|
||||
reason.add(SKILLS + "." + FISHING + ".FishermansDiet.RankChange should be at least 1!");
|
||||
}*/
|
||||
@ -657,18 +641,8 @@ public class AdvancedConfig extends ConfigValidated {
|
||||
return getDoubleValue(SKILLS, AXES, GREATER_IMPACT, BONUS_DAMAGE);
|
||||
}
|
||||
|
||||
public int getArmorImpactIncreaseLevel() {
|
||||
int increaseLevel = getIntValue(SKILLS, AXES, ARMOR_IMPACT, INCREASE_LEVEL);
|
||||
|
||||
if (mcMMO.isRetroModeEnabled())
|
||||
return increaseLevel * 10;
|
||||
|
||||
return increaseLevel;
|
||||
}
|
||||
|
||||
public double getImpactChance() {
|
||||
return getDoubleValue(SKILLS, AXES, ARMOR_IMPACT, CHANCE);
|
||||
}
|
||||
public double getImpactChance() { return config.getDouble("Skills.Axes.ArmorImpact.Chance", 25.0D); }
|
||||
public double getImpactDurabilityDamageMultiplier() { return config.getDouble("Skills.Axes.ArmorImpact.DamagePerRank", 6.5D); }
|
||||
|
||||
public double getArmorImpactMaxDurabilityDamage() {
|
||||
return getDoubleValue(SKILLS, AXES, ARMOR_IMPACT, MAX_PERCENTAGE_DURABILITY_DAMAGE);
|
||||
|
@ -20,7 +20,8 @@ public class ConfigSectionSkillLevelCap {
|
||||
@Setting(value = "Level-Cap",
|
||||
comment = "Players will be unable to level past this value" +
|
||||
"\nThe cap is the same for both Retro and Standard, " +
|
||||
"so a cap of 50 will be the same value in either mode.")
|
||||
"so a cap of 50 will be the same value in either mode." +
|
||||
"\nA level cap of 0 or below will result in no level cap.")
|
||||
private int levelCap = LEVEL_CAP_DEFAULT;
|
||||
|
||||
/*
|
||||
@ -32,6 +33,9 @@ public class ConfigSectionSkillLevelCap {
|
||||
}
|
||||
|
||||
public int getLevelCap() {
|
||||
if(levelCap <= 0)
|
||||
return Integer.MAX_VALUE;
|
||||
|
||||
return levelCap;
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,17 @@ public interface DatabaseManager {
|
||||
* Remove a user from the database.
|
||||
*
|
||||
* @param playerName The name of the user to remove
|
||||
* @param uuid player UUID, can be null
|
||||
* @return true if the user was successfully removed, false otherwise
|
||||
*/
|
||||
boolean removeUser(String playerName);
|
||||
public boolean removeUser(String playerName, UUID uuid);
|
||||
|
||||
/**
|
||||
* Removes any cache used for faster lookups
|
||||
* Currently only used for SQL
|
||||
* @param uuid target UUID to cleanup
|
||||
*/
|
||||
public void cleanupUser(UUID uuid);
|
||||
|
||||
/**
|
||||
* Save a user to the database.
|
||||
|
@ -209,7 +209,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
mcMMO.p.getLogger().info("Purged " + removedPlayers + " users from the database.");
|
||||
}
|
||||
|
||||
public boolean removeUser(String playerName) {
|
||||
public boolean removeUser(String playerName, UUID uuid) {
|
||||
//NOTE: UUID is unused for FlatFile for this interface implementation
|
||||
boolean worked = false;
|
||||
|
||||
BufferedReader in = null;
|
||||
@ -260,6 +261,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
return worked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUser(UUID uuid) {
|
||||
//Not used in FlatFile
|
||||
}
|
||||
|
||||
public boolean saveUser(PlayerProfile profile) {
|
||||
String playerName = profile.getPlayerName();
|
||||
UUID uuid = profile.getUniqueId();
|
||||
|
@ -176,7 +176,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
||||
}
|
||||
|
||||
public boolean removeUser(String playerName) {
|
||||
public boolean removeUser(String playerName, UUID uuid) {
|
||||
boolean success = false;
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
@ -202,12 +202,20 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
if (success) {
|
||||
if(uuid != null)
|
||||
cleanupUser(uuid);
|
||||
|
||||
Misc.profileCleanup(playerName);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public void cleanupUser(UUID uuid) {
|
||||
if(cachedUserIDs.containsKey(uuid))
|
||||
cachedUserIDs.remove(uuid);
|
||||
}
|
||||
|
||||
public boolean saveUser(PlayerProfile profile) {
|
||||
boolean success = true;
|
||||
PreparedStatement statement = null;
|
||||
|
@ -193,7 +193,12 @@ public class Party {
|
||||
}
|
||||
|
||||
public int getXpToLevel() {
|
||||
<<<<<<< HEAD
|
||||
return mcMMO.getFormulaManager().getPartyCachedXpToLevel(level);
|
||||
=======
|
||||
FormulaType formulaType = ExperienceConfig.getInstance().getFormulaType();
|
||||
return (mcMMO.getFormulaManager().getXPtoNextLevel(level, formulaType)) * (getOnlineMembers().size() + Config.getInstance().getPartyXpCurveMultiplier());
|
||||
>>>>>>> ff1bb0deed61cda7daa75a374da3942de9e2e172
|
||||
}
|
||||
|
||||
public String getXpToLevelPercentage() {
|
||||
|
@ -56,6 +56,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import sun.security.krb5.Config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -514,6 +515,9 @@ public class McMMOPlayer {
|
||||
* @param xp Experience amount to process
|
||||
*/
|
||||
public void beginUnsharedXpGain(PrimarySkillType skill, float xp, XPGainReason xpGainReason, XPGainSource xpGainSource) {
|
||||
if(player.getGameMode() == GameMode.CREATIVE)
|
||||
return;
|
||||
|
||||
applyXpGain(skill, modifyXpGain(skill, xp), xpGainReason, xpGainSource);
|
||||
|
||||
if (party == null) {
|
||||
@ -767,8 +771,7 @@ public class McMMOPlayer {
|
||||
* @return Modified experience
|
||||
*/
|
||||
private float modifyXpGain(PrimarySkillType primarySkillType, float xp) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE
|
||||
|| ((primarySkillType.getMaxLevel() <= getSkillLevel(primarySkillType))
|
||||
if (((primarySkillType.getMaxLevel() <= getSkillLevel(primarySkillType))
|
||||
&& mcMMO.getPlayerLevelingSettings().isLevelCapEnabled(primarySkillType))
|
||||
|| (mcMMO.getPlayerLevelingSettings().getConfigSectionLevelCaps().getPowerLevel().getLevelCap() <= getPowerLevel())) {
|
||||
return 0;
|
||||
@ -1016,5 +1019,8 @@ public class McMMOPlayer {
|
||||
if (inParty()) {
|
||||
party.removeOnlineMember(thisPlayer);
|
||||
}
|
||||
|
||||
//Remove user from cache
|
||||
mcMMO.getDatabaseManager().cleanupUser(thisPlayer.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ public class PlayerProfile {
|
||||
int level = (mcMMO.getConfigManager().getConfigLeveling().getConfigExperienceFormula().isCumulativeCurveEnabled()) ? UserManager.getPlayer(playerName).getPowerLevel() : skills.get(primarySkillType);
|
||||
FormulaType formulaType = mcMMO.getConfigManager().getConfigLeveling().getFormulaType();
|
||||
|
||||
return mcMMO.getFormulaManager().getCachedXpToLevel(level, formulaType);
|
||||
return mcMMO.getFormulaManager().getXPtoNextLevel(level, formulaType);
|
||||
}
|
||||
|
||||
private int getChildSkillLevel(PrimarySkillType primarySkillType) {
|
||||
|
@ -64,6 +64,12 @@ public enum PrimarySkillType {
|
||||
WOODCUTTING(WoodcuttingManager.class, Color.OLIVE, SuperAbilityType.TREE_FELLER, ToolType.AXE,
|
||||
ImmutableList.of(SubSkillType.WOODCUTTING_LEAF_BLOWER, SubSkillType.WOODCUTTING_TREE_FELLER, SubSkillType.WOODCUTTING_HARVEST_LUMBER));
|
||||
|
||||
private Class<? extends SkillManager> managerClass;
|
||||
private Color skillColor;
|
||||
private SuperAbilityType ability;
|
||||
private ToolType tool;
|
||||
private List<SubSkillType> subSkillTypes;
|
||||
|
||||
public static final List<String> SKILL_NAMES;
|
||||
public static final List<String> SUBSKILL_NAMES;
|
||||
public static final List<PrimarySkillType> CHILD_SKILLS;
|
||||
@ -99,19 +105,13 @@ public enum PrimarySkillType {
|
||||
NON_CHILD_SKILLS = ImmutableList.copyOf(nonChildSkills);
|
||||
}
|
||||
|
||||
private Class<? extends SkillManager> managerClass;
|
||||
private Color runescapeColor;
|
||||
private SuperAbilityType ability;
|
||||
private ToolType tool;
|
||||
private List<SubSkillType> subSkillTypes;
|
||||
|
||||
PrimarySkillType(Class<? extends SkillManager> managerClass, Color runescapeColor, List<SubSkillType> subSkillTypes) {
|
||||
this(managerClass, runescapeColor, null, null, subSkillTypes);
|
||||
private PrimarySkillType(Class<? extends SkillManager> managerClass, Color skillColor, List<SubSkillType> subSkillTypes) {
|
||||
this(managerClass, skillColor, null, null, subSkillTypes);
|
||||
}
|
||||
|
||||
PrimarySkillType(Class<? extends SkillManager> managerClass, Color runescapeColor, SuperAbilityType ability, ToolType tool, List<SubSkillType> subSkillTypes) {
|
||||
private PrimarySkillType(Class<? extends SkillManager> managerClass, Color skillColor, SuperAbilityType ability, ToolType tool, List<SubSkillType> subSkillTypes) {
|
||||
this.managerClass = managerClass;
|
||||
this.runescapeColor = runescapeColor;
|
||||
this.skillColor = skillColor;
|
||||
this.ability = ability;
|
||||
this.tool = tool;
|
||||
this.subSkillTypes = subSkillTypes;
|
||||
@ -241,7 +241,7 @@ public enum PrimarySkillType {
|
||||
}
|
||||
|
||||
/* public void celebrateLevelUp(Player player) {
|
||||
ParticleEffectUtils.fireworkParticleShower(player, runescapeColor);
|
||||
ParticleEffectUtils.fireworkParticleShower(player, skillColor);
|
||||
}*/
|
||||
|
||||
public boolean shouldProcess(Entity target) {
|
||||
|
@ -14,9 +14,7 @@ public class Axes {
|
||||
public static double criticalHitPVPModifier = AdvancedConfig.getInstance().getCriticalStrikesPVPModifier();
|
||||
public static double criticalHitPVEModifier = AdvancedConfig.getInstance().getCriticalStrikesPVEModifier();
|
||||
|
||||
public static int impactIncreaseLevel = AdvancedConfig.getInstance().getArmorImpactIncreaseLevel();
|
||||
//public static double impactChance = AdvancedConfig.getInstance().getImpactChance();
|
||||
public static double impactMaxDurabilityModifier = AdvancedConfig.getInstance().getArmorImpactMaxDurabilityDamage() / 100D;
|
||||
public static double impactChance = AdvancedConfig.getInstance().getImpactChance();
|
||||
|
||||
public static double greaterImpactBonusDamage = AdvancedConfig.getInstance().getGreaterImpactBonusDamage();
|
||||
//public static double greaterImpactChance = AdvancedConfig.getInstance().getGreaterImpactChance();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.skills.axes;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
@ -112,19 +113,19 @@ public class AxesManager extends SkillManager {
|
||||
* @param target The {@link LivingEntity} being affected by Impact
|
||||
*/
|
||||
public void impactCheck(LivingEntity target) {
|
||||
int durabilityDamage = getImpactDurabilityDamage();
|
||||
double durabilityDamage = getImpactDurabilityDamage();
|
||||
|
||||
for (ItemStack armor : target.getEquipment().getArmorContents()) {
|
||||
if (armor != null && ItemUtils.isArmor(armor)) {
|
||||
if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_STATIC_CHANCE, SubSkillType.AXES_ARMOR_IMPACT, getPlayer())) {
|
||||
SkillUtils.handleDurabilityChange(armor, durabilityDamage, Axes.impactMaxDurabilityModifier);
|
||||
SkillUtils.handleDurabilityChange(armor, durabilityDamage, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getImpactDurabilityDamage() {
|
||||
return 1 + (getSkillLevel() / Axes.impactIncreaseLevel);
|
||||
public double getImpactDurabilityDamage() {
|
||||
return AdvancedConfig.getInstance().getImpactDurabilityDamageMultiplier() * RankUtils.getRank(getPlayer(), SubSkillType.AXES_ARMOR_IMPACT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,20 +13,29 @@ public class FormulaManager {
|
||||
private static File formulaFile = new File(mcMMO.getFlatFileDirectory() + "formula.yml");
|
||||
|
||||
// Experience needed to reach a level, cached values to improve conversion speed
|
||||
private final Map<Integer, Integer> experienceNeededLinear = new HashMap<>();
|
||||
private final Map<Integer, Integer> experienceNeededExponential = new HashMap<>();
|
||||
private Map<Integer, Integer> experienceNeededRetroLinear;
|
||||
private Map<Integer, Integer> experienceNeededStandardLinear;
|
||||
private Map<Integer, Integer> experienceNeededRetroExponential;
|
||||
private Map<Integer, Integer> experienceNeededStandardExponential;
|
||||
|
||||
private FormulaType previousFormula;
|
||||
|
||||
//Used for XP formula scaling
|
||||
private boolean retroModeEnabled;
|
||||
|
||||
public FormulaManager() {
|
||||
/* Setting for Classic Mode (Scales a lot of stuff up by * 10) */
|
||||
retroModeEnabled = mcMMO.isRetroModeEnabled();
|
||||
initExperienceNeededMaps();
|
||||
loadFormula();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize maps used for XP to next level
|
||||
*/
|
||||
private void initExperienceNeededMaps() {
|
||||
experienceNeededRetroLinear = new HashMap<>();
|
||||
experienceNeededRetroExponential = new HashMap<>();
|
||||
experienceNeededStandardLinear = new HashMap<>();
|
||||
experienceNeededStandardExponential = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formula type that was used before converting
|
||||
*
|
||||
@ -50,7 +59,7 @@ public class FormulaManager {
|
||||
* the amount of levels and experience, using the previously
|
||||
* used formula type.
|
||||
*
|
||||
* @param skillLevel Amount of levels
|
||||
* @param skillLevel Amount of levels
|
||||
* @param skillXPLevel Amount of experience
|
||||
* @return The total amount of experience
|
||||
*/
|
||||
@ -58,7 +67,7 @@ public class FormulaManager {
|
||||
int totalXP = 0;
|
||||
|
||||
for (int level = 0; level < skillLevel; level++) {
|
||||
totalXP += getCachedXpToLevel(level, previousFormula);
|
||||
totalXP += getXPtoNextLevel(level, previousFormula);
|
||||
}
|
||||
|
||||
totalXP += skillXPLevel;
|
||||
@ -71,28 +80,17 @@ public class FormulaManager {
|
||||
* the new formula type.
|
||||
*
|
||||
* @param primarySkillType skill where new levels and experience are calculated for
|
||||
* @param experience total amount of experience
|
||||
* @param formulaType The new {@link FormulaType}
|
||||
* @param experience total amount of experience
|
||||
* @param formulaType The new {@link FormulaType}
|
||||
* @return the amount of levels and experience
|
||||
*/
|
||||
public int[] calculateNewLevel(PrimarySkillType primarySkillType, int experience, FormulaType formulaType) {
|
||||
int newLevel = 0;
|
||||
int remainder = 0;
|
||||
int maxLevel = mcMMO.getPlayerLevelingSettings().getLevelCap(primarySkillType);
|
||||
int maxLevel = mcMMO.getConfigManager().getConfigLeveling().getLevelCap(primarySkillType);
|
||||
|
||||
while (experience > 0 && newLevel < Integer.MAX_VALUE) {
|
||||
//Level Cap
|
||||
if (mcMMO.getPlayerLevelingSettings().isLevelCapEnabled(primarySkillType)) {
|
||||
//Break the loop if we're at the cap
|
||||
if (newLevel + 1 > mcMMO.getPlayerLevelingSettings().getLevelCap(primarySkillType))
|
||||
break;
|
||||
|
||||
//If the maximum level is at or below our starting level, then the player can't level up anymore
|
||||
if (maxLevel <= mcMMO.getPlayerLevelingSettings().getConfigSectionLevelingGeneral().getStartingLevel())
|
||||
return new int[]{newLevel, remainder};
|
||||
}
|
||||
|
||||
int experienceToNextLevel = getCachedXpToLevel(newLevel, formulaType);
|
||||
while (experience > 0 && newLevel < maxLevel) {
|
||||
int experienceToNextLevel = getXPtoNextLevel(newLevel, formulaType);
|
||||
|
||||
if (experience - experienceToNextLevel < 0) {
|
||||
remainder = experience;
|
||||
@ -103,7 +101,7 @@ public class FormulaManager {
|
||||
experience -= experienceToNextLevel;
|
||||
}
|
||||
|
||||
return new int[]{newLevel, remainder};
|
||||
return new int[]{ newLevel, remainder };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,77 +109,102 @@ public class FormulaManager {
|
||||
* if cache doesn't contain the given value it is calculated and added
|
||||
* to the cached data.
|
||||
*
|
||||
* @param level level to check
|
||||
* @param level level to check
|
||||
* @param formulaType The {@link FormulaType} used
|
||||
* @return amount of experience needed to reach next level
|
||||
*/
|
||||
public int getCachedXpToLevel(int level, FormulaType formulaType) {
|
||||
int experience;
|
||||
|
||||
public int getXPtoNextLevel(int level, FormulaType formulaType) {
|
||||
/**
|
||||
* Retro mode XP requirements are the default requirements
|
||||
* Standard mode XP requirements are multiplied by a factor of 10
|
||||
*/
|
||||
int xpNeededMultiplier = retroModeEnabled ? 1 : 10;
|
||||
|
||||
//TODO: When the heck is Unknown used?
|
||||
if (formulaType == FormulaType.UNKNOWN) {
|
||||
formulaType = FormulaType.LINEAR;
|
||||
}
|
||||
|
||||
int base = mcMMO.getConfigManager().getConfigLeveling().getBase(formulaType);
|
||||
double multiplier = mcMMO.getConfigManager().getConfigLeveling().getMultiplier(formulaType);
|
||||
double exponent = mcMMO.getConfigManager().getConfigLeveling().getExponentialExponent();
|
||||
return processXPToNextLevel(level, formulaType);
|
||||
}
|
||||
|
||||
switch (formulaType) {
|
||||
case LINEAR:
|
||||
if (!experienceNeededLinear.containsKey(level)) {
|
||||
experience = (int) Math.floor(xpNeededMultiplier * (base + level * multiplier));
|
||||
experienceNeededLinear.put(level, experience);
|
||||
}
|
||||
|
||||
return experienceNeededLinear.get(level);
|
||||
|
||||
case EXPONENTIAL:
|
||||
if (!experienceNeededExponential.containsKey(level)) {
|
||||
experience = (int) Math.floor(xpNeededMultiplier * (multiplier * Math.pow(level, exponent) + base));
|
||||
experienceNeededExponential.put(level, experience);
|
||||
}
|
||||
|
||||
return experienceNeededExponential.get(level);
|
||||
|
||||
default:
|
||||
return 0;
|
||||
/**
|
||||
* Gets the value of XP needed for the next level based on the level Scaling, the level, and the formula type
|
||||
* @param level target level
|
||||
* @param formulaType target formulaType
|
||||
*/
|
||||
private int processXPToNextLevel(int level, FormulaType formulaType) {
|
||||
if(mcMMO.isRetroModeEnabled())
|
||||
{
|
||||
return processXPRetroToNextLevel(level, formulaType);
|
||||
} else {
|
||||
return processStandardXPToNextLevel(level, formulaType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cached amount of experience needed to reach the next party level,
|
||||
* if cache doesn't contain the given value it is calculated and added
|
||||
* to the cached data.
|
||||
* <p>
|
||||
* Parties use the exponential leveling formula
|
||||
*
|
||||
* @param level level to check
|
||||
* @return amount of experience needed to reach next level
|
||||
* Calculate the XP needed for the next level for the linear formula for Standard scaling (1-100)
|
||||
* @param level target level
|
||||
* @return raw xp needed to reach the next level
|
||||
*/
|
||||
public int getPartyCachedXpToLevel(int level) {
|
||||
int experience;
|
||||
private int processStandardXPToNextLevel(int level, FormulaType formulaType) {
|
||||
Map<Integer, Integer> experienceMapRef = formulaType == FormulaType.LINEAR ? experienceNeededStandardLinear : experienceNeededStandardExponential;
|
||||
|
||||
/**
|
||||
* Retro mode XP requirements are the default requirements
|
||||
* Standard mode XP requirements are multiplied by a factor of 10
|
||||
*/
|
||||
int base = mcMMO.getConfigManager().getConfigLeveling().getBase(FormulaType.EXPONENTIAL);
|
||||
double multiplier = mcMMO.getConfigManager().getConfigLeveling().getMultiplier(FormulaType.EXPONENTIAL);
|
||||
double exponent = mcMMO.getConfigManager().getConfigLeveling().getExponentialExponent();
|
||||
if(!experienceMapRef.containsKey(level)) {
|
||||
int experienceSum = 0;
|
||||
int retroIndex = (level * 10) + 1;
|
||||
|
||||
if (!experienceNeededExponential.containsKey(level)) {
|
||||
experience = (int) Math.floor((multiplier * Math.pow(level, exponent) + base));
|
||||
experience *= mcMMO.getConfigManager().getConfigParty().getPartyXP().getPartyLevel().getPartyXpCurveMultiplier();
|
||||
experienceNeededExponential.put(level, experience);
|
||||
//Sum the range of levels in Retro that this Standard level would represent
|
||||
for(int x = retroIndex; x < (retroIndex + 10); x++) {
|
||||
//calculateXPNeeded doesn't cache results so we use that instead of invoking the Retro XP methods to avoid memory bloat
|
||||
experienceSum += calculateXPNeeded(x, formulaType);
|
||||
}
|
||||
|
||||
experienceMapRef.put(level, experienceSum);
|
||||
}
|
||||
|
||||
return experienceNeededExponential.get(level);
|
||||
return experienceMapRef.get(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the XP to next level for Retro Mode scaling
|
||||
* Results are cached to reduce needless operations
|
||||
* @param level target level
|
||||
* @param formulaType target formula type
|
||||
* @return raw xp needed to reach the next level based on formula type
|
||||
*/
|
||||
private int processXPRetroToNextLevel(int level, FormulaType formulaType) {
|
||||
Map<Integer, Integer> experienceMapRef = formulaType == FormulaType.LINEAR ? experienceNeededRetroLinear : experienceNeededRetroExponential;
|
||||
|
||||
if (!experienceMapRef.containsKey(level)) {
|
||||
int experience = calculateXPNeeded(level, formulaType);
|
||||
experienceMapRef.put(level, experience);
|
||||
}
|
||||
|
||||
return experienceMapRef.get(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual math to get the XP needed for a level in RetroMode scaling
|
||||
* Standard uses a sum of RetroMode XP needed levels for its own thing, so it uses this too
|
||||
* @param level target level
|
||||
* @param formulaType target formulatype
|
||||
* @return the raw XP needed for the next level based on formula type
|
||||
*/
|
||||
private int calculateXPNeeded(int level, FormulaType formulaType) {
|
||||
int base = mcMMO.getConfigManager().getConfigLeveling().getConfigExperienceFormula().getBase(formulaType);
|
||||
double multiplier = mcMMO.getConfigManager().getConfigLeveling().getConfigExperienceFormula().getMultiplier(formulaType);
|
||||
|
||||
switch(formulaType) {
|
||||
case LINEAR:
|
||||
return (int) Math.floor(base + level * multiplier);
|
||||
case EXPONENTIAL:
|
||||
double exponent = mcMMO.getConfigManager().getConfigLeveling().getConfigExperienceFormula().getExponentialExponent();
|
||||
return (int) Math.floor(multiplier * Math.pow(level, exponent) + base);
|
||||
default:
|
||||
//TODO: Should never be called
|
||||
mcMMO.p.getLogger().severe("Invalid formula specified for calculation, defaulting to Linear");
|
||||
return calculateXPNeeded(level, FormulaType.LINEAR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,8 +229,9 @@ public class FormulaManager {
|
||||
|
||||
try {
|
||||
formulasFile.save(formulaFile);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -53,19 +53,14 @@ public class NotificationManager {
|
||||
* Sends players notifications from mcMMO
|
||||
* This does this by sending out an event so other plugins can cancel it
|
||||
* This event in particular is provided with a source player, and players near the source player are sent the information
|
||||
*
|
||||
* @param source the source player for this event
|
||||
* @param targetPlayer the recipient player for this message
|
||||
* @param notificationType type of notification
|
||||
* @param key Locale Key for the string to use with this event
|
||||
* @param values values to be injected into the locale string
|
||||
*/
|
||||
public static void sendNearbyPlayersInformation(Player source, NotificationType notificationType, String key, String... values) {
|
||||
Location location = source.getLocation();
|
||||
for (Player otherPlayer : source.getWorld().getPlayers()) {
|
||||
if (otherPlayer != source && Misc.isNear(location, otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) {
|
||||
sendPlayerInformation(otherPlayer, notificationType, key, values);
|
||||
}
|
||||
}
|
||||
public static void sendNearbyPlayersInformation(Player targetPlayer, NotificationType notificationType, String key, String... values)
|
||||
{
|
||||
sendPlayerInformation(targetPlayer, notificationType, key, values);
|
||||
}
|
||||
|
||||
public static void sendPlayerInformation(Player player, NotificationType notificationType, String key, String... values) {
|
||||
|
@ -116,7 +116,7 @@ public class SkillUtils {
|
||||
|
||||
for (Player otherPlayer : player.getWorld().getPlayers()) {
|
||||
if (otherPlayer != player && Misc.isNear(location, otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) {
|
||||
NotificationManager.sendNearbyPlayersInformation(player, notificationType, key, player.getName());
|
||||
NotificationManager.sendNearbyPlayersInformation(otherPlayer, notificationType, key, player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -225,7 +225,7 @@ public class SkillUtils {
|
||||
* @param durabilityModifier the amount to modify the durability by
|
||||
* @param maxDamageModifier the amount to adjust the max damage by
|
||||
*/
|
||||
public static void handleDurabilityChange(ItemStack itemStack, int durabilityModifier, double maxDamageModifier) {
|
||||
public static void handleDurabilityChange(ItemStack itemStack, double durabilityModifier, double maxDamageModifier) {
|
||||
if (itemStack.hasItemMeta() && itemStack.getItemMeta().isUnbreakable()) {
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user