RequestAcquireSkillInfo.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 com.l2jserver.gameserver.network.clientpackets;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.datatables.SkillSpellbookTable;
  19. import com.l2jserver.gameserver.datatables.SkillTable;
  20. import com.l2jserver.gameserver.datatables.SkillTreeTable;
  21. import com.l2jserver.gameserver.datatables.SubPledgeSkillTree;
  22. import com.l2jserver.gameserver.datatables.SubPledgeSkillTree.SubUnitSkill;
  23. import com.l2jserver.gameserver.model.L2PledgeSkillLearn;
  24. import com.l2jserver.gameserver.model.L2Skill;
  25. import com.l2jserver.gameserver.model.L2SkillLearn;
  26. import com.l2jserver.gameserver.model.L2SquadTrainer;
  27. import com.l2jserver.gameserver.model.L2TransformSkillLearn;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.actor.instance.L2TransformManagerInstance;
  32. import com.l2jserver.gameserver.model.quest.Quest;
  33. import com.l2jserver.gameserver.network.serverpackets.AcquireSkillInfo;
  34. /**
  35. * This class ...
  36. *
  37. * @version $Revision: 1.5.2.1.2.5 $ $Date: 2005/04/06 16:13:48 $
  38. */
  39. public class RequestAcquireSkillInfo extends L2GameClientPacket
  40. {
  41. private static final String _C__6B_REQUESTAQUIRESKILLINFO = "[C] 6B RequestAcquireSkillInfo";
  42. private static Logger _log = Logger.getLogger(RequestAcquireSkillInfo.class.getName());
  43. private int _id;
  44. private int _level;
  45. private int _skillType;
  46. @Override
  47. protected void readImpl()
  48. {
  49. _id = readD();
  50. _level = readD();
  51. _skillType = readD();
  52. }
  53. @Override
  54. protected void runImpl()
  55. {
  56. if (_id <= 0 || _level <= 0) // minimal sanity check
  57. return;
  58. final L2PcInstance activeChar = getClient().getActiveChar();
  59. if (activeChar == null)
  60. return;
  61. final L2Npc trainer = activeChar.getLastFolkNPC();
  62. if (!(trainer instanceof L2NpcInstance))
  63. return;
  64. if (!trainer.canInteract(activeChar) && !activeChar.isGM())
  65. return;
  66. final L2Skill skill = SkillTable.getInstance().getInfo(_id, _level);
  67. boolean canteach = false;
  68. if (skill == null)
  69. {
  70. if (Config.DEBUG)
  71. _log.warning("skill id " + _id + " level " + _level
  72. + " is undefined. aquireSkillInfo failed.");
  73. return;
  74. }
  75. if (_skillType == 0)
  76. {
  77. if (trainer instanceof L2TransformManagerInstance)
  78. {
  79. int itemId = 0;
  80. L2TransformSkillLearn[] skillst = SkillTreeTable.getInstance().getAvailableTransformSkills(activeChar);
  81. for (L2TransformSkillLearn s : skillst)
  82. {
  83. if (s.getId() == _id && s.getLevel() == _level)
  84. {
  85. canteach = true;
  86. itemId = s.getItemId();
  87. break;
  88. }
  89. }
  90. if (!canteach)
  91. return; // cheater
  92. int requiredSp = 0;
  93. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), requiredSp,0);
  94. // all transformations require scrolls
  95. asi.addRequirement(99, itemId, 1, 50);
  96. sendPacket(asi);
  97. return;
  98. }
  99. if (!trainer.getTemplate().canTeach(activeChar.getSkillLearningClassId()))
  100. return; // cheater
  101. L2SkillLearn[] skills = SkillTreeTable.getInstance().getAvailableSkills(activeChar, activeChar.getSkillLearningClassId());
  102. for (L2SkillLearn s : skills)
  103. {
  104. if (s.getId() == _id && s.getLevel() == _level)
  105. {
  106. canteach = true;
  107. break;
  108. }
  109. }
  110. if (!canteach)
  111. return; // cheater
  112. int requiredSp = SkillTreeTable.getInstance().getSkillCost(activeChar, skill);
  113. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), requiredSp,0);
  114. int spbId = -1;
  115. if (Config.DIVINE_SP_BOOK_NEEDED && skill.getId() == L2Skill.SKILL_DIVINE_INSPIRATION)
  116. spbId = SkillSpellbookTable.getInstance().getBookForSkill(skill, _level);
  117. else if (Config.SP_BOOK_NEEDED && skill.getLevel() == 1)
  118. spbId = SkillSpellbookTable.getInstance().getBookForSkill(skill);
  119. if (spbId > -1)
  120. asi.addRequirement(99, spbId, 1, 50);
  121. sendPacket(asi);
  122. }
  123. else if (_skillType == 2)
  124. {
  125. int requiredRep = 0;
  126. int itemId = 0;
  127. int itemCount = 0;
  128. L2PledgeSkillLearn[] skills = SkillTreeTable.getInstance().getAvailablePledgeSkills(activeChar);
  129. for (L2PledgeSkillLearn s : skills)
  130. {
  131. if (s.getId() == _id && s.getLevel() == _level)
  132. {
  133. canteach = true;
  134. requiredRep = s.getRepCost();
  135. itemId = s.getItemId();
  136. itemCount = s.getItemCount();
  137. break;
  138. }
  139. }
  140. if (!canteach)
  141. return; // cheater
  142. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), requiredRep, 2);
  143. if (Config.LIFE_CRYSTAL_NEEDED)
  144. asi.addRequirement(1, itemId, itemCount, 0);
  145. sendPacket(asi);
  146. }
  147. else if (_skillType == 3)
  148. {
  149. if (trainer instanceof L2SquadTrainer)
  150. {
  151. SubUnitSkill sus = SubPledgeSkillTree.getInstance().getSkill(SkillTable.getSkillHashCode(skill));
  152. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), sus.getReputation(), 3);
  153. asi.addRequirement(0, sus.getItemId(), sus.getCount(), 0);
  154. sendPacket(asi);
  155. }
  156. }
  157. else if (_skillType == 4)
  158. {
  159. Quest[] qlst = trainer.getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_LEARN);
  160. if ((qlst != null) && qlst.length == 1)
  161. {
  162. if (!qlst[0].notifyAcquireSkillInfo(trainer, activeChar, skill))
  163. {
  164. qlst[0].notifyAcquireSkillList(trainer, activeChar);
  165. return;
  166. }
  167. }
  168. else
  169. {
  170. return;
  171. }
  172. }
  173. else if (_skillType == 6)
  174. {
  175. int costid = 0;
  176. int costcount = 0;
  177. L2SkillLearn[] skillsc = SkillTreeTable.getInstance().getAvailableSpecialSkills(activeChar);
  178. for (L2SkillLearn s : skillsc)
  179. {
  180. L2Skill sk = SkillTable.getInstance().getInfo(s.getId(), s.getLevel());
  181. if (sk == null || sk != skill)
  182. continue;
  183. canteach = true;
  184. costid = s.getIdCost();
  185. costcount = s.getCostCount();
  186. }
  187. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), 0, 6);
  188. asi.addRequirement(5, costid, costcount, 0);
  189. sendPacket(asi);
  190. }
  191. else // Common Skills
  192. {
  193. int costid = 0;
  194. int costcount = 0;
  195. int spcost = 0;
  196. L2SkillLearn[] skillsc = SkillTreeTable.getInstance().getAvailableSkills(activeChar);
  197. for (L2SkillLearn s : skillsc)
  198. {
  199. L2Skill sk = SkillTable.getInstance().getInfo(s.getId(), s.getLevel());
  200. if (sk == null || sk != skill)
  201. continue;
  202. canteach = true;
  203. costid = s.getIdCost();
  204. costcount = s.getCostCount();
  205. spcost = s.getSpCost();
  206. }
  207. AcquireSkillInfo asi = new AcquireSkillInfo(skill.getId(), skill.getLevel(), spcost, 1);
  208. asi.addRequirement(4, costid, costcount, 0);
  209. sendPacket(asi);
  210. }
  211. }
  212. /*
  213. * (non-Javadoc)
  214. *
  215. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  216. */
  217. @Override
  218. public String getType()
  219. {
  220. return _C__6B_REQUESTAQUIRESKILLINFO;
  221. }
  222. }