ExEnchantSkillInfoDetail.java 3.8 KB

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