GeneralDropItem.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright (C) 2004-2015 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.Collection;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.datatables.ItemTable;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.holders.ItemHolder;
  26. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  27. import com.l2jserver.gameserver.model.items.L2Item;
  28. import com.l2jserver.gameserver.util.Util;
  29. import com.l2jserver.util.Rnd;
  30. /**
  31. * @author NosBit
  32. */
  33. public class GeneralDropItem implements IDropItem
  34. {
  35. private final int _itemId;
  36. private final long _min;
  37. private final long _max;
  38. private final double _chance;
  39. /**
  40. * @param itemId the item id
  41. * @param min the min count
  42. * @param max the max count
  43. * @param chance the chance of this drop item
  44. */
  45. public GeneralDropItem(int itemId, long min, long max, double chance)
  46. {
  47. _itemId = itemId;
  48. _min = min;
  49. _max = max;
  50. _chance = chance;
  51. }
  52. protected double getGlobalChanceMultiplier()
  53. {
  54. return 1.;
  55. }
  56. protected double getGlobalAmountMultiplier()
  57. {
  58. return 1.;
  59. }
  60. private final long getMinMax(L2Character victim, L2Character killer, long val)
  61. {
  62. double multiplier = 1;
  63. // individual drop amount
  64. Float individualDropAmountMultiplier = Config.RATE_DROP_AMOUNT_MULTIPLIER.get(getItemId());
  65. if (individualDropAmountMultiplier != null)
  66. {
  67. // individual amount list multiplier
  68. multiplier *= individualDropAmountMultiplier;
  69. }
  70. else
  71. {
  72. final L2Item item = ItemTable.getInstance().getTemplate(getItemId());
  73. // global amount multiplier
  74. if ((item != null) && item.hasExImmediateEffect())
  75. {
  76. // global herb amount multiplier
  77. multiplier *= Config.RATE_HERB_DROP_AMOUNT_MULTIPLIER;
  78. }
  79. else
  80. {
  81. // drop type specific amount multiplier
  82. multiplier *= getGlobalAmountMultiplier();
  83. }
  84. }
  85. // global champions amount multiplier
  86. if (victim.isChampion())
  87. {
  88. multiplier *= getItemId() != Inventory.ADENA_ID ? Config.L2JMOD_CHAMPION_REWARDS : Config.L2JMOD_CHAMPION_ADENAS_REWARDS;
  89. }
  90. return (long) (val * multiplier);
  91. }
  92. /**
  93. * Gets the item id
  94. * @return the item id
  95. */
  96. public int getItemId()
  97. {
  98. return _itemId;
  99. }
  100. /**
  101. * Gets the min drop count
  102. * @return the min
  103. */
  104. public long getMin()
  105. {
  106. return _min;
  107. }
  108. /**
  109. * Gets the min drop count
  110. * @param victim the victim
  111. * @param killer the killer
  112. * @return the min modified by any rates.
  113. */
  114. public long getMin(L2Character victim, L2Character killer)
  115. {
  116. return getMinMax(victim, killer, getMin());
  117. }
  118. /**
  119. * Gets the max drop count
  120. * @return the max
  121. */
  122. public long getMax()
  123. {
  124. return _max;
  125. }
  126. /**
  127. * Gets the max drop count
  128. * @param victim the victim
  129. * @param killer the killer
  130. * @return the max modified by any rates.
  131. */
  132. public long getMax(L2Character victim, L2Character killer)
  133. {
  134. return getMinMax(victim, killer, getMax());
  135. }
  136. /**
  137. * Gets the chance of this drop item.
  138. * @return the chance
  139. */
  140. public double getChance()
  141. {
  142. return _chance;
  143. }
  144. /**
  145. * Gets the chance of this drop item.
  146. * @param victim the victim
  147. * @param killer the killer
  148. * @return the chance modified by any rates.
  149. */
  150. public double getChance(L2Character victim, L2Character killer)
  151. {
  152. double multiplier = 1;
  153. // individual drop chance
  154. Float individualDropChanceMultiplier = Config.RATE_DROP_CHANCE_MULTIPLIER.get(getItemId());
  155. if (individualDropChanceMultiplier != null)
  156. {
  157. multiplier *= individualDropChanceMultiplier;
  158. }
  159. else
  160. {
  161. final L2Item item = ItemTable.getInstance().getTemplate(getItemId());
  162. if ((item != null) && item.hasExImmediateEffect())
  163. {
  164. multiplier *= Config.RATE_HERB_DROP_CHANCE_MULTIPLIER;
  165. }
  166. else
  167. {
  168. multiplier *= getGlobalChanceMultiplier();
  169. }
  170. }
  171. if (victim.isChampion())
  172. {
  173. multiplier *= Config.L2JMOD_CHAMPION_REWARDS;
  174. }
  175. return (getChance() * multiplier);
  176. }
  177. /*
  178. * (non-Javadoc)
  179. * @see com.l2jserver.gameserver.model.drop.IDropItem#calculateDrops(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.actor.L2Character)
  180. */
  181. @Override
  182. public Collection<ItemHolder> calculateDrops(L2Character victim, L2Character killer)
  183. {
  184. final int levelDifference = victim.getLevel() - killer.getLevel();
  185. final double levelGapChanceToDrop;
  186. if (getItemId() == Inventory.ADENA_ID)
  187. {
  188. 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);
  189. }
  190. else
  191. {
  192. 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);
  193. }
  194. // There is a chance of level gap that it wont drop this item
  195. if (levelGapChanceToDrop < (Rnd.nextDouble() * 100))
  196. {
  197. return null;
  198. }
  199. final double chance = getChance(victim, killer);
  200. int successes;
  201. if (!Config.L2JMOD_OLD_DROP_BEHAVIOR)
  202. {
  203. successes = chance > (Rnd.nextDouble() * 100) ? 1 : 0;
  204. }
  205. else
  206. {
  207. successes = (int) (chance / 100);
  208. successes += (chance % 100) > (Rnd.nextDouble() * 100) ? 1 : 0;
  209. }
  210. if (successes > 0)
  211. {
  212. final Collection<ItemHolder> items = new ArrayList<>(1);
  213. items.add(new ItemHolder(getItemId(), Rnd.get(getMin(victim, killer), getMax(victim, killer)) * successes));
  214. return items;
  215. }
  216. return null;
  217. }
  218. }