mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 14:16:45 +01:00
2fee9df625
the event itself.
94 lines
4.3 KiB
Java
94 lines
4.3 KiB
Java
package com.gmail.nossr50.skills.acrobatics;
|
|
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
import com.gmail.nossr50.config.Config;
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
import com.gmail.nossr50.skills.utilities.PerksUtils;
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
|
import com.gmail.nossr50.util.Misc;
|
|
import com.gmail.nossr50.util.Permissions;
|
|
import com.gmail.nossr50.util.Users;
|
|
|
|
public final class Acrobatics {
|
|
public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax();
|
|
public static int dodgeMaxBonusLevel = AdvancedConfig.getInstance().getDodgeMaxBonusLevel();
|
|
public static int dodgeXpModifier = AdvancedConfig.getInstance().getDodgeXPModifier();
|
|
|
|
public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax();
|
|
public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel();
|
|
public static int rollThreshold = AdvancedConfig.getInstance().getRollDamageThreshold();
|
|
|
|
public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax();
|
|
public static int gracefulRollMaxBonusLevel = AdvancedConfig.getInstance().getGracefulRollMaxBonusLevel();
|
|
public static int gracefulRollThreshold = AdvancedConfig.getInstance().getGracefulRollDamageThreshold();
|
|
public static int gracefulRollSuccessModifier = AdvancedConfig.getInstance().getGracefulRollSuccessModifer();
|
|
|
|
public static int rollXpModifier = AdvancedConfig.getInstance().getRollXPModifier();
|
|
public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier();
|
|
|
|
public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled();
|
|
public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled();
|
|
|
|
private Acrobatics() {};
|
|
|
|
public static boolean canRoll(Player player) {
|
|
return (player.getItemInHand().getType() != Material.ENDER_PEARL) && !(afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player);
|
|
}
|
|
|
|
public static int processRoll(Player player, int damage) {
|
|
if (player.isSneaking() && Permissions.gracefulRoll(player)) {
|
|
return processGracefulRoll(player, damage);
|
|
}
|
|
|
|
int modifiedDamage = calculateModifiedDamage(damage, rollThreshold);
|
|
|
|
if (!isFatal(player, modifiedDamage) && isSuccessfulRoll(player, rollMaxChance, rollMaxBonusLevel, 1)) {
|
|
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text"));
|
|
applyXpGain(player, damage, rollXpModifier);
|
|
|
|
return modifiedDamage;
|
|
}
|
|
else if (!isFatal(player, damage)) {
|
|
applyXpGain(player, damage, fallXpModifier);
|
|
}
|
|
|
|
return damage;
|
|
}
|
|
|
|
private static int processGracefulRoll(Player player, int damage) {
|
|
int modifiedDamage = calculateModifiedDamage(damage, gracefulRollThreshold);
|
|
|
|
if (!isFatal(player, modifiedDamage) && isSuccessfulRoll(player, gracefulRollMaxChance, gracefulRollMaxBonusLevel, gracefulRollSuccessModifier)) {
|
|
player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
|
|
applyXpGain(player, damage, rollXpModifier);
|
|
|
|
return modifiedDamage;
|
|
}
|
|
else if (!isFatal(player, damage)) {
|
|
applyXpGain(player, damage, fallXpModifier);
|
|
}
|
|
|
|
return damage;
|
|
}
|
|
|
|
private static boolean isFatal(Player player, int damage) {
|
|
return player.getHealth() - damage < 1;
|
|
}
|
|
|
|
private static int calculateModifiedDamage(int damage, int damageThreshold) {
|
|
return Math.max(damage - damageThreshold, 0);
|
|
}
|
|
|
|
private static boolean isSuccessfulRoll(Player player, double maxChance, int maxLevel, int successModifier) {
|
|
double successChance = (maxChance / maxLevel) * Math.min(Users.getPlayer(player).getProfile().getSkillLevel(SkillType.ACROBATICS), maxLevel) * successModifier;
|
|
|
|
return successChance > Misc.getRandom().nextInt(PerksUtils.handleLuckyPerks(player, SkillType.ACROBATICS));
|
|
}
|
|
|
|
private static void applyXpGain(Player player, int baseXp, int multiplier) {
|
|
Users.getPlayer(player).beginXpGain(SkillType.ACROBATICS, baseXp * multiplier);
|
|
}
|
|
} |