Extractable.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.templates.skills.L2SkillType;
  27. import com.l2jserver.util.Rnd;
  28. /**
  29. * @author Zoey76
  30. */
  31. public class Extractable implements ISkillHandler
  32. {
  33. private static final L2SkillType[] SKILL_TYPES =
  34. {
  35. L2SkillType.EXTRACTABLE,
  36. L2SkillType.EXTRACTABLE_FISH
  37. };
  38. @Override
  39. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  40. {
  41. if (!(activeChar instanceof L2PcInstance))
  42. {
  43. return;
  44. }
  45. final L2ExtractableSkill exItem = skill.getExtractableSkill();
  46. if (exItem == null)
  47. {
  48. return;
  49. }
  50. if (exItem.getProductItemsArray().isEmpty())
  51. {
  52. _log.warning("Extractable Item Skill with no data, probably wrong/empty table with Skill Id: " + skill.getId());
  53. return;
  54. }
  55. final double rndNum = 100 * Rnd.nextDouble();
  56. double chance = 0;
  57. double chanceFrom = 0;
  58. int[] createItemID = new int[20];
  59. int[] createAmount = new int[20];
  60. //Explanation for future changes:
  61. //You get one chance for the current skill, then you can fall into
  62. //one of the "areas" like in a roulette.
  63. //Example: for an item like Id1,A1,30;Id2,A2,50;Id3,A3,20;
  64. //#---#-----#--#
  65. //0 30 80 100
  66. //If you get chance equal 45% you fall into the second zone 30-80.
  67. //Meaning you get the second production list.
  68. //Calculate extraction
  69. for (L2ExtractableProductItem expi : exItem.getProductItemsArray())
  70. {
  71. chance = expi.getChance();
  72. if ((rndNum >= chanceFrom) && (rndNum <= (chance + chanceFrom)))
  73. {
  74. for (int i = 0; i < expi.getId().length; i++)
  75. {
  76. createItemID[i] = expi.getId()[i];
  77. if (skill.getSkillType() == L2SkillType.EXTRACTABLE_FISH)
  78. {
  79. createAmount[i] = (int) (expi.getAmmount()[i] * Config.RATE_EXTR_FISH);
  80. }
  81. else
  82. {
  83. createAmount[i] = expi.getAmmount()[i];
  84. }
  85. }
  86. break;
  87. }
  88. chanceFrom += chance;
  89. }
  90. final L2PcInstance player = activeChar.getActingPlayer();
  91. if (createItemID[0] <= 0)
  92. {
  93. player.sendPacket(SystemMessageId.NOTHING_INSIDE_THAT);
  94. return;
  95. }
  96. for (int i = 0; i < createItemID.length; i++)
  97. {
  98. if (createItemID[i] <= 0)
  99. {
  100. continue;
  101. }
  102. if (ItemTable.getInstance().createDummyItem(createItemID[i]) == null)
  103. {
  104. _log.warning("Extractable Item Skill Id:" + skill.getId() + " createItemID " + createItemID[i] + " doesn't have a template!");
  105. player.sendPacket(SystemMessageId.NOTHING_INSIDE_THAT);
  106. return;
  107. }
  108. if (ItemTable.getInstance().createDummyItem(createItemID[i]).isStackable())
  109. {
  110. player.addItem("Extract", createItemID[i], createAmount[i], targets[0], true);
  111. }
  112. else
  113. {
  114. for (int j = 0; j < createAmount[i]; j++)
  115. {
  116. player.addItem("Extract", createItemID[i], 1, targets[0], true);
  117. }
  118. }
  119. }
  120. }
  121. @Override
  122. public L2SkillType[] getSkillIds()
  123. {
  124. return SKILL_TYPES;
  125. }
  126. }