GroupedGeneralDropItem.java 3.6 KB

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