2012-06-11 22:11:23 +02:00
|
|
|
package com.gmail.nossr50.skills.acrobatics;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
|
|
|
2012-11-08 03:41:18 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-06-11 22:11:23 +02:00
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2013-01-10 15:26:01 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
2013-01-08 22:07:29 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2012-06-13 18:31:20 +02:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2012-06-11 22:11:23 +02:00
|
|
|
|
2013-01-10 15:26:01 +01:00
|
|
|
public class AcrobaticsManager extends SkillManager {
|
2013-01-08 22:07:29 +01:00
|
|
|
private static Config config = Config.getInstance();
|
|
|
|
|
2012-06-11 22:11:23 +02:00
|
|
|
public AcrobaticsManager (Player player) {
|
2013-01-10 15:26:01 +01:00
|
|
|
super(player, SkillType.ACROBATICS);
|
2012-06-11 22:11:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for fall damage reduction.
|
|
|
|
*
|
|
|
|
* @param event The event to check
|
|
|
|
*/
|
|
|
|
public void rollCheck(EntityDamageEvent event) {
|
2013-01-08 22:07:29 +01:00
|
|
|
if (Misc.isCitizensNPC(player) || !Permissions.roll(player)) {
|
2012-06-11 22:11:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-08 22:07:29 +01:00
|
|
|
if (config.getAcrobaticsAFKDisabled() && player.isInsideVehicle()) {
|
2012-11-08 03:41:18 +01:00
|
|
|
return;
|
2013-01-08 22:07:29 +01:00
|
|
|
}
|
2012-11-08 03:41:18 +01:00
|
|
|
|
2012-06-11 22:11:23 +02:00
|
|
|
RollEventHandler eventHandler = new RollEventHandler(this, event);
|
|
|
|
|
2013-01-02 00:34:32 +01:00
|
|
|
int randomChance = 100;
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.luckyAcrobatics(player)) {
|
2012-07-02 17:09:55 +02:00
|
|
|
randomChance = (int) (randomChance * 0.75);
|
|
|
|
}
|
|
|
|
|
2013-01-08 22:07:29 +01:00
|
|
|
float chance;
|
|
|
|
|
2013-01-02 00:34:32 +01:00
|
|
|
if (eventHandler.isGraceful) {
|
2013-01-08 22:07:29 +01:00
|
|
|
chance = ((float) Acrobatics.GRACEFUL_MAX_CHANCE / Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
chance = ((float) Acrobatics.ROLL_MAX_CHANCE / Acrobatics.ROLL_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
|
2013-01-02 00:34:32 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 05:46:35 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
|
2012-06-11 22:11:23 +02:00
|
|
|
eventHandler.modifyEventDamage();
|
|
|
|
eventHandler.sendAbilityMessage();
|
2012-06-12 02:37:09 +02:00
|
|
|
eventHandler.processXPGain(eventHandler.damage * Acrobatics.ROLL_XP_MODIFIER);
|
2012-06-11 22:11:23 +02:00
|
|
|
}
|
2012-06-12 14:10:18 +02:00
|
|
|
else if (!eventHandler.isFatal(event.getDamage())) {
|
2012-06-12 02:37:09 +02:00
|
|
|
eventHandler.processXPGain(eventHandler.damage * Acrobatics.FALL_XP_MODIFIER);
|
2012-06-11 22:11:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for dodge damage reduction.
|
|
|
|
*
|
|
|
|
* @param event The event to check
|
|
|
|
*/
|
2012-06-12 16:23:34 +02:00
|
|
|
public void dodgeCheck(EntityDamageEvent event) {
|
2013-01-08 22:07:29 +01:00
|
|
|
if (Misc.isCitizensNPC(player) || !Permissions.dodge(player)) {
|
2012-06-11 22:11:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
|
|
|
|
|
2013-01-02 00:34:32 +01:00
|
|
|
int randomChance = 100;
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.luckyAcrobatics(player)) {
|
2012-07-02 17:09:55 +02:00
|
|
|
randomChance = (int) (randomChance * 0.75);
|
|
|
|
}
|
|
|
|
|
2013-01-08 22:07:29 +01:00
|
|
|
float chance = ((float) Acrobatics.DODGE_MAX_CHANCE / Acrobatics.DODGE_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
|
2013-01-02 00:34:32 +01:00
|
|
|
|
2013-01-10 05:46:35 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
|
2012-06-11 22:11:23 +02:00
|
|
|
eventHandler.modifyEventDamage();
|
|
|
|
eventHandler.sendAbilityMessage();
|
2012-06-12 14:10:18 +02:00
|
|
|
eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER);
|
2012-06-11 22:11:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|