GroupedGeneralDropItem.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2004-2014 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.model.drops;
  20. import java.util.ArrayList;
  21. import java.util.Collections;
  22. import java.util.List;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.instance.L2RaidBossInstance;
  25. import com.l2jserver.gameserver.model.holders.ItemHolder;
  26. import com.l2jserver.util.Rnd;
  27. /**
  28. * @author Nos
  29. */
  30. public class GroupedGeneralDropItem implements IDropItem
  31. {
  32. private final double _chance;
  33. private List<GeneralDropItem> _items;
  34. /**
  35. * @param chance the chance of this drop item.
  36. */
  37. public GroupedGeneralDropItem(double chance)
  38. {
  39. _chance = chance;
  40. }
  41. /**
  42. * Gets the chance of this drop item.
  43. * @return the chance
  44. */
  45. public double getChance()
  46. {
  47. return _chance;
  48. }
  49. /**
  50. * Gets the chance of this drop item.
  51. * @param victim the victim
  52. * @param killer the killer
  53. * @return the chance modified by any rates.
  54. */
  55. public double getChance(L2Character victim, L2Character killer)
  56. {
  57. return getChance();
  58. }
  59. /**
  60. * Gets the items.
  61. * @return the items
  62. */
  63. public List<GeneralDropItem> getItems()
  64. {
  65. return _items;
  66. }
  67. /**
  68. * Sets an item list to this drop item.
  69. * @param items the item list
  70. */
  71. public void setItems(List<GeneralDropItem> items)
  72. {
  73. _items = Collections.unmodifiableList(items);
  74. }
  75. /*
  76. * (non-Javadoc)
  77. * @see com.l2jserver.gameserver.model.drop.IDropItem#calculateDrops(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.actor.L2Character)
  78. */
  79. @Override
  80. public List<ItemHolder> calculateDrops(L2Character victim, L2Character killer)
  81. {
  82. int levelDifference = victim.getLevel() - killer.getLevel();
  83. double chanceModifier;
  84. if (victim instanceof L2RaidBossInstance)
  85. {
  86. chanceModifier = Math.max(0, Math.min(1, (levelDifference * 0.15) + 1));
  87. }
  88. else
  89. {
  90. chanceModifier = 1;
  91. double levelGapChanceToDrop;
  92. if (levelDifference >= -5)
  93. {
  94. levelGapChanceToDrop = 100;
  95. }
  96. else if (levelDifference >= -10)
  97. {
  98. levelGapChanceToDrop = levelDifference;
  99. levelGapChanceToDrop *= 18;
  100. levelGapChanceToDrop += 190;
  101. }
  102. else
  103. {
  104. levelGapChanceToDrop = 10;
  105. }
  106. // There is a chance of level gap that it wont drop this item
  107. if (levelGapChanceToDrop < (Rnd.nextDouble() * 100))
  108. {
  109. return null;
  110. }
  111. }
  112. if ((getChance(victim, killer) * chanceModifier) > (Rnd.nextDouble() * 100))
  113. {
  114. double random = (Rnd.nextDouble() * 100);
  115. double totalChance = 0;
  116. for (GeneralDropItem item : getItems())
  117. {
  118. // Grouped item chance rates should not be modified.
  119. totalChance += item.getChance();
  120. if (totalChance > random)
  121. {
  122. long amount = Rnd.get(item.getMin(victim, killer), item.getMax(victim, killer));
  123. List<ItemHolder> items = new ArrayList<>(1);
  124. items.add(new ItemHolder(item.getItemId(), amount));
  125. return items;
  126. }
  127. }
  128. }
  129. return null;
  130. }
  131. }