GeneralDropItem.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.List;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.holders.ItemHolder;
  25. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  26. import com.l2jserver.gameserver.util.Util;
  27. import com.l2jserver.util.Rnd;
  28. /**
  29. * @author Nos
  30. */
  31. public class GeneralDropItem implements IDropItem
  32. {
  33. private final int _itemId;
  34. private final long _min;
  35. private final long _max;
  36. private final double _chance;
  37. /**
  38. * @param itemId the item id
  39. * @param min the min count
  40. * @param max the max count
  41. * @param chance the chance of this drop item
  42. */
  43. public GeneralDropItem(int itemId, long min, long max, double chance)
  44. {
  45. _itemId = itemId;
  46. _min = min;
  47. _max = max;
  48. _chance = chance;
  49. }
  50. /**
  51. * Gets the item id
  52. * @return the item id
  53. */
  54. public int getItemId()
  55. {
  56. return _itemId;
  57. }
  58. /**
  59. * Gets the min drop count
  60. * @return the min
  61. */
  62. public long getMin()
  63. {
  64. return _min;
  65. }
  66. /**
  67. * Gets the min drop count
  68. * @param victim the victim
  69. * @param killer the killer
  70. * @return the min modified by any rates.
  71. */
  72. public long getMin(L2Character victim, L2Character killer)
  73. {
  74. double multiplier = 1;
  75. if (victim.isChampion())
  76. {
  77. multiplier *= getItemId() != Inventory.ADENA_ID ? Config.L2JMOD_CHAMPION_REWARDS : Config.L2JMOD_CHAMPION_ADENAS_REWARDS;
  78. }
  79. Float dropChanceMultiplier = Config.RATE_DROP_AMOUNT_MULTIPLIER.get(getItemId());
  80. if (dropChanceMultiplier != null)
  81. {
  82. multiplier *= dropChanceMultiplier;
  83. }
  84. return (long) (getMin() * multiplier);
  85. }
  86. /**
  87. * Gets the max drop count
  88. * @return the max
  89. */
  90. public long getMax()
  91. {
  92. return _max;
  93. }
  94. /**
  95. * Gets the max drop count
  96. * @param victim the victim
  97. * @param killer the killer
  98. * @return the max modified by any rates.
  99. */
  100. public long getMax(L2Character victim, L2Character killer)
  101. {
  102. double multiplier = 1;
  103. if (victim.isChampion())
  104. {
  105. multiplier *= getItemId() != Inventory.ADENA_ID ? Config.L2JMOD_CHAMPION_REWARDS : Config.L2JMOD_CHAMPION_ADENAS_REWARDS;
  106. }
  107. Float dropChanceMultiplier = Config.RATE_DROP_AMOUNT_MULTIPLIER.get(getItemId());
  108. if (dropChanceMultiplier != null)
  109. {
  110. multiplier *= dropChanceMultiplier;
  111. }
  112. return (long) (getMax() * multiplier);
  113. }
  114. /**
  115. * Gets the chance of this drop item.
  116. * @return the chance
  117. */
  118. public double getChance()
  119. {
  120. return _chance;
  121. }
  122. /**
  123. * Gets the chance of this drop item.
  124. * @param victim the victim
  125. * @param killer the killer
  126. * @return the chance modified by any rates.
  127. */
  128. public double getChance(L2Character victim, L2Character killer)
  129. {
  130. float multiplier = 1;
  131. Float dropChanceMultiplier = Config.RATE_DROP_CHANCE_MULTIPLIER.get(getItemId());
  132. if (dropChanceMultiplier != null)
  133. {
  134. multiplier *= dropChanceMultiplier;
  135. }
  136. return getChance() * multiplier;
  137. }
  138. /*
  139. * (non-Javadoc)
  140. * @see com.l2jserver.gameserver.model.drop.IDropItem#calculateDrops(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.actor.L2Character)
  141. */
  142. @Override
  143. public List<ItemHolder> calculateDrops(L2Character victim, L2Character killer)
  144. {
  145. final int levelDifference = victim.getLevel() - killer.getLevel();
  146. final double levelGapChanceToDrop;
  147. if (getItemId() == Inventory.ADENA_ID)
  148. {
  149. levelGapChanceToDrop = Util.map(levelDifference, -Config.DROP_ADENA_MAX_LEVEL_DIFFERENCE, -Config.DROP_ADENA_MIN_LEVEL_DIFFERENCE, Config.DROP_ADENA_MIN_LEVEL_GAP_CHANCE, 100.0);
  150. }
  151. else
  152. {
  153. 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);
  154. }
  155. // There is a chance of level gap that it wont drop this item
  156. if (levelGapChanceToDrop < (Rnd.nextDouble() * 100))
  157. {
  158. return null;
  159. }
  160. if (getChance(victim, killer) > (Rnd.nextDouble() * 100))
  161. {
  162. final long amount = Rnd.get(getMin(victim, killer), getMax(victim, killer));
  163. final List<ItemHolder> items = new ArrayList<>(1);
  164. items.add(new ItemHolder(getItemId(), amount));
  165. return items;
  166. }
  167. return null;
  168. }
  169. }