/** * Downgrades a skill owned by the player. The player must own the skill and it must not currently * be level 0 for the player to downgrade the skill. This will refund the skill point cost when * downgrading the skill. * * @param skill skill to downgrade * @return true if successfully downgraded, false otherwise */ public boolean downgradeSkill(Skill skill) { // Cannot be null if (skill == null) { return false; } // Must be a valid available skill PlayerSkill data = skills.get(skill.getName().toLowerCase()); if (data == null) { return false; } // Must not be a free skill if (data.getCost() == 0) { return false; } // Must not be required by another skill for (PlayerSkill s : skills.values()) { if (s.getData().getSkillReq() != null && s.getData().getSkillReq().equalsIgnoreCase(skill.getName()) && data.getLevel() <= s.getData().getSkillReqLevel()) { return false; } } int cost = skill.getCost(data.getLevel() - 1); if (data.getLevel() > 0) { // Upgrade event PlayerSkillDowngradeEvent event = new PlayerSkillDowngradeEvent(this, data, cost); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return false; } // Apply upgrade data.getPlayerClass().givePoints(cost, PointSource.REFUND); data.addLevels(-1); // Passive calls Player player = getPlayer(); if (player != null && skill instanceof PassiveSkill) { if (data.getLevel() == 0) { ((PassiveSkill) skill).stopEffects(player, 1); } else { ((PassiveSkill) skill).update(player, data.getLevel() + 1, data.getLevel()); } } // Clear bindings if (data.getLevel() == 0) { clearBinds(skill); } return true; } else { return false; } }
/** * Compares skills based on their stats for skill tree arrangement -> Skills with lower * level requirements come first -> Then its skills with lower costs -> Then its skills * alphabetically * * @param skill1 skill being compared * @param skill2 skill to compare to * @return -1, 0, or 1 */ @Override public int compare(Skill skill1, Skill skill2) { return skill1.getLevelReq(0) > skill2.getLevelReq(0) ? 1 : skill1.getLevelReq(0) < skill2.getLevelReq(0) ? -1 : skill1.getName().compareTo(skill2.getName()); }
/** * Resets the class data for the owner under the given group. This will remove the profession * entirely, leaving no remaining data until the player professes again to a starting class. * * @param group group to reset */ public void reset(String group) { stopPassives(getPlayer()); clearBonuses(); PlayerClass playerClass = classes.remove(group); if (playerClass != null) { // Remove skills RPGClass data = playerClass.getData(); for (Skill skill : data.getSkills()) { skills.remove(skill.getName()); combos.removeSkill(skill); } // Update GUI features if (getPlayer() != null) { ClassBoardManager.clear(new VersionPlayer(getPlayer())); } // Call the event Bukkit.getPluginManager().callEvent(new PlayerClassChangeEvent(playerClass, data, null)); } // Restore default class if applicable GroupSettings settings = SkillAPI.getSettings().getGroupSettings(group); RPGClass rpgClass = settings.getDefault(); if (rpgClass != null && settings.getPermission() == null) { setClass(rpgClass); } updateHealthAndMana(player.getPlayer()); }
/** * Upgrades a skill owned by the player. The player must own the skill, have enough skill points, * meet the level and skill requirements, and not have maxed out the skill already in order to * upgrade the skill. This will consume the skill point cost while upgrading the skill. * * @param skill skill to upgrade * @return true if successfully was upgraded, false otherwise */ public boolean upgradeSkill(Skill skill) { // Cannot be null if (skill == null) { return false; } // Must be a valid available skill PlayerSkill data = skills.get(skill.getName().toLowerCase()); if (data == null) { return false; } // Must meet any skill requirements if (skill.getSkillReq() != null) { PlayerSkill req = skills.get(skill.getSkillReq().toLowerCase()); if (req != null && req.getLevel() < skill.getSkillReqLevel()) { return false; } } int level = data.getPlayerClass().getLevel(); int points = data.getPlayerClass().getPoints(); int cost = data.getCost(); if (!data.isMaxed() && level >= data.getLevelReq() && points >= cost) { // Upgrade event PlayerSkillUpgradeEvent event = new PlayerSkillUpgradeEvent(this, data, cost); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return false; } // Apply upgrade data.getPlayerClass().usePoints(cost); data.addLevels(1); // Passive calls Player player = getPlayer(); if (player != null && skill instanceof PassiveSkill) { if (data.getLevel() == 1) { ((PassiveSkill) skill).initialize(player, data.getLevel()); } else { ((PassiveSkill) skill).update(player, data.getLevel() - 1, data.getLevel()); } } // Unlock event if (data.getLevel() == 1) { Bukkit.getPluginManager().callEvent(new PlayerSkillUnlockEvent(this, data)); this.autoLevel(); } return true; } else { return false; } }
/** * Sets the professed class for the player for the corresponding group. This will not save any * skills, experience, or levels of the previous class if there was any. The new class will start * at level 1 with 0 experience. * * @param rpgClass class to assign to the player * @return the player-specific data for the new class */ public PlayerClass setClass(RPGClass rpgClass) { PlayerClass c = classes.remove(rpgClass.getGroup()); if (c != null) { for (Skill skill : c.getData().getSkills()) { skills.remove(skill.getName().toLowerCase()); combos.removeSkill(skill); } } PlayerClass classData = new PlayerClass(this, rpgClass); classes.put(rpgClass.getGroup(), classData); // Add in missing skills for (Skill skill : rpgClass.getSkills()) { giveSkill(skill, classData); } updateHealthAndMana(getPlayer()); updateScoreboard(); return classes.get(rpgClass.getGroup()); }