Add roll event, remove particle flag from the dodge event.

This commit is contained in:
GJ 2013-10-23 09:35:04 -04:00 committed by TfT_02
parent e10b70c422
commit 20967bea92
5 changed files with 82 additions and 84 deletions

View File

@ -5,13 +5,11 @@ import org.bukkit.entity.Player;
public class McMMOPlayerDodgeEvent extends McMMOPlayerAcrobaticsEvent { public class McMMOPlayerDodgeEvent extends McMMOPlayerAcrobaticsEvent {
private double damageTaken; private double damageTaken;
private float xpGained; private float xpGained;
private boolean useParticles;
public McMMOPlayerDodgeEvent(Player player, double damageTaken, float xpGained) { public McMMOPlayerDodgeEvent(Player player, double damageTaken, float xpGained) {
super(player); super(player);
this.damageTaken = damageTaken; this.damageTaken = damageTaken;
this.xpGained = xpGained; this.xpGained = xpGained;
useParticles = true;
} }
public double getDamageTaken() { public double getDamageTaken() {
@ -29,12 +27,4 @@ public class McMMOPlayerDodgeEvent extends McMMOPlayerAcrobaticsEvent {
public void setXpGained(float xpGained) { public void setXpGained(float xpGained) {
this.xpGained = xpGained; this.xpGained = xpGained;
} }
public boolean shouldUseParticles() {
return useParticles;
}
public void setUseParticles(boolean useParticles) {
this.useParticles = useParticles;
}
} }

View File

@ -0,0 +1,36 @@
package com.gmail.nossr50.events.skills.acrobatics;
import org.bukkit.entity.Player;
public class McMMOPlayerRollEvent extends McMMOPlayerAcrobaticsEvent {
private double damageTaken;
private float xpGained;
private boolean graceful;
public McMMOPlayerRollEvent(Player player, double damageTaken, float xpGained, boolean graceful) {
super(player);
this.damageTaken = damageTaken;
this.xpGained = xpGained;
this.graceful = graceful;
}
public double getDamageTaken() {
return damageTaken;
}
public void setDamageTaken(double damageTaken) {
this.damageTaken = damageTaken;
}
public float getXpGained() {
return xpGained;
}
public void setXpGained(float xpGained) {
this.xpGained = xpGained;
}
public boolean isGraceful() {
return graceful;
}
}

View File

@ -40,7 +40,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.runnables.skills.BleedTimerTask; import com.gmail.nossr50.runnables.skills.BleedTimerTask;
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;
@ -236,16 +235,8 @@ public class EntityListener implements Listener {
return; return;
} }
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager(); event.setDamage(mcMMOPlayer.getAcrobaticsManager().roll(event.getDamage()));
event.setCancelled(event.getDamage() == 0);
if (acrobaticsManager.canRoll()) {
event.setDamage(acrobaticsManager.rollCheck(event.getDamage()));
if (event.getDamage() == 0) {
event.setCancelled(true);
return;
}
}
break; break;
case BLOCK_EXPLOSION: case BLOCK_EXPLOSION:

View File

@ -27,11 +27,11 @@ public final class Acrobatics {
private Acrobatics() {}; private Acrobatics() {};
protected static double calculateModifiedDodgeDamage(double damage, double damageModifier) { protected static double calculateModifiedDodgeDamage(double damage) {
return Math.max(damage / damageModifier, 1.0); return Math.max(damage / dodgeDamageModifier, 1.0);
} }
protected static double calculateModifiedRollDamage(double damage, double damageThreshold) { protected static double calculateModifiedRollDamage(double damage, boolean isGraceful) {
return Math.max(damage - damageThreshold, 0.0); return Math.max(damage - (isGraceful ? gracefulRollThreshold : rollThreshold), 0.0);
} }
} }

View File

@ -13,6 +13,7 @@ import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.acrobatics.McMMOPlayerDodgeEvent; import com.gmail.nossr50.events.skills.acrobatics.McMMOPlayerDodgeEvent;
import com.gmail.nossr50.events.skills.acrobatics.McMMOPlayerRollEvent;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -42,47 +43,28 @@ public class AcrobaticsManager extends SkillManager {
* @param damage The amount of damage initially dealt by the event * @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise * @return the modified event damage if the ability was successful, the original event damage otherwise
*/ */
public double rollCheck(double damage) { public double roll(double damage) {
Player player = getPlayer(); if (!canRoll()) {
if (player.isSneaking() && Permissions.gracefulRoll(player)) {
return gracefulRollCheck(damage);
}
double modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.rollThreshold);
if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.rollMaxChance, Acrobatics.rollMaxBonusLevel)) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text"));
applyXpGain(calculateRollXP(damage, true));
return modifiedDamage;
}
else if (!isFatal(damage)) {
applyXpGain(calculateRollXP(damage, false));
}
lastFallLocation = player.getLocation();
return damage; return damage;
} }
/** Player player = getPlayer();
* Handle the damage reduction and XP gain from the Graceful Roll ability boolean isGraceful = player.isSneaking() && Permissions.gracefulRoll(player);
* double modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, isGraceful);
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
private double gracefulRollCheck(double damage) {
double modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.gracefulRollThreshold);
if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.gracefulRollMaxChance, Acrobatics.gracefulRollMaxBonusLevel)) { if (!isFatal(modifiedDamage) && isSuccessfulRoll(isGraceful)) {
getPlayer().sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc")); McMMOPlayerRollEvent event = new McMMOPlayerRollEvent(player, modifiedDamage, calculateRollXP(damage, true), isGraceful);
applyXpGain(calculateRollXP(damage, true)); mcMMO.p.getServer().getPluginManager().callEvent(event);
return modifiedDamage; if (event.isCancelled()) {
return damage;
}
return event.getDamageTaken();
} }
else if (!isFatal(damage)) { else if (!isFatal(damage)) {
applyXpGain(calculateRollXP(damage, false)); applyXpGain(calculateRollXP(damage, false));
lastFallLocation = player.getLocation();
} }
return damage; return damage;
@ -115,25 +97,6 @@ public class AcrobaticsManager extends SkillManager {
return fallTries > Config.getInstance().getAcrobaticsAFKMaxTries(); return fallTries > Config.getInstance().getAcrobaticsAFKMaxTries();
} }
private boolean isSuccessfulRoll(double maxChance, int maxLevel) {
return (maxChance / maxLevel) * Math.min(getSkillLevel(), maxLevel) > Misc.getRandom().nextInt(activationChance);
}
private boolean isFatal(double damage) {
return getPlayer().getHealth() - damage < 1;
}
private float calculateRollXP(double damage, boolean isRoll) {
ItemStack boots = getPlayer().getInventory().getBoots();
float xp = (float) (damage * (isRoll ? Acrobatics.rollXpModifier : Acrobatics.fallXpModifier));
if (boots != null && boots.containsEnchantment(Enchantment.PROTECTION_FALL)) {
xp *= Acrobatics.featherFallXPModifier;
}
return xp;
}
/** /**
* Handle the damage reduction and XP gain from the Dodge ability * Handle the damage reduction and XP gain from the Dodge ability
* *
@ -142,7 +105,7 @@ public class AcrobaticsManager extends SkillManager {
* @return the modified event damage if the ability was successful, the original event damage otherwise * @return the modified event damage if the ability was successful, the original event damage otherwise
*/ */
public double dodge(Entity damager, double damage) { public double dodge(Entity damager, double damage) {
double modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier); double modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage);
if (!canDodge(damager, modifiedDamage)) { if (!canDodge(damager, modifiedDamage)) {
return damage; return damage;
@ -157,20 +120,38 @@ public class AcrobaticsManager extends SkillManager {
return damage; return damage;
} }
if (event.shouldUseParticles()) {
ParticleEffectUtils.playDodgeEffect(player); ParticleEffectUtils.playDodgeEffect(player);
}
if (mcMMOPlayer.useChatNotifications()) { if (mcMMOPlayer.useChatNotifications()) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc")); player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
} }
// Why do we check respawn cooldown here?
// No, seriously, why?
if (SkillUtils.cooldownExpired(mcMMOPlayer.getRespawnATS(), Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS)) { if (SkillUtils.cooldownExpired(mcMMOPlayer.getRespawnATS(), Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS)) {
applyXpGain(event.getXpGained()); applyXpGain(event.getXpGained());
} }
return event.getDamageTaken(); return event.getDamageTaken();
} }
private boolean isSuccessfulRoll(boolean isGraceful) {
double maxChance = isGraceful ? Acrobatics.gracefulRollMaxChance : Acrobatics.rollMaxChance;
int maxLevel = isGraceful ? Acrobatics.gracefulRollMaxBonusLevel : Acrobatics.rollMaxBonusLevel;
return (maxChance / maxLevel) * Math.min(getSkillLevel(), maxLevel) > Misc.getRandom().nextInt(activationChance);
}
private float calculateRollXP(double damage, boolean isRoll) {
ItemStack boots = getPlayer().getInventory().getBoots();
float xp = (float) (damage * (isRoll ? Acrobatics.rollXpModifier : Acrobatics.fallXpModifier));
if (boots != null && boots.containsEnchantment(Enchantment.PROTECTION_FALL)) {
xp *= Acrobatics.featherFallXPModifier;
}
return xp;
}
private boolean isFatal(double damage) {
return getPlayer().getHealth() - damage < 1;
}
} }