Add event for Dodge

This commit is contained in:
GJ 2013-10-22 12:52:06 -04:00 committed by TfT_02
parent 071c568353
commit e10b70c422
5 changed files with 110 additions and 44 deletions

View File

@ -0,0 +1,24 @@
package com.gmail.nossr50.events.skills.acrobatics;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerSkillEvent;
public abstract class McMMOPlayerAcrobaticsEvent extends McMMOPlayerSkillEvent implements Cancellable {
private boolean cancelled;
protected McMMOPlayerAcrobaticsEvent(Player player) {
super(player, SkillType.ACROBATICS);
cancelled = false;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -0,0 +1,40 @@
package com.gmail.nossr50.events.skills.acrobatics;
import org.bukkit.entity.Player;
public class McMMOPlayerDodgeEvent extends McMMOPlayerAcrobaticsEvent {
private double damageTaken;
private float xpGained;
private boolean useParticles;
public McMMOPlayerDodgeEvent(Player player, double damageTaken, float xpGained) {
super(player);
this.damageTaken = damageTaken;
this.xpGained = xpGained;
useParticles = true;
}
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 shouldUseParticles() {
return useParticles;
}
public void setUseParticles(boolean useParticles) {
this.useParticles = useParticles;
}
}

View File

@ -8,9 +8,11 @@ import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; 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.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;
@ -30,44 +32,8 @@ public class AcrobaticsManager extends SkillManager {
return !exploitPrevention() && Permissions.roll(getPlayer()); return !exploitPrevention() && Permissions.roll(getPlayer());
} }
public boolean canDodge(Entity damager) { private boolean canDodge(Entity damager, double modifiedDamage) {
if (Permissions.dodge(getPlayer())) { return (Permissions.dodge(getPlayer()) && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) && skill.shouldProcess(damager) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Acrobatics.dodgeMaxChance, Acrobatics.dodgeMaxBonusLevel) && !isFatal(modifiedDamage));
if (damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) {
return false;
}
return skill.shouldProcess(damager);
}
return false;
}
/**
* Handle the damage reduction and XP gain from the Dodge ability
*
* @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
*/
public double dodgeCheck(double damage) {
double modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier);
Player player = getPlayer();
if (!isFatal(modifiedDamage) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Acrobatics.dodgeMaxChance, Acrobatics.dodgeMaxBonusLevel)) {
ParticleEffectUtils.playDodgeEffect(player);
if (mcMMOPlayer.useChatNotifications()) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
}
// Why do we check respawn cooldown here?
if (SkillUtils.cooldownExpired(mcMMOPlayer.getRespawnATS(), Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS)) {
applyXpGain((float) (damage * Acrobatics.dodgeXpModifier));
}
return modifiedDamage;
}
return damage;
} }
/** /**
@ -167,4 +133,44 @@ public class AcrobaticsManager extends SkillManager {
return xp; return xp;
} }
/**
* Handle the damage reduction and XP gain from the Dodge ability
*
* @param damager The entity that dealt the damage
* @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
*/
public double dodge(Entity damager, double damage) {
double modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier);
if (!canDodge(damager, modifiedDamage)) {
return damage;
}
Player player = getPlayer();
McMMOPlayerDodgeEvent event = new McMMOPlayerDodgeEvent(player, modifiedDamage, (float) (damage * Acrobatics.dodgeXpModifier));
mcMMO.p.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return damage;
}
if (event.shouldUseParticles()) {
ParticleEffectUtils.playDodgeEffect(player);
}
if (mcMMOPlayer.useChatNotifications()) {
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)) {
applyXpGain(event.getXpGained());
}
return event.getDamageTaken();
}
} }

View File

@ -107,7 +107,7 @@ public final class ChimaeraWing {
if (warmup > 0) { if (warmup > 0) {
player.sendMessage(LocaleLoader.getString("Teleport.Commencing", warmup)); player.sendMessage(LocaleLoader.getString("Teleport.Commencing", warmup));
new ChimaeraWingWarmup(mcMMOPlayer).runTaskLater(mcMMO.p, 20 * warmup); new ChimaeraWingWarmup(mcMMOPlayer).runTaskLater(mcMMO.p, Misc.TICK_CONVERSION_FACTOR * warmup);
} }
else { else {
chimaeraExecuteTeleport(); chimaeraExecuteTeleport();

View File

@ -28,7 +28,6 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.skills.AwardCombatXpTask; import com.gmail.nossr50.runnables.skills.AwardCombatXpTask;
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.ArcheryManager; import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxesManager; import com.gmail.nossr50.skills.axes.AxesManager;
import com.gmail.nossr50.skills.swords.Swords; import com.gmail.nossr50.skills.swords.Swords;
@ -281,11 +280,8 @@ public final class CombatUtils {
Player player = (Player) target; Player player = (Player) target;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
if (acrobaticsManager.canDodge(damager)) { event.setDamage(mcMMOPlayer.getAcrobaticsManager().dodge(damager, event.getDamage()));
event.setDamage(acrobaticsManager.dodgeCheck(event.getDamage()));
}
if (ItemUtils.isSword(player.getItemInHand())) { if (ItemUtils.isSword(player.getItemInHand())) {
if (!SkillType.SWORDS.shouldProcess(target)) { if (!SkillType.SWORDS.shouldProcess(target)) {