mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-09-17 10:17:54 +02:00
Fix double drops for mining
This commit is contained in:
@@ -4,6 +4,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.skills.PerksUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
@@ -112,7 +113,7 @@ public final class Motd {
|
||||
* @param player Target player
|
||||
*/
|
||||
public static void displayActivationPerks(Player player) {
|
||||
int perkAmount = PerksUtils.handleActivationPerks(player, 0, 0);
|
||||
int perkAmount = SkillUtils.getEnduranceLength(player);
|
||||
|
||||
if (perkAmount > 0) {
|
||||
player.sendMessage(PERK_PREFIX + LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Perks.ActivationTime.Name"), LocaleLoader.getString("Perks.ActivationTime.Desc", perkAmount)));
|
||||
|
@@ -32,7 +32,7 @@ public class RandomChanceUtil {
|
||||
public static boolean isActivationSuccessful(SkillActivationType skillActivationType, SubSkillType subSkillType, Player player) {
|
||||
switch (skillActivationType) {
|
||||
case RANDOM_LINEAR_100_SCALE_WITH_CAP:
|
||||
return checkRandomChanceExecutionSuccess(player, subSkillType, true);
|
||||
return checkRandomChanceExecutionSuccess(player, subSkillType);
|
||||
case RANDOM_STATIC_CHANCE:
|
||||
return checkRandomStaticChanceExecutionSuccess(player, subSkillType);
|
||||
case ALWAYS_FIRES:
|
||||
@@ -97,8 +97,6 @@ public class RandomChanceUtil {
|
||||
public static boolean checkRandomChanceExecutionSuccess(RandomChanceSkill randomChance) {
|
||||
double chanceOfSuccess = calculateChanceOfSuccess(randomChance);
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
//Check the odds
|
||||
return rollDice(chanceOfSuccess, 100);
|
||||
}
|
||||
@@ -135,10 +133,10 @@ public class RandomChanceUtil {
|
||||
return chanceOfSuccess;
|
||||
}*/
|
||||
|
||||
private static double calculateChanceOfSuccess(RandomChanceSkill randomChance) {
|
||||
double skillLevel = randomChance.getSkillLevel();
|
||||
double maximumProbability = randomChance.getProbabilityCap();
|
||||
double maximumBonusLevel = randomChance.getMaximumBonusLevelCap();
|
||||
private static double calculateChanceOfSuccess(RandomChanceSkill randomChanceSkill) {
|
||||
double skillLevel = randomChanceSkill.getSkillLevel();
|
||||
double maximumProbability = randomChanceSkill.getProbabilityCap();
|
||||
double maximumBonusLevel = randomChanceSkill.getMaximumBonusLevelCap();
|
||||
|
||||
double chanceOfSuccess;
|
||||
|
||||
@@ -147,11 +145,11 @@ public class RandomChanceUtil {
|
||||
chanceOfSuccess = maximumProbability;
|
||||
} else {
|
||||
//Get chance of success
|
||||
chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), maximumProbability, maximumBonusLevel);
|
||||
chanceOfSuccess = getChanceOfSuccess(randomChanceSkill.getXPos(), maximumProbability, maximumBonusLevel);
|
||||
}
|
||||
|
||||
//Add Luck
|
||||
chanceOfSuccess = addLuck(randomChance.isLucky(), chanceOfSuccess);
|
||||
chanceOfSuccess = addLuck(randomChanceSkill.isLucky(), chanceOfSuccess);
|
||||
|
||||
return chanceOfSuccess;
|
||||
}
|
||||
@@ -198,10 +196,6 @@ public class RandomChanceUtil {
|
||||
return 0.1337; //Puts on shades
|
||||
}
|
||||
|
||||
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) {
|
||||
return checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType));
|
||||
}
|
||||
|
@@ -88,8 +88,8 @@ public class ScoreboardManager {
|
||||
// Include child skills
|
||||
skillLabelBuilder.put(type, getShortenedName(colors.get(i) + type.getName(), false));
|
||||
|
||||
if (type.getAbility() != null) {
|
||||
abilityLabelBuilder.put(type.getAbility(), getShortenedName(colors.get(i) + type.getAbility().getName()));
|
||||
if (type.getSuperAbility() != null) {
|
||||
abilityLabelBuilder.put(type.getSuperAbility(), getShortenedName(colors.get(i) + type.getSuperAbility().getName()));
|
||||
|
||||
if (type == PrimarySkillType.MINING) {
|
||||
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, getShortenedName(colors.get(i) + SuperAbilityType.BLAST_MINING.getName()));
|
||||
@@ -110,8 +110,8 @@ public class ScoreboardManager {
|
||||
// Include child skills
|
||||
skillLabelBuilder.put(type, getShortenedName(ChatColor.GREEN + type.getName()));
|
||||
|
||||
if (type.getAbility() != null) {
|
||||
abilityLabelBuilder.put(type.getAbility(), formatAbility(type.getAbility().getName()));
|
||||
if (type.getSuperAbility() != null) {
|
||||
abilityLabelBuilder.put(type.getSuperAbility(), formatAbility(type.getSuperAbility().getName()));
|
||||
|
||||
if (type == PrimarySkillType.MINING) {
|
||||
abilityLabelBuilder.put(SuperAbilityType.BLAST_MINING, formatAbility(SuperAbilityType.BLAST_MINING.getName()));
|
||||
|
@@ -418,7 +418,7 @@ public class ScoreboardWrapper {
|
||||
|
||||
sidebarObjective.getScore(ScoreboardManager.LABEL_LEVEL).setScore(mcMMOPlayer.getSkillLevel(targetSkill));
|
||||
|
||||
if (targetSkill.getAbility() != null) {
|
||||
if (targetSkill.getSuperAbility() != null) {
|
||||
boolean stopUpdating;
|
||||
|
||||
if (targetSkill == PrimarySkillType.MINING) {
|
||||
@@ -433,7 +433,7 @@ public class ScoreboardWrapper {
|
||||
|
||||
stopUpdating = (secondsSB == 0 && secondsBM == 0);
|
||||
} else {
|
||||
SuperAbilityType ability = targetSkill.getAbility();
|
||||
SuperAbilityType ability = targetSkill.getSuperAbility();
|
||||
Score cooldown = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(ability));
|
||||
int seconds = Math.max(mcMMOPlayer.calculateTimeRemaining(ability), 0);
|
||||
|
||||
|
@@ -23,22 +23,6 @@ public final class PerksUtils {
|
||||
return cooldown;
|
||||
}
|
||||
|
||||
public static int handleActivationPerks(Player player, int ticks, int maxTicks) {
|
||||
if (maxTicks != 0) {
|
||||
ticks = Math.min(ticks, maxTicks);
|
||||
}
|
||||
|
||||
if (Permissions.twelveSecondActivationBoost(player)) {
|
||||
ticks += 12;
|
||||
} else if (Permissions.eightSecondActivationBoost(player)) {
|
||||
ticks += 8;
|
||||
} else if (Permissions.fourSecondActivationBoost(player)) {
|
||||
ticks += 4;
|
||||
}
|
||||
|
||||
return ticks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate activation chance for a skill.
|
||||
*
|
||||
|
@@ -7,10 +7,12 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -37,35 +39,57 @@ public class SkillUtils {
|
||||
mcMMOPlayer.beginXpGain(skill, xp, xpGainReason, xpGainSource);
|
||||
}
|
||||
|
||||
/*
|
||||
* Skill Stat Calculations
|
||||
/**
|
||||
* Calculates how long a given ability should last in seconds
|
||||
* Does not factor in perks
|
||||
* @param mcMMOPlayer target mcMMO Player
|
||||
* @param skill target skill
|
||||
* @param superAbilityType target Super Ability
|
||||
* @return how long an ability should last in seconds
|
||||
*/
|
||||
public static int calculateAbilityLength(McMMOPlayer mcMMOPlayer, PrimarySkillType skill, SuperAbilityType superAbilityType) {
|
||||
//These values change depending on whether or not the server is in retro mode
|
||||
int abilityLengthVar = mcMMO.getConfigManager().getConfigSuperAbilities().getSuperAbilityStartingSeconds();
|
||||
|
||||
public static String[] calculateLengthDisplayValues(Player player, float skillValue, PrimarySkillType skill) {
|
||||
int maxLength = skill.getAbility().getMaxLength();
|
||||
int abilityLengthVar = AdvancedConfig.getInstance().getAbilityLength();
|
||||
int abilityLengthCap = AdvancedConfig.getInstance().getAbilityLengthCap();
|
||||
int maxLength = mcMMO.getConfigManager().getConfigSuperAbilities().getMaxLengthForSuper(superAbilityType);
|
||||
|
||||
int length;
|
||||
int skillLevel = mcMMOPlayer.getSkillLevel(skill);
|
||||
|
||||
if (abilityLengthCap > 0) {
|
||||
length = (int) Math.min(abilityLengthCap, 2 + (skillValue / abilityLengthVar));
|
||||
int ticks;
|
||||
|
||||
//Ability cap of 0 or below means no cap
|
||||
if (maxLength > 0) {
|
||||
ticks = Math.min(2 + (Math.min(maxLength, skillLevel) / abilityLengthVar), maxLength);
|
||||
} else {
|
||||
length = 2 + (int) (skillValue / abilityLengthVar);
|
||||
ticks = Math.min(2 + (Math.min(maxLength, skillLevel) / abilityLengthVar), maxLength);
|
||||
}
|
||||
|
||||
int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength);
|
||||
|
||||
if (maxLength != 0) {
|
||||
length = Math.min(length, maxLength);
|
||||
}
|
||||
|
||||
return new String[]{String.valueOf(length), String.valueOf(enduranceLength)};
|
||||
return ticks;
|
||||
}
|
||||
|
||||
/*
|
||||
* Others
|
||||
/**
|
||||
* Calculates how long a given ability should last in seconds
|
||||
* Adds in perks if the player has any
|
||||
* @param mcMMOPlayer target mcMMO Player
|
||||
* @param skill target skill
|
||||
* @param superAbilityType target Super Ability
|
||||
* @return how long an ability should last in seconds
|
||||
*/
|
||||
public static int calculateAbilityLengthPerks(McMMOPlayer mcMMOPlayer, PrimarySkillType skill, SuperAbilityType superAbilityType) {
|
||||
return getEnduranceLength(mcMMOPlayer.getPlayer()) + calculateAbilityLength(mcMMOPlayer, skill, superAbilityType);
|
||||
}
|
||||
|
||||
public static int getEnduranceLength(Player player) {
|
||||
if (Permissions.twelveSecondActivationBoost(player)) {
|
||||
return 12;
|
||||
} else if (Permissions.eightSecondActivationBoost(player)) {
|
||||
return 8;
|
||||
} else if (Permissions.fourSecondActivationBoost(player)) {
|
||||
return 4;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int handleFoodSkills(Player player, int eventFoodLevel, SubSkillType subSkillType) {
|
||||
int curRank = RankUtils.getRank(player, subSkillType);
|
||||
@@ -172,11 +196,11 @@ public class SkillUtils {
|
||||
|
||||
if(abilityLengthCap > 0)
|
||||
{
|
||||
ticks = PerksUtils.handleActivationPerks(player, Math.min(abilityLengthCap, 2 + (mcMMOPlayer.getSkillLevel(skill) / abilityLengthVar)),
|
||||
skill.getAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR;
|
||||
ticks = PerksUtils.calculateAbilityLength(player, Math.min(abilityLengthCap, 2 + (mcMMOPlayer.getSkillLevel(skill) / abilityLengthVar)),
|
||||
skill.getSuperAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR;
|
||||
} else {
|
||||
ticks = PerksUtils.handleActivationPerks(player, 2 + ((mcMMOPlayer.getSkillLevel(skill)) / abilityLengthVar),
|
||||
skill.getAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR;
|
||||
ticks = PerksUtils.calculateAbilityLength(player, 2 + ((mcMMOPlayer.getSkillLevel(skill)) / abilityLengthVar),
|
||||
skill.getSuperAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR;
|
||||
}
|
||||
|
||||
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);
|
||||
|
Reference in New Issue
Block a user