ItemInfo.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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;
  20. import com.l2jserver.gameserver.model.items.L2Item;
  21. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  22. /**
  23. * Get all information from L2ItemInstance to generate ItemInfo.
  24. */
  25. public class ItemInfo
  26. {
  27. /** Identifier of the L2ItemInstance */
  28. private int _objectId;
  29. /** The L2Item template of the L2ItemInstance */
  30. private L2Item _item;
  31. /** The level of enchant on the L2ItemInstance */
  32. private int _enchant;
  33. /** The augmentation of the item */
  34. private int _augmentation;
  35. /** The quantity of L2ItemInstance */
  36. private long _count;
  37. /** The price of the L2ItemInstance */
  38. private int _price;
  39. /** The custom L2ItemInstance types (used loto, race tickets) */
  40. private int _type1;
  41. private int _type2;
  42. /** If True the L2ItemInstance is equipped */
  43. private int _equipped;
  44. /** The action to do clientside (1=ADD, 2=MODIFY, 3=REMOVE) */
  45. private int _change;
  46. /** The mana of this item */
  47. private int _mana;
  48. private int _time;
  49. private int _location;
  50. private int _elemAtkType = -2;
  51. private int _elemAtkPower = 0;
  52. private final int[] _elemDefAttr =
  53. {
  54. 0,
  55. 0,
  56. 0,
  57. 0,
  58. 0,
  59. 0
  60. };
  61. private int[] _option;
  62. /**
  63. * Get all information from L2ItemInstance to generate ItemInfo.
  64. * @param item
  65. */
  66. public ItemInfo(L2ItemInstance item)
  67. {
  68. if (item == null)
  69. {
  70. return;
  71. }
  72. // Get the Identifier of the L2ItemInstance
  73. _objectId = item.getObjectId();
  74. // Get the L2Item of the L2ItemInstance
  75. _item = item.getItem();
  76. // Get the enchant level of the L2ItemInstance
  77. _enchant = item.getEnchantLevel();
  78. // Get the augmentation boni
  79. if (item.isAugmented())
  80. {
  81. _augmentation = item.getAugmentation().getAugmentationId();
  82. }
  83. else
  84. {
  85. _augmentation = 0;
  86. }
  87. // Get the quantity of the L2ItemInstance
  88. _count = item.getCount();
  89. // Get custom item types (used loto, race tickets)
  90. _type1 = item.getCustomType1();
  91. _type2 = item.getCustomType2();
  92. // Verify if the L2ItemInstance is equipped
  93. _equipped = item.isEquipped() ? 1 : 0;
  94. // Get the action to do clientside
  95. switch (item.getLastChange())
  96. {
  97. case (L2ItemInstance.ADDED):
  98. {
  99. _change = 1;
  100. break;
  101. }
  102. case (L2ItemInstance.MODIFIED):
  103. {
  104. _change = 2;
  105. break;
  106. }
  107. case (L2ItemInstance.REMOVED):
  108. {
  109. _change = 3;
  110. break;
  111. }
  112. }
  113. // Get shadow item mana
  114. _mana = item.getMana();
  115. _time = item.isTimeLimitedItem() ? (int) (item.getRemainingTime() / 1000) : -9999;
  116. _location = item.getLocationSlot();
  117. _elemAtkType = item.getAttackElementType();
  118. _elemAtkPower = item.getAttackElementPower();
  119. for (byte i = 0; i < 6; i++)
  120. {
  121. _elemDefAttr[i] = item.getElementDefAttr(i);
  122. }
  123. _option = item.getEnchantOptions();
  124. }
  125. public ItemInfo(L2ItemInstance item, int change)
  126. {
  127. this(item);
  128. _change = change;
  129. }
  130. public ItemInfo(TradeItem item)
  131. {
  132. if (item == null)
  133. {
  134. return;
  135. }
  136. // Get the Identifier of the L2ItemInstance
  137. _objectId = item.getObjectId();
  138. // Get the L2Item of the L2ItemInstance
  139. _item = item.getItem();
  140. // Get the enchant level of the L2ItemInstance
  141. _enchant = item.getEnchant();
  142. // Get the augmentation boni
  143. _augmentation = 0;
  144. // Get the quantity of the L2ItemInstance
  145. _count = item.getCount();
  146. // Get custom item types (used loto, race tickets)
  147. _type1 = item.getCustomType1();
  148. _type2 = item.getCustomType2();
  149. // Verify if the L2ItemInstance is equipped
  150. _equipped = 0;
  151. // Get the action to do clientside
  152. _change = 0;
  153. // Get shadow item mana
  154. _mana = -1;
  155. _time = -9999;
  156. _location = item.getLocationSlot();
  157. _elemAtkType = item.getAttackElementType();
  158. _elemAtkPower = item.getAttackElementPower();
  159. for (byte i = 0; i < 6; i++)
  160. {
  161. _elemDefAttr[i] = item.getElementDefAttr(i);
  162. }
  163. _option = item.getEnchantOptions();
  164. }
  165. public int getObjectId()
  166. {
  167. return _objectId;
  168. }
  169. public L2Item getItem()
  170. {
  171. return _item;
  172. }
  173. public int getEnchant()
  174. {
  175. return _enchant;
  176. }
  177. public int getAugmentationBonus()
  178. {
  179. return _augmentation;
  180. }
  181. public long getCount()
  182. {
  183. return _count;
  184. }
  185. public int getPrice()
  186. {
  187. return _price;
  188. }
  189. public int getCustomType1()
  190. {
  191. return _type1;
  192. }
  193. public int getCustomType2()
  194. {
  195. return _type2;
  196. }
  197. public int getEquipped()
  198. {
  199. return _equipped;
  200. }
  201. public int getChange()
  202. {
  203. return _change;
  204. }
  205. public int getMana()
  206. {
  207. return _mana;
  208. }
  209. public int getTime()
  210. {
  211. return _time;
  212. }
  213. public int getLocation()
  214. {
  215. return _location;
  216. }
  217. public int getAttackElementType()
  218. {
  219. return _elemAtkType;
  220. }
  221. public int getAttackElementPower()
  222. {
  223. return _elemAtkPower;
  224. }
  225. public int getElementDefAttr(byte i)
  226. {
  227. return _elemDefAttr[i];
  228. }
  229. public int[] getEnchantOptions()
  230. {
  231. return _option;
  232. }
  233. }