RequestCrystallizeItem.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 net.sf.l2j.gameserver.clientpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.model.L2ItemInstance;
  19. import net.sf.l2j.gameserver.model.L2Skill;
  20. import net.sf.l2j.gameserver.model.L2World;
  21. import net.sf.l2j.gameserver.model.PcInventory;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  23. import net.sf.l2j.gameserver.network.SystemMessageId;
  24. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  25. import net.sf.l2j.gameserver.serverpackets.InventoryUpdate;
  26. import net.sf.l2j.gameserver.serverpackets.ItemList;
  27. import net.sf.l2j.gameserver.serverpackets.StatusUpdate;
  28. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  29. import net.sf.l2j.gameserver.templates.L2Item;
  30. import net.sf.l2j.gameserver.util.IllegalPlayerAction;
  31. import net.sf.l2j.gameserver.util.Util;
  32. /**
  33. * This class ...
  34. *
  35. * @version $Revision: 1.2.2.3.2.5 $ $Date: 2005/03/27 15:29:30 $
  36. */
  37. public final class RequestCrystallizeItem extends L2GameClientPacket
  38. {
  39. private static final String _C__72_REQUESTDCRYSTALLIZEITEM = "[C] 72 RequestCrystallizeItem";
  40. private static Logger _log = Logger.getLogger(RequestCrystallizeItem.class.getName());
  41. private int _objectId;
  42. private int _count;
  43. @Override
  44. protected void readImpl()
  45. {
  46. _objectId = readD();
  47. _count = readD();
  48. }
  49. @Override
  50. protected void runImpl()
  51. {
  52. L2PcInstance activeChar = getClient().getActiveChar();
  53. if (activeChar == null)
  54. {
  55. _log.fine("RequestCrystalizeItem: activeChar was null");
  56. return;
  57. }
  58. if (_count <= 0)
  59. {
  60. Util.handleIllegalPlayerAction(activeChar,
  61. "[RequestCrystallizeItem] count <= 0! ban! oid: "
  62. + _objectId + " owner: " + activeChar.getName(),
  63. IllegalPlayerAction.PUNISH_KICK);
  64. return;
  65. }
  66. if (activeChar.getPrivateStoreType() != 0
  67. || activeChar.isInCrystallize())
  68. {
  69. activeChar
  70. .sendPacket(new SystemMessage(
  71. SystemMessageId.CANNOT_TRADE_DISCARD_DROP_ITEM_WHILE_IN_SHOPMODE));
  72. return;
  73. }
  74. int skillLevel = activeChar.getSkillLevel(L2Skill.SKILL_CRYSTALLIZE);
  75. if (skillLevel <= 0)
  76. {
  77. SystemMessage sm = new SystemMessage(
  78. SystemMessageId.CRYSTALLIZE_LEVEL_TOO_LOW);
  79. activeChar.sendPacket(sm);
  80. sm = null;
  81. ActionFailed af = ActionFailed.STATIC_PACKET;
  82. activeChar.sendPacket(af);
  83. return;
  84. }
  85. PcInventory inventory = activeChar.getInventory();
  86. if (inventory != null)
  87. {
  88. L2ItemInstance item = inventory.getItemByObjectId(_objectId);
  89. if (item == null || item.isWear())
  90. {
  91. ActionFailed af = ActionFailed.STATIC_PACKET;
  92. activeChar.sendPacket(af);
  93. return;
  94. }
  95. if (item.isHeroItem())
  96. return;
  97. if (_count > item.getCount())
  98. {
  99. _count = activeChar.getInventory().getItemByObjectId(_objectId)
  100. .getCount();
  101. }
  102. }
  103. L2ItemInstance itemToRemove = activeChar.getInventory()
  104. .getItemByObjectId(_objectId);
  105. if (itemToRemove == null || itemToRemove.isWear())
  106. {
  107. return;
  108. }
  109. if (!itemToRemove.getItem().isCrystallizable()
  110. || (itemToRemove.getItem().getCrystalCount() <= 0)
  111. || (itemToRemove.getItem().getCrystalType() == L2Item.CRYSTAL_NONE))
  112. {
  113. _log.warning("" + activeChar.getObjectId()
  114. + " tried to crystallize "
  115. + itemToRemove.getItem().getItemId());
  116. return;
  117. }
  118. // Check if the char can crystallize items and return if false;
  119. boolean canCrystallize = true;
  120. switch (itemToRemove.getItem().getCrystalType())
  121. {
  122. case L2Item.CRYSTAL_C:
  123. {
  124. if (skillLevel <= 1)
  125. {
  126. canCrystallize = false;
  127. }
  128. break;
  129. }
  130. case L2Item.CRYSTAL_B:
  131. {
  132. if (skillLevel <= 2)
  133. {
  134. canCrystallize = false;
  135. }
  136. break;
  137. }
  138. case L2Item.CRYSTAL_A:
  139. {
  140. if (skillLevel <= 3)
  141. {
  142. canCrystallize = false;
  143. }
  144. break;
  145. }
  146. case L2Item.CRYSTAL_S:
  147. case L2Item.CRYSTAL_S80:
  148. {
  149. if (skillLevel <= 4)
  150. {
  151. canCrystallize = false;
  152. }
  153. break;
  154. }
  155. }
  156. if (!canCrystallize)
  157. {
  158. SystemMessage sm = new SystemMessage(SystemMessageId.CRYSTALLIZE_LEVEL_TOO_LOW);
  159. activeChar.sendPacket(sm);
  160. sm = null;
  161. ActionFailed af = ActionFailed.STATIC_PACKET;
  162. activeChar.sendPacket(af);
  163. return;
  164. }
  165. activeChar.setInCrystallize(true);
  166. // unequip if needed
  167. if (itemToRemove.isEquipped())
  168. {
  169. L2ItemInstance[] unequiped = activeChar.getInventory()
  170. .unEquipItemInSlotAndRecord(itemToRemove.getLocationSlot());
  171. InventoryUpdate iu = new InventoryUpdate();
  172. for (int i = 0; i < unequiped.length; i++)
  173. {
  174. iu.addModifiedItem(unequiped[i]);
  175. }
  176. activeChar.sendPacket(iu);
  177. // activeChar.updatePDef();
  178. // activeChar.updatePAtk();
  179. // activeChar.updateMDef();
  180. // activeChar.updateMAtk();
  181. // activeChar.updateAccuracy();
  182. // activeChar.updateCriticalChance();
  183. }
  184. // remove from inventory
  185. L2ItemInstance removedItem = activeChar.getInventory().destroyItem(
  186. "Crystalize", _objectId, _count, activeChar, null);
  187. // add crystals
  188. int crystalId = itemToRemove.getItem().getCrystalItemId();
  189. int crystalAmount = itemToRemove.getCrystalCount();
  190. L2ItemInstance createditem = activeChar.getInventory().addItem(
  191. "Crystalize", crystalId, crystalAmount, activeChar,
  192. itemToRemove);
  193. SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  194. sm.addItemName(crystalId);
  195. sm.addNumber(crystalAmount);
  196. activeChar.sendPacket(sm);
  197. sm = null;
  198. // send inventory update
  199. if (!Config.FORCE_INVENTORY_UPDATE)
  200. {
  201. InventoryUpdate iu = new InventoryUpdate();
  202. if (removedItem.getCount() == 0)
  203. iu.addRemovedItem(removedItem);
  204. else
  205. iu.addModifiedItem(removedItem);
  206. if (createditem.getCount() != crystalAmount)
  207. iu.addModifiedItem(createditem);
  208. else
  209. iu.addNewItem(createditem);
  210. activeChar.sendPacket(iu);
  211. } else
  212. activeChar.sendPacket(new ItemList(activeChar, false));
  213. // status & user info
  214. StatusUpdate su = new StatusUpdate(activeChar.getObjectId());
  215. su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
  216. activeChar.sendPacket(su);
  217. activeChar.broadcastUserInfo();
  218. L2World world = L2World.getInstance();
  219. world.removeObject(removedItem);
  220. activeChar.setInCrystallize(false);
  221. }
  222. /*
  223. * (non-Javadoc)
  224. *
  225. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  226. */
  227. @Override
  228. public String getType()
  229. {
  230. return _C__72_REQUESTDCRYSTALLIZEITEM;
  231. }
  232. }