mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-30 00:56:47 +01:00
Add roll event, remove particle flag from the dodge event.
This commit is contained in:
parent
e10b70c422
commit
20967bea92
@ -5,13 +5,11 @@ 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() {
|
||||
@ -29,12 +27,4 @@ public class McMMOPlayerDodgeEvent extends McMMOPlayerAcrobaticsEvent {
|
||||
public void setXpGained(float xpGained) {
|
||||
this.xpGained = xpGained;
|
||||
}
|
||||
|
||||
public boolean shouldUseParticles() {
|
||||
return useParticles;
|
||||
}
|
||||
|
||||
public void setUseParticles(boolean useParticles) {
|
||||
this.useParticles = useParticles;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -40,7 +40,6 @@ import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
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.fishing.Fishing;
|
||||
import com.gmail.nossr50.skills.herbalism.Herbalism;
|
||||
@ -236,16 +235,8 @@ public class EntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
||||
|
||||
if (acrobaticsManager.canRoll()) {
|
||||
event.setDamage(acrobaticsManager.rollCheck(event.getDamage()));
|
||||
|
||||
if (event.getDamage() == 0) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
event.setDamage(mcMMOPlayer.getAcrobaticsManager().roll(event.getDamage()));
|
||||
event.setCancelled(event.getDamage() == 0);
|
||||
break;
|
||||
|
||||
case BLOCK_EXPLOSION:
|
||||
|
@ -27,11 +27,11 @@ public final class Acrobatics {
|
||||
|
||||
private Acrobatics() {};
|
||||
|
||||
protected static double calculateModifiedDodgeDamage(double damage, double damageModifier) {
|
||||
return Math.max(damage / damageModifier, 1.0);
|
||||
protected static double calculateModifiedDodgeDamage(double damage) {
|
||||
return Math.max(damage / dodgeDamageModifier, 1.0);
|
||||
}
|
||||
|
||||
protected static double calculateModifiedRollDamage(double damage, double damageThreshold) {
|
||||
return Math.max(damage - damageThreshold, 0.0);
|
||||
protected static double calculateModifiedRollDamage(double damage, boolean isGraceful) {
|
||||
return Math.max(damage - (isGraceful ? gracefulRollThreshold : rollThreshold), 0.0);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
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.skills.SkillManager;
|
||||
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
|
||||
* @return the modified event damage if the ability was successful, the original event damage otherwise
|
||||
*/
|
||||
public double rollCheck(double damage) {
|
||||
Player player = getPlayer();
|
||||
|
||||
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();
|
||||
|
||||
public double roll(double damage) {
|
||||
if (!canRoll()) {
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the damage reduction and XP gain from the Graceful Roll 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
|
||||
*/
|
||||
private double gracefulRollCheck(double damage) {
|
||||
double modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.gracefulRollThreshold);
|
||||
Player player = getPlayer();
|
||||
boolean isGraceful = player.isSneaking() && Permissions.gracefulRoll(player);
|
||||
double modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, isGraceful);
|
||||
|
||||
if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.gracefulRollMaxChance, Acrobatics.gracefulRollMaxBonusLevel)) {
|
||||
getPlayer().sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
|
||||
applyXpGain(calculateRollXP(damage, true));
|
||||
if (!isFatal(modifiedDamage) && isSuccessfulRoll(isGraceful)) {
|
||||
McMMOPlayerRollEvent event = new McMMOPlayerRollEvent(player, modifiedDamage, calculateRollXP(damage, true), isGraceful);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
return modifiedDamage;
|
||||
if (event.isCancelled()) {
|
||||
return damage;
|
||||
}
|
||||
|
||||
return event.getDamageTaken();
|
||||
}
|
||||
else if (!isFatal(damage)) {
|
||||
applyXpGain(calculateRollXP(damage, false));
|
||||
lastFallLocation = player.getLocation();
|
||||
}
|
||||
|
||||
return damage;
|
||||
@ -115,25 +97,6 @@ public class AcrobaticsManager extends SkillManager {
|
||||
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
|
||||
*
|
||||
@ -142,7 +105,7 @@ public class AcrobaticsManager extends SkillManager {
|
||||
* @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);
|
||||
double modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage);
|
||||
|
||||
if (!canDodge(damager, modifiedDamage)) {
|
||||
return damage;
|
||||
@ -157,20 +120,38 @@ public class AcrobaticsManager extends SkillManager {
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user