/** * Calculate the time remaining until the ability's cooldown expires. * * @param ability AbilityType whose cooldown to check * @return the number of seconds remaining before the cooldown expires */ public int calculateTimeRemaining(AbilityType ability) { long deactivatedTimestamp = profile.getAbilityDATS(ability) * Misc.TIME_CONVERSION_FACTOR; return (int) (((deactivatedTimestamp + (PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR); }
/** * Check to see if an ability can be activated. * * @param skill The skill the ability is based on */ public void checkAbilityActivation(SkillType skill) { ToolType tool = skill.getTool(); AbilityType ability = skill.getAbility(); setToolPreparationMode(tool, false); if (getAbilityMode(ability)) { return; } int timeRemaining = calculateTimeRemaining(ability); if (timeRemaining > 0) { /* * Axes and Woodcutting are odd because they share the same tool. * We show them the too tired message when they take action. */ if (skill == SkillType.WOODCUTTING || skill == SkillType.AXES) { player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining)); } return; } if (EventUtils.callPlayerAbilityActivateEvent(player, skill).isCancelled()) { return; } int ticks = PerksUtils.handleActivationPerks( player, 2 + (getSkillLevel(skill) / AdvancedConfig.getInstance().getAbilityLength()), ability.getMaxLength()); // Notify people that ability has been activated ParticleEffectUtils.playAbilityEnabledEffect(player); if (useChatNotifications()) { player.sendMessage(ability.getAbilityOn()); } SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player)); // Enable the ability profile.setAbilityDATS( ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR)); setAbilityMode(ability, true); if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) { SkillUtils.handleAbilitySpeedIncrease(player); } new AbilityDisableTask(this, ability) .runTaskLater(mcMMO.p, ticks * Misc.TICK_CONVERSION_FACTOR); }
protected String[] calculateLengthDisplayValues(Player player, float skillValue) { int maxLength = skill.getAbility().getMaxLength(); int length = 2 + (int) (skillValue / AdvancedConfig.getInstance().getAbilityLength()); int enduranceLength = PerksUtils.handleActivationPerks(player, length, maxLength); if (maxLength != 0) { length = Math.min(length, maxLength); } return new String[] {String.valueOf(length), String.valueOf(enduranceLength)}; }
/** * Modifies an experience gain using skill modifiers, global rate and perks * * @param skillType Skill being used * @param xp Experience amount to process * @return Modified experience */ private float modifyXpGain(SkillType skillType, float xp) { if (player.getGameMode() == GameMode.CREATIVE || (skillType.getMaxLevel() <= getSkillLevel(skillType)) || (Config.getInstance().getPowerLevelCap() <= getPowerLevel())) { return 0; } xp = (float) (xp / skillType.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); if (Config.getInstance().getToolModsEnabled()) { CustomTool tool = mcMMO.getModManager().getTool(player.getItemInHand()); if (tool != null) { xp *= tool.getXpMultiplier(); } } return PerksUtils.handleXpPerks(player, xp, skillType); }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandUtils.noConsoleUsage(sender)) { return true; } switch (args.length) { case 0: Player player = (Player) sender; McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); boolean isLucky = Permissions.lucky(player, skill); boolean hasEndurance = (PerksUtils.handleActivationPerks(player, 0, 0) != 0); float skillValue = mcMMOPlayer.getSkillLevel(skill); permissionsCheck(player); dataCalculations(player, skillValue, isLucky); if (Config.getInstance().getSkillUseBoard()) { ScoreboardManager.enablePlayerSkillScoreboard(player, skill); } if (!skill.isChildSkill()) { player.sendMessage(LocaleLoader.getString("Skills.Header", skillName)); player.sendMessage( LocaleLoader.getString( "Commands.XPGain", LocaleLoader.getString( "Commands.XPGain." + StringUtils.getCapitalized(skill.toString())))); player.sendMessage( LocaleLoader.getString( "Effects.Level", (int) skillValue, mcMMOPlayer.getSkillXpLevel(skill), mcMMOPlayer.getXpToLevel(skill))); } else { player.sendMessage( LocaleLoader.getString( "Skills.Header", skillName + " " + LocaleLoader.getString("Skills.Child"))); player.sendMessage( LocaleLoader.getString( "Commands.XPGain", LocaleLoader.getString("Commands.XPGain.Child"))); player.sendMessage(LocaleLoader.getString("Effects.Child", (int) skillValue)); player.sendMessage( LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Skills.Parents"))); Set<SkillType> parents = FamilyTree.getParents(skill); for (SkillType parent : parents) { player.sendMessage( parent.getName() + " - " + LocaleLoader.getString( "Effects.Level", mcMMOPlayer.getSkillLevel(parent), mcMMOPlayer.getSkillXpLevel(parent), mcMMOPlayer.getXpToLevel(parent))); } } List<String> effectMessages = effectsDisplay(); if (!effectMessages.isEmpty()) { player.sendMessage( LocaleLoader.getString("Skills.Header", LocaleLoader.getString("Effects.Effects"))); if (isLucky) { String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix"); player.sendMessage( perkPrefix + LocaleLoader.getString( "Effects.Template", LocaleLoader.getString("Perks.Lucky.Name"), LocaleLoader.getString("Perks.Lucky.Desc", skillName))); } for (String message : effectMessages) { player.sendMessage(message); } } List<String> statsMessages = statsDisplay(player, skillValue, hasEndurance, isLucky); if (!statsMessages.isEmpty()) { player.sendMessage( LocaleLoader.getString( "Skills.Header", LocaleLoader.getString("Commands.Stats.Self"))); for (String message : statsMessages) { player.sendMessage(message); } } player.sendMessage( LocaleLoader.getString("Guides.Available", skillName, skillName.toLowerCase())); return true; default: return skillGuideCommand.onCommand(sender, command, label, args); } }
public SkillManager(McMMOPlayer mcMMOPlayer, SkillType skill) { this.mcMMOPlayer = mcMMOPlayer; this.activationChance = PerksUtils.handleLuckyPerks(mcMMOPlayer.getPlayer(), skill); this.skill = skill; }