/** * Shows the skill tree for the player. If the player has multiple trees, this will show the list * of skill trees they can view. * * @param player player to show the skill tree for * @return true if able to show the player, false otherwise */ public boolean showSkills(Player player) { // Cannot show an invalid player, and cannot show no skills if (player == null || classes.size() == 0 || skills.size() == 0) { return false; } // Show skill tree of only class if (classes.size() == 1) { PlayerClass playerClass = classes.get(classes.keySet().toArray(new String[1])[0]); if (playerClass.getData().getSkills().size() == 0) { return false; } player.openInventory( ((InventoryTree) playerClass.getData().getSkillTree()).getInventory(this)); return true; } // Show list of classes that have skill trees else { Inventory inv = InventoryManager.createInventory( TreeListener.CLASS_LIST_KEY, (classes.size() + 8) / 9, player.getName()); for (PlayerClass c : classes.values()) { inv.addItem(c.getData().getIcon()); } player.openInventory(inv); return true; } }
/** * Gives skill points to the player for all classes matching the experience source * * @param amount amount of levels to give * @param source source of the levels */ public void givePoints(int amount, ExpSource source) { for (PlayerClass playerClass : classes.values()) { if (playerClass.getData().receivesExp(source)) { playerClass.givePoints(amount); } } }
/** * 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()); }
/** * Updates the player's max health and mana using class data. * * @param player player to update the health and mana for */ public void updateHealthAndMana(Player player) { if (player == null) { return; } // Update maxes double health = bonusHealth; maxMana = bonusMana; for (PlayerClass c : classes.values()) { health += c.getHealth(); maxMana += c.getMana(); } if (health == bonusHealth) { health += SkillAPI.getSettings().getDefaultHealth(); } if (health == 0) { health = 20; } if (SkillAPI.getSettings().isModifyHealth()) VersionManager.setMaxHealth(player, health); mana = Math.min(mana, maxMana); // Health scaling is available starting with 1.6.2 if (SkillAPI.getSettings().isModifyHealth() && VersionManager.isVersionAtLeast(VersionManager.V1_6_2)) { if (SkillAPI.getSettings().isOldHealth()) { player.setHealthScaled(true); player.setHealthScale(20); } else { player.setHealthScaled(false); } } }
/** Causes the player to lose experience as a penalty (generally for dying) */ public void loseExp() { for (PlayerClass playerClass : classes.values()) { double penalty = playerClass.getData().getGroupSettings().getDeathPenalty(); if (penalty > 0) { playerClass.loseExp(penalty); } } }
/** Regenerates mana for the player based on the regen amounts of professed classes */ public void regenMana() { double amount = 0; for (PlayerClass c : classes.values()) { if (c.getData().hasManaRegen()) { amount += c.getData().getManaRegen(); } } if (amount > 0) { giveMana(amount, ManaSource.REGEN); } }
/** * Gives levels to the player for all classes matching the experience source * * @param amount amount of levels to give * @param source source of the levels */ public void giveLevels(int amount, ExpSource source) { for (PlayerClass playerClass : classes.values()) { RPGClass data = playerClass.getData(); if (data.receivesExp(source)) { int exp = 0; int count = 0; int temp = amount; while (temp > 0) { temp--; exp += data.getRequiredExp(playerClass.getLevel() + count++); } playerClass.giveExp(exp, source); } } updateHealthAndMana(getPlayer()); }
/** * Checks whether or not the player is professed as the class or any of its children. * * @param rpgClass class to check * @return true if professed as the class or one of its children, false otherwise */ public boolean isClass(RPGClass rpgClass) { if (rpgClass == null) { return false; } PlayerClass pc = classes.get(rpgClass.getGroup()); if (pc == null) return false; RPGClass temp = pc.getData(); while (temp != null) { if (temp == rpgClass) { return true; } temp = temp.getParent(); } return false; }
/** * Checks whether or not the player can profess into the given class. This checks to make sure the * player is currently professed as the parent of the given class and is high enough of a level to * do so. * * @param rpgClass class to check * @return true if can profess, false otherwise */ public boolean canProfess(RPGClass rpgClass) { if (rpgClass.isNeedsPermission()) { Player p = getPlayer(); if (p == null || (!p.hasPermission(Permissions.CLASS) && !p.hasPermission( Permissions.CLASS + "." + rpgClass.getName().toLowerCase().replace(" ", "-")))) { return false; } } if (classes.containsKey(rpgClass.getGroup())) { PlayerClass current = classes.get(rpgClass.getGroup()); return rpgClass.getParent() == current.getData() && current.getData().getMaxLevel() <= current.getLevel(); } else { return !rpgClass.hasParent(); } }
private final String formatClassForDisplay(PlayerClass className) { String classNameStr = className.toString(); char[] charArray = classNameStr.toCharArray(); for (int i = 1; i < charArray.length; i++) if (Character.isUpperCase(charArray[i])) { classNameStr = classNameStr.substring(0, i) + " " + classNameStr.substring(i); } return classNameStr; }
/** * 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()); }
/** * Professes the player into the class if they are able to. This will reset the class data if the * group options are set to reset upon profession. Otherwise, all skills, experience, and levels * of the current class under the group will be retained and carried over into the new profession. * * @param rpgClass class to profess into * @return true if successfully professed, false otherwise */ public boolean profess(RPGClass rpgClass) { if (rpgClass != null && canProfess(rpgClass)) { // Reset data if applicable if (SkillAPI.getSettings().getGroupSettings(rpgClass.getGroup()).isProfessReset()) { reset(rpgClass.getGroup()); } // Inherit previous class data if any PlayerClass current = classes.get(rpgClass.getGroup()); RPGClass previous; if (current == null) { previous = null; current = new PlayerClass(this, rpgClass); classes.put(rpgClass.getGroup(), current); } else { previous = current.getData(); current.setClassData(rpgClass); } // Add skills for (Skill skill : rpgClass.getSkills()) { if (!skills.containsKey(skill.getKey())) { skills.put(skill.getKey(), new PlayerSkill(this, skill, current)); combos.addSkill(skill); } } Bukkit.getPluginManager() .callEvent(new PlayerClassChangeEvent(current, previous, current.getData())); updateHealthAndMana(getPlayer()); updateScoreboard(); return true; } else { return false; } }
@Override public void onBypassFeedback(L2PcInstance player, String command) { String[] commandStr = command.split(" "); String actualCommand = commandStr[0]; // Get actual command String cmdParams = ""; String cmdParams2 = ""; if (commandStr.length >= 2) { cmdParams = commandStr[1]; } if (commandStr.length >= 3) { cmdParams2 = commandStr[2]; } commandStr = null; if (actualCommand.equalsIgnoreCase("create_clan")) { if (cmdParams.equals("")) return; ClanTable.getInstance().createClan(player, cmdParams); } else if (actualCommand.equalsIgnoreCase("create_academy")) { if (cmdParams.equals("")) return; createSubPledge(player, cmdParams, null, L2Clan.SUBUNIT_ACADEMY, 5); } else if (actualCommand.equalsIgnoreCase("create_royal")) { if (cmdParams.equals("")) return; createSubPledge(player, cmdParams, cmdParams2, L2Clan.SUBUNIT_ROYAL1, 6); } else if (actualCommand.equalsIgnoreCase("create_knight")) { if (cmdParams.equals("")) return; createSubPledge(player, cmdParams, cmdParams2, L2Clan.SUBUNIT_KNIGHT1, 7); } else if (actualCommand.equalsIgnoreCase("assign_subpl_leader")) { if (cmdParams.equals("")) return; assignSubPledgeLeader(player, cmdParams, cmdParams2); } else if (actualCommand.equalsIgnoreCase("create_ally")) { if (cmdParams.equals("")) return; if (!player.isClanLeader()) { player.sendPacket(new SystemMessage(SystemMessageId.ONLY_CLAN_LEADER_CREATE_ALLIANCE)); return; } player.getClan().createAlly(player, cmdParams); } else if (actualCommand.equalsIgnoreCase("dissolve_ally")) { if (!player.isClanLeader()) { player.sendPacket(new SystemMessage(SystemMessageId.FEATURE_ONLY_FOR_ALLIANCE_LEADER)); return; } player.getClan().dissolveAlly(player); } else if (actualCommand.equalsIgnoreCase("dissolve_clan")) { dissolveClan(player, player.getClanId()); } else if (actualCommand.equalsIgnoreCase("change_clan_leader")) { if (cmdParams.equals("")) return; changeClanLeader(player, cmdParams); } else if (actualCommand.equalsIgnoreCase("recover_clan")) { recoverClan(player, player.getClanId()); } else if (actualCommand.equalsIgnoreCase("increase_clan_level")) { if (!player.isClanLeader()) { player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT)); return; } player.getClan().levelUpClan(player); } else if (actualCommand.equalsIgnoreCase("learn_clan_skills")) { showPledgeSkillList(player); } else if (command.startsWith("Subclass")) { int cmdChoice = Integer.parseInt(command.substring(9, 10).trim()); // Subclasses may not be changed while a skill is in use. if (player.isCastingNow() || player.isAllSkillsDisabled()) { player.sendPacket( new SystemMessage(SystemMessageId.SUBCLASS_NO_CHANGE_OR_CREATE_WHILE_SKILL_IN_USE)); return; } if (player.getPet() != null && player.getPet().isSummonInstance) { if (player.getPet().isCastingNow() || player.getPet().isAllSkillsDisabled()) { player.sendPacket( new SystemMessage(SystemMessageId.SUBCLASS_NO_CHANGE_OR_CREATE_WHILE_SKILL_IN_USE)); return; } } if (player.isCursedWeaponEquiped()) { player.sendMessage("You can`t change Subclass while Cursed weapon equiped!"); return; } TextBuilder content = new TextBuilder("<html><body>"); NpcHtmlMessage html = new NpcHtmlMessage(getObjectId()); Set<PlayerClass> subsAvailable; int paramOne = 0; int paramTwo = 0; try { int endIndex = command.length(); if (command.length() > 13) { endIndex = 13; paramTwo = Integer.parseInt(command.substring(13).trim()); } paramOne = Integer.parseInt(command.substring(11, endIndex).trim()); } catch (Exception NumberFormatException) { } switch (cmdChoice) { case 1: // Add Subclass - Initial // Avoid giving player an option to add a new sub class, if they have three already. if (player.getTotalSubClasses() == Config.ALT_MAX_SUBCLASS_COUNT) { player.sendMessage("You can now only change one of your current sub classes."); return; } subsAvailable = getAvailableSubClasses(player); if (subsAvailable != null && !subsAvailable.isEmpty()) { content.append("Add Subclass:<br>Which sub class do you wish to add?<br>"); for (PlayerClass subClass : subsAvailable) { content.append( "<a action=\"bypass -h npc_" + getObjectId() + "_Subclass 4 " + subClass.ordinal() + "\" msg=\"1268;" + formatClassForDisplay(subClass) + "\">" + formatClassForDisplay(subClass) + "</a><br>"); } } else { player.sendMessage("There are no sub classes available at this time."); return; } break; case 2: // Change Class - Initial content.append("Change Subclass:<br>"); final int baseClassId = player.getBaseClass(); if (player.getSubClasses().isEmpty()) { content.append( "You can't change sub classes when you don't have a sub class to begin with.<br>" + "<a action=\"bypass -h npc_" + getObjectId() + "_Subclass 1\">Add subclass.</a>"); } else { content.append("Which class would you like to switch to?<br>"); if (baseClassId == player.getActiveClass()) { content.append( CharTemplateTable.getClassNameById(baseClassId) + " <font color=\"LEVEL\">(Base Class)</font><br><br>"); } else { content.append( "<a action=\"bypass -h npc_" + getObjectId() + "_Subclass 5 0\">" + CharTemplateTable.getClassNameById(baseClassId) + "</a> " + "<font color=\"LEVEL\">(Base Class)</font><br><br>"); } for (Iterator<SubClass> subList = iterSubClasses(player); subList.hasNext(); ) { SubClass subClass = subList.next(); int subClassId = subClass.getClassId(); if (subClassId == player.getActiveClass()) { content.append(CharTemplateTable.getClassNameById(subClassId) + "<br>"); } else { content.append( "<a action=\"bypass -h npc_" + getObjectId() + "_Subclass 5 " + subClass.getClassIndex() + "\">" + CharTemplateTable.getClassNameById(subClassId) + "</a><br>"); } } } break; case 3: // Change/Cancel Subclass - Initial content.append( "Change Subclass:<br>Which of the following sub classes would you like to change?<br>"); int classIndex = 1; for (Iterator<SubClass> subList = iterSubClasses(player); subList.hasNext(); ) { SubClass subClass = subList.next(); content.append("Sub-class " + classIndex + "<br1>"); content.append( "<a action=\"bypass -h npc_" + getObjectId() + "_Subclass 6 " + subClass.getClassIndex() + "\">" + CharTemplateTable.getClassNameById(subClass.getClassId()) + "</a><br>"); classIndex++; } content.append( "<br>If you change a sub class, you'll start at level 40 after the 2nd class transfer."); break; case 4: // Add Subclass - Action (Subclass 4 x[x]) boolean allowAddition = true; /* * If the character is less than level 75 on any of their previously chosen * classes then disallow them to change to their most recently added sub-class choice. */ if (player.getLevel() < 75) { player.sendMessage( "You may not add a new sub class before you are level 75 on your previous class."); allowAddition = false; } if (player._event != null) { player.sendMessage("Недоступно в данный момент."); return; } if (Olympiad.getInstance().isRegisteredInComp(player) || player.getOlympiadGameId() > 0) { player.sendPacket( new SystemMessage( SystemMessageId .YOU_HAVE_ALREADY_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_AN_EVENT)); return; } if (allowAddition) { if (!player.getSubClasses().isEmpty()) { for (Iterator<SubClass> subList = iterSubClasses(player); subList.hasNext(); ) { SubClass subClass = subList.next(); if (subClass.getLevel() < 75) { player.sendMessage( "You may not add a new sub class before you are level 75 on your previous sub class."); allowAddition = false; break; } } } } /* * If quest checking is enabled, verify if the character has completed the Mimir's Elixir (Path to Subclass) * and Fate's Whisper (A Grade Weapon) quests by checking for instances of their unique reward items. * * If they both exist, remove both unique items and continue with adding the sub-class. */ if (!Config.ALT_GAME_SUBCLASS_WITHOUT_QUESTS) { QuestState qs = player.getQuestState("235_MimirsElixir"); if (qs == null || !qs.getState().getName().equalsIgnoreCase("Completed")) { player.sendMessage( "You must have completed the Mimir's Elixir quest to continue adding your sub class."); return; } /*qs = player.getQuestState("234_FatesWhisper"); if(qs == null || qs.getState().getName() != "Completed") { player.sendMessage("You must have completed the Fate's Whisper quest to continue adding your sub class."); return; }*/ } ////////////////// \\\\\\\\\\\\\\\\\\ if (allowAddition) { String className = CharTemplateTable.getClassNameById(paramOne); if (!player.addSubClass(paramOne, player.getTotalSubClasses() + 1)) { player.sendMessage("The sub class could not be added."); return; } player.setActiveClass(player.getTotalSubClasses()); content.append( "Add Subclass:<br>The sub class of <font color=\"LEVEL\">" + className + "</font> has been added."); player.sendPacket( new SystemMessage(SystemMessageId.CLASS_TRANSFER)); // Transfer to new class. className = null; } else { html.setFile("data/html/villagemaster/SubClass_Fail.htm"); } break; case 5: // Change Class - Action /* * If the character is less than level 75 on any of their previously chosen * classes then disallow them to change to their most recently added sub-class choice. * fix: in waiting for battle in oly can change sublcass * Note: paramOne = classIndex */ if (Olympiad.getInstance().isRegisteredInComp(player) || player.getOlympiadGameId() > 0 || Olympiad.getInstance().isRegistered(player)) { player.sendPacket( new SystemMessage( SystemMessageId .YOU_HAVE_ALREADY_BEEN_REGISTERED_IN_A_WAITING_LIST_OF_AN_EVENT)); return; } // sub class exploit fix if (!FloodProtector.getInstance() .tryPerformAction(player.getObjectId(), FloodProtector.PROTECTED_SUBCLASS)) { player.sendMessage( "You can change Subclass only every " + Config.PROTECTED_SUBCLASS_C + " Millisecond(s)"); return; } player.setActiveClass(paramOne); content.append( "Change Subclass:<br>Your active sub class is now a <font color=\"LEVEL\">" + CharTemplateTable.getClassNameById(player.getActiveClass()) + "</font>."); player.sendPacket( new SystemMessage( SystemMessageId.SUBCLASS_TRANSFER_COMPLETED)); // Transfer completed. break; case 6: // Change/Cancel Subclass - Choice content.append( "Please choose a sub class to change to. If the one you are looking for is not here, " + "please seek out the appropriate master for that class.<br>" + "<font color=\"LEVEL\">Warning!</font> All classes and skills for this class will be removed.<br><br>"); subsAvailable = getAvailableSubClasses(player); if (subsAvailable != null && !subsAvailable.isEmpty()) { for (PlayerClass subClass : subsAvailable) { content.append( "<a action=\"bypass -h npc_" + getObjectId() + "_Subclass 7 " + paramOne + " " + subClass.ordinal() + "\">" + formatClassForDisplay(subClass) + "</a><br>"); } } else { player.sendMessage("There are no sub classes available at this time."); return; } break; case 7: // Change Subclass - Action // check player skills if (Config.CHECK_SKILLS_ON_ENTER && !Config.ALT_GAME_SKILL_LEARN) { player.checkAllowedSkills(); } /* * Warning: the information about this subclass will be removed from the * subclass list even if false! */ if (!FloodProtector.getInstance() .tryPerformAction(player.getObjectId(), FloodProtector.PROTECTED_SUBCLASS)) { _log.warn("Player " + player.getName() + " has performed a subclass change too fast"); player.sendMessage( "You can change Subclass only every " + Config.PROTECTED_SUBCLASS_C + " Millisecond(s)"); return; } if (player.modifySubClass(paramOne, paramTwo)) { player.setActiveClass(paramOne); content.append( "Change Subclass:<br>Your sub class has been changed to <font color=\"LEVEL\">" + CharTemplateTable.getClassNameById(paramTwo) + "</font>."); player.sendPacket( new SystemMessage(SystemMessageId.ADD_NEW_SUBCLASS)); // Subclass added. // check player skills if (Config.CHECK_SKILLS_ON_ENTER && !Config.ALT_GAME_SKILL_LEARN) { player.checkAllowedSkills(); } } else { /* * This isn't good! modifySubClass() removed subclass from memory * we must update _classIndex! Else IndexOutOfBoundsException can turn * up some place down the line along with other seemingly unrelated * problems. */ player.setActiveClass( 0); // Also updates _classIndex plus switching _classid to baseclass. player.sendMessage( "The sub class could not be added, you have been reverted to your base class."); return; } break; } content.append("</body></html>"); // If the content is greater than for a basic blank page, // then assume no external HTML file was assigned. if (content.length() > 26) { html.setHtml(content.toString()); } player.sendPacket(html); content = null; html = null; subsAvailable = null; } else { // this class dont know any other commands, let forward // the command to the parent class super.onBypassFeedback(player, command); } actualCommand = null; cmdParams = null; cmdParams2 = null; }
/** * Updates the scoreboard with the player's current class. This is already done by the API and * doesn't need to be done by other plugins. */ public void updateScoreboard() { PlayerClass main = getMainClass(); if (main != null && !init) { ClassBoardManager.update(this, main.getData().getPrefix(), main.getData().getPrefixColor()); } }
/** * Gives experience to the player from the given source * * @param amount amount of experience to give * @param source source of the experience */ public void giveExp(double amount, ExpSource source) { for (PlayerClass playerClass : classes.values()) { playerClass.giveExp(amount, source); } }
/** * Checks whether or not the player is professed as the class without checking child classes. * * @param rpgClass class to check * @return true if professed as the specific class, false otherwise */ public boolean isExactClass(RPGClass rpgClass) { if (rpgClass == null) return false; PlayerClass c = classes.get(rpgClass.getGroup()); return (c != null) && (c.getData() == rpgClass); }
private final Set<PlayerClass> getAvailableSubClasses(L2PcInstance player) { final PlayerRace npcRace = getVillageMasterRace(); final ClassType npcTeachType = getVillageMasterTeachType(); // get player base class final int currentBaseId = player.getBaseClass(); final ClassId baseCID = ClassId.values()[currentBaseId]; // we need 2nd occupation ID final int baseClassId; if (baseCID.level() > 2) baseClassId = baseCID.getParent().ordinal(); else baseClassId = currentBaseId; PlayerClass currClass = PlayerClass.values()[baseClassId]; /** * If the race of your main class is Elf or Dark Elf, you may not select each class as a * subclass to the other class, and you may not select Overlord and Warsmith class as a * subclass. You may not select a similar class as the subclass. The occupations classified as * similar classes are as follows: Treasure Hunter, Plainswalker and Abyss Walker Hawkeye, * Silver Ranger and Phantom Ranger Paladin, Dark Avenger, Temple Knight and Shillien Knight * Warlocks, Elemental Summoner and Phantom Summoner Elder and Shillien Elder Swordsinger and * Bladedancer Sorcerer, Spellsinger and Spellhowler */ Set<PlayerClass> availSubs = currClass.getAvailableSubclasses(player); if (availSubs != null && !availSubs.isEmpty()) { for (PlayerClass availSub : availSubs) { for (SubClass subClass : player.getSubClasses().values()) if (subClass.getClassId() == availSub.ordinal()) { availSubs.remove(PlayerClass.values()[availSub.ordinal()]); } for (Iterator<SubClass> subList = iterSubClasses(player); subList.hasNext(); ) { SubClass prevSubClass = subList.next(); int subClassId = prevSubClass.getClassId(); if (subClassId >= 88) { subClassId = ClassId.values()[subClassId].getParent().getId(); } if (availSub.ordinal() == subClassId || availSub.ordinal() == player.getBaseClass()) { availSubs.remove(PlayerClass.values()[availSub.ordinal()]); } } if (npcRace == PlayerRace.Human || npcRace == PlayerRace.LightElf) { // If the master is human or light elf, ensure that fighter-type // masters only teach fighter classes, and priest-type masters // only teach priest classes etc. if (!availSub.isOfType(npcTeachType)) { availSubs.remove(availSub); } else if (!availSub.isOfRace(PlayerRace.Human) && !availSub.isOfRace(PlayerRace.LightElf)) { availSubs.remove(availSub); } } else { // If the master is not human and not light elf, // then remove any classes not of the same race as the master. if (npcRace != PlayerRace.Human && npcRace != PlayerRace.LightElf && !availSub.isOfRace(npcRace)) { availSubs.remove(availSub); } } } } currClass = null; return availSubs; }