SkillTransferValidator.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 custom.Validators;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.datatables.SkillTreesData;
  18. import com.l2jserver.gameserver.model.L2Skill;
  19. import com.l2jserver.gameserver.model.L2SkillLearn;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.quest.Quest;
  22. import com.l2jserver.gameserver.model.quest.QuestState;
  23. import com.l2jserver.gameserver.util.Util;
  24. /**
  25. * @author Zoey76
  26. */
  27. public final class SkillTransferValidator extends Quest
  28. {
  29. public SkillTransferValidator(int id, String name, String descr)
  30. {
  31. super(id, name, descr);
  32. setOnEnterWorld(true);
  33. }
  34. private static final String qn = "SkillTransfer";
  35. private static final int[][] PORMANDERS =
  36. {
  37. { 15307, 1 }, // Cardinal (97)
  38. { 15308, 1 }, // Eva's Saint (105)
  39. { 15309, 4 } // Shillen Saint (112)
  40. };
  41. @Override
  42. public String onEnterWorld(L2PcInstance player)
  43. {
  44. givePormanders(player);
  45. return null;
  46. }
  47. private void givePormanders(L2PcInstance player)
  48. {
  49. final int index = getTransferClassIndex(player);
  50. if (index >= 0)
  51. {
  52. QuestState st = player.getQuestState(qn);
  53. if (st == null)
  54. st = newQuestState(player);
  55. final String name = qn + String.valueOf(player.getClassId().getId());
  56. if (st.getInt(name) == 0)
  57. {
  58. st.setInternal(name, "1");
  59. if (st.getGlobalQuestVar(name).isEmpty())
  60. {
  61. st.saveGlobalQuestVar(name, "1");
  62. player.addItem(qn, PORMANDERS[index][0], PORMANDERS[index][1], null, true);
  63. }
  64. }
  65. if (Config.SKILL_CHECK_ENABLE && (!player.isGM() || Config.SKILL_CHECK_GM))
  66. {
  67. int count = PORMANDERS[index][1] - (int)player.getInventory().getInventoryItemCount(PORMANDERS[index][0], -1, false);
  68. for (L2Skill sk : player.getAllSkills())
  69. {
  70. for (L2SkillLearn s : SkillTreesData.getInstance().getTransferSkillTree(player.getClassId()).values())
  71. {
  72. if (s.getSkillId() == sk.getId())
  73. {
  74. // Holy Weapon allowed for Shilien Saint/Inquisitor stance
  75. if (sk.getId() == 1043 && index == 2 && player.isInStance())
  76. continue;
  77. count--;
  78. if (count < 0)
  79. {
  80. Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " has too many transfered skills or items, skill:" + s.getName() + " ("+sk.getId() + "/" + sk.getLevel() + "), class:" + player.getTemplate().className, 1);
  81. if (Config.SKILL_CHECK_REMOVE)
  82. player.removeSkill(sk);
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. private int getTransferClassIndex(L2PcInstance player)
  91. {
  92. switch (player.getClassId().getId())
  93. {
  94. case 97: // Cardinal
  95. return 0;
  96. case 105: // Eva's Saint
  97. return 1;
  98. case 112: // Shillien Saint
  99. return 2;
  100. default:
  101. return -1;
  102. }
  103. }
  104. public static void main(String[] args)
  105. {
  106. new SkillTransferValidator(-1, qn, "custom");
  107. }
  108. }