RequestAcquireSkillInfo.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.gameserver.data.xml.impl.SkillTreesData;
  21. import com.l2jserver.gameserver.datatables.SkillData;
  22. import com.l2jserver.gameserver.model.ClanPrivilege;
  23. import com.l2jserver.gameserver.model.L2SkillLearn;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.base.AcquireSkillType;
  28. import com.l2jserver.gameserver.model.skills.Skill;
  29. import com.l2jserver.gameserver.network.serverpackets.AcquireSkillInfo;
  30. /**
  31. * Request Acquire Skill Info client packet implementation.
  32. * @author Zoey76
  33. */
  34. public final class RequestAcquireSkillInfo extends L2GameClientPacket
  35. {
  36. private static final String _C__73_REQUESTACQUIRESKILLINFO = "[C] 73 RequestAcquireSkillInfo";
  37. private int _id;
  38. private int _level;
  39. private AcquireSkillType _skillType;
  40. @Override
  41. protected void readImpl()
  42. {
  43. _id = readD();
  44. _level = readD();
  45. _skillType = AcquireSkillType.getAcquireSkillType(readD());
  46. }
  47. @Override
  48. protected void runImpl()
  49. {
  50. if ((_id <= 0) || (_level <= 0))
  51. {
  52. _log.warning(RequestAcquireSkillInfo.class.getSimpleName() + ": Invalid Id: " + _id + " or level: " + _level + "!");
  53. return;
  54. }
  55. final L2PcInstance activeChar = getClient().getActiveChar();
  56. if (activeChar == null)
  57. {
  58. return;
  59. }
  60. final L2Npc trainer = activeChar.getLastFolkNPC();
  61. if (!(trainer instanceof L2NpcInstance))
  62. {
  63. return;
  64. }
  65. if (!trainer.canInteract(activeChar) && !activeChar.isGM())
  66. {
  67. return;
  68. }
  69. final Skill skill = SkillData.getInstance().getSkill(_id, _level);
  70. if (skill == null)
  71. {
  72. _log.warning(RequestAcquireSkillInfo.class.getSimpleName() + ": Skill Id: " + _id + " level: " + _level + " is undefined. " + RequestAcquireSkillInfo.class.getName() + " failed.");
  73. return;
  74. }
  75. // Hack check. Doesn't apply to all Skill Types
  76. final int prevSkillLevel = activeChar.getSkillLevel(_id);
  77. if ((prevSkillLevel > 0) && !((_skillType == AcquireSkillType.TRANSFER) || (_skillType == AcquireSkillType.SUBPLEDGE)))
  78. {
  79. if (prevSkillLevel == _level)
  80. {
  81. _log.warning(RequestAcquireSkillInfo.class.getSimpleName() + ": Player " + activeChar.getName() + " is trequesting info for a skill that already knows, Id: " + _id + " level: " + _level + "!");
  82. }
  83. else if (prevSkillLevel != (_level - 1))
  84. {
  85. _log.warning(RequestAcquireSkillInfo.class.getSimpleName() + ": Player " + activeChar.getName() + " is requesting info for skill Id: " + _id + " level " + _level + " without knowing it's previous level!");
  86. }
  87. }
  88. final L2SkillLearn s = SkillTreesData.getInstance().getSkillLearn(_skillType, _id, _level, activeChar);
  89. if (s == null)
  90. {
  91. return;
  92. }
  93. switch (_skillType)
  94. {
  95. case TRANSFORM:
  96. case FISHING:
  97. case SUBCLASS:
  98. case COLLECT:
  99. case TRANSFER:
  100. {
  101. sendPacket(new AcquireSkillInfo(_skillType, s));
  102. break;
  103. }
  104. case CLASS:
  105. {
  106. if (trainer.getTemplate().canTeach(activeChar.getLearningClass()))
  107. {
  108. final int customSp = s.getCalculatedLevelUpSp(activeChar.getClassId(), activeChar.getLearningClass());
  109. sendPacket(new AcquireSkillInfo(_skillType, s, customSp));
  110. }
  111. break;
  112. }
  113. case PLEDGE:
  114. {
  115. if (!activeChar.isClanLeader())
  116. {
  117. return;
  118. }
  119. sendPacket(new AcquireSkillInfo(_skillType, s));
  120. break;
  121. }
  122. case SUBPLEDGE:
  123. {
  124. if (!activeChar.isClanLeader() || !activeChar.hasClanPrivilege(ClanPrivilege.CL_TROOPS_FAME))
  125. {
  126. return;
  127. }
  128. sendPacket(new AcquireSkillInfo(_skillType, s));
  129. break;
  130. }
  131. }
  132. }
  133. @Override
  134. public String getType()
  135. {
  136. return _C__73_REQUESTACQUIRESKILLINFO;
  137. }
  138. }