Change Acrobatics roll handling to take event.getDamage() instead of the

event. Also adds a few new config options in advanced.yml for further
customizing roll behavior.
This commit is contained in:
GJ 2013-02-22 13:39:47 -05:00
parent 63974f3968
commit e85a0f6cfc
6 changed files with 83 additions and 132 deletions

View File

@ -20,6 +20,7 @@ public class AdvancedConfig extends ConfigLoader {
protected void loadKeys() { protected void loadKeys() {
// TODO Do we need to use this? // TODO Do we need to use this?
} }
/* GENERAL */ /* GENERAL */
public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); } public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); }
@ -29,9 +30,12 @@ public class AdvancedConfig extends ConfigLoader {
public double getRollChanceMax() { return config.getDouble("Skills.Acrobatics.Roll_ChanceMax", 100.0D); } public double getRollChanceMax() { return config.getDouble("Skills.Acrobatics.Roll_ChanceMax", 100.0D); }
public int getRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.Roll_MaxBonusLevel", 1000); } public int getRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.Roll_MaxBonusLevel", 1000); }
public int getRollDamageThreshold() { return config.getInt("Skills.Acrobatics.Roll_DamageThreshold", 7); }
public double getGracefulRollChanceMax() { return config.getDouble("Skills.Acrobatics.GracefulRoll_ChanceMax", 100.0D); } public double getGracefulRollChanceMax() { return config.getDouble("Skills.Acrobatics.GracefulRoll_ChanceMax", 100.0D); }
public int getGracefulRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.GracefulRoll_MaxBonusLevel", 500); } public int getGracefulRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.GracefulRoll_MaxBonusLevel", 500); }
public int getGracefulRollDamageThreshold() { return config.getInt("Skills.Acrobatics.GracefulRoll_DamageThreshold", 14); }
public int getGracefulRollSuccessModifer() { return config.getInt("Skills.Acrobatics.GracefulRoll_SuccessModifier", 2); }
public int getDodgeXPModifier() { return config.getInt("Skills.Acrobatics.Dodge_XP_Modifier", 120); } public int getDodgeXPModifier() { return config.getInt("Skills.Acrobatics.Dodge_XP_Modifier", 120); }
public int getRollXPModifier() { return config.getInt("Skills.Acrobatics.Roll_XP_Modifier", 80); } public int getRollXPModifier() { return config.getInt("Skills.Acrobatics.Roll_XP_Modifier", 80); }

View File

