2012-01-09 20:00:13 +01:00
|
|
|
package com.gmail.nossr50.skills;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.Users;
|
2012-03-12 22:28:13 +01:00
|
|
|
import com.gmail.nossr50.m;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.mcPermissions;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-03-03 20:48:40 +01:00
|
|
|
import com.gmail.nossr50.locale.mcLocale;
|
2012-03-12 06:45:08 +01:00
|
|
|
import com.gmail.nossr50.party.Party;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
|
|
|
public class Acrobatics {
|
2012-03-12 06:45:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for fall damage reduction.
|
|
|
|
*
|
|
|
|
* @param player The player whose fall damage to modify
|
|
|
|
* @param event The event to check
|
|
|
|
*/
|
|
|
|
public static void acrobaticsCheck(Player player, EntityDamageEvent event) {
|
|
|
|
final int ROLL_XP_MODIFIER = 80;
|
|
|
|
final int FALL_XP_MODIFIER = 120;
|
2012-03-12 17:45:03 +01:00
|
|
|
final int MAX_BONUS_LEVEL = 1000;
|
2012-03-12 06:45:08 +01:00
|
|
|
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
int acrovar = PP.getSkillLevel(SkillType.ACROBATICS);
|
|
|
|
boolean gracefulRoll = player.isSneaking();
|
|
|
|
int damage = event.getDamage();
|
2012-03-12 17:45:03 +01:00
|
|
|
int health = player.getHealth();
|
2012-03-12 06:45:08 +01:00
|
|
|
|
|
|
|
if (gracefulRoll) {
|
|
|
|
acrovar = acrovar * 2;
|
|
|
|
}
|
|
|
|
|
2012-03-12 17:45:03 +01:00
|
|
|
if (acrovar > MAX_BONUS_LEVEL || Math.random() * 1000 <= acrovar) {
|
2012-03-12 06:45:08 +01:00
|
|
|
int threshold = 7;
|
|
|
|
|
|
|
|
if (gracefulRoll) {
|
|
|
|
threshold = threshold * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int newDamage = damage - threshold;
|
|
|
|
|
|
|
|
if (newDamage < 0) {
|
|
|
|
newDamage = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for death */
|
2012-03-12 17:45:03 +01:00
|
|
|
if (health - damage >= 1) {
|
2012-03-12 06:45:08 +01:00
|
|
|
PP.addXP(SkillType.ACROBATICS, damage * ROLL_XP_MODIFIER, player);
|
|
|
|
Skills.XpCheckSkill(SkillType.ACROBATICS, player);
|
|
|
|
|
|
|
|
event.setDamage(newDamage);
|
|
|
|
|
|
|
|
if (event.getDamage() <= 0) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gracefulRoll) {
|
|
|
|
player.sendMessage(mcLocale.getString("Acrobatics.GracefulRoll"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player.sendMessage(mcLocale.getString("Acrobatics.Roll"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-12 17:45:03 +01:00
|
|
|
else if (health - damage >= 1) {
|
2012-03-12 06:45:08 +01:00
|
|
|
PP.addXP(SkillType.ACROBATICS, event.getDamage() * FALL_XP_MODIFIER, player);
|
|
|
|
Skills.XpCheckSkill(SkillType.ACROBATICS, player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for dodge damage reduction.
|
|
|
|
*
|
|
|
|
* @param event The event to check
|
|
|
|
*/
|
|
|
|
public static void dodgeChecks(EntityDamageByEntityEvent event) {
|
|
|
|
final int DODGE_MODIFIER = 120;
|
2012-03-12 17:45:03 +01:00
|
|
|
final int MAX_BONUS_LEVEL = 800;
|
2012-03-12 06:45:08 +01:00
|
|
|
|
|
|
|
Player defender = (Player) event.getEntity();
|
|
|
|
PlayerProfile PPd = Users.getProfile(defender);
|
2012-03-12 17:45:03 +01:00
|
|
|
int damage = event.getDamage();
|
2012-03-12 06:45:08 +01:00
|
|
|
|
|
|
|
/* PARTY CHECK */
|
2012-03-12 08:26:39 +01:00
|
|
|
if (event.getDamager() instanceof Player) {
|
|
|
|
Player attacker = (Player) event.getDamager();
|
|
|
|
|
|
|
|
if (Party.getInstance().inSameParty(defender, attacker)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-12 06:45:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mcPermissions.getInstance().acrobatics(defender)) {
|
2012-03-12 17:45:03 +01:00
|
|
|
int skillLevel = PPd.getSkillLevel(SkillType.ACROBATICS);
|
2012-03-12 22:28:13 +01:00
|
|
|
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
2012-03-12 06:45:08 +01:00
|
|
|
|
|
|
|
if (Math.random() * 4000 <= skillCheck) {
|
|
|
|
defender.sendMessage(mcLocale.getString("Acrobatics.Dodge"));
|
|
|
|
|
2012-03-12 17:45:03 +01:00
|
|
|
if (System.currentTimeMillis() >= (5000 + PPd.getRespawnATS()) && defender.getHealth() >= 1) {
|
|
|
|
PPd.addXP(SkillType.ACROBATICS, damage * DODGE_MODIFIER, defender);
|
2012-03-12 06:45:08 +01:00
|
|
|
Skills.XpCheckSkill(SkillType.ACROBATICS, defender);
|
|
|
|
}
|
|
|
|
|
2012-03-12 17:45:03 +01:00
|
|
|
int newDamage = damage / 2;
|
2012-03-12 06:45:08 +01:00
|
|
|
|
2012-03-12 17:45:03 +01:00
|
|
|
if (newDamage <= 0) {
|
2012-03-12 06:45:08 +01:00
|
|
|
event.setDamage(1);
|
|
|
|
}
|
2012-03-12 17:45:03 +01:00
|
|
|
else {
|
|
|
|
event.setDamage(newDamage);
|
|
|
|
}
|
2012-03-12 06:45:08 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
|
|
|
}
|