RequestAquireSkillInfo.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 net.sf.l2j.gameserver.clientpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.datatables.SkillSpellbookTable;
  19. import net.sf.l2j.gameserver.datatables.SkillTable;
  20. import net.sf.l2j.gameserver.datatables.SkillTreeTable;
  21. import net.sf.l2j.gameserver.model.L2PledgeSkillLearn;
  22. import net.sf.l2j.gameserver.model.L2Skill;
  23. import net.sf.l2j.gameserver.model.L2SkillLearn;
  24. import net.sf.l2j.gameserver.model.L2TransformSkillLearn;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2FolkInstance;
  26. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  28. import net.sf.l2j.gameserver.model.actor.instance.L2TransformManagerInstance;
  29. import net.sf.l2j.gameserver.serverpackets.AcquireSkillInfo;
  30. /**
  31. * This class ...
  32. *
  33. * @version $Revision: 1.5.2.1.2.5 $ $Date: 2005/04/06 16:13:48 $
  34. */
  35. public class RequestAquireSkillInfo extends L2GameClientPacket
  36. {
  37. private static final String _C__6B_REQUESTAQUIRESKILLINFO = "[C] 6B RequestAquireSkillInfo";
  38. private static Logger _log = Logger.getLogger(RequestAquireSkillInfo.class.getName());
  39. private int _id;
  40. private int _level;
  41. private int _skillType;
  42. @Override
  43. protected void readImpl()
  44. {
  45. _id = readD();
  46. _level = readD();
  47. _skillType = readD();
  48. }
  49. @Override
  50. protected void runImpl()
  51. {
  52. L2PcInstance activeChar = getClient().getActiveChar();
  53. if (activeChar == null)
  54. return;
  55. L2FolkInstance trainer = activeChar.getLastFolkNPC();
  56. if ((trainer == null || !activeChar.isInsideRadius(trainer, L2NpcInstance.INTERACTION_DISTANCE, false, false)) && !activeChar.isGM())
  57. return;
  58. L2Skill skill = SkillTable.getInstance().getInfo(_id, _level);
  59. boolean canteach = false;
  60. if (skill == null)
  61. {
  62. if (Config.DEBUG)
  63. _log.warning("skill id " + _id + " level " + _level
  64. + " is undefined. aquireSkillInfo failed.");
  65. return;
  66. }
  67. if (_skillType == 0)
  68. {
  69. if (trainer instanceof L2TransformManagerInstance)
  70. {
  71. int itemId = 0;
  72. L2TransformSkillLearn[] skillst = SkillTreeTable.getInstance().getAvailableTransformSkills(activeChar);
  73. for (L2TransformSkillLearn s : skillst)
  74. {
  75. if (s.getId() == _id && s.getLevel() == _level)
  76. {
  77. canteach = true;
  78. itemId = s.getItemId();
  79. break;
  80. }
  81. }
  82. if (!canteach)
  83. return; // cheater
  84. int requiredSp = 0;
  85. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), requiredSp,0);
  86. if (Config.SP_BOOK_NEEDED)
  87. {
  88. asi.addRequirement(99, itemId, 1, 50);
  89. }
  90. sendPacket(asi);
  91. return;
  92. }
  93. if (!trainer.getTemplate().canTeach(activeChar.getSkillLearningClassId()))
  94. return; // cheater
  95. L2SkillLearn[] skills = SkillTreeTable.getInstance().getAvailableSkills(activeChar, activeChar.getSkillLearningClassId());
  96. for (L2SkillLearn s : skills)
  97. {
  98. if (s.getId() == _id && s.getLevel() == _level)
  99. {
  100. canteach = true;
  101. break;
  102. }
  103. }
  104. if (!canteach)
  105. return; // cheater
  106. int requiredSp = SkillTreeTable.getInstance().getSkillCost(activeChar, skill);
  107. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), requiredSp,0);
  108. if (Config.SP_BOOK_NEEDED)
  109. {
  110. int spbId = -1;
  111. if (skill.getId() == L2Skill.SKILL_DIVINE_INSPIRATION)
  112. spbId = SkillSpellbookTable.getInstance().getBookForSkill(skill, _level);
  113. else
  114. spbId = SkillSpellbookTable.getInstance().getBookForSkill(skill);
  115. if (skill.getId() == L2Skill.SKILL_DIVINE_INSPIRATION || skill.getLevel() == 1 && spbId > -1)
  116. asi.addRequirement(99, spbId, 1, 50);
  117. }
  118. sendPacket(asi);
  119. }
  120. else if (_skillType == 2)
  121. {
  122. int requiredRep = 0;
  123. int itemId = 0;
  124. L2PledgeSkillLearn[] skills = SkillTreeTable.getInstance().getAvailablePledgeSkills(activeChar);
  125. for (L2PledgeSkillLearn s : skills)
  126. {
  127. if (s.getId() == _id && s.getLevel() == _level)
  128. {
  129. canteach = true;
  130. requiredRep = s.getRepCost();
  131. itemId = s.getItemId();
  132. break;
  133. }
  134. }
  135. if (!canteach)
  136. return; // cheater
  137. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), requiredRep,2);
  138. if (Config.LIFE_CRYSTAL_NEEDED)
  139. {
  140. asi.addRequirement(1, itemId, 1, 0);
  141. }
  142. sendPacket(asi);
  143. }
  144. else // Common Skills
  145. {
  146. int costid = 0;
  147. int costcount = 0;
  148. int spcost = 0;
  149. L2SkillLearn[] skillsc = SkillTreeTable.getInstance().getAvailableSkills(activeChar);
  150. for (L2SkillLearn s : skillsc)
  151. {
  152. L2Skill sk = SkillTable.getInstance().getInfo(s.getId(), s.getLevel());
  153. if (sk == null || sk != skill)
  154. continue;
  155. canteach = true;
  156. costid = s.getIdCost();
  157. costcount = s.getCostCount();
  158. spcost = s.getSpCost();
  159. }
  160. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), spcost, 1);
  161. asi.addRequirement(4, costid, costcount, 0);
  162. sendPacket(asi);
  163. }
  164. }
  165. /*
  166. * (non-Javadoc)
  167. *
  168. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  169. */
  170. @Override
  171. public String getType()
  172. {
  173. return _C__6B_REQUESTAQUIRESKILLINFO;
  174. }
  175. }