ExEnchantSkillInfo.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.serverpackets;
  16. import com.l2jserver.gameserver.datatables.EnchantGroupsTable;
  17. import com.l2jserver.gameserver.model.L2EnchantSkillLearn;
  18. import com.l2jserver.gameserver.model.L2EnchantSkillGroup.EnchantSkillDetail;
  19. import javolution.util.FastList;
  20. public final class ExEnchantSkillInfo extends L2GameServerPacket
  21. {
  22. private static final String _S__FE_18_EXENCHANTSKILLINFO = "[S] FE:2a ExEnchantSkillInfo";
  23. private FastList<Integer> _routes; //skill lvls for each route
  24. private final int _id;
  25. private final int _lvl;
  26. private boolean _maxEnchanted = false;
  27. public ExEnchantSkillInfo(int id, int lvl)
  28. {
  29. _routes = new FastList<Integer>();
  30. _id = id;
  31. _lvl = lvl;
  32. L2EnchantSkillLearn enchantLearn = EnchantGroupsTable.getInstance().getSkillEnchantmentBySkillId(_id);
  33. // do we have this skill?
  34. if (enchantLearn != null)
  35. {
  36. // skill already enchanted?
  37. if (_lvl > 100)
  38. {
  39. _maxEnchanted = enchantLearn.isMaxEnchant(_lvl);
  40. // get detail for next level
  41. EnchantSkillDetail esd = enchantLearn.getEnchantSkillDetail(_lvl);
  42. // if it exists add it
  43. if (esd != null)
  44. {
  45. _routes.add(_lvl); // current enchant add firts
  46. }
  47. int skillLvL = (_lvl % 100);
  48. for (int route : enchantLearn.getAllRoutes())
  49. {
  50. if ((route * 100 + skillLvL) == _lvl) // skip current
  51. continue;
  52. // add other levels of all routes - same lvl as enchanted
  53. // lvl
  54. _routes.add(route * 100 + skillLvL);
  55. }
  56. }
  57. else
  58. // not already enchanted
  59. {
  60. for (int route : enchantLearn.getAllRoutes())
  61. {
  62. // add first level (+1) of all routes
  63. _routes.add(route * 100 + 1);
  64. }
  65. }
  66. }
  67. }
  68. /*
  69. * (non-Javadoc)
  70. *
  71. * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#writeImpl()
  72. */
  73. @Override
  74. protected void writeImpl()
  75. {
  76. writeC(0xfe);
  77. writeH(0x2a);
  78. writeD(_id);
  79. writeD(_lvl);
  80. writeD(_maxEnchanted ? 0 : 1);
  81. writeD(_lvl > 100 ? 1 : 0); // enchanted?
  82. writeD(_routes.size());
  83. for (Integer level : _routes)
  84. {
  85. writeD(level);
  86. }
  87. }
  88. /*
  89. * (non-Javadoc)
  90. *
  91. * @see com.l2jserver.gameserver.BasePacket#getType()
  92. */
  93. @Override
  94. public String getType()
  95. {
  96. return _S__FE_18_EXENCHANTSKILLINFO;
  97. }
  98. }