GeneralDropItem.java 5.2 KB

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