L2DropData.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright (C) 2004-2013 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;
  20. import java.util.Arrays;
  21. /**
  22. * Special thanks to nuocnam.
  23. * @author LittleVexy
  24. */
  25. public class L2DropData
  26. {
  27. public static final int MAX_CHANCE = 1000000;
  28. private int _itemId;
  29. private int _minDrop;
  30. private int _maxDrop;
  31. private double _chance;
  32. private String _questID = null;
  33. private String[] _stateID = null;
  34. public L2DropData()
  35. {
  36. }
  37. public L2DropData(int id, int min, int max, double chance)
  38. {
  39. _itemId = id;
  40. _minDrop = min;
  41. _maxDrop = max;
  42. _chance = chance;
  43. }
  44. /**
  45. * Returns the ID of the item dropped
  46. * @return int
  47. */
  48. public int getItemId()
  49. {
  50. return _itemId;
  51. }
  52. /**
  53. * Sets the ID of the item dropped
  54. * @param itemId : int designating the ID of the item
  55. */
  56. public void setItemId(int itemId)
  57. {
  58. _itemId = itemId;
  59. }
  60. /**
  61. * Returns the minimum quantity of items dropped
  62. * @return int
  63. */
  64. public int getMinDrop()
  65. {
  66. return _minDrop;
  67. }
  68. /**
  69. * Returns the maximum quantity of items dropped
  70. * @return int
  71. */
  72. public int getMaxDrop()
  73. {
  74. return _maxDrop;
  75. }
  76. /**
  77. * Returns the chance of having a drop
  78. * @return int
  79. */
  80. public double getChance()
  81. {
  82. return _chance;
  83. }
  84. /**
  85. * Sets the value for minimal quantity of dropped items
  86. * @param mindrop : int designating the quantity
  87. */
  88. public void setMinDrop(int mindrop)
  89. {
  90. _minDrop = mindrop;
  91. }
  92. /**
  93. * Sets the value for maximal quantity of dopped items
  94. * @param maxdrop : int designating the quantity of dropped items
  95. */
  96. public void setMaxDrop(int maxdrop)
  97. {
  98. _maxDrop = maxdrop;
  99. }
  100. /**
  101. * Sets the chance of having the item for a drop
  102. * @param chance : int designating the chance
  103. */
  104. public void setChance(double chance)
  105. {
  106. _chance = chance;
  107. }
  108. /**
  109. * Returns the stateID.
  110. * @return String[]
  111. */
  112. public String[] getStateIDs()
  113. {
  114. return _stateID;
  115. }
  116. /**
  117. * Adds states of the dropped item
  118. * @param list : String[]
  119. */
  120. public void addStates(String[] list)
  121. {
  122. _stateID = list;
  123. }
  124. /**
  125. * Returns the questID.
  126. * @return String designating the ID of the quest
  127. */
  128. public String getQuestID()
  129. {
  130. return _questID;
  131. }
  132. /**
  133. * Sets the questID
  134. * @param questID the quest Id to set.
  135. */
  136. public void setQuestID(String questID)
  137. {
  138. _questID = questID;
  139. }
  140. /**
  141. * Returns if the dropped item is requested for a quest
  142. * @return boolean
  143. */
  144. public boolean isQuestDrop()
  145. {
  146. return (_questID != null) && (_stateID != null);
  147. }
  148. /**
  149. * Returns a report of the object
  150. * @return String
  151. */
  152. @Override
  153. public String toString()
  154. {
  155. String out = "ItemID: " + getItemId() + " Min: " + getMinDrop() + " Max: " + getMaxDrop() + " Chance: " + (getChance() / 10000.0) + "%";
  156. if (isQuestDrop())
  157. {
  158. out += " QuestID: " + getQuestID() + " StateID's: " + Arrays.toString(getStateIDs());
  159. }
  160. return out;
  161. }
  162. @Override
  163. public int hashCode()
  164. {
  165. final int prime = 31;
  166. int result = 1;
  167. result = (prime * result) + _itemId;
  168. return result;
  169. }
  170. @Override
  171. public boolean equals(Object obj)
  172. {
  173. if (this == obj)
  174. {
  175. return true;
  176. }
  177. if (obj == null)
  178. {
  179. return false;
  180. }
  181. if (!(obj instanceof L2DropData))
  182. {
  183. return false;
  184. }
  185. final L2DropData other = (L2DropData) obj;
  186. if (_itemId != other._itemId)
  187. {
  188. return false;
  189. }
  190. return true;
  191. }
  192. }