GeneralDropItem.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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.List;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.drops.strategy.IAmountMultiplierStrategy;
  23. import com.l2jserver.gameserver.model.drops.strategy.IChanceMultiplierStrategy;
  24. import com.l2jserver.gameserver.model.drops.strategy.IDropCalculationStrategy;
  25. import com.l2jserver.gameserver.model.drops.strategy.IKillerChanceModifierStrategy;
  26. import com.l2jserver.gameserver.model.drops.strategy.INonGroupedKillerChanceModifierStrategy;
  27. import com.l2jserver.gameserver.model.drops.strategy.IPreciseDeterminationStrategy;
  28. import com.l2jserver.gameserver.model.holders.ItemHolder;
  29. /**
  30. * @author NosBit
  31. */
  32. public final class GeneralDropItem implements IDropItem
  33. {
  34. private final int _itemId;
  35. private final long _min;
  36. private final long _max;
  37. private final double _chance;
  38. protected final IAmountMultiplierStrategy _amountStrategy;
  39. protected final IChanceMultiplierStrategy _chanceStrategy;
  40. protected final IPreciseDeterminationStrategy _preciseStrategy;
  41. protected final INonGroupedKillerChanceModifierStrategy _killerStrategy;
  42. protected final IDropCalculationStrategy _dropCalculationStrategy;
  43. /**
  44. * @param itemId the item id
  45. * @param min the min count
  46. * @param max the max count
  47. * @param chance the chance of this drop item
  48. */
  49. public GeneralDropItem(int itemId, long min, long max, double chance)
  50. {
  51. this(itemId, min, max, chance, 1, 1);
  52. }
  53. public GeneralDropItem(int itemId, long min, long max, double chance, double defaultAmountMultiplier, double defaultChanceMultiplier)
  54. {
  55. this(itemId, min, max, defaultChanceMultiplier, IAmountMultiplierStrategy.DEFAULT_STRATEGY(defaultAmountMultiplier), IChanceMultiplierStrategy.DEFAULT_STRATEGY(defaultChanceMultiplier));
  56. }
  57. public GeneralDropItem(int itemId, long min, long max, double chance, IAmountMultiplierStrategy amountMultiplierStrategy, IChanceMultiplierStrategy chanceMultiplierStrategy)
  58. {
  59. this(itemId, min, max, chance, amountMultiplierStrategy, chanceMultiplierStrategy, IPreciseDeterminationStrategy.DEFAULT, IKillerChanceModifierStrategy.DEFAULT_NONGROUP_STRATEGY);
  60. }
  61. public GeneralDropItem(int itemId, long min, long max, double chance, IAmountMultiplierStrategy amountMultiplierStrategy, IChanceMultiplierStrategy chanceMultiplierStrategy, IPreciseDeterminationStrategy preciseStrategy, INonGroupedKillerChanceModifierStrategy killerStrategy)
  62. {
  63. this(itemId, min, max, chance, amountMultiplierStrategy, chanceMultiplierStrategy, preciseStrategy, killerStrategy, IDropCalculationStrategy.DEFAULT_STRATEGY);
  64. }
  65. public GeneralDropItem(int itemId, long min, long max, double chance, IAmountMultiplierStrategy amountMultiplierStrategy, IChanceMultiplierStrategy chanceMultiplierStrategy, IPreciseDeterminationStrategy preciseStrategy, INonGroupedKillerChanceModifierStrategy killerStrategy, IDropCalculationStrategy dropCalculationStrategy)
  66. {
  67. _itemId = itemId;
  68. _min = min;
  69. _max = max;
  70. _chance = chance;
  71. _amountStrategy = amountMultiplierStrategy;
  72. _chanceStrategy = chanceMultiplierStrategy;
  73. _preciseStrategy = preciseStrategy;
  74. _killerStrategy = killerStrategy;
  75. _dropCalculationStrategy = dropCalculationStrategy;
  76. }
  77. /**
  78. * @return the _amountStrategy
  79. */
  80. public final IAmountMultiplierStrategy getAmountStrategy()
  81. {
  82. return _amountStrategy;
  83. }
  84. /**
  85. * @return the _chanceStrategy
  86. */
  87. public final IChanceMultiplierStrategy getChanceStrategy()
  88. {
  89. return _chanceStrategy;
  90. }
  91. /**
  92. * @return the _preciseStrategy
  93. */
  94. public final IPreciseDeterminationStrategy getPreciseStrategy()
  95. {
  96. return _preciseStrategy;
  97. }
  98. /**
  99. * @return the _killerStrategy
  100. */
  101. public final INonGroupedKillerChanceModifierStrategy getKillerChanceModifierStrategy()
  102. {
  103. return _killerStrategy;
  104. }
  105. /**
  106. * @return the _dropCalculationStrategy
  107. */
  108. public final IDropCalculationStrategy getDropCalculationStrategy()
  109. {
  110. return _dropCalculationStrategy;
  111. }
  112. /**
  113. * Gets the item id
  114. * @return the item id
  115. */
  116. public final int getItemId()
  117. {
  118. return _itemId;
  119. }
  120. /**
  121. * Gets the base min drop count
  122. * @return the min
  123. */
  124. public final long getMin()
  125. {
  126. return _min;
  127. }
  128. /**
  129. * Gets the min drop count modified by server rates
  130. * @param victim the victim who drops the item
  131. * @return the min modified by any rates.
  132. */
  133. public final long getMin(L2Character victim)
  134. {
  135. return (long) (getMin() * getAmountMultiplier(victim));
  136. }
  137. /**
  138. * Gets the base max drop count
  139. * @return the max
  140. */
  141. public final long getMax()
  142. {
  143. return _max;
  144. }
  145. /**
  146. * Gets the max drop count modified by server rates
  147. * @param victim the victim who drops the item
  148. * @return the max modified by any rates.
  149. */
  150. public final long getMax(L2Character victim)
  151. {
  152. return (long) (getMax() * getAmountMultiplier(victim));
  153. }
  154. /**
  155. * Gets the chance of this drop item.
  156. * @return the chance
  157. */
  158. public final double getChance()
  159. {
  160. return _chance;
  161. }
  162. /**
  163. * Gets the general chance to drop this item modified by rates. <br>
  164. * This shall be used in calculating chance within drop groups.
  165. * @param victim the victim who drops the item
  166. * @return the chance modified by any rates.
  167. */
  168. public final double getChance(L2Character victim)
  169. {
  170. return getChance() * getChanceMultiplier(victim);
  171. }
  172. /**
  173. * Gets the chance of dropping this item for current killer and victim (modified by server rates and another rules based on killer) <br>
  174. * This shall be used to calculate chance outside of drop groups.
  175. * @param victim the victim who drops the item
  176. * @param killer who kills the victim
  177. * @return a chance to drop modified by deep blue drop rules
  178. */
  179. public final double getChance(L2Character victim, L2Character killer)
  180. {
  181. return (getKillerChanceModifier(victim, killer) * getChance(victim));
  182. }
  183. @Override
  184. public final List<ItemHolder> calculateDrops(L2Character victim, L2Character killer)
  185. {
  186. return _dropCalculationStrategy.calculateDrops(this, victim, killer);
  187. }
  188. /**
  189. * @return <code>true</code> if chance over 100% should be handled
  190. */
  191. public final boolean isPreciseCalculated()
  192. {
  193. return _preciseStrategy.isPreciseCalculated(this);
  194. }
  195. /**
  196. * This handles by default deep blue drop rules. It may also be used to handle another drop chance rules based on killer
  197. * @param victim the victim who drops the item
  198. * @param killer who kills the victim
  199. * @return a number between 0 and 1 (usually)
  200. */
  201. protected final double getKillerChanceModifier(L2Character victim, L2Character killer)
  202. {
  203. return _killerStrategy.getKillerChanceModifier(this, victim, killer);
  204. }
  205. /**
  206. * This gets standard server rates for this item
  207. * @param victim who drops the item
  208. * @return
  209. */
  210. protected final double getAmountMultiplier(L2Character victim)
  211. {
  212. return _amountStrategy.getAmountMultiplier(this, victim);
  213. }
  214. /**
  215. * This gets standard server rates for this item
  216. * @param victim who drops the item
  217. * @return
  218. */
  219. protected final double getChanceMultiplier(L2Character victim)
  220. {
  221. return _chanceStrategy.getChanceMultiplier(this, victim);
  222. }
  223. }