2013-01-22 18:43:25 +01:00
|
|
|
package com.gmail.nossr50.skills;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-09 07:23:32 +01:00
|
|
|
import org.bukkit.block.Block;
|
2012-03-04 09:54:26 +01:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2013-01-24 21:46:29 +01:00
|
|
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
2012-03-04 09:54:26 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.getspout.spoutapi.SpoutManager;
|
|
|
|
import org.getspout.spoutapi.player.SpoutPlayer;
|
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-11-21 21:49:54 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2012-04-26 16:27:57 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-03-27 07:09:28 +02:00
|
|
|
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.spout.SpoutConfig;
|
2012-06-05 16:13:10 +02:00
|
|
|
import com.gmail.nossr50.spout.SpoutStuff;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.ModChecks;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
public class SkillTools {
|
2012-12-24 22:56:25 +01:00
|
|
|
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
|
|
|
public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength();
|
2013-01-24 20:19:26 +01:00
|
|
|
public static boolean abilitiesEnabled = Config.getInstance().getAbilitiesEnabled();
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2013-01-24 21:46:29 +01:00
|
|
|
public static void handleFoodSkills(Player player, SkillType skill, FoodLevelChangeEvent event, int baseLevel, int maxLevel, int rankChange) {
|
|
|
|
int skillLevel = Users.getProfile(player).getSkillLevel(skill);
|
|
|
|
int currentFoodLevel = player.getFoodLevel();
|
|
|
|
int newFoodLevel = event.getFoodLevel();
|
|
|
|
int foodChange = newFoodLevel - currentFoodLevel;
|
|
|
|
|
|
|
|
for (int i = baseLevel; i <= maxLevel; i+= rankChange) {
|
|
|
|
if (skillLevel >= i) {
|
|
|
|
foodChange++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we don't go over the max value */
|
|
|
|
newFoodLevel = currentFoodLevel + foodChange;
|
|
|
|
if (newFoodLevel > 20) {
|
|
|
|
event.setFoodLevel(20);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
event.setFoodLevel(newFoodLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Checks to see if the cooldown for an item or ability is expired.
|
|
|
|
*
|
|
|
|
* @param oldTime The time the ability or item was last used
|
|
|
|
* @param cooldown The amount of time that must pass between uses
|
2012-06-22 03:50:48 +02:00
|
|
|
* @param player The player whose cooldown is being checked
|
2012-03-13 19:09:32 +01:00
|
|
|
* @return true if the cooldown is over, false otherwise
|
|
|
|
*/
|
2013-01-10 05:03:17 +01:00
|
|
|
public static boolean cooldownOver(long oldTime, int cooldown, Player player) {
|
2012-03-13 19:09:32 +01:00
|
|
|
long currentTime = System.currentTimeMillis();
|
2012-06-22 03:50:48 +02:00
|
|
|
int adjustedCooldown = cooldown;
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2012-06-22 03:50:48 +02:00
|
|
|
//Reduced Cooldown Donor Perks
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.cooldownsHalved(player)) {
|
2012-06-22 16:57:51 +02:00
|
|
|
adjustedCooldown = (int) (adjustedCooldown * 0.5);
|
2012-06-22 03:50:48 +02:00
|
|
|
}
|
2013-01-07 02:52:31 +01:00
|
|
|
else if (Permissions.cooldownsThirded(player)) {
|
2012-06-22 16:57:51 +02:00
|
|
|
adjustedCooldown = (int) (adjustedCooldown * 0.66);
|
2012-06-22 03:50:48 +02:00
|
|
|
}
|
2013-01-07 02:52:31 +01:00
|
|
|
else if (Permissions.cooldownsQuartered(player)) {
|
2012-06-22 16:57:51 +02:00
|
|
|
adjustedCooldown = (int) (adjustedCooldown * 0.75);
|
2012-06-22 03:50:48 +02:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:49:17 +01:00
|
|
|
if (currentTime - oldTime >= (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the time remaining until the cooldown expires.
|
|
|
|
*
|
|
|
|
* @param deactivatedTimeStamp Time of deactivation
|
|
|
|
* @param cooldown The length of the cooldown
|
|
|
|
* @return the number of seconds remaining before the cooldown expires
|
|
|
|
*/
|
2012-11-13 06:57:57 +01:00
|
|
|
public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown, Player player) {
|
|
|
|
int adjustedCooldown = cooldown;
|
|
|
|
|
|
|
|
//Reduced Cooldown Donor Perks
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.cooldownsHalved(player)) {
|
2012-11-13 06:57:57 +01:00
|
|
|
adjustedCooldown = (int) (adjustedCooldown * 0.5);
|
|
|
|
}
|
2013-01-07 02:52:31 +01:00
|
|
|
else if (Permissions.cooldownsThirded(player)) {
|
2012-11-13 06:57:57 +01:00
|
|
|
adjustedCooldown = (int) (adjustedCooldown * 0.66);
|
|
|
|
}
|
2013-01-07 02:52:31 +01:00
|
|
|
else if (Permissions.cooldownsQuartered(player)) {
|
2012-11-13 06:57:57 +01:00
|
|
|
adjustedCooldown = (int) (adjustedCooldown * 0.75);
|
|
|
|
}
|
|
|
|
|
2013-01-10 03:49:17 +01:00
|
|
|
return (int) (((deactivatedTimeStamp + (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a message to the player when the cooldown expires.
|
|
|
|
*
|
|
|
|
* @param player The player to send a message to
|
2012-07-03 16:04:04 +02:00
|
|
|
* @param profile The profile of the player
|
2012-03-13 19:09:32 +01:00
|
|
|
* @param ability The ability to watch cooldowns for
|
|
|
|
*/
|
2012-07-03 16:04:04 +02:00
|
|
|
public static void watchCooldown(Player player, PlayerProfile profile, AbilityType ability) {
|
2013-01-10 05:03:17 +01:00
|
|
|
if (player == null || profile == null || ability == null)
|
2012-11-08 04:04:17 +01:00
|
|
|
return;
|
|
|
|
|
2013-01-10 03:49:17 +01:00
|
|
|
if (!profile.getAbilityInformed(ability) && cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.setAbilityInformed(ability, true);
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(ability.getAbilityRefresh());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process activating abilities & readying the tool.
|
|
|
|
*
|
|
|
|
* @param player The player using the ability
|
|
|
|
* @param skill The skill the ability is tied to
|
|
|
|
*/
|
|
|
|
public static void activationCheck(Player player, SkillType skill) {
|
2012-04-27 05:58:21 +02:00
|
|
|
if (Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && !player.isSneaking()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
2012-03-13 19:09:32 +01:00
|
|
|
AbilityType ability = skill.getAbility();
|
|
|
|
ToolType tool = skill.getTool();
|
|
|
|
ItemStack inHand = player.getItemInHand();
|
|
|
|
|
2012-06-28 17:20:53 +02:00
|
|
|
if (ModChecks.isCustomTool(inHand) && !ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/* Check if any abilities are active */
|
2012-07-10 20:02:48 +02:00
|
|
|
if (profile == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
if (!profile.getAbilityUse()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-27 08:33:35 +02:00
|
|
|
for (AbilityType x : AbilityType.values()) {
|
2012-07-03 16:04:04 +02:00
|
|
|
if (profile.getAbilityMode(x)) {
|
2012-03-27 08:33:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/* Woodcutting & Axes need to be treated differently.
|
|
|
|
* Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action
|
|
|
|
*/
|
2012-07-03 16:04:04 +02:00
|
|
|
if (ability.getPermissions(player) && tool.inHand(inHand) && !profile.getToolPreparationMode(tool)) {
|
2012-04-05 05:30:56 +02:00
|
|
|
if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) {
|
2013-01-10 03:49:17 +01:00
|
|
|
if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
2013-01-16 15:08:45 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.TooTired", new Object[] { calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player) }));
|
2012-04-05 05:30:56 +02:00
|
|
|
return;
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 05:58:21 +02:00
|
|
|
if (Config.getInstance().getAbilityMessagesEnabled()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(tool.getRaiseTool());
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.setToolPreparationATS(tool, System.currentTimeMillis());
|
|
|
|
profile.setToolPreparationMode(tool, true);
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Monitors various things relating to skill abilities.
|
|
|
|
*
|
|
|
|
* @param player The player using the skill
|
2012-07-03 16:04:04 +02:00
|
|
|
* @param profile The profile of the player
|
2012-03-13 19:09:32 +01:00
|
|
|
* @param curTime The current system time
|
|
|
|
* @param skill The skill being monitored
|
|
|
|
*/
|
2012-07-03 16:04:04 +02:00
|
|
|
public static void monitorSkill(Player player, PlayerProfile profile, long curTime, SkillType skill) {
|
2012-03-13 19:09:32 +01:00
|
|
|
final int FOUR_SECONDS = 4000;
|
|
|
|
|
|
|
|
ToolType tool = skill.getTool();
|
|
|
|
AbilityType ability = skill.getAbility();
|
|
|
|
|
2012-07-10 20:02:48 +02:00
|
|
|
if (profile == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-10 03:49:17 +01:00
|
|
|
if (profile.getToolPreparationMode(tool) && curTime - (profile.getToolPreparationATS(tool) * Misc.TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) {
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.setToolPreparationMode(tool, false);
|
2012-07-03 14:40:56 +02:00
|
|
|
|
|
|
|
if (Config.getInstance().getAbilityMessagesEnabled()) {
|
|
|
|
player.sendMessage(tool.getLowerTool());
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ability.getPermissions(player)) {
|
2013-01-10 03:49:17 +01:00
|
|
|
if (profile.getAbilityMode(ability) && (profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) {
|
2013-01-24 15:44:28 +01:00
|
|
|
if (ability == AbilityType.BERSERK) {
|
|
|
|
player.setCanPickupItems(true);
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.setAbilityMode(ability, false);
|
|
|
|
profile.setAbilityInformed(ability, false);
|
2012-03-13 19:09:32 +01:00
|
|
|
player.sendMessage(ability.getAbilityOff());
|
|
|
|
|
2013-01-10 03:47:03 +01:00
|
|
|
Misc.sendSkillMessage(player, ability.getAbilityPlayerOff(player));
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the XP of a skill.
|
|
|
|
*
|
|
|
|
* @param skillType The skill to check
|
|
|
|
* @param player The player whose skill to check
|
2012-06-04 15:30:51 +02:00
|
|
|
* @param profile The profile of the player whose skill to check
|
2012-03-13 19:09:32 +01:00
|
|
|
*/
|
2012-06-04 15:30:51 +02:00
|
|
|
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
|
2012-03-29 04:45:34 +02:00
|
|
|
int skillups = 0;
|
2012-04-03 06:56:05 +02:00
|
|
|
|
2012-06-04 15:30:51 +02:00
|
|
|
if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
2012-03-28 20:37:17 +02:00
|
|
|
|
2012-06-04 15:30:51 +02:00
|
|
|
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
2012-07-06 17:57:17 +02:00
|
|
|
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= Users.getPlayer(player).getPowerLevel() + 1)) {
|
2012-06-04 15:30:51 +02:00
|
|
|
profile.removeXP(skillType, profile.getXpToLevel(skillType));
|
2012-03-13 19:09:32 +01:00
|
|
|
skillups++;
|
2012-06-04 15:30:51 +02:00
|
|
|
profile.skillUp(skillType, 1);
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType);
|
2012-06-07 00:02:22 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-04-18 14:19:49 +02:00
|
|
|
else {
|
2012-06-04 15:30:51 +02:00
|
|
|
profile.addLevels(skillType, 0);
|
2012-04-18 14:19:49 +02:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
String capitalized = Misc.getCapitalized(skillType.toString());
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/* Spout Stuff */
|
2012-07-07 19:58:51 +02:00
|
|
|
if (mcMMO.spoutEnabled) {
|
2012-07-03 16:14:01 +02:00
|
|
|
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2012-07-07 19:58:51 +02:00
|
|
|
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
2012-07-03 16:14:01 +02:00
|
|
|
SpoutStuff.levelUpNotification(skillType, spoutPlayer);
|
2012-04-17 22:22:57 +02:00
|
|
|
|
2012-04-03 16:08:37 +02:00
|
|
|
/* Update custom titles */
|
2012-05-23 16:50:47 +02:00
|
|
|
if (SpoutConfig.getInstance().getShowPowerLevel()) {
|
2013-01-16 17:42:01 +01:00
|
|
|
spoutPlayer.setTitle(LocaleLoader.getString("Spout.Title", new Object[] {spoutPlayer.getName(), Users.getPlayer(player).getPowerLevel()} ));
|
2012-04-03 16:08:37 +02:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-06-04 15:30:51 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", new Object[] {String.valueOf(skillups), profile.getSkillLevel(skillType)}));
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-06-04 15:30:51 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", new Object[] {String.valueOf(skillups), profile.getSkillLevel(skillType)}));
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-29 16:44:37 +02:00
|
|
|
|
2012-07-07 19:58:51 +02:00
|
|
|
if (mcMMO.spoutEnabled) {
|
2012-07-03 16:14:01 +02:00
|
|
|
SpoutPlayer spoutPlayer = (SpoutPlayer) player;
|
2012-07-07 19:58:51 +02:00
|
|
|
|
|
|
|
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
2012-05-23 16:50:47 +02:00
|
|
|
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
2012-07-07 19:58:51 +02:00
|
|
|
profile.getSpoutHud().updateXpBar();
|
2012-03-29 04:45:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check XP of all skills.
|
|
|
|
*
|
|
|
|
* @param player The player to check XP for.
|
2012-06-06 01:19:39 +02:00
|
|
|
* @param profile The profile of the player whose skill to check
|
2012-03-13 19:09:32 +01:00
|
|
|
*/
|
2012-06-06 01:19:39 +02:00
|
|
|
public static void xpCheckAll(Player player, PlayerProfile profile) {
|
|
|
|
for (SkillType skillType : SkillType.values()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
//Don't want to do anything with this one
|
2013-01-24 15:08:30 +01:00
|
|
|
if (skillType == SkillType.ALL || skillType.isChildSkill()) {
|
2012-03-13 19:09:32 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-06-06 01:19:39 +02:00
|
|
|
xpCheckSkill(skillType, player, profile);
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the skill represented by the given string
|
|
|
|
*
|
|
|
|
* @param skillName The name of the skill
|
|
|
|
* @return the SkillType if it exists, null otherwise
|
|
|
|
*/
|
|
|
|
public static SkillType getSkillType(String skillName) {
|
|
|
|
for (SkillType x : SkillType.values()) {
|
2012-05-21 14:39:19 +02:00
|
|
|
if (x.toString().equals(skillName.toUpperCase())) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return x;
|
2012-05-21 14:39:19 +02:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-05-21 14:39:19 +02:00
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
return null;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given string represents a valid skill
|
|
|
|
*
|
|
|
|
* @param skillname The name of the skill to check
|
|
|
|
* @return true if this is a valid skill, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isSkill(String skillName) {
|
|
|
|
if (getSkillType(skillName) != null) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2013-01-16 06:06:14 +01:00
|
|
|
public static boolean isLocalizedSkill(String skillName) {
|
|
|
|
for (SkillType skill : SkillType.values()) {
|
|
|
|
if (skillName.equalsIgnoreCase(LocaleLoader.getString(Misc.getCapitalized(skill.toString() + ".SkillName")))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String translateLocalizedSkill(String skillName) {
|
|
|
|
for (SkillType skill : SkillType.values()) {
|
|
|
|
if (skillName.equalsIgnoreCase(LocaleLoader.getString(Misc.getCapitalized(skill.toString() + ".SkillName")))) {
|
|
|
|
return skill.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-01-16 20:03:07 +01:00
|
|
|
public static String localizeSkillName(SkillType skill) {
|
|
|
|
return Misc.getCapitalized(LocaleLoader.getString(Misc.getCapitalized(skill.toString()) + ".SkillName"));
|
|
|
|
}
|
|
|
|
|
2012-03-13 19:09:32 +01:00
|
|
|
/**
|
|
|
|
* Check if the player has any combat skill permissions.
|
|
|
|
*
|
|
|
|
* @param player The player to check permissions for
|
|
|
|
* @return true if the player has combat skills, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean hasCombatSkills(Player player) {
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.axes(player)
|
|
|
|
|| Permissions.archery(player)
|
|
|
|
|| Permissions.swords(player)
|
|
|
|
|| Permissions.taming(player)
|
|
|
|
|| Permissions.unarmed(player)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the player has any gathering skill permissions.
|
|
|
|
*
|
|
|
|
* @param player The player to check permissions for
|
|
|
|
* @return true if the player has gathering skills, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean hasGatheringSkills(Player player) {
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.excavation(player)
|
|
|
|
|| Permissions.fishing(player)
|
|
|
|
|| Permissions.herbalism(player)
|
|
|
|
|| Permissions.mining(player)
|
|
|
|
|| Permissions.woodcutting(player)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the player has any misc skill permissions.
|
|
|
|
*
|
|
|
|
* @param player The player to check permissions for
|
|
|
|
* @return true if the player has misc skills, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean hasMiscSkills(Player player) {
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.acrobatics(player) || Permissions.repair(player)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle tool durability loss from abilities.
|
|
|
|
*
|
2012-05-21 13:41:49 +02:00
|
|
|
* @param inHand The item to damage
|
2012-03-13 19:09:32 +01:00
|
|
|
* @param durabilityLoss The durability to remove from the item
|
|
|
|
*/
|
2012-05-21 13:41:49 +02:00
|
|
|
public static void abilityDurabilityLoss(ItemStack inHand, int durabilityLoss) {
|
2012-04-27 05:58:21 +02:00
|
|
|
if (Config.getInstance().getAbilitiesDamageTools()) {
|
2012-05-21 14:31:29 +02:00
|
|
|
if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
|
|
|
|
int level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
|
2013-01-10 05:46:35 +01:00
|
|
|
if (Misc.getRandom().nextInt(level + 1) > 0) {
|
2012-05-21 14:31:29 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-03-04 09:54:26 +01:00
|
|
|
}
|
2012-05-21 14:31:29 +02:00
|
|
|
inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));
|
2012-03-04 09:54:26 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2012-02-27 23:28:32 +01:00
|
|
|
/**
|
|
|
|
* Check to see if an ability can be activated.
|
2012-03-13 19:09:32 +01:00
|
|
|
*
|
2012-02-27 23:28:32 +01:00
|
|
|
* @param player The player activating the ability
|
|
|
|
* @param type The skill the ability is based on
|
|
|
|
*/
|
2012-03-13 19:09:32 +01:00
|
|
|
public static void abilityCheck(Player player, SkillType type) {
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
2012-03-27 08:33:35 +02:00
|
|
|
ToolType tool = type.getTool();
|
2013-01-25 18:33:48 +01:00
|
|
|
AbilityType ability = type.getAbility();
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.setToolPreparationMode(tool, false);
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2012-06-22 20:20:28 +02:00
|
|
|
/* Axes and Woodcutting are odd because they share the same tool.
|
|
|
|
* We show them the too tired message when they take action.
|
|
|
|
*/
|
|
|
|
if (type == SkillType.WOODCUTTING || type == SkillType.AXES) {
|
2013-01-10 03:49:17 +01:00
|
|
|
if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
2013-01-16 15:08:45 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.TooTired", new Object[] { calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player) }));
|
2012-06-22 20:20:28 +02:00
|
|
|
return;
|
2012-06-22 05:01:02 +02:00
|
|
|
}
|
2012-06-22 20:20:28 +02:00
|
|
|
}
|
2012-06-22 05:01:02 +02:00
|
|
|
|
2012-11-21 21:49:54 +01:00
|
|
|
int ticks = 2 + (profile.getSkillLevel(type) / abilityLengthIncreaseLevel);
|
2012-06-15 16:58:38 +02:00
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.activationTwelve(player)) {
|
2012-06-22 20:20:28 +02:00
|
|
|
ticks = ticks + 12;
|
|
|
|
}
|
2013-01-07 02:52:31 +01:00
|
|
|
else if (Permissions.activationEight(player)) {
|
2012-06-22 20:20:28 +02:00
|
|
|
ticks = ticks + 8;
|
|
|
|
}
|
2013-01-07 02:52:31 +01:00
|
|
|
else if (Permissions.activationFour(player)) {
|
2012-06-22 20:20:28 +02:00
|
|
|
ticks = ticks + 4;
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2012-06-22 20:20:28 +02:00
|
|
|
int maxTicks = ability.getMaxTicks();
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2012-06-22 20:20:28 +02:00
|
|
|
if (maxTicks != 0 && ticks > maxTicks) {
|
|
|
|
ticks = maxTicks;
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
if (!profile.getAbilityMode(ability) && cooldownOver(profile.getSkillDATS(ability), ability.getCooldown(), player)) {
|
2012-06-22 20:20:28 +02:00
|
|
|
player.sendMessage(ability.getAbilityOn());
|
|
|
|
|
2013-01-10 03:47:03 +01:00
|
|
|
Misc.sendSkillMessage(player, ability.getAbilityPlayer(player));
|
2012-06-22 20:20:28 +02:00
|
|
|
|
2013-01-10 03:49:17 +01:00
|
|
|
profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.setAbilityMode(ability, true);
|
2013-01-24 15:44:28 +01:00
|
|
|
if (ability == AbilityType.BERSERK) {
|
|
|
|
player.setCanPickupItems(false);
|
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
}
|
2012-02-27 23:28:32 +01:00
|
|
|
}
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if ability should be triggered.
|
|
|
|
*
|
|
|
|
* @param player The player using the ability
|
|
|
|
* @param block The block modified by the ability
|
|
|
|
* @param ability The ability to check
|
|
|
|
* @return true if the ability should activate, false otherwise
|
|
|
|
*/
|
2012-03-09 07:23:32 +01:00
|
|
|
public static boolean triggerCheck(Player player, Block block, AbilityType ability) {
|
2012-03-13 19:09:32 +01:00
|
|
|
boolean activate = true;
|
|
|
|
|
|
|
|
switch (ability) {
|
|
|
|
case BERSERK:
|
|
|
|
case GIGA_DRILL_BREAKER:
|
|
|
|
case SUPER_BREAKER:
|
|
|
|
case LEAF_BLOWER:
|
2012-06-14 16:24:58 +02:00
|
|
|
if (!ability.blockCheck(block)) {
|
|
|
|
activate = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
if (!Misc.blockBreakSimulate(block, player, true)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
activate = false;
|
|
|
|
break;
|
|
|
|
}
|
2012-06-14 16:24:58 +02:00
|
|
|
break;
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
case GREEN_TERRA:
|
2012-05-10 15:54:29 +02:00
|
|
|
if (!ability.blockCheck(block)) {
|
2012-03-13 19:09:32 +01:00
|
|
|
activate = false;
|
|
|
|
break;
|
|
|
|
}
|
2012-03-14 18:33:00 +01:00
|
|
|
break;
|
2012-03-13 19:09:32 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
activate = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return activate;
|
2012-03-09 07:23:32 +01:00
|
|
|
}
|
2012-06-04 15:30:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the processing of XP gain from individual skills.
|
|
|
|
*
|
|
|
|
* @param player The player that gained XP
|
|
|
|
* @param profile The profile of the player gaining XP
|
|
|
|
* @param type The type of skill to gain XP from
|
|
|
|
* @param xp the amount of XP to gain
|
|
|
|
*/
|
|
|
|
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
|
2013-01-25 18:33:48 +01:00
|
|
|
if ((type.getMaxLevel() < profile.getSkillLevel(type) + 1) || (Misc.getPowerLevelCap() < Users.getPlayer(player).getPowerLevel() + 1)) {
|
|
|
|
return;
|
2012-06-12 14:10:18 +02:00
|
|
|
}
|
2013-01-25 18:33:48 +01:00
|
|
|
|
|
|
|
Users.getPlayer(player).addXP(type, xp);
|
|
|
|
xpCheckSkill(type, player, profile);
|
2012-06-04 15:30:51 +02:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|