Extractable.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 handlers.skillhandlers;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.datatables.ItemTable;
  18. import com.l2jserver.gameserver.handler.ISkillHandler;
  19. import com.l2jserver.gameserver.model.L2ExtractableProductItem;
  20. import com.l2jserver.gameserver.model.L2ExtractableSkill;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.L2Skill;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  27. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  28. import com.l2jserver.gameserver.util.Util;
  29. import com.l2jserver.util.Rnd;
  30. /**
  31. * @author Zoey76, based on previous version.
  32. */
  33. public class Extractable implements ISkillHandler
  34. {
  35. //FIXME: Remove this once skill reuse will be global for main/subclass.
  36. private static final int[] protectedSkillIds = { 323, 324, 419, 519, 520, 620, 1324, 1387 };
  37. private static final L2SkillType[] SKILL_TYPES =
  38. {
  39. L2SkillType.EXTRACTABLE,
  40. L2SkillType.EXTRACTABLE_FISH
  41. };
  42. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  43. {
  44. if (!(activeChar instanceof L2PcInstance))
  45. {
  46. return;
  47. }
  48. L2ExtractableSkill exItem = skill.getExtractableSkill();
  49. if (exItem == null)
  50. {
  51. return;
  52. }
  53. if (exItem.getProductItemsArray().isEmpty())
  54. {
  55. _log.warning("Extractable Item Skill with no data, probably wrong/empty table with Skill Id: " + skill.getId());
  56. return;
  57. }
  58. final double rndNum = 100 * Rnd.nextDouble();
  59. double chance = 0;
  60. double chanceFrom = 0;
  61. int[] createItemID = new int[20];
  62. int[] createAmount = new int[20];
  63. //Explanation for future changes:
  64. //You get one chance for the current skill, then you can fall into
  65. //one of the "areas" like in a roulette.
  66. //Example: for an item like Id1,A1,30;Id2,A2,50;Id3,A3,20;
  67. //#---#-----#--#
  68. //0 30 80 100
  69. //If you get chance equal 45% you fall into the second zone 30-80.
  70. //Meaning you get the second production list.
  71. //Calculate extraction
  72. for (L2ExtractableProductItem expi : exItem.getProductItemsArray())
  73. {
  74. chance = expi.getChance();
  75. if ((rndNum >= chanceFrom) && (rndNum <= (chance + chanceFrom)))
  76. {
  77. for (int i = 0; i < expi.getId().length; i++)
  78. {
  79. createItemID[i] = expi.getId()[i];
  80. if (skill.getSkillType() == L2SkillType.EXTRACTABLE_FISH)
  81. {
  82. createAmount[i] = (int) (expi.getAmmount()[i] * Config.RATE_EXTR_FISH);
  83. }
  84. else
  85. {
  86. createAmount[i] = expi.getAmmount()[i];
  87. }
  88. }
  89. break;
  90. }
  91. chanceFrom += chance;
  92. }
  93. L2PcInstance player = (L2PcInstance) activeChar;
  94. //FIXME: Remove this once skill reuse will be global for main/subclass.
  95. if (player.isSubClassActive() && (skill.getReuseDelay() > 0) && !Util.contains(protectedSkillIds, skill.getId()))
  96. {
  97. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.MAIN_CLASS_SKILL_ONLY));
  98. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED).addSkillName(skill));
  99. return;
  100. }
  101. if (createItemID[0] <= 0)
  102. {
  103. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOTHING_INSIDE_THAT));
  104. return;
  105. }
  106. else
  107. {
  108. for (int i = 0; i < createItemID.length; i++)
  109. {
  110. if (createItemID[i] <= 0)
  111. {
  112. continue;
  113. }
  114. if (ItemTable.getInstance().createDummyItem(createItemID[i]) == null)
  115. {
  116. _log.warning("Extractable Item Skill Id:" + skill.getId() + " createItemID " + createItemID[i] + " doesn't have a template!");
  117. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOTHING_INSIDE_THAT));
  118. return;
  119. }
  120. if (ItemTable.getInstance().createDummyItem(createItemID[i]).isStackable())
  121. {
  122. player.addItem("Extract", createItemID[i], createAmount[i], targets[0], false);
  123. }
  124. else
  125. {
  126. for (int j = 0; j < createAmount[i]; j++)
  127. {
  128. player.addItem("Extract", createItemID[i], 1, targets[0], false);
  129. }
  130. }
  131. if (createItemID[i] == 57)
  132. {
  133. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S1_ADENA);;
  134. sm.addNumber(createAmount[i]);
  135. player.sendPacket(sm);
  136. }
  137. else
  138. {
  139. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S);;
  140. sm.addItemName(createItemID[i]);
  141. if (createAmount[i] > 1)
  142. {
  143. sm.addNumber(createAmount[i]);
  144. }
  145. player.sendPacket(sm);
  146. }
  147. }
  148. }
  149. }
  150. public L2SkillType[] getSkillIds()
  151. {
  152. return SKILL_TYPES;
  153. }
  154. }