SkillList.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.bypasshandlers;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.datatables.SkillTreesData;
  18. import com.l2jserver.gameserver.handler.IBypassHandler;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.base.ClassId;
  24. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  25. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  26. public class SkillList implements IBypassHandler
  27. {
  28. private static final String[] COMMANDS =
  29. {
  30. "SkillList"
  31. };
  32. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  33. {
  34. if (!(target instanceof L2NpcInstance))
  35. return false;
  36. if (Config.ALT_GAME_SKILL_LEARN)
  37. {
  38. try
  39. {
  40. String id = command.substring(9).trim();
  41. if (id.length() != 0)
  42. {
  43. L2NpcInstance.showSkillList(activeChar, (L2Npc)target, ClassId.values()[Integer.parseInt(id)]);
  44. }
  45. else
  46. {
  47. boolean own_class = false;
  48. ClassId[] classesToTeach = ((L2NpcInstance)target).getClassesToTeach();
  49. if (classesToTeach != null)
  50. {
  51. for (ClassId cid : classesToTeach)
  52. {
  53. if (cid.equalsOrChildOf(activeChar.getClassId()))
  54. {
  55. own_class = true;
  56. break;
  57. }
  58. }
  59. }
  60. String text = "<html><body><center>Skill learning:</center><br>";
  61. if (!own_class)
  62. {
  63. String charType = activeChar.getClassId().isMage() ? "fighter" : "mage";
  64. text +=
  65. "Skills of your class are the easiest to learn.<br>"+
  66. "Skills of another class of your race are a little harder.<br>"+
  67. "Skills for classes of another race are extremely difficult.<br>"+
  68. "But the hardest of all to learn are the "+ charType +"skills!<br>";
  69. }
  70. // make a list of classes
  71. if (classesToTeach != null)
  72. {
  73. int count = 0;
  74. ClassId classCheck = activeChar.getClassId();
  75. while ((count == 0) && (classCheck != null))
  76. {
  77. for (ClassId cid : classesToTeach)
  78. {
  79. if (cid.level() > classCheck.level())
  80. continue;
  81. if (SkillTreesData.getInstance().getAvailableSkills(activeChar, cid, false, false).isEmpty())
  82. continue;
  83. text += "<a action=\"bypass -h npc_%objectId%_SkillList "+cid.getId()+"\">Learn "+cid+"'s class Skills</a><br>\n";
  84. count++;
  85. }
  86. classCheck = classCheck.getParent();
  87. }
  88. classCheck = null;
  89. }
  90. else
  91. text += "No Skills.<br>";
  92. text += "</body></html>";
  93. NpcHtmlMessage html = new NpcHtmlMessage(((L2Npc)target).getObjectId());
  94. html.setHtml(text);
  95. html.replace("%objectId%", String.valueOf(((L2Npc)target).getObjectId()));
  96. activeChar.sendPacket(html);
  97. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  98. }
  99. }
  100. catch (Exception e)
  101. {
  102. _log.info("Exception in " + getClass().getSimpleName());
  103. }
  104. }
  105. else
  106. {
  107. L2NpcInstance.showSkillList(activeChar, (L2Npc) target, activeChar.getClassId());
  108. }
  109. return true;
  110. }
  111. public String[] getBypassList()
  112. {
  113. return COMMANDS;
  114. }
  115. }