123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- 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.Permissions;
- import com.gmail.nossr50.util.Users;
- public class AcrobaticsManager {
- private Player player;
- private PlayerProfile profile;
- private int skillLevel;
- public AcrobaticsManager (Player player) {
- this.player = player;
- this.profile = Users.getProfile(player);
- this.skillLevel = profile.getSkillLevel(SkillType.ACROBATICS);
- this.permissionInstance = Permissions.getInstance();
- }
- /**
- * Check for fall damage reduction.
- *
- * @param event The event to check
- */
- public void rollCheck(EntityDamageEvent event) {
- if(player == null)
- return;
- if (!Permissions.roll(player)) {
- return;
- }
- if(Config.getInstance().getAcrobaticsAFKDisabled() && player.isInsideVehicle())
- return;
- RollEventHandler eventHandler = new RollEventHandler(this, event);
- int randomChance = 100;
- if (Permissions.luckyAcrobatics(player)) {
- randomChance = (int) (randomChance * 0.75);
- }
- float chance = (float) (((double) Acrobatics.ROLL_MAX_CHANCE / (double) Acrobatics.ROLL_MAX_BONUS_LEVEL) * skillLevel);
- if (chance > Acrobatics.ROLL_MAX_CHANCE) chance = Acrobatics.ROLL_MAX_CHANCE;
- if (eventHandler.isGraceful) {
- chance = (float) (((double) Acrobatics.GRACEFUL_MAX_CHANCE / (double) Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * skillLevel);
- if (chance > Acrobatics.GRACEFUL_MAX_CHANCE) chance = Acrobatics.GRACEFUL_MAX_CHANCE;
- }
- if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
- eventHandler.modifyEventDamage();
- eventHandler.sendAbilityMessage();
- eventHandler.processXPGain(eventHandler.damage * Acrobatics.ROLL_XP_MODIFIER);
- }
- else if (!eventHandler.isFatal(event.getDamage())) {
- 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(player == null)
- return;
- if (!Permissions.dodge(player)) {
- return;
- }
- DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
- int randomChance = 100;
- if (Permissions.luckyAcrobatics(player)) {
- randomChance = (int) (randomChance * 0.75);
- }
- float chance = (float) (((double) Acrobatics.DODGE_MAX_CHANCE / (double) Acrobatics.DODGE_MAX_BONUS_LEVEL) * skillLevel);
- if (chance > Acrobatics.DODGE_MAX_CHANCE) chance = Acrobatics.DODGE_MAX_CHANCE;
- if (chance > Acrobatics.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;
- }
- }
|