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.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-06-13 18:31:20 +02:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2012-06-11 22:11:23 +02:00
|
|
|
import com.gmail.nossr50.util.Users;
|
|
|
|
|
|
|
|
public class AcrobaticsManager {
|
|
|
|
private Player player;
|
|
|
|
private PlayerProfile profile;
|
|
|
|
private int skillLevel;
|
2013-01-01 23:32:22 +01:00
|
|
|
private Permissions permissionInstance;
|
2012-06-11 22:11:23 +02:00
|
|
|
|
|
|
|
public AcrobaticsManager (Player player) {
|
|
|
|
this.player = player;
|
|
|
|
this.profile = Users.getProfile(player);
|
|
|
|
this.skillLevel = profile.getSkillLevel(SkillType.ACROBATICS);
|
2013-01-01 23:32:22 +01:00
|
|
|
this.permissionInstance = Permissions.getInstance();
|
2012-06-11 22:11:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for fall damage reduction.
|
|
|
|
*
|
|
|
|
* @param event The event to check
|
|
|
|
*/
|
|
|
|
public void rollCheck(EntityDamageEvent event) {
|
2012-10-30 19:46:52 +01:00
|
|
|
if(player == null)
|
|
|
|
return;
|
|
|
|
|
2012-06-13 18:31:20 +02:00
|
|
|
if (!permissionInstance.roll(player)) {
|
2012-06-11 22:11:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-08 03:41:18 +01:00
|
|
|
if(Config.getInstance().getAcrobaticsAFKDisabled() && player.isInsideVehicle())
|
|
|
|
return;
|
|
|
|
|
2012-06-11 22:11:23 +02:00
|
|
|
RollEventHandler eventHandler = new RollEventHandler(this, event);
|
|
|
|
|
2012-07-02 17:09:55 +02:00
|
|
|
int randomChance = 1000;
|
|
|
|
|
|
|
|
if (player.hasPermission("mcmmo.perks.lucky.acrobatics")) {
|
|
|
|
randomChance = (int) (randomChance * 0.75);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Acrobatics.getRandom().nextInt(randomChance) <= eventHandler.skillModifier && !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) {
|
2012-10-30 19:46:52 +01:00
|
|
|
if(player == null)
|
|
|
|
return;
|
|
|
|
|
2012-06-13 18:31:20 +02:00
|
|
|
if (!permissionInstance.dodge(player)) {
|
2012-06-11 22:11:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
|
|
|
|
|
2012-07-02 17:09:55 +02:00
|
|
|
int randomChance = 4000;
|
|
|
|
|
|
|
|
if (player.hasPermission("mcmmo.perks.lucky.acrobatics")) {
|
|
|
|
randomChance = (int) (randomChance * 0.75);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Acrobatics.getRandom().nextInt(randomChance) <= eventHandler.skillModifier && !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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Player getPlayer() {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected PlayerProfile getProfile() {
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int getSkillLevel() {
|
|
|
|
return skillLevel;
|
|
|
|
}
|
|
|
|
}
|