mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Move Roll checks into the manager.
This commit is contained in:
parent
d46b134dbb
commit
d409610a55
@ -180,7 +180,7 @@ public class EntityListener implements Listener {
|
|||||||
switch (cause) {
|
switch (cause) {
|
||||||
case FALL:
|
case FALL:
|
||||||
if (Acrobatics.canRoll(player)) {
|
if (Acrobatics.canRoll(player)) {
|
||||||
event.setDamage(Acrobatics.processRoll(player, event.getDamage()));
|
event.setDamage(SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).processRoll(event.getDamage()));
|
||||||
|
|
||||||
if (event.getDamage() == 0) {
|
if (event.getDamage() == 0) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@ -54,42 +54,6 @@ public final class Acrobatics {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int processRoll(Player player, int damage) {
|
|
||||||
if (player.isSneaking() && Permissions.gracefulRoll(player)) {
|
|
||||||
return processGracefulRoll(player, damage);
|
|
||||||
}
|
|
||||||
|
|
||||||
int modifiedDamage = calculateModifiedRollDamage(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 = calculateModifiedRollDamage(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static boolean isFatal(Player player, int damage) {
|
protected static boolean isFatal(Player player, int damage) {
|
||||||
return player.getHealth() - damage < 1;
|
return player.getHealth() - damage < 1;
|
||||||
}
|
}
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
package com.gmail.nossr50.skills.acrobatics;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
|
|
||||||
public abstract class AcrobaticsEventHandler {
|
|
||||||
protected AcrobaticsManager manager;
|
|
||||||
|
|
||||||
protected EntityDamageEvent event;
|
|
||||||
protected int damage;
|
|
||||||
protected int skillModifier;
|
|
||||||
protected int modifiedDamage;
|
|
||||||
|
|
||||||
protected AcrobaticsEventHandler(AcrobaticsManager manager, EntityDamageEvent event) {
|
|
||||||
this.manager = manager;
|
|
||||||
this.event = event;
|
|
||||||
this.damage = event.getDamage();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate the skill modifier applied for this event.
|
|
||||||
*/
|
|
||||||
protected abstract void calculateSkillModifier();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate the modified damage for this event.
|
|
||||||
*/
|
|
||||||
protected abstract void calculateModifiedDamage();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modify the damage dealt by this event.
|
|
||||||
*/
|
|
||||||
protected abstract void modifyEventDamage();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send the ability message for this event.
|
|
||||||
*/
|
|
||||||
protected abstract void sendAbilityMessage();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process Xp gain from this event.
|
|
||||||
*/
|
|
||||||
protected abstract void processXpGain(int xp);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check to ensure you're not gaining XP after you die.
|
|
||||||
*
|
|
||||||
* @param damage The damage to be dealt
|
|
||||||
* @return true if the damage is fatal, false otherwise
|
|
||||||
*/
|
|
||||||
protected boolean isFatal(int damage) {
|
|
||||||
Player player = manager.getMcMMOPlayer().getPlayer();
|
|
||||||
|
|
||||||
if (player.getHealth() - damage < 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,6 +10,7 @@ import com.gmail.nossr50.skills.utilities.SkillTools;
|
|||||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.ParticleEffectUtils;
|
import com.gmail.nossr50.util.ParticleEffectUtils;
|
||||||
|
import com.gmail.nossr50.util.Permissions;
|
||||||
|
|
||||||
public class AcrobaticsManager extends SkillManager {
|
public class AcrobaticsManager extends SkillManager {
|
||||||
public AcrobaticsManager (McMMOPlayer mcMMOPlayer) {
|
public AcrobaticsManager (McMMOPlayer mcMMOPlayer) {
|
||||||
@ -17,9 +18,10 @@ public class AcrobaticsManager extends SkillManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for dodge damage reduction.
|
* Handle the damage reduction and XP gain from the Dodge ability
|
||||||
*
|
*
|
||||||
* @param event The event to check
|
* @param damage The amount of damage initially dealt by the event
|
||||||
|
* @return the modified event damage if the dodge was successful, the original event damage otherwise
|
||||||
*/
|
*/
|
||||||
public int dodgeCheck(int damage) {
|
public int dodgeCheck(int damage) {
|
||||||
int modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier);
|
int modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier);
|
||||||
@ -44,4 +46,48 @@ public class AcrobaticsManager extends SkillManager {
|
|||||||
|
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the damage reduction and XP gain from the Roll ability
|
||||||
|
*
|
||||||
|
* @param damage The amount of damage initially dealt by the event
|
||||||
|
* @return the modified event damage if the roll was successful, the original event damage otherwise
|
||||||
|
*/
|
||||||
|
public int processRoll(int damage) {
|
||||||
|
Player player = getPlayer();
|
||||||
|
|
||||||
|
if (player.isSneaking() && Permissions.gracefulRoll(player)) {
|
||||||
|
return processGracefulRoll(player, damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
int modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.rollThreshold);
|
||||||
|
|
||||||
|
if (!Acrobatics.isFatal(player, modifiedDamage) && Acrobatics.isSuccessfulRoll(player, Acrobatics.rollMaxChance, Acrobatics.rollMaxBonusLevel, 1)) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text"));
|
||||||
|
applyXpGain(damage * Acrobatics.rollXpModifier);
|
||||||
|
|
||||||
|
return modifiedDamage;
|
||||||
|
}
|
||||||
|
else if (!Acrobatics.isFatal(player, damage)) {
|
||||||
|
applyXpGain(damage * Acrobatics.fallXpModifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int processGracefulRoll(Player player, int damage) {
|
||||||
|
int modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.gracefulRollThreshold);
|
||||||
|
|
||||||
|
if (!Acrobatics.isFatal(player, modifiedDamage) && Acrobatics.isSuccessfulRoll(player, Acrobatics.gracefulRollMaxChance, Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollSuccessModifier)) {
|
||||||
|
player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
|
||||||
|
applyXpGain(damage * Acrobatics.rollXpModifier);
|
||||||
|
|
||||||
|
return modifiedDamage;
|
||||||
|
}
|
||||||
|
else if (!Acrobatics.isFatal(player, damage)) {
|
||||||
|
applyXpGain(damage * Acrobatics.fallXpModifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
package com.gmail.nossr50.skills.acrobatics;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
|
||||||
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.Misc;
|
|
||||||
import com.gmail.nossr50.util.ParticleEffectUtils;
|
|
||||||
|
|
||||||
public class DodgeEventHandler extends AcrobaticsEventHandler {
|
|
||||||
protected DodgeEventHandler(AcrobaticsManager manager, EntityDamageEvent event) {
|
|
||||||
super(manager, event);
|
|
||||||
|
|
||||||
calculateSkillModifier();
|
|
||||||
calculateModifiedDamage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void calculateSkillModifier() {
|
|
||||||
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Acrobatics.dodgeMaxBonusLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void calculateModifiedDamage() {
|
|
||||||
int modifiedDamage = damage / 2;
|
|
||||||
|
|
||||||
if (modifiedDamage <= 0) {
|
|
||||||
modifiedDamage = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.modifiedDamage = modifiedDamage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void modifyEventDamage() {
|
|
||||||
event.setDamage(modifiedDamage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void sendAbilityMessage() {
|
|
||||||
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
|
|
||||||
Player dodgingPlayer = mcMMOPlayer.getPlayer();
|
|
||||||
|
|
||||||
ParticleEffectUtils.playDodgeEffect(dodgingPlayer);
|
|
||||||
|
|
||||||
if (mcMMOPlayer.getProfile().useChatNotifications()) {
|
|
||||||
dodgingPlayer.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void processXpGain(int xp) {
|
|
||||||
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
|
|
||||||
|
|
||||||
if (System.currentTimeMillis() >= mcMMOPlayer.getProfile().getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) {
|
|
||||||
manager.getMcMMOPlayer().beginXpGain(SkillType.ACROBATICS, xp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user