/** * 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; } }
private void autoLevel(Skill skill) { PlayerSkill data = skills.get(skill.getKey()); if (data == null) return; if (!SkillAPI.isLoaded()) return; int lastLevel = data.getLevel(); while (data.getData().canAutoLevel() && !data.isMaxed() && data.getLevelReq() <= data.getPlayerClass().getLevel()) { upgradeSkill(skill); if (lastLevel == data.getLevel()) { break; } lastLevel++; } }