ExEnchantSkillInfo.java 3.2 KB

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