mcMMO/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java

104 lines
3.4 KiB
Java
Raw Normal View History

package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.util.Misc;
2012-06-13 18:31:20 +02:00
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class AcrobaticsManager {
private static Config config = Config.getInstance();
private Player player;
private PlayerProfile profile;
2013-01-07 02:59:31 +01:00
private int skillLevel;
public AcrobaticsManager (Player player) {
this.player = player;
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(SkillType.ACROBATICS);
}
/**
* Check for fall damage reduction.
*
* @param event The event to check
*/
public void rollCheck(EntityDamageEvent event) {
if (Misc.isCitizensNPC(player) || !Permissions.roll(player)) {
return;
}
if (config.getAcrobaticsAFKDisabled() && player.isInsideVehicle()) {
return;
}
RollEventHandler eventHandler = new RollEventHandler(this, event);
int randomChance = 100;
2013-01-07 02:52:31 +01:00
if (Permissions.luckyAcrobatics(player)) {
randomChance = (int) (randomChance * 0.75);
}
float chance;
if (eventHandler.isGraceful) {
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;
}
if (chance > Misc.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessage();
2012-06-12 02:37:09 +02:00
eventHandler.processXPGain(eventHandler.damage * Acrobatics.ROLL_XP_MODIFIER);
}
else if (!eventHandler.isFatal(event.getDamage())) {
2012-06-12 02:37:09 +02:00
eventHandler.processXPGain(eventHandler.damage * Acrobatics.FALL_XP_MODIFIER);
}
}
/**
* Check for dodge damage reduction.
*
* @param event The event to check
*/
public void dodgeCheck(EntityDamageEvent event) {
if (Misc.isCitizensNPC(player) || !Permissions.dodge(player)) {
return;
}
DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
int randomChance = 100;
2013-01-07 02:52:31 +01:00
if (Permissions.luckyAcrobatics(player)) {
randomChance = (int) (randomChance * 0.75);
}
float chance = ((float) Acrobatics.DODGE_MAX_CHANCE / Acrobatics.DODGE_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
if (chance > Misc.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessage();
eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER);
}
}
protected Player getPlayer() {
return player;
}
protected PlayerProfile getProfile() {
return profile;
}
protected int getSkillLevel() {
return skillLevel;
}
}