Handle all our donor perks in one class.

This commit is contained in:
GJ
2013-02-18 11:41:44 -05:00
parent 671be42472
commit 083a89c1a3
13 changed files with 115 additions and 164 deletions

View File

@ -0,0 +1,78 @@
package com.gmail.nossr50.skills.utilities;
import org.bukkit.entity.Player;
import com.gmail.nossr50.util.Permissions;
public final class PerksUtils {
private static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75;
private static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100;
private PerksUtils() {};
public static int handleCooldownPerks(Player player, int cooldown) {
if (Permissions.cooldownsHalved(player)) {
cooldown *= 0.5;
}
else if (Permissions.cooldownsThirded(player)) {
cooldown *= (1.0 / 3.0);
}
else if (Permissions.cooldownsQuartered(player)) {
cooldown *= 0.75;
}
return cooldown;
}
public static int handleActivationPerks(Player player, int ticks, int maxTicks) {
if (Permissions.activationTwelve(player)) {
ticks += 12;
}
else if (Permissions.activationEight(player)) {
ticks += 8;
}
else if (Permissions.activationFour(player)) {
ticks += 4;
}
if (maxTicks != 0 && ticks > maxTicks) {
ticks = maxTicks;
}
return ticks;
}
public static int handleXpPerks(Player player, int xp) {
if (player.hasPermission("mcmmo.perks.xp.quadruple")) {
xp *= 4;
}
else if (player.hasPermission("mcmmo.perks.xp.triple")) {
xp *= 3;
}
else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) {
xp *= 2.5;
}
else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) {
xp *= 2;
}
else if (player.hasPermission("mcmmo.perks.xp.50percentboost")) {
xp *= 1.5;
}
return xp;
}
/**
* Calculate activation chance for a skill.
*
* @param isLucky true if the player has the appropriate "lucky" perk, false otherwise
* @return the activation chance
*/
public static int handleLuckyPerks(boolean isLucky) {
if (isLucky) {
return LUCKY_SKILL_ACTIVATION_CHANCE;
}
return NORMAL_SKILL_ACTIVATION_CHANCE;
}
}

View File

@ -41,9 +41,6 @@ public class SkillTools {
public static int toolDurabilityLoss = Config.getInstance().getAbilityToolDamage();
public static int abilityLengthIncreaseLevel = AdvancedConfig.getInstance().getAbilityLength();
public static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75;
public static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100;
public static void handleFoodSkills(Player player, SkillType skill, FoodLevelChangeEvent event, int baseLevel, int maxLevel, int rankChange) {
int skillLevel = Users.getPlayer(player).getProfile().getSkillLevel(skill);
@ -70,18 +67,7 @@ public class SkillTools {
*/
public static boolean cooldownOver(long oldTime, int cooldown, Player player) {
long currentTime = System.currentTimeMillis();
int adjustedCooldown = cooldown;
//Reduced Cooldown Donor Perks
if (Permissions.cooldownsHalved(player)) {
adjustedCooldown = (int) (adjustedCooldown * 0.5);
}
else if (Permissions.cooldownsThirded(player)) {
adjustedCooldown = (int) (adjustedCooldown * 0.66);
}
else if (Permissions.cooldownsQuartered(player)) {
adjustedCooldown = (int) (adjustedCooldown * 0.75);
}
int adjustedCooldown = PerksUtils.handleCooldownPerks(player, cooldown);
if (currentTime - oldTime >= (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) {
return true;
@ -98,20 +84,7 @@ public class SkillTools {
* @return the number of seconds remaining before the cooldown expires
*/
public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown, Player player) {
int adjustedCooldown = cooldown;
//Reduced Cooldown Donor Perks
if (Permissions.cooldownsHalved(player)) {
adjustedCooldown = (int) (adjustedCooldown * 0.5);
}
else if (Permissions.cooldownsThirded(player)) {
adjustedCooldown = (int) (adjustedCooldown * 0.66);
}
else if (Permissions.cooldownsQuartered(player)) {
adjustedCooldown = (int) (adjustedCooldown * 0.75);
}
return (int) (((deactivatedTimeStamp + (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
return (int) (((deactivatedTimeStamp + (PerksUtils.handleCooldownPerks(player, cooldown) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
}
/**
@ -386,24 +359,6 @@ public class SkillTools {
return false;
}
/**
* Handle tool durability loss from abilities.
*
* @param inHand The item to damage
* @param durabilityLoss The durability to remove from the item
*/
public static void abilityDurabilityLoss(ItemStack inHand, int durabilityLoss) {
if (Config.getInstance().getAbilitiesDamageTools()) {
if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
int level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
if (Misc.getRandom().nextInt(level + 1) > 0) {
return;
}
}
inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));
}
}
/**
* Check to see if an ability can be activated.
*
@ -427,30 +382,12 @@ public class SkillTools {
}
}
int ticks = 2 + (profile.getSkillLevel(type) / abilityLengthIncreaseLevel);
if (Permissions.activationTwelve(player)) {
ticks = ticks + 12;
}
else if (Permissions.activationEight(player)) {
ticks = ticks + 8;
}
else if (Permissions.activationFour(player)) {
ticks = ticks + 4;
}
int maxTicks = ability.getMaxTicks();
if (maxTicks != 0 && ticks > maxTicks) {
ticks = maxTicks;
}
if (!profile.getAbilityMode(ability) && cooldownOver(profile.getSkillDATS(ability), ability.getCooldown(), player)) {
player.sendMessage(ability.getAbilityOn());
SkillTools.sendSkillMessage(player, ability.getAbilityPlayer(player));
profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
profile.setSkillDATS(ability, System.currentTimeMillis() + (PerksUtils.handleActivationPerks(player, 2 + (profile.getSkillLevel(type) / abilityLengthIncreaseLevel), ability.getMaxTicks()) * Misc.TIME_CONVERSION_FACTOR));
profile.setAbilityMode(ability, true);
if (ability == AbilityType.BERSERK) {
@ -504,20 +441,6 @@ public class SkillTools {
return activate;
}
/**
* Calculate activation chance for a skill.
*
* @param isLucky true if the player has the appropriate "lucky" perk, false otherwise
* @return the activation chance
*/
public static int calculateActivationChance(boolean isLucky) {
if (isLucky) {
return LUCKY_SKILL_ACTIVATION_CHANCE;
}
return NORMAL_SKILL_ACTIVATION_CHANCE;
}
public static void sendSkillMessage(Player player, String message) {
for (Player otherPlayer : player.getWorld().getPlayers()) {
if (otherPlayer != player && Misc.isNear(player.getLocation(), otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) {