@ -34,7 +34,6 @@ import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.skills.acrobatics.Acrobatics; import com.gmail.nossr50.skills.acrobatics.Acrobatics;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.Archery; import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.fishing.Fishing; import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.skills.herbalism.Herbalism; import com.gmail.nossr50.skills.herbalism.Herbalism;
@ -176,8 +175,11 @@ public class EntityListener implements Listener {
if (!CombatTools.isInvincible(player, event.getDamage())) { if (!CombatTools.isInvincible(player, event.getDamage())) {
if (cause == DamageCause.FALL && player.getItemInHand().getType() != Material.ENDER_PEARL && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player)) { if (cause == DamageCause.FALL && player.getItemInHand().getType() != Material.ENDER_PEARL && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player)) {
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(mcMMOPlayer); event.setDamage(Acrobatics.processRoll(player, event.getDamage()));
acrobaticsManager.rollCheck(event);
if (event.getDamage() == 0) {
event.setCancelled(true);
}
} }
else if (cause == DamageCause.BLOCK_EXPLOSION && Permissions.demolitionsExpertise(player)) { else if (cause == DamageCause.BLOCK_EXPLOSION && Permissions.demolitionsExpertise(player)) {
MiningManager miningManager = new MiningManager(mcMMOPlayer); MiningManager miningManager = new MiningManager(mcMMOPlayer);

View File

@ -1,22 +1,89 @@
package com.gmail.nossr50.skills.acrobatics; package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; 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 class Acrobatics { public final class Acrobatics {
public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax(); public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax();
public static int dodgeMaxBonusLevel = AdvancedConfig.getInstance().getDodgeMaxBonusLevel(); public static int dodgeMaxBonusLevel = AdvancedConfig.getInstance().getDodgeMaxBonusLevel();
public static int dodgeXpModifier = AdvancedConfig.getInstance().getDodgeXPModifier(); public static int dodgeXpModifier = AdvancedConfig.getInstance().getDodgeXPModifier();
public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax(); public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax();
public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel(); public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel();
public static int rollThreshold = AdvancedConfig.getInstance().getRollDamageThreshold();
public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax(); public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax();
public static int gracefulRollMaxBonusLevel = AdvancedConfig.getInstance().getGracefulRollMaxBonusLevel(); 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 rollXpModifier = AdvancedConfig.getInstance().getRollXPModifier();
public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier(); public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier();
public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled(); public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled();
public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled(); public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled();
private Acrobatics() {};
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);
}
} }

View File

@ -12,33 +12,6 @@ public class AcrobaticsManager extends SkillManager {
super(mcMMOPlayer, SkillType.ACROBATICS); super(mcMMOPlayer, SkillType.ACROBATICS);
} }
/**
* Check for fall damage reduction.
*
* @param event The event to check
*/
public void rollCheck(EntityDamageEvent event) {
RollEventHandler eventHandler = new RollEventHandler(this, event);
double chance;
if (eventHandler.isGraceful) {
chance = (Acrobatics.gracefulRollMaxChance / Acrobatics.gracefulRollMaxBonusLevel) * eventHandler.skillModifier;
}
else {
chance = (Acrobatics.rollMaxChance / Acrobatics.rollMaxBonusLevel) * eventHandler.skillModifier;
}
if (chance > Misc.getRandom().nextInt(activationChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessage();
eventHandler.processXpGain(eventHandler.damage * Acrobatics.rollXpModifier);
}
else if (!eventHandler.isFatal(event.getDamage())) {
eventHandler.processXpGain(eventHandler.damage * Acrobatics.fallXpModifier);
}
}
/** /**
* Check for dodge damage reduction. * Check for dodge damage reduction.
* *

View File

@ -1,101 +0,0 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Permissions;
public class RollEventHandler extends AcrobaticsEventHandler {
protected boolean isGraceful;
private int damageThreshold;
protected RollEventHandler(AcrobaticsManager manager, EntityDamageEvent event) {
super(manager, event);
isGracefulRoll();
calculateSkillModifier();
calculateDamageThreshold();
calculateModifiedDamage();
}
@Override
protected void calculateSkillModifier() {
int skillModifer = manager.getSkillLevel();
if (isGraceful) {
skillModifer = skillModifer * 2;
}
skillModifer = SkillTools.skillCheck(skillModifer, Acrobatics.rollMaxBonusLevel);
this.skillModifier = skillModifer;
}
@Override
protected void calculateModifiedDamage() {
int modifiedDamage = damage - damageThreshold;
if (modifiedDamage < 0) {
modifiedDamage = 0;
}
this.modifiedDamage = modifiedDamage;
}
@Override
protected void modifyEventDamage() {
event.setDamage(modifiedDamage);
if (event.getDamage() == 0) {
event.setCancelled(true);
}
}
@Override
protected void sendAbilityMessage() {
Player player = manager.getMcMMOPlayer().getPlayer();
if (isGraceful) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
}
else {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text"));
}
}
@Override
protected void processXpGain(int xp) {
manager.getMcMMOPlayer().beginXpGain(SkillType.ACROBATICS, xp);
}
/**
* Check if this is a graceful roll.
*/
private void isGracefulRoll() {
Player player = manager.getMcMMOPlayer().getPlayer();
if (Permissions.gracefulRoll(player)) {
this.isGraceful = player.isSneaking();
}
else {
this.isGraceful = false;
}
}
/**
* Calculate the damage threshold for this event.
*/
private void calculateDamageThreshold() {
int damageThreshold = 7;
if (isGraceful) {
damageThreshold = damageThreshold * 2;
}
this.damageThreshold = damageThreshold;
}
}

View File

@ -27,13 +27,19 @@ Skills:
# Roll_ChanceMax: Maximum chance of rolling when on Roll_MaxBonusLevel or higher # Roll_ChanceMax: Maximum chance of rolling when on Roll_MaxBonusLevel or higher
# Roll_MaxBonusLevel: On this level or higher, the roll chance will not go higher than Roll_ChanceMax # Roll_MaxBonusLevel: On this level or higher, the roll chance will not go higher than Roll_ChanceMax
# Roll_DamageThreshold: The max damage a player can negate with a roll
Roll_ChanceMax: 100.0 Roll_ChanceMax: 100.0
Roll_MaxBonusLevel: 1000 Roll_MaxBonusLevel: 1000
Roll_DamageThreshold: 7
# GracefulRoll_ChanceMax: Maximum chance of graceful rolling when on GracefulRoll_MaxBonusLevel or higher # GracefulRoll_ChanceMax: Maximum chance of graceful rolling when on GracefulRoll_MaxBonusLevel or higher
# GracefulRoll_MaxBonusLevel: On this level or higher, the graceful roll chance will not go higher than GracefulRoll_ChanceMax # GracefulRoll_MaxBonusLevel: On this level or higher, the graceful roll chance will not go higher than GracefulRoll_ChanceMax
# GracefulRoll_DamageThreshold: The max damage a player can negate with a graceful roll
# GracefulRoll_SuccessModifier: Graceful rolls will be this many times more likely to succeed than regular rolls
GracefulRoll_ChanceMax: 100.0 GracefulRoll_ChanceMax: 100.0
GracefulRoll_MaxBonusLevel: 500 GracefulRoll_MaxBonusLevel: 500
GracefulRoll_DamageThreshold: 14
GracefulRoll_SuccessModifier: 2
# Amount of experience for performing a dodge, roll or fall # Amount of experience for performing a dodge, roll or fall
Dodge_XP_Modifier: 120 Dodge_XP_Modifier: 120