RequestExEnchantSkillInfo.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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.List;
  17. import java.util.logging.Logger;
  18. import net.sf.l2j.gameserver.datatables.SkillTable;
  19. import net.sf.l2j.gameserver.datatables.SkillTreeTable;
  20. import net.sf.l2j.gameserver.model.L2EnchantSkillLearn;
  21. import net.sf.l2j.gameserver.model.L2Skill;
  22. import net.sf.l2j.gameserver.model.L2EnchantSkillLearn.EnchantSkillDetail;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2FolkInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  26. import net.sf.l2j.gameserver.serverpackets.ExEnchantSkillInfo;
  27. import net.sf.l2j.gameserver.serverpackets.ExEnchantSkillList.EnchantSkillType;
  28. /**
  29. * Format (ch) dd
  30. * c: (id) 0xD0
  31. * h: (subid) 0x06
  32. * d: skill id
  33. * d: skill lvl
  34. * @author -Wooden-
  35. *
  36. */
  37. public final class RequestExEnchantSkillInfo extends L2GameClientPacket
  38. {
  39. private static final Logger _log = Logger.getLogger(RequestExEnchantSkillInfo.class.getName());
  40. private static final String _C__D0_06_REQUESTEXENCHANTSKILLINFO = "[C] D0:06 RequestExEnchantSkillInfo";
  41. private static final int TYPE_NORMAL_ENCHANT = 0;
  42. private static final int TYPE_SAFE_ENCHANT = 1;
  43. private static final int TYPE_UNTRAIN_ENCHANT = 2;
  44. private static final int TYPE_CHANGE_ENCHANT = 3;
  45. private int _type;
  46. private int _skillId;
  47. private int _skillLvl;
  48. @Override
  49. protected void readImpl()
  50. {
  51. _type = readD();
  52. _skillId = readD();
  53. _skillLvl = readD();
  54. }
  55. /* (non-Javadoc)
  56. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#runImpl()
  57. */
  58. @Override
  59. protected void runImpl()
  60. {
  61. L2PcInstance activeChar = getClient().getActiveChar();
  62. if (activeChar == null)
  63. return;
  64. if (activeChar.getLevel() < 76)
  65. return;
  66. L2FolkInstance trainer = activeChar.getLastFolkNPC();
  67. if ((trainer == null || !activeChar.isInsideRadius(trainer, L2NpcInstance.INTERACTION_DISTANCE, false, false)) && !activeChar.isGM())
  68. return;
  69. L2Skill skill = SkillTable.getInstance().getInfo(_skillId, _skillLvl);
  70. if (skill == null || skill.getId() != _skillId)
  71. {
  72. activeChar.sendMessage("This skill doesn't yet have enchant info in Datapack");
  73. return;
  74. }
  75. if (!trainer.getTemplate().canTeach(activeChar.getClassId()) && !activeChar.isGM())
  76. return; // cheater
  77. switch (_type)
  78. {
  79. case TYPE_NORMAL_ENCHANT:
  80. this.showEnchantInfo(activeChar, false);
  81. break;
  82. case TYPE_SAFE_ENCHANT:
  83. this.showEnchantInfo(activeChar, true);
  84. break;
  85. case TYPE_UNTRAIN_ENCHANT:
  86. this.showUntrainEnchantInfo(activeChar);
  87. break;
  88. case TYPE_CHANGE_ENCHANT:
  89. this.showChangeEnchantInfo(activeChar);
  90. break;
  91. default:
  92. _log.severe("Unknown skill enchant type: "+_type);
  93. break;
  94. }
  95. }
  96. public void showEnchantInfo(L2PcInstance activeChar, boolean isSafeEnchant)
  97. {
  98. ExEnchantSkillInfo asi = new ExEnchantSkillInfo(isSafeEnchant ? EnchantSkillType.SAFE : EnchantSkillType.NORMAL, _skillId);
  99. L2EnchantSkillLearn enchantLearn = SkillTreeTable.getInstance().getSkillEnchantmentBySkillId(_skillId);
  100. // do we have this skill?
  101. if (enchantLearn != null)
  102. {
  103. // skill already enchanted?
  104. if (_skillLvl > 100)
  105. {
  106. // get detail for next level
  107. EnchantSkillDetail esd = enchantLearn.getEnchantSkillDetail(_skillLvl + 1);
  108. // if it exists add it
  109. if (esd != null)
  110. {
  111. asi.addEnchantSkillDetail(activeChar, esd);
  112. }
  113. }
  114. else // not already enchanted
  115. {
  116. for (List<EnchantSkillDetail> esd : enchantLearn.getEnchantRoutes())
  117. {
  118. // add first level (+1) of all routes
  119. asi.addEnchantSkillDetail(activeChar, esd.get(0));
  120. }
  121. }
  122. sendPacket(asi);
  123. }
  124. }
  125. public void showChangeEnchantInfo(L2PcInstance activeChar)
  126. {
  127. ExEnchantSkillInfo asi = new ExEnchantSkillInfo(EnchantSkillType.CHANGE_ROUTE, _skillId);
  128. L2EnchantSkillLearn enchantLearn = SkillTreeTable.getInstance().getSkillEnchantmentBySkillId(_skillId);
  129. // do we have this skill?
  130. if (enchantLearn != null)
  131. {
  132. // skill already enchanted?
  133. if (_skillLvl > 100)
  134. {
  135. // get current enchant type
  136. int currentType = L2EnchantSkillLearn.getEnchantType(_skillLvl);
  137. List<EnchantSkillDetail>[] routes = enchantLearn.getEnchantRoutes();
  138. List<EnchantSkillDetail> route;
  139. for (int i = 0; i < routes.length; i++)
  140. {
  141. // skip current route
  142. if (i != currentType)
  143. {
  144. route = routes[i];
  145. EnchantSkillDetail esd = route.get(L2EnchantSkillLearn.getEnchantIndex(_skillLvl));
  146. if (esd != null)
  147. {
  148. asi.addEnchantSkillDetail(activeChar, esd);
  149. }
  150. }
  151. }
  152. sendPacket(asi);
  153. }
  154. else
  155. {
  156. _log.warning("Client: "+this.getClient()+" requested change route information for unenchanted skill");
  157. }
  158. }
  159. }
  160. public void showUntrainEnchantInfo(L2PcInstance activeChar)
  161. {
  162. ExEnchantSkillInfo asi = new ExEnchantSkillInfo(EnchantSkillType.UNTRAIN, _skillId);
  163. L2EnchantSkillLearn enchantLearn = SkillTreeTable.getInstance().getSkillEnchantmentBySkillId(_skillId);
  164. // do we have this skill?
  165. if (enchantLearn != null)
  166. {
  167. // skill already enchanted?
  168. if (_skillLvl > 100)
  169. {
  170. EnchantSkillDetail currentLevelDetail = enchantLearn.getEnchantSkillDetail(_skillLvl);
  171. if (currentLevelDetail != null)
  172. {
  173. // no previous enchant level, return to original
  174. if (_skillLvl%100 == 1)
  175. {
  176. asi.addEnchantSkillDetail(enchantLearn.getBaseLevel(), 100, currentLevelDetail.getSpCost(), currentLevelDetail.getExp());
  177. }
  178. else
  179. {
  180. // get detail for previous level
  181. EnchantSkillDetail esd = enchantLearn.getEnchantSkillDetail(_skillLvl - 1);
  182. // if it exists add it
  183. if (esd != null)
  184. {
  185. asi.addEnchantSkillDetail(esd.getLevel(), 100, currentLevelDetail.getSpCost(), currentLevelDetail.getExp());
  186. }
  187. }
  188. }
  189. else
  190. {
  191. _log.warning("Client: "+this.getClient()+" tried to untrain enchanted skill, but server doesnt has data for his current skill enchantment level");
  192. }
  193. sendPacket(asi);
  194. }
  195. else
  196. {
  197. _log.warning("Client: "+this.getClient()+" requested untrain information for unenchanted skill");
  198. }
  199. }
  200. }
  201. /* (non-Javadoc)
  202. * @see net.sf.l2j.gameserver.BasePacket#getType()
  203. */
  204. @Override
  205. public String getType()
  206. {
  207. return _C__D0_06_REQUESTEXENCHANTSKILLINFO;
  208. }
  209. }