ExEnchantSkillInfo.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.serverpackets;
  16. import javolution.util.FastList;
  17. import net.sf.l2j.gameserver.datatables.SkillTreeTable;
  18. import net.sf.l2j.gameserver.model.L2EnchantSkillLearn.EnchantSkillDetail;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.serverpackets.ExEnchantSkillList.EnchantSkillType;
  21. public final class ExEnchantSkillInfo extends L2GameServerPacket
  22. {
  23. private static final String _S__FE_18_EXENCHANTSKILLINFO = "[S] FE:2a ExEnchantSkillInfo";
  24. private FastList<SkillEnchantDetailElement> _routes;
  25. private final int _id;
  26. private final EnchantSkillType _type;
  27. private final int _xpSpCostMultiplier;
  28. public ExEnchantSkillInfo(EnchantSkillType type, int id)
  29. {
  30. _routes = new FastList<SkillEnchantDetailElement>();
  31. _id = id;
  32. _type = type;
  33. _xpSpCostMultiplier = (type == EnchantSkillType.SAFE ? SkillTreeTable.SAFE_ENCHANT_COST_MULTIPLIER : SkillTreeTable.NORMAL_ENCHANT_COST_MULTIPLIER);
  34. }
  35. static class SkillEnchantDetailElement
  36. {
  37. public final int _level;
  38. public final int _rate;
  39. public final int _spCost;
  40. public final int _expCost;
  41. public SkillEnchantDetailElement(int level, int rate, int spCost, int expCost)
  42. {
  43. _level = level;
  44. _rate = rate;
  45. _spCost = spCost;
  46. _expCost = expCost;
  47. }
  48. public SkillEnchantDetailElement(L2PcInstance cha, EnchantSkillDetail esd)
  49. {
  50. this(esd.getLevel(), esd.getRate(cha), esd.getSpCost(), esd.getExp());
  51. }
  52. public SkillEnchantDetailElement(int rate, EnchantSkillDetail esd)
  53. {
  54. this(esd.getLevel(), rate, esd.getSpCost(), esd.getExp());
  55. }
  56. }
  57. public void addEnchantSkillDetail(L2PcInstance cha, EnchantSkillDetail esd)
  58. {
  59. _routes.add(new SkillEnchantDetailElement(cha, esd));
  60. }
  61. public void addEnchantSkillDetail(int rate, EnchantSkillDetail esd)
  62. {
  63. _routes.add(new SkillEnchantDetailElement(rate, esd));
  64. }
  65. public void addEnchantSkillDetail(int level, int rate, int spCost, int expCost)
  66. {
  67. _routes.add(new SkillEnchantDetailElement(level, rate, spCost, expCost));
  68. }
  69. /* (non-Javadoc)
  70. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#writeImpl()
  71. */
  72. @Override
  73. protected void writeImpl()
  74. {
  75. writeC(0xfe);
  76. writeH(0x2a);
  77. writeD(_type.ordinal()); // safe enchant
  78. writeD(_routes.size());
  79. for (SkillEnchantDetailElement sede : _routes)
  80. {
  81. writeD(_id);
  82. writeD(sede._level);
  83. writeD(sede._rate);
  84. writeD(sede._spCost * _xpSpCostMultiplier);
  85. writeQ(sede._expCost * _xpSpCostMultiplier);
  86. writeD(0); // required item count
  87. writeD(0); // req type?
  88. writeD(0); // required itemId
  89. writeD(0); // ?
  90. }
  91. }
  92. /* (non-Javadoc)
  93. * @see net.sf.l2j.gameserver.BasePacket#getType()
  94. */
  95. @Override
  96. public String getType()
  97. {
  98. return _S__FE_18_EXENCHANTSKILLINFO;
  99. }
  100. }