L2DropData.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model;
  16. import java.util.Arrays;
  17. /**
  18. * Special thanks to nuocnam.
  19. * @author LittleVexy
  20. */
  21. public class L2DropData
  22. {
  23. public static final int MAX_CHANCE = 1000000;
  24. private int _itemId;
  25. private int _minDrop;
  26. private int _maxDrop;
  27. private double _chance;
  28. private String _questID = null;
  29. private String[] _stateID = null;
  30. public L2DropData()
  31. {
  32. }
  33. public L2DropData(int id, int min, int max, double chance)
  34. {
  35. _itemId = id;
  36. _minDrop = min;
  37. _maxDrop = max;
  38. _chance = chance;
  39. }
  40. /**
  41. * Returns the ID of the item dropped
  42. * @return int
  43. */
  44. public int getItemId()
  45. {
  46. return _itemId;
  47. }
  48. /**
  49. * Sets the ID of the item dropped
  50. * @param itemId : int designating the ID of the item
  51. */
  52. public void setItemId(int itemId)
  53. {
  54. _itemId = itemId;
  55. }
  56. /**
  57. * Returns the minimum quantity of items dropped
  58. * @return int
  59. */
  60. public int getMinDrop()
  61. {
  62. return _minDrop;
  63. }
  64. /**
  65. * Returns the maximum quantity of items dropped
  66. * @return int
  67. */
  68. public int getMaxDrop()
  69. {
  70. return _maxDrop;
  71. }
  72. /**
  73. * Returns the chance of having a drop
  74. * @return int
  75. */
  76. public double getChance()
  77. {
  78. return _chance;
  79. }
  80. /**
  81. * Sets the value for minimal quantity of dropped items
  82. * @param mindrop : int designating the quantity
  83. */
  84. public void setMinDrop(int mindrop)
  85. {
  86. _minDrop = mindrop;
  87. }
  88. /**
  89. * Sets the value for maximal quantity of dopped items
  90. * @param maxdrop : int designating the quantity of dropped items
  91. */
  92. public void setMaxDrop(int maxdrop)
  93. {
  94. _maxDrop = maxdrop;
  95. }
  96. /**
  97. * Sets the chance of having the item for a drop
  98. * @param chance : int designating the chance
  99. */
  100. public void setChance(double chance)
  101. {
  102. _chance = chance;
  103. }
  104. /**
  105. * Returns the stateID.
  106. * @return String[]
  107. */
  108. public String[] getStateIDs()
  109. {
  110. return _stateID;
  111. }
  112. /**
  113. * Adds states of the dropped item
  114. * @param list : String[]
  115. */
  116. public void addStates(String[] list)
  117. {
  118. _stateID = list;
  119. }
  120. /**
  121. * Returns the questID.
  122. * @return String designating the ID of the quest
  123. */
  124. public String getQuestID()
  125. {
  126. return _questID;
  127. }
  128. /**
  129. * Sets the questID
  130. * @param questID the quest Id to set.
  131. */
  132. public void setQuestID(String questID)
  133. {
  134. _questID = questID;
  135. }
  136. /**
  137. * Returns if the dropped item is requested for a quest
  138. * @return boolean
  139. */
  140. public boolean isQuestDrop()
  141. {
  142. return (_questID != null) && (_stateID != null);
  143. }
  144. /**
  145. * Returns a report of the object
  146. * @return String
  147. */
  148. @Override
  149. public String toString()
  150. {
  151. String out = "ItemID: " + getItemId() + " Min: " + getMinDrop() + " Max: " + getMaxDrop() + " Chance: " + (getChance() / 10000.0) + "%";
  152. if (isQuestDrop())
  153. {
  154. out += " QuestID: " + getQuestID() + " StateID's: " + Arrays.toString(getStateIDs());
  155. }
  156. return out;
  157. }
  158. @Override
  159. public int hashCode()
  160. {
  161. final int prime = 31;
  162. int result = 1;
  163. result = (prime * result) + _itemId;
  164. return result;
  165. }
  166. @Override
  167. public boolean equals(Object obj)
  168. {
  169. if (this == obj)
  170. {
  171. return true;
  172. }
  173. if (obj == null)
  174. {
  175. return false;
  176. }
  177. if (!(obj instanceof L2DropData))
  178. {
  179. return false;
  180. }
  181. final L2DropData other = (L2DropData) obj;
  182. if (_itemId != other._itemId)
  183. {
  184. return false;
  185. }
  186. return true;
  187. }
  188. }