ExEnchantSkillInfoDetail.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.Config;
  17. import com.l2jserver.gameserver.datatables.EnchantGroupsTable;
  18. import com.l2jserver.gameserver.model.L2EnchantSkillLearn;
  19. import com.l2jserver.gameserver.model.L2EnchantSkillGroup.EnchantSkillDetail;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. /**
  22. *
  23. * @author KenM
  24. */
  25. public class ExEnchantSkillInfoDetail extends L2GameServerPacket
  26. {
  27. private static final int TYPE_NORMAL_ENCHANT = 0;
  28. private static final int TYPE_SAFE_ENCHANT = 1;
  29. private static final int TYPE_UNTRAIN_ENCHANT = 2;
  30. private static final int TYPE_CHANGE_ENCHANT = 3;
  31. private int bookId = 0;
  32. private int reqCount = 0;
  33. private int multi = 1;
  34. private final int _type;
  35. private final int _skillid;
  36. private final int _skilllvl;
  37. private final int _chance;
  38. private int _sp;
  39. private final int _adenacount;
  40. public ExEnchantSkillInfoDetail(int type, int skillid, int skilllvl, L2PcInstance ply)
  41. {
  42. L2EnchantSkillLearn enchantLearn = EnchantGroupsTable.getInstance().getSkillEnchantmentBySkillId(skillid);
  43. EnchantSkillDetail esd = null;
  44. // do we have this skill?
  45. if (enchantLearn != null)
  46. {
  47. if (skilllvl > 100)
  48. {
  49. esd = enchantLearn.getEnchantSkillDetail(skilllvl);
  50. }
  51. else
  52. esd = enchantLearn.getFirstRouteGroup().getEnchantGroupDetails().get(0);
  53. }
  54. if (esd == null)
  55. throw new IllegalArgumentException("Skill "+skillid + " dont have enchant data for level "+skilllvl);
  56. if (type == 0)
  57. multi = EnchantGroupsTable.NORMAL_ENCHANT_COST_MULTIPLIER;
  58. else if (type == 1)
  59. multi = EnchantGroupsTable.SAFE_ENCHANT_COST_MULTIPLIER;
  60. _chance = esd.getRate(ply);
  61. _sp = esd.getSpCost();
  62. if (type == TYPE_UNTRAIN_ENCHANT)
  63. _sp = (int) (0.8 * _sp);
  64. _adenacount = esd.getAdenaCost() * multi;
  65. _type = type;
  66. _skillid = skillid;
  67. _skilllvl = skilllvl;
  68. switch (type)
  69. {
  70. case TYPE_NORMAL_ENCHANT:
  71. bookId = EnchantGroupsTable.NORMAL_ENCHANT_BOOK;
  72. reqCount = ((_skilllvl % 100 > 1) ? 0 : 1) ;
  73. break;
  74. case TYPE_SAFE_ENCHANT:
  75. bookId = EnchantGroupsTable.SAFE_ENCHANT_BOOK;
  76. reqCount = 1;
  77. break;
  78. case TYPE_UNTRAIN_ENCHANT:
  79. bookId = EnchantGroupsTable.UNTRAIN_ENCHANT_BOOK;
  80. reqCount = 1;
  81. break;
  82. case TYPE_CHANGE_ENCHANT:
  83. bookId = EnchantGroupsTable.CHANGE_ENCHANT_BOOK;
  84. reqCount = 1;
  85. break;
  86. default:
  87. return;
  88. }
  89. if (type != TYPE_SAFE_ENCHANT && !Config.ES_SP_BOOK_NEEDED)
  90. reqCount = 0;
  91. }
  92. /**
  93. * @see com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket#getType()
  94. */
  95. @Override
  96. public String getType()
  97. {
  98. return "[S] FE:5E ExEnchantSkillInfoDetail";
  99. }
  100. /**
  101. * @see com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket#writeImpl()
  102. */
  103. @Override
  104. protected void writeImpl()
  105. {
  106. writeC(0xfe);
  107. writeH(0x5e);
  108. writeD(_type);
  109. writeD(_skillid);
  110. writeD(_skilllvl);
  111. writeD(_sp * multi); // sp
  112. writeD(_chance); // exp
  113. writeD(2); // items count?
  114. writeD(57); // adena //TODO unhardcode me
  115. writeD(_adenacount); // adena count
  116. writeD(bookId); // ItemId Required
  117. writeD(reqCount);
  118. }
  119. }