SkillList.java 4.2 KB

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