2012-06-11 22:11:23 +02:00
|
|
|
package com.gmail.nossr50.skills.acrobatics;
|
|
|
|
|
2013-02-22 23:55:15 +01:00
|
|
|
import org.bukkit.Material;
|
2013-02-26 00:00:15 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.LightningStrike;
|
2013-02-22 19:39:47 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2012-11-21 21:49:54 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2013-01-25 02:10:50 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-02-22 19:39:47 +01:00
|
|
|
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;
|
2012-11-21 21:49:54 +01:00
|
|
|
|
2013-02-22 19:39:47 +01:00
|
|
|
public final class Acrobatics {
|
2013-01-14 18:41:39 +01:00
|
|
|
public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax();
|
|
|
|
public static int dodgeMaxBonusLevel = AdvancedConfig.getInstance().getDodgeMaxBonusLevel();
|
2013-01-11 05:15:53 +01:00
|
|
|
public static int dodgeXpModifier = AdvancedConfig.getInstance().getDodgeXPModifier();
|
2013-02-26 00:00:15 +01:00
|
|
|
public static int dodgeDamageModifier = AdvancedConfig.getInstance().getDodgeDamageModifier();
|
2013-01-08 22:07:29 +01:00
|
|
|
|
2013-01-14 18:41:39 +01:00
|
|
|
public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax();
|
|
|
|
public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel();
|
2013-02-22 19:39:47 +01:00
|
|
|
public static int rollThreshold = AdvancedConfig.getInstance().getRollDamageThreshold();
|
2013-01-25 02:10:50 +01:00
|
|
|
|
2013-01-14 18:41:39 +01:00
|
|
|
public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax();
|
|
|
|
public static int gracefulRollMaxBonusLevel = AdvancedConfig.getInstance().getGracefulRollMaxBonusLevel();
|
2013-02-22 19:39:47 +01:00
|
|
|
public static int gracefulRollThreshold = AdvancedConfig.getInstance().getGracefulRollDamageThreshold();
|
|
|
|
public static int gracefulRollSuccessModifier = AdvancedConfig.getInstance().getGracefulRollSuccessModifer();
|
2012-06-12 17:07:27 +02:00
|
|
|
|
2013-01-11 05:15:53 +01:00
|
|
|
public static int rollXpModifier = AdvancedConfig.getInstance().getRollXPModifier();
|
|
|
|
public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier();
|
2013-01-25 02:10:50 +01:00
|
|
|
|
|
|
|
public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled();
|
|
|
|
public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled();
|
2013-02-22 19:39:47 +01:00
|
|
|
|
|
|
|
private Acrobatics() {};
|
|
|
|
|
2013-02-22 23:55:15 +01:00
|
|
|
public static boolean canRoll(Player player) {
|
|
|
|
return (player.getItemInHand().getType() != Material.ENDER_PEARL) && !(afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player);
|
|
|
|
}
|
|
|
|
|
2013-02-26 00:00:15 +01:00
|
|
|
public static boolean canDodge(Player player, Entity damager) {
|
|
|
|
if (Permissions.dodge(player)) {
|
|
|
|
if (damager instanceof Player && SkillType.ACROBATICS.getPVPEnabled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (!(damager instanceof Player) && SkillType.ACROBATICS.getPVEEnabled() && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-22 19:39:47 +01:00
|
|
|
public static int processRoll(Player player, int damage) {
|
|
|
|
if (player.isSneaking() && Permissions.gracefulRoll(player)) {
|
|
|
|
return processGracefulRoll(player, damage);
|
|
|
|
}
|
|
|
|
|
2013-02-26 00:00:15 +01:00
|
|
|
int modifiedDamage = calculateModifiedRollDamage(damage, rollThreshold);
|
2013-02-22 19:39:47 +01:00
|
|
|
|
|
|
|
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) {
|
2013-02-26 00:00:15 +01:00
|
|
|
int modifiedDamage = calculateModifiedRollDamage(damage, gracefulRollThreshold);
|
2013-02-22 19:39:47 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-26 00:00:15 +01:00
|
|
|
protected static boolean isFatal(Player player, int damage) {
|
2013-02-22 19:39:47 +01:00
|
|
|
return player.getHealth() - damage < 1;
|
|
|
|
}
|
|
|
|
|
2013-02-26 00:00:15 +01:00
|
|
|
protected static int calculateModifiedDodgeDamage(int damage, int damageModifier) {
|
|
|
|
return Math.max(damage / damageModifier, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static int calculateModifiedRollDamage(int damage, int damageThreshold) {
|
2013-02-22 19:39:47 +01:00
|
|
|
return Math.max(damage - damageThreshold, 0);
|
|
|
|
}
|
|
|
|
|
2013-02-26 00:00:15 +01:00
|
|
|
protected static boolean isSuccessfulRoll(Player player, double maxChance, int maxLevel, int successModifier) {
|
2013-02-22 19:39:47 +01:00
|
|
|
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);
|
|
|
|
}
|
2013-02-16 00:32:49 +01:00
|
|
|
}
|