ExEnchantSkillInfo.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.serverpackets;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import com.l2jserver.gameserver.data.xml.impl.EnchantSkillGroupsData;
  23. import com.l2jserver.gameserver.model.L2EnchantSkillGroup.EnchantSkillHolder;
  24. import com.l2jserver.gameserver.model.L2EnchantSkillLearn;
  25. public final class ExEnchantSkillInfo extends L2GameServerPacket
  26. {
  27. private final List<Integer> _routes = new ArrayList<>(); // skill lvls for each route
  28. private final int _id;
  29. private final int _lvl;
  30. private boolean _maxEnchanted = false;
  31. public ExEnchantSkillInfo(int id, int lvl)
  32. {
  33. _id = id;
  34. _lvl = lvl;
  35. L2EnchantSkillLearn enchantLearn = EnchantSkillGroupsData.getInstance().getSkillEnchantmentBySkillId(_id);
  36. // do we have this skill?
  37. if (enchantLearn != null)
  38. {
  39. // skill already enchanted?
  40. if (_lvl > 100)
  41. {
  42. _maxEnchanted = enchantLearn.isMaxEnchant(_lvl);
  43. // get detail for next level
  44. EnchantSkillHolder esd = enchantLearn.getEnchantSkillHolder(_lvl);
  45. // if it exists add it
  46. if (esd != null)
  47. {
  48. _routes.add(_lvl); // current enchant add firts
  49. }
  50. int skillLvL = (_lvl % 100);
  51. for (int route : enchantLearn.getAllRoutes())
  52. {
  53. if (((route * 100) + skillLvL) == _lvl)
  54. {
  55. continue;
  56. }
  57. // add other levels of all routes - same lvl as enchanted
  58. // lvl
  59. _routes.add((route * 100) + skillLvL);
  60. }
  61. }
  62. else
  63. // not already enchanted
  64. {
  65. for (int route : enchantLearn.getAllRoutes())
  66. {
  67. // add first level (+1) of all routes
  68. _routes.add((route * 100) + 1);
  69. }
  70. }
  71. }
  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 (int level : _routes)
  84. {
  85. writeD(level);
  86. }
  87. }
  88. }