Code: Select all
Index: java/net/sf/l2j/gameserver/model/actor/instance/L2ClassMasterInstance.java===================================================================--- java/net/sf/l2j/gameserver/model/actor/instance/L2ClassMasterInstance.java (revision 3345)+++ java/net/sf/l2j/gameserver/model/actor/instance/L2ClassMasterInstance.java (working copy)@@ -15,12 +15,11 @@ package net.sf.l2j.gameserver.model.actor.instance; import java.util.Collection;+ import net.sf.l2j.Config; import net.sf.l2j.gameserver.ai.CtrlIntention; import net.sf.l2j.gameserver.datatables.CharTemplateTable; import net.sf.l2j.gameserver.model.base.ClassId;-import net.sf.l2j.gameserver.model.base.ClassLevel;-import net.sf.l2j.gameserver.model.base.PlayerClass; import net.sf.l2j.gameserver.model.quest.Quest; import net.sf.l2j.gameserver.network.SystemMessageId; import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;@@ -32,24 +31,15 @@ import net.sf.l2j.gameserver.util.StringUtil; /**- * This class ...- *- * @version $Revision: 1.4.2.1.2.7 $ $Date: 2005/03/27 15:29:32 $+ * This class is for the classmaster (Roy the Cat) */ public final class L2ClassMasterInstance extends L2NpcInstance {- //private static Logger _log = Logger.getLogger(L2ClassMasterInstance.class.getName());- private static final int[] BASE_CLASS_IDS = {0, 10, 18, 25, 31, 38, 44,- 49, 53};- private static final int[] FIRST_CLASS_IDS = {1, 4, 7, 11, 15, 19, 22,- 26, 29, 32, 35, 39, 42, 45, 47, 50, 54, 56};- private static final int[] SECOND_CLASS_IDS = {2, 3, 5, 6, 9, 8, 12, 13,- 14, 16, 17, 20, 21, 23, 24, 27, 28, 30, 33, 34, 36, 37, 40, 41,- 43, 46, 48, 51, 52, 55, 57};- private static final int[] THIRD_CLASS_IDS = {88, 89, 90, 91, 92, 93,- 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,- 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118};-+ private static final int[] BASE_CLASS_IDS = { 0, 10, 18, 25, 31, 38, 44, 49, 53, 123, 124 };+ private static final int[] FIRST_CLASS_IDS = { 1, 4, 7, 11, 15, 19, 22, 26, 29, 32, 35, 39, 42, 45, 47, 50, 54, 56, 125, 126 };+ private static final int[] SECOND_CLASS_IDS = { 2, 3, 5, 6, 9, 8, 12, 13, 14, 16, 17, 20, 21, 23, 24, 27, 28, 30, 33, 34, 36, 37, 40, 41, 43, 46, 48, 51, 52, 55, 57, 127, 128, 129, 130, 135 };+ private static final int[] THIRD_CLASS_IDS = { 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 131, 132, 133, 134, 136 };+ /** * @param template */@@ -57,23 +47,24 @@ { super(objectId, template); }-+ @Override public void onAction(L2PcInstance player) {- if (!canTarget(player)) return;-+ if (!canTarget(player))+ return;+ player.setLastFolkNPC(this);-+ // Check if the L2PcInstance already target the L2NpcInstance if (getObjectId() != player.getTargetId()) { // Set the target of the L2PcInstance player player.setTarget(this);-+ // Send a Server->Client packet MyTargetSelected to the L2PcInstance player player.sendPacket(new MyTargetSelected(getObjectId(), 0));-+ // Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client player.sendPacket(new ValidateLocation(this)); }@@ -84,345 +75,241 @@ player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this); return; }-+ if (Config.DEBUG) _log.fine("ClassMaster activated");-- ClassId classId = player.getClassId();-- int jobLevel = 0;- int level = player.getLevel();- ClassLevel lvl = PlayerClass.values()[classId.getId()].getLevel();- switch (lvl)+ + if (player.isGM()) {- case First:- jobLevel = 1;- break;- case Second:- jobLevel = 2;- break;- default:- jobLevel = 3;+ showChatWindowChooseClass(player); }-+ + ClassId classId = player.getClassId();+ int jobLevel = classId.level();+ int newJobLevel = jobLevel + 1;+ int level = player.getLevel();+ if (!Config.ALLOW_CLASS_MASTERS) jobLevel = 3;-- if(player.isGM())+ + if (((level >= 20 && jobLevel == 0) || (level >= 40 && jobLevel == 1) || (level >= 76 && jobLevel == 2)) && Config.ALLOW_CLASS_MASTERS) {- showChatWindowChooseClass(player);- }- else if (((level >= 20 && jobLevel == 1 ) ||- (level >= 40 && jobLevel == 2 )) && Config.ALLOW_CLASS_MASTERS)- {- showChatWindow(player, classId.getId());- }- else if (level >= 76 && Config.ALLOW_CLASS_MASTERS && classId.getId() < 88)- {- for (int i = 0; i < SECOND_CLASS_IDS.length; i++)+ NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());+ final StringBuilder sb = StringUtil.startAppend(500, "<html><body>");+ + StringUtil.append(sb, "<center>", String.valueOf(CharTemplateTable.getInstance().getClassNameById(classId.getId())), " Class Master:</center><br>");+ + for (ClassId child : ClassId.values()) {- if (classId.getId() == SECOND_CLASS_IDS[i])- {- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());- final String sb = StringUtil.concat(- "<html><body<table width=200>" +- "<tr><td><center>",- String.valueOf(CharTemplateTable.getInstance().getClassNameById(player.getClassId().getId())),- " Class Master:</center></td></tr>" +- "<tr><td><br></td></tr>" +- "<tr><td><a action=\"bypass -h npc_",- String.valueOf(getObjectId()),- "_change_class ",- String.valueOf(88+i),- "\">Advance to ",- CharTemplateTable.getInstance().getClassNameById(88+i),- "</a></td></tr>" +- "<tr><td><br></td></tr>" +- "</table></body></html>"- );- html.setHtml(sb);- player.sendPacket(html);- break;- }+ if (child.childOf(classId) && child.level() == newJobLevel)+ StringUtil.append(sb, "<a action=\"bypass -h npc_", String.valueOf(getObjectId()), "_change_class ", String.valueOf(child.getId()), "\"> ", CharTemplateTable.getInstance().getClassNameById(child.getId()), "</a><br>"); }+ + StringUtil.append(sb, "</body></html>");+ html.setHtml(sb.toString());+ player.sendPacket(html); }- else if (level >= 76 && Config.ALLOW_CLASS_MASTERS && ((classId.getId() >= 123 && classId.getId() < 131 ) || classId.getId() == 135)) // this is for Kamael Race 3rd Transfer- {- showChatWindow(player, classId.getId());- } else {+ final Collection<Quest> quests = Quest.findAllEvents(); + NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());- final Collection<Quest> quests = Quest.findAllEvents();- final StringBuilder sb = new StringBuilder(30 + 50 + quests.size() * 50);- sb.append("<html><body>");+ final StringBuilder sb = StringUtil.startAppend(30 + 50 + quests.size() * 50, "<html><body>", getName(), ":<br>");+ switch (jobLevel) {+ case 0:+ StringUtil.append(sb, "Come back here when you reach level 20 to change your class.<br>");+ break; case 1:- sb.append("Come back here when you reach level 20 to change your class.<br>");+ StringUtil.append(sb, "Come back here when you reach level 40 to change your class.<br>"); break; case 2:- sb.append("Come back here when you reach level 40 to change your class.<br>");+ StringUtil.append(sb, "Come back here when you reached level 76 to change your class.<br>"); break; case 3:- sb.append("There are no more class changes for you.<br>");+ StringUtil.append(sb, "There are no more class changes for you.<br>"); break; }-- for (Quest q : quests) {- StringUtil.append(sb,- "Event: <a action=\"bypass -h Quest ",- q.getName(),- "\">",- q.getDescr(),- "</a><br>"- );- }-- sb.append("</body></html>");+ + for (Quest q : quests)+ {+ StringUtil.append(sb, "Event: <a action=\"bypass -h Quest ", q.getName(), "\">", q.getDescr(), "</a><br>");+ }+ + StringUtil.append(sb, "</body></html>"); html.setHtml(sb.toString()); player.sendPacket(html); } } player.sendPacket(ActionFailed.STATIC_PACKET); }-+ @Override public String getHtmlPath(int npcId, int val) { return "data/html/classmaster/" + val + ".htm"; }-+ @Override public void onBypassFeedback(L2PcInstance player, String command) {- if(command.startsWith("1stClass"))+ if (command.startsWith("1stClass")) {- if(player.isGM())+ if (player.isGM()) { showChatWindow1st(player); } }- else if(command.startsWith("2ndClass"))+ else if (command.startsWith("2ndClass")) {- if(player.isGM())+ if (player.isGM()) { showChatWindow2nd(player); } }- else if(command.startsWith("3rdClass"))+ else if (command.startsWith("3rdClass")) {- if(player.isGM())+ if (player.isGM()) { showChatWindow3rd(player); } }- else if(command.startsWith("baseClass"))+ else if (command.startsWith("baseClass")) {- if(player.isGM())+ if (player.isGM()) { showChatWindowBase(player); } }- else if(command.startsWith("change_class"))+ else if (command.startsWith("change_class")) {- int val = Integer.parseInt(command.substring(13));-- // Exploit prevention- ClassId classId = player.getClassId();- int level = player.getLevel();- int jobLevel = 0;- int newJobLevel = 0;-- ClassLevel lvlnow = PlayerClass.values()[classId.getId()].getLevel();-- if(player.isGM())- {- changeClass(player, val);-- if(player.getClassId().level() == 3)- player.sendPacket(new SystemMessage(SystemMessageId.THIRD_CLASS_TRANSFER)); // system sound 3rd occupation- else- player.sendPacket(new SystemMessage(SystemMessageId.CLASS_TRANSFER)); // system sound for 1st and 2nd occupation-- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());- final String sb = StringUtil.concat(- "<html><body>" +- "You have now become a <font color=\"LEVEL\">",- CharTemplateTable.getInstance().getClassNameById(player.getClassId().getId()),- "</font>." +- "</body></html>"- );- html.setHtml(sb);- player.sendPacket(html);- return;- }- switch (lvlnow)- {- case First:- jobLevel = 1;- break;- case Second:- jobLevel = 2;- break;- case Third:- jobLevel = 3;- break;- default:- jobLevel = 4;- }-- if(jobLevel == 4) return; // no more job changes-- ClassLevel lvlnext = PlayerClass.values()[val].getLevel();- switch (lvlnext)- {- case First:- newJobLevel = 1;- break;- case Second:- newJobLevel = 2;- break;- case Third:- newJobLevel = 3;- break;- default:- newJobLevel = 4;- }-- // prevents changing between same level jobs- if(newJobLevel != jobLevel + 1) return;-- if (level < 20 && newJobLevel > 1) return;- if (level < 40 && newJobLevel > 2) return;- if (level < 75 && newJobLevel > 3) return;- // -- prevention ends--- changeClass(player, val);-- if(player.getClassId().level() == 3)- player.sendPacket(new SystemMessage(SystemMessageId.THIRD_CLASS_TRANSFER)); // system sound 3rd occupation- else- player.sendPacket(new SystemMessage(SystemMessageId.CLASS_TRANSFER)); // system sound for 1st and 2nd occupation- - player.rewardSkills();-- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());- final String sb = StringUtil.concat(- "<html><body>" +- "You have now become a <font color=\"LEVEL\">",- CharTemplateTable.getInstance().getClassNameById(player.getClassId().getId()),- "</font>." +- "</body></html>"- );- html.setHtml(sb);- player.sendPacket(html);- }- else- {- super.onBypassFeedback(player, command);- }- }- private void showChatWindowChooseClass(L2PcInstance player) {- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());- final String objectIdString = String.valueOf(getObjectId());- final String sb = StringUtil.concat(- "<html>" +- "<body>" +- "<table width=200>" +- "<tr><td><center>GM Class Master:</center></td></tr>" +- "<tr><td><br></td></tr>" +- "<tr><td><a action=\"bypass -h npc_",- objectIdString,- "_baseClass\">Base Classes.</a></td></tr>" +- "<tr><td><a action=\"bypass -h npc_",- objectIdString,- "_1stClass\">1st Classes.</a></td></tr>" +- "<tr><td><a action=\"bypass -h npc_",- objectIdString,- "_2ndClass\">2nd Classes.</a></td></tr>" +- "<tr><td><a action=\"bypass -h npc_",- objectIdString,- "_3rdClass\">3rd Classes.</a></td></tr>" +- "<tr><td><br></td></tr>" +- "</table>" +- "<br><font color=\"LEVEL\">Please notice this menu is only available for Game Masters, not for normal players ;)</font>" +- "</body>" +- "</html>"- );- html.setHtml(sb);- player.sendPacket(html);+ int val = Integer.parseInt(command.substring(13));+ + if (!player.isGM())+ {+ // Exploit prevention+ ClassId classId = player.getClassId();+ ClassId newClassId = ClassId.values()[val];+ int level = player.getLevel();+ int jobLevel = classId.level();+ int newJobLevel = newClassId.level();+ + // prevents changing to class not in same class tree+ if (!newClassId.childOf(classId))+ return;+ + // prevents changing between same level jobs+ if (newJobLevel != jobLevel + 1)+ return;+ + // check for player level+ if (level < 20 && newJobLevel > 1)+ return;+ if (level < 40 && newJobLevel > 2)+ return;+ if (level < 76 && newJobLevel > 3)+ return;+ // -- prevention ends+ }+ + changeClass(player, val);+ + if (player.getClassId().level() == 3)+ player.sendPacket(new SystemMessage(SystemMessageId.THIRD_CLASS_TRANSFER)); // system sound 3rd occupation+ else+ player.sendPacket(new SystemMessage(SystemMessageId.CLASS_TRANSFER)); // system sound for 1st and 2nd occupation+ + player.rewardSkills();+ + NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());+ final String sb = StringUtil.concat("<html><body>", getName(), ":<br>", "You have now become a <font color=\"LEVEL\">", CharTemplateTable.getInstance().getClassNameById(val), "</font>.</body></html>");+ html.setHtml(sb);+ player.sendPacket(html);+ + // Update the overloaded status of the L2PcInstance+ player.refreshOverloaded();+ // Update the expertise status of the L2PcInstance+ player.refreshExpertisePenalty();+ }+ else+ {+ super.onBypassFeedback(player, command);+ } }-- private void showChatWindow1st(L2PcInstance player) {- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());- html.setHtml(createGMClassMasterHtml(FIRST_CLASS_IDS));- player.sendPacket(html);+ + private void showChatWindowChooseClass(L2PcInstance player)+ {+ NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());+ final String objectIdString = String.valueOf(getObjectId());+ final String sb = StringUtil.concat("<html><body><table width=200>"+ + "<tr><td><center>GM Class Master:</center></td></tr>" + "<tr><td><br></td></tr>" + "<tr><td><a action=\"bypass -h npc_", objectIdString, "_baseClass\">Base Classes.</a></td></tr>"+ + "<tr><td><a action=\"bypass -h npc_", objectIdString, "_1stClass\">1st Classes.</a></td></tr>"+ + "<tr><td><a action=\"bypass -h npc_", objectIdString, "_2ndClass\">2nd Classes.</a></td></tr>"+ + "<tr><td><a action=\"bypass -h npc_", objectIdString, "_3rdClass\">3rd Classes.</a></td></tr>" + "<tr><td><br></td></tr>"+ + "</table>"+ + "<br><font color=\"LEVEL\">Please notice this menu is only available for Game Masters, not for normal players ;)</font>"+ + "</body></html>");+ html.setHtml(sb);+ player.sendPacket(html); }-- private void showChatWindow2nd(L2PcInstance player) {- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());- html.setHtml(createGMClassMasterHtml(SECOND_CLASS_IDS));- player.sendPacket(html);+ + private void showChatWindow1st(L2PcInstance player)+ {+ NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());+ html.setHtml(createGMClassMasterHtml(FIRST_CLASS_IDS));+ player.sendPacket(html); }-- private void showChatWindow3rd(L2PcInstance player) {- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());- html.setHtml(createGMClassMasterHtml(THIRD_CLASS_IDS));- player.sendPacket(html);+ + private void showChatWindow2nd(L2PcInstance player)+ {+ NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());+ html.setHtml(createGMClassMasterHtml(SECOND_CLASS_IDS));+ player.sendPacket(html); }-- private void showChatWindowBase(L2PcInstance player) {- NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());- html.setHtml(createGMClassMasterHtml(BASE_CLASS_IDS));- player.sendPacket(html);+ + private void showChatWindow3rd(L2PcInstance player)+ {+ NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());+ html.setHtml(createGMClassMasterHtml(THIRD_CLASS_IDS));+ player.sendPacket(html); }-+ + private void showChatWindowBase(L2PcInstance player)+ {+ NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());+ html.setHtml(createGMClassMasterHtml(BASE_CLASS_IDS));+ player.sendPacket(html);+ }+ private void changeClass(L2PcInstance player, int val) {- if (Config.DEBUG) _log.fine("Changing class to ClassId:"+val);- player.setClassId(val);-- if (player.isSubClassActive())- player.getSubClasses().get(player.getClassIndex()).setClassId(player.getActiveClass());- else- player.setBaseClass(player.getActiveClass());-+ if (Config.DEBUG)+ _log.fine("Changing class to ClassId:" + val);+ player.setClassId(val);+ + if (player.isSubClassActive())+ player.getSubClasses().get(player.getClassIndex()).setClassId(player.getActiveClass());+ else+ player.setBaseClass(player.getActiveClass());+ player.broadcastUserInfo(); }-- private String createGMClassMasterHtml(final int[] classIds) {- final String objectIdString = String.valueOf(getObjectId());- final CharTemplateTable charTemplateTable =- CharTemplateTable.getInstance();- final StringBuilder sbString =- new StringBuilder(100 + classIds.length * 100);- sbString.append(- "<html>" +- "<body>" +- "<table width=200>" +- "<tr><td><center>GM Class Master:</center></td></tr>" +- "<tr><td><br></td></tr>");-- for (int classId : classIds) {- StringUtil.append(sbString,- "<tr><td><a action=\"bypass -h npc_",- objectIdString,- "_change_class ",- String.valueOf(classId),- "\">Advance to ",- charTemplateTable.getClassNameById(classId),- "</a></td></tr>"- );- }-- sbString.append(- "</table>" +- "</body>" +- "</html>"- );-- return sbString.toString();- }+ + private String createGMClassMasterHtml(final int[] classIds)+ {+ final String objectIdString = String.valueOf(getObjectId());+ final CharTemplateTable charTemplateTable = CharTemplateTable.getInstance();+ final StringBuilder sbString = new StringBuilder(100 + classIds.length * 100);+ sbString.append("<html><body><table width=200><tr><td><center>GM Class Master:</center></td></tr><tr><td><br></td></tr>");+ + for (int classId : classIds)+ {+ StringUtil.append(sbString, "<tr><td><a action=\"bypass -h npc_", objectIdString, "_change_class ", String.valueOf(classId), "\">Advance to ", charTemplateTable.getClassNameById(classId), "</a></td></tr>");+ }+ + sbString.append("</table></body></html>");+ + return sbString.toString();+ } }