AcquireSkillInfo.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.Config;
  23. import com.l2jserver.gameserver.model.L2SkillLearn;
  24. import com.l2jserver.gameserver.model.base.AcquireSkillType;
  25. import com.l2jserver.gameserver.model.holders.ItemHolder;
  26. import com.l2jserver.gameserver.model.skills.CommonSkill;
  27. /**
  28. * Acquire Skill Info server packet implementation.
  29. * @author Zoey76
  30. */
  31. public class AcquireSkillInfo extends L2GameServerPacket
  32. {
  33. private final AcquireSkillType _type;
  34. private final int _id;
  35. private final int _level;
  36. private final int _spCost;
  37. private final List<Req> _reqs;
  38. /**
  39. * Private class containing learning skill requisites.
  40. */
  41. private static class Req
  42. {
  43. public int itemId;
  44. public long count;
  45. public int type;
  46. public int unk;
  47. /**
  48. * @param pType TODO identify.
  49. * @param pItemId the item Id.
  50. * @param itemCount the item count.
  51. * @param pUnk TODO identify.
  52. */
  53. public Req(int pType, int pItemId, long itemCount, int pUnk)
  54. {
  55. itemId = pItemId;
  56. type = pType;
  57. count = itemCount;
  58. unk = pUnk;
  59. }
  60. }
  61. /**
  62. * Constructor for the acquire skill info object.
  63. * @param skillType the skill learning type.
  64. * @param skillLearn the skill learn.
  65. */
  66. public AcquireSkillInfo(AcquireSkillType skillType, L2SkillLearn skillLearn)
  67. {
  68. _id = skillLearn.getSkillId();
  69. _level = skillLearn.getSkillLevel();
  70. _spCost = skillLearn.getLevelUpSp();
  71. _type = skillType;
  72. _reqs = new ArrayList<>();
  73. if ((skillType != AcquireSkillType.PLEDGE) || Config.LIFE_CRYSTAL_NEEDED)
  74. {
  75. for (ItemHolder item : skillLearn.getRequiredItems())
  76. {
  77. if (!Config.DIVINE_SP_BOOK_NEEDED && (_id == CommonSkill.DIVINE_INSPIRATION.getId()))
  78. {
  79. continue;
  80. }
  81. _reqs.add(new Req(99, item.getId(), item.getCount(), 50));
  82. }
  83. }
  84. }
  85. /**
  86. * Special constructor for Alternate Skill Learning system.<br>
  87. * Sets a custom amount of SP.
  88. * @param skillType the skill learning type.
  89. * @param skillLearn the skill learn.
  90. * @param sp the custom SP amount.
  91. */
  92. public AcquireSkillInfo(AcquireSkillType skillType, L2SkillLearn skillLearn, int sp)
  93. {
  94. _id = skillLearn.getSkillId();
  95. _level = skillLearn.getSkillLevel();
  96. _spCost = sp;
  97. _type = skillType;
  98. _reqs = new ArrayList<>();
  99. for (ItemHolder item : skillLearn.getRequiredItems())
  100. {
  101. _reqs.add(new Req(99, item.getId(), item.getCount(), 50));
  102. }
  103. }
  104. @Override
  105. protected final void writeImpl()
  106. {
  107. writeC(0x91);
  108. writeD(_id);
  109. writeD(_level);
  110. writeD(_spCost);
  111. writeD(_type.ordinal());
  112. writeD(_reqs.size());
  113. for (Req temp : _reqs)
  114. {
  115. writeD(temp.type);
  116. writeD(temp.itemId);
  117. writeQ(temp.count);
  118. writeD(temp.unk);
  119. }
  120. }
  121. }