Advertisement
SmiDmi

Visual message about successful enchantment

Oct 1st, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 46.98 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2J_Mobius_6.0_Fafurion
  3. Index: java/org/l2jmobius/gameserver/network/serverpackets/ExItemAnnounce.java
  4. ===================================================================
  5. --- java/org/l2jmobius/gameserver/network/serverpackets/ExItemAnnounce.java (nonexistent)
  6. +++ java/org/l2jmobius/gameserver/network/serverpackets/ExItemAnnounce.java (working copy)
  7. @@ -0,0 +1,54 @@
  8. +/*
  9. + * This file is part of the L2J Mobius project.
  10. + *
  11. + * This program is free software: you can redistribute it and/or modify
  12. + * it under the terms of the GNU General Public License as published by
  13. + * the Free Software Foundation, either version 3 of the License, or
  14. + * (at your option) any later version.
  15. + *
  16. + * This program is distributed in the hope that it will be useful,
  17. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. + * General Public License for more details.
  20. + *
  21. + * You should have received a copy of the GNU General Public License
  22. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. + */
  24. +package org.l2jmobius.gameserver.network.serverpackets;
  25. +
  26. +import org.l2jmobius.commons.network.PacketWriter;
  27. +import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
  28. +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  29. +import org.l2jmobius.gameserver.network.OutgoingPackets;
  30. +
  31. +/**
  32. + * @author NviX
  33. + */
  34. +public class ExItemAnnounce implements IClientOutgoingPacket
  35. +{
  36. +    private final ItemInstance _item;
  37. +   private final PlayerInstance _player;
  38. +  
  39. +    /**
  40. +     * @param item
  41. +     */
  42. +    public ExItemAnnounce(ItemInstance item, PlayerInstance player)
  43. +    {
  44. +        _item = item;
  45. +       _player = player;
  46. +    }
  47. +  
  48. +  
  49. +    @Override
  50. +    public boolean write(PacketWriter packet)
  51. +    {
  52. +        OutgoingPackets.EX_ITEM_ANNOUNCE.writeId(packet);
  53. +        packet.writeC(0x00); // item icon
  54. +        packet.writeString(_player.getName()); // name of player
  55. +        packet.writeD(_item.getId()); // item id
  56. +        packet.writeD(_item.getEnchantLevel()); // enchant level
  57. +        packet.writeC(0x00); // name of item
  58. +        return true;
  59. +    }
  60. +  
  61. +}
  62. \ No newline at end of file
  63. Index: java/org/l2jmobius/gameserver/network/clientpackets/RequestEnchantItem.java
  64. ===================================================================
  65. --- java/org/l2jmobius/gameserver/network/clientpackets/RequestEnchantItem.java (revision 5961)
  66. +++ java/org/l2jmobius/gameserver/network/clientpackets/RequestEnchantItem.java (working copy)
  67. @@ -1,463 +1,465 @@
  68. -/*
  69. - * This file is part of the L2J Mobius project.
  70. - *
  71. - * This program is free software: you can redistribute it and/or modify
  72. - * it under the terms of the GNU General Public License as published by
  73. - * the Free Software Foundation, either version 3 of the License, or
  74. - * (at your option) any later version.
  75. - *
  76. - * This program is distributed in the hope that it will be useful,
  77. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  78. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  79. - * General Public License for more details.
  80. - *
  81. - * You should have received a copy of the GNU General Public License
  82. - * along with this program. If not, see <http://www.gnu.org/licenses/>.
  83. - */
  84. -package org.l2jmobius.gameserver.network.clientpackets;
  85. -
  86. -import java.util.logging.Logger;
  87. -
  88. -import org.l2jmobius.Config;
  89. -import org.l2jmobius.commons.network.PacketReader;
  90. -import org.l2jmobius.commons.util.Rnd;
  91. -import org.l2jmobius.gameserver.data.xml.impl.EnchantItemData;
  92. -import org.l2jmobius.gameserver.enums.ItemSkillType;
  93. -import org.l2jmobius.gameserver.enums.UserInfoType;
  94. -import org.l2jmobius.gameserver.model.World;
  95. -import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  96. -import org.l2jmobius.gameserver.model.actor.request.EnchantItemRequest;
  97. -import org.l2jmobius.gameserver.model.items.Item;
  98. -import org.l2jmobius.gameserver.model.items.enchant.EnchantResultType;
  99. -import org.l2jmobius.gameserver.model.items.enchant.EnchantScroll;
  100. -import org.l2jmobius.gameserver.model.items.enchant.EnchantSupportItem;
  101. -import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
  102. -import org.l2jmobius.gameserver.model.skills.CommonSkill;
  103. -import org.l2jmobius.gameserver.model.skills.Skill;
  104. -import org.l2jmobius.gameserver.network.GameClient;
  105. -import org.l2jmobius.gameserver.network.SystemMessageId;
  106. -import org.l2jmobius.gameserver.network.serverpackets.EnchantResult;
  107. -import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
  108. -import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
  109. -import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
  110. -import org.l2jmobius.gameserver.util.Util;
  111. -
  112. -public class RequestEnchantItem implements IClientIncomingPacket
  113. -{
  114. -   protected static final Logger LOGGER_ENCHANT = Logger.getLogger("enchant.items");
  115. -  
  116. -   private int _objectId;
  117. -   private int _supportId;
  118. -  
  119. -   @Override
  120. -   public boolean read(GameClient client, PacketReader packet)
  121. -   {
  122. -       _objectId = packet.readD();
  123. -       _supportId = packet.readD();
  124. -       return true;
  125. -   }
  126. -  
  127. -   @Override
  128. -   public void run(GameClient client)
  129. -   {
  130. -       final PlayerInstance player = client.getPlayer();
  131. -       if (player == null)
  132. -       {
  133. -           return;
  134. -       }
  135. -      
  136. -       final EnchantItemRequest request = player.getRequest(EnchantItemRequest.class);
  137. -       if ((request == null) || request.isProcessing())
  138. -       {
  139. -           return;
  140. -       }
  141. -      
  142. -       request.setEnchantingItem(_objectId);
  143. -       request.setProcessing(true);
  144. -      
  145. -       if (!player.isOnline() || client.isDetached())
  146. -       {
  147. -           player.removeRequest(request.getClass());
  148. -           return;
  149. -       }
  150. -      
  151. -       if (player.isProcessingTransaction() || player.isInStoreMode())
  152. -       {
  153. -           client.sendPacket(SystemMessageId.YOU_CANNOT_ENCHANT_WHILE_OPERATING_A_PRIVATE_STORE_OR_PRIVATE_WORKSHOP);
  154. -           player.removeRequest(request.getClass());
  155. -           return;
  156. -       }
  157. -      
  158. -       final ItemInstance item = request.getEnchantingItem();
  159. -       final ItemInstance scroll = request.getEnchantingScroll();
  160. -       final ItemInstance support = request.getSupportItem();
  161. -       if ((item == null) || (scroll == null))
  162. -       {
  163. -           player.removeRequest(request.getClass());
  164. -           return;
  165. -       }
  166. -      
  167. -       // template for scroll
  168. -       final EnchantScroll scrollTemplate = EnchantItemData.getInstance().getEnchantScroll(scroll);
  169. -       if (scrollTemplate == null)
  170. -       {
  171. -           return;
  172. -       }
  173. -      
  174. -       // template for support item, if exist
  175. -       EnchantSupportItem supportTemplate = null;
  176. -       if (support != null)
  177. -       {
  178. -           if (support.getObjectId() != _supportId)
  179. -           {
  180. -               player.removeRequest(request.getClass());
  181. -               return;
  182. -           }
  183. -           supportTemplate = EnchantItemData.getInstance().getSupportItem(support);
  184. -       }
  185. -      
  186. -       // first validation check - also over enchant check
  187. -       if (!scrollTemplate.isValid(item, supportTemplate) || (Config.DISABLE_OVER_ENCHANTING && (item.getEnchantLevel() == scrollTemplate.getMaxEnchantLevel())))
  188. -       {
  189. -           client.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITIONS);
  190. -           player.removeRequest(request.getClass());
  191. -           client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  192. -           return;
  193. -       }
  194. -      
  195. -       // fast auto-enchant cheat check
  196. -       if ((request.getTimestamp() == 0) || ((System.currentTimeMillis() - request.getTimestamp()) < 2000))
  197. -       {
  198. -           Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " use autoenchant program ", Config.DEFAULT_PUNISH);
  199. -           player.removeRequest(request.getClass());
  200. -           client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  201. -           return;
  202. -       }
  203. -      
  204. -       // attempting to destroy scroll
  205. -       if (player.getInventory().destroyItem("Enchant", scroll.getObjectId(), 1, player, item) == null)
  206. -       {
  207. -           client.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
  208. -           Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " tried to enchant with a scroll he doesn't have", Config.DEFAULT_PUNISH);
  209. -           player.removeRequest(request.getClass());
  210. -           client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  211. -           return;
  212. -       }
  213. -      
  214. -       // attempting to destroy support if exist
  215. -       if (support != null)
  216. -       {
  217. -           if (player.getInventory().destroyItem("Enchant", support.getObjectId(), 1, player, item) == null)
  218. -           {
  219. -               client.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
  220. -               Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " tried to enchant with a support item he doesn't have", Config.DEFAULT_PUNISH);
  221. -               player.removeRequest(request.getClass());
  222. -               client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  223. -               return;
  224. -           }
  225. -       }
  226. -      
  227. -       final InventoryUpdate iu = new InventoryUpdate();
  228. -       synchronized (item)
  229. -       {
  230. -           // last validation check
  231. -           if ((item.getOwnerId() != player.getObjectId()) || (item.isEnchantable() == 0))
  232. -           {
  233. -               client.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITIONS);
  234. -               player.removeRequest(request.getClass());
  235. -               client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  236. -               return;
  237. -           }
  238. -          
  239. -           final EnchantResultType resultType = scrollTemplate.calculateSuccess(player, item, supportTemplate);
  240. -           switch (resultType)
  241. -           {
  242. -               case ERROR:
  243. -               {
  244. -                   client.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITIONS);
  245. -                   player.removeRequest(request.getClass());
  246. -                   client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  247. -                   break;
  248. -               }
  249. -               case SUCCESS:
  250. -               {
  251. -                   final Item it = item.getItem();
  252. -                   // Increase enchant level only if scroll's base template has chance, some armors can success over +20 but they shouldn't have increased.
  253. -                   if (scrollTemplate.getChance(player, item) > 0)
  254. -                   {
  255. -                       if (scrollTemplate.isGiant())
  256. -                       {
  257. -                           if (((supportTemplate != null) && (supportTemplate.getId() == 23785)) || ((supportTemplate != null) && (supportTemplate.getId() == 23786))) // Lesser Giant's Lucky Enchant Stones. Increase from +2 to +4
  258. -                           {
  259. -                               item.setEnchantLevel(Math.min(item.getEnchantLevel() + 2 + Rnd.get(3), scrollTemplate.getMaxEnchantLevel()));
  260. -                           }
  261. -                           else
  262. -                           {
  263. -                               item.setEnchantLevel(Math.min(item.getEnchantLevel() + 1 + Rnd.get(3), scrollTemplate.getMaxEnchantLevel()));
  264. -                           }
  265. -                       }
  266. -                       else
  267. -                       {
  268. -                           item.setEnchantLevel(item.getEnchantLevel() + 1);
  269. -                       }
  270. -                       item.updateDatabase();
  271. -                   }
  272. -                   client.sendPacket(new EnchantResult(EnchantResult.SUCCESS, item));
  273. -                  
  274. -                   if (Config.LOG_ITEM_ENCHANTS)
  275. -                   {
  276. -                       if (item.getEnchantLevel() > 0)
  277. -                       {
  278. -                           if (support == null)
  279. -                           {
  280. -                               LOGGER_ENCHANT.info("Success, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  281. -                           }
  282. -                           else
  283. -                           {
  284. -                               LOGGER_ENCHANT.info("Success, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  285. -                           }
  286. -                       }
  287. -                       else if (support == null)
  288. -                       {
  289. -                           LOGGER_ENCHANT.info("Success, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  290. -                       }
  291. -                       else
  292. -                       {
  293. -                           LOGGER_ENCHANT.info("Success, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  294. -                       }
  295. -                   }
  296. -                  
  297. -                   // announce the success
  298. -                   final int minEnchantAnnounce = item.isArmor() ? 6 : 7;
  299. -                   final int maxEnchantAnnounce = item.isArmor() ? 0 : 15;
  300. -                   if ((item.getEnchantLevel() == minEnchantAnnounce) || (item.getEnchantLevel() == maxEnchantAnnounce))
  301. -                   {
  302. -                       final SystemMessage sm = new SystemMessage(SystemMessageId.C1_HAS_SUCCESSFULLY_ENCHANTED_A_S2_S3);
  303. -                       sm.addString(player.getName());
  304. -                       sm.addInt(item.getEnchantLevel());
  305. -                       sm.addItemName(item);
  306. -                       player.broadcastPacket(sm);
  307. -                      
  308. -                       final Skill skill = CommonSkill.FIREWORK.getSkill();
  309. -                       if (skill != null)
  310. -                       {
  311. -                           player.broadcastPacket(new MagicSkillUse(player, player, skill.getId(), skill.getLevel(), skill.getHitTime(), skill.getReuseDelay()));
  312. -                       }
  313. -                   }
  314. -                  
  315. -                   if (item.isEquipped())
  316. -                   {
  317. -                       if (item.isArmor())
  318. -                       {
  319. -                           it.forEachSkill(ItemSkillType.ON_ENCHANT, holder ->
  320. -                           {
  321. -                               // add skills bestowed from +4 armor
  322. -                               if (item.getEnchantLevel() >= holder.getValue())
  323. -                               {
  324. -                                   player.addSkill(holder.getSkill(), false);
  325. -                                   player.sendSkillList();
  326. -                               }
  327. -                           });
  328. -                       }
  329. -                       player.broadcastUserInfo(); // update user info
  330. -                   }
  331. -                   break;
  332. -               }
  333. -               case FAILURE:
  334. -               {
  335. -                   if (scrollTemplate.isSafe())
  336. -                   {
  337. -                       // safe enchant - remain old value
  338. -                       client.sendPacket(SystemMessageId.ENCHANT_FAILED_THE_ENCHANT_VALUE_FOR_THE_CORRESPONDING_ITEM_WILL_BE_EXACTLY_RETAINED);
  339. -                       client.sendPacket(new EnchantResult(EnchantResult.SAFE_FAIL, item));
  340. -                      
  341. -                       if (Config.LOG_ITEM_ENCHANTS)
  342. -                       {
  343. -                           if (item.getEnchantLevel() > 0)
  344. -                           {
  345. -                               if (support == null)
  346. -                               {
  347. -                                   LOGGER_ENCHANT.info("Safe Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  348. -                               }
  349. -                               else
  350. -                               {
  351. -                                   LOGGER_ENCHANT.info("Safe Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  352. -                               }
  353. -                           }
  354. -                           else if (support == null)
  355. -                           {
  356. -                               LOGGER_ENCHANT.info("Safe Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  357. -                           }
  358. -                           else
  359. -                           {
  360. -                               LOGGER_ENCHANT.info("Safe Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  361. -                           }
  362. -                       }
  363. -                   }
  364. -                   else
  365. -                   {
  366. -                       // unequip item on enchant failure to avoid item skills stack
  367. -                       if (item.isEquipped())
  368. -                       {
  369. -                           if (item.getEnchantLevel() > 0)
  370. -                           {
  371. -                               final SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2_HAS_BEEN_UNEQUIPPED);
  372. -                               sm.addInt(item.getEnchantLevel());
  373. -                               sm.addItemName(item);
  374. -                               client.sendPacket(sm);
  375. -                           }
  376. -                           else
  377. -                           {
  378. -                               final SystemMessage sm = new SystemMessage(SystemMessageId.S1_HAS_BEEN_UNEQUIPPED);
  379. -                               sm.addItemName(item);
  380. -                               client.sendPacket(sm);
  381. -                           }
  382. -                          
  383. -                           final ItemInstance[] unequiped = player.getInventory().unEquipItemInSlotAndRecord(item.getLocationSlot());
  384. -                           for (ItemInstance itm : unequiped)
  385. -                           {
  386. -                               iu.addModifiedItem(itm);
  387. -                           }
  388. -                          
  389. -                           player.sendInventoryUpdate(iu);
  390. -                           player.broadcastUserInfo();
  391. -                       }
  392. -                      
  393. -                       if (scrollTemplate.isBlessed() || ((supportTemplate != null) && supportTemplate.isBlessed()))
  394. -                       {
  395. -                           // blessed enchant - clear enchant value
  396. -                           client.sendPacket(SystemMessageId.THE_BLESSED_ENCHANT_FAILED_THE_ENCHANT_VALUE_OF_THE_ITEM_BECAME_0);
  397. -                          
  398. -                           item.setEnchantLevel(0);
  399. -                           item.updateDatabase();
  400. -                           client.sendPacket(new EnchantResult(EnchantResult.BLESSED_FAIL, 0, 0));
  401. -                          
  402. -                           if (Config.LOG_ITEM_ENCHANTS)
  403. -                           {
  404. -                               if (item.getEnchantLevel() > 0)
  405. -                               {
  406. -                                   if (support == null)
  407. -                                   {
  408. -                                       LOGGER_ENCHANT.info("Blessed Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  409. -                                   }
  410. -                                   else
  411. -                                   {
  412. -                                       LOGGER_ENCHANT.info("Blessed Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  413. -                                   }
  414. -                               }
  415. -                               else if (support == null)
  416. -                               {
  417. -                                   LOGGER_ENCHANT.info("Blessed Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  418. -                               }
  419. -                               else
  420. -                               {
  421. -                                   LOGGER_ENCHANT.info("Blessed Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  422. -                               }
  423. -                           }
  424. -                       }
  425. -                       else
  426. -                       {
  427. -                           // enchant failed, destroy item
  428. -                           final int crystalId = item.getItem().getCrystalItemId();
  429. -                           int count = item.getCrystalCount() - ((item.getItem().getCrystalCount() + 1) / 2);
  430. -                           if (count < 1)
  431. -                           {
  432. -                               count = 1;
  433. -                           }
  434. -                          
  435. -                           if (player.getInventory().destroyItem("Enchant", item, player, null) == null)
  436. -                           {
  437. -                               // unable to destroy item, cheater ?
  438. -                               Util.handleIllegalPlayerAction(player, "Unable to delete item on enchant failure from player " + player.getName() + ", possible cheater !", Config.DEFAULT_PUNISH);
  439. -                               player.removeRequest(request.getClass());
  440. -                               client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  441. -                              
  442. -                               if (Config.LOG_ITEM_ENCHANTS)
  443. -                               {
  444. -                                   if (item.getEnchantLevel() > 0)
  445. -                                   {
  446. -                                       if (support == null)
  447. -                                       {
  448. -                                           LOGGER_ENCHANT.info("Unable to destroy, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  449. -                                       }
  450. -                                       else
  451. -                                       {
  452. -                                           LOGGER_ENCHANT.info("Unable to destroy, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  453. -                                       }
  454. -                                   }
  455. -                                   else if (support == null)
  456. -                                   {
  457. -                                       LOGGER_ENCHANT.info("Unable to destroy, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  458. -                                   }
  459. -                                   else
  460. -                                   {
  461. -                                       LOGGER_ENCHANT.info("Unable to destroy, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  462. -                                   }
  463. -                               }
  464. -                               return;
  465. -                           }
  466. -                          
  467. -                           World.getInstance().removeObject(item);
  468. -                           ItemInstance crystals = null;
  469. -                           if (crystalId != 0)
  470. -                           {
  471. -                               crystals = player.getInventory().addItem("Enchant", crystalId, count, player, item);
  472. -                              
  473. -                               final SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S);
  474. -                               sm.addItemName(crystals);
  475. -                               sm.addLong(count);
  476. -                               client.sendPacket(sm);
  477. -                           }
  478. -                          
  479. -                           if (!Config.FORCE_INVENTORY_UPDATE)
  480. -                           {
  481. -                               if (crystals != null)
  482. -                               {
  483. -                                   iu.addItem(crystals);
  484. -                               }
  485. -                           }
  486. -                          
  487. -                           if (crystalId == 0)
  488. -                           {
  489. -                               client.sendPacket(new EnchantResult(EnchantResult.NO_CRYSTAL, 0, 0));
  490. -                           }
  491. -                           else
  492. -                           {
  493. -                               client.sendPacket(new EnchantResult(EnchantResult.FAIL, crystalId, count));
  494. -                           }
  495. -                          
  496. -                           if (Config.LOG_ITEM_ENCHANTS)
  497. -                           {
  498. -                               if (item.getEnchantLevel() > 0)
  499. -                               {
  500. -                                   if (support == null)
  501. -                                   {
  502. -                                       LOGGER_ENCHANT.info("Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  503. -                                   }
  504. -                                   else
  505. -                                   {
  506. -                                       LOGGER_ENCHANT.info("Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  507. -                                   }
  508. -                               }
  509. -                               else if (support == null)
  510. -                               {
  511. -                                   LOGGER_ENCHANT.info("Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  512. -                               }
  513. -                               else
  514. -                               {
  515. -                                   LOGGER_ENCHANT.info("Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  516. -                               }
  517. -                           }
  518. -                       }
  519. -                   }
  520. -                   break;
  521. -               }
  522. -           }
  523. -          
  524. -           player.sendItemList();
  525. -          
  526. -           request.setProcessing(false);
  527. -           player.broadcastUserInfo(UserInfoType.ENCHANTLEVEL);
  528. -       }
  529. -   }
  530. -}
  531. +/*
  532. + * This file is part of the L2J Mobius project.
  533. + *
  534. + * This program is free software: you can redistribute it and/or modify
  535. + * it under the terms of the GNU General Public License as published by
  536. + * the Free Software Foundation, either version 3 of the License, or
  537. + * (at your option) any later version.
  538. + *
  539. + * This program is distributed in the hope that it will be useful,
  540. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  541. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  542. + * General Public License for more details.
  543. + *
  544. + * You should have received a copy of the GNU General Public License
  545. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  546. + */
  547. +package org.l2jmobius.gameserver.network.clientpackets;
  548. +
  549. +import java.util.logging.Logger;
  550. +
  551. +import org.l2jmobius.Config;
  552. +import org.l2jmobius.commons.network.PacketReader;
  553. +import org.l2jmobius.commons.util.Rnd;
  554. +import org.l2jmobius.gameserver.data.xml.impl.EnchantItemData;
  555. +import org.l2jmobius.gameserver.enums.ItemSkillType;
  556. +import org.l2jmobius.gameserver.enums.UserInfoType;
  557. +import org.l2jmobius.gameserver.model.World;
  558. +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  559. +import org.l2jmobius.gameserver.model.actor.request.EnchantItemRequest;
  560. +import org.l2jmobius.gameserver.model.items.Item;
  561. +import org.l2jmobius.gameserver.model.items.enchant.EnchantResultType;
  562. +import org.l2jmobius.gameserver.model.items.enchant.EnchantScroll;
  563. +import org.l2jmobius.gameserver.model.items.enchant.EnchantSupportItem;
  564. +import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
  565. +import org.l2jmobius.gameserver.model.skills.CommonSkill;
  566. +import org.l2jmobius.gameserver.model.skills.Skill;
  567. +import org.l2jmobius.gameserver.network.GameClient;
  568. +import org.l2jmobius.gameserver.network.SystemMessageId;
  569. +import org.l2jmobius.gameserver.network.serverpackets.EnchantResult;
  570. +import org.l2jmobius.gameserver.network.serverpackets.ExItemAnnounce;
  571. +import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
  572. +import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
  573. +import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
  574. +import org.l2jmobius.gameserver.util.Util;
  575. +
  576. +public class RequestEnchantItem implements IClientIncomingPacket
  577. +{
  578. +   protected static final Logger LOGGER_ENCHANT = Logger.getLogger("enchant.items");
  579. +  
  580. +   private int _objectId;
  581. +   private int _supportId;
  582. +  
  583. +   @Override
  584. +   public boolean read(GameClient client, PacketReader packet)
  585. +   {
  586. +       _objectId = packet.readD();
  587. +       _supportId = packet.readD();
  588. +       return true;
  589. +   }
  590. +  
  591. +   @Override
  592. +   public void run(GameClient client)
  593. +   {
  594. +       final PlayerInstance player = client.getPlayer();
  595. +       if (player == null)
  596. +       {
  597. +           return;
  598. +       }
  599. +      
  600. +       final EnchantItemRequest request = player.getRequest(EnchantItemRequest.class);
  601. +       if ((request == null) || request.isProcessing())
  602. +       {
  603. +           return;
  604. +       }
  605. +      
  606. +       request.setEnchantingItem(_objectId);
  607. +       request.setProcessing(true);
  608. +      
  609. +       if (!player.isOnline() || client.isDetached())
  610. +       {
  611. +           player.removeRequest(request.getClass());
  612. +           return;
  613. +       }
  614. +      
  615. +       if (player.isProcessingTransaction() || player.isInStoreMode())
  616. +       {
  617. +           client.sendPacket(SystemMessageId.YOU_CANNOT_ENCHANT_WHILE_OPERATING_A_PRIVATE_STORE_OR_PRIVATE_WORKSHOP);
  618. +           player.removeRequest(request.getClass());
  619. +           return;
  620. +       }
  621. +      
  622. +       final ItemInstance item = request.getEnchantingItem();
  623. +       final ItemInstance scroll = request.getEnchantingScroll();
  624. +       final ItemInstance support = request.getSupportItem();
  625. +       if ((item == null) || (scroll == null))
  626. +       {
  627. +           player.removeRequest(request.getClass());
  628. +           return;
  629. +       }
  630. +      
  631. +       // template for scroll
  632. +       final EnchantScroll scrollTemplate = EnchantItemData.getInstance().getEnchantScroll(scroll);
  633. +       if (scrollTemplate == null)
  634. +       {
  635. +           return;
  636. +       }
  637. +      
  638. +       // template for support item, if exist
  639. +       EnchantSupportItem supportTemplate = null;
  640. +       if (support != null)
  641. +       {
  642. +           if (support.getObjectId() != _supportId)
  643. +           {
  644. +               player.removeRequest(request.getClass());
  645. +               return;
  646. +           }
  647. +           supportTemplate = EnchantItemData.getInstance().getSupportItem(support);
  648. +       }
  649. +      
  650. +       // first validation check - also over enchant check
  651. +       if (!scrollTemplate.isValid(item, supportTemplate) || (Config.DISABLE_OVER_ENCHANTING && (item.getEnchantLevel() == scrollTemplate.getMaxEnchantLevel())))
  652. +       {
  653. +           client.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITIONS);
  654. +           player.removeRequest(request.getClass());
  655. +           client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  656. +           return;
  657. +       }
  658. +      
  659. +       // fast auto-enchant cheat check
  660. +       if ((request.getTimestamp() == 0) || ((System.currentTimeMillis() - request.getTimestamp()) < 2000))
  661. +       {
  662. +           Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " use autoenchant program ", Config.DEFAULT_PUNISH);
  663. +           player.removeRequest(request.getClass());
  664. +           client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  665. +           return;
  666. +       }
  667. +      
  668. +       // attempting to destroy scroll
  669. +       if (player.getInventory().destroyItem("Enchant", scroll.getObjectId(), 1, player, item) == null)
  670. +       {
  671. +           client.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
  672. +           Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " tried to enchant with a scroll he doesn't have", Config.DEFAULT_PUNISH);
  673. +           player.removeRequest(request.getClass());
  674. +           client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  675. +           return;
  676. +       }
  677. +      
  678. +       // attempting to destroy support if exist
  679. +       if (support != null)
  680. +       {
  681. +           if (player.getInventory().destroyItem("Enchant", support.getObjectId(), 1, player, item) == null)
  682. +           {
  683. +               client.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
  684. +               Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " tried to enchant with a support item he doesn't have", Config.DEFAULT_PUNISH);
  685. +               player.removeRequest(request.getClass());
  686. +               client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  687. +               return;
  688. +           }
  689. +       }
  690. +      
  691. +       final InventoryUpdate iu = new InventoryUpdate();
  692. +       synchronized (item)
  693. +       {
  694. +           // last validation check
  695. +           if ((item.getOwnerId() != player.getObjectId()) || (item.isEnchantable() == 0))
  696. +           {
  697. +               client.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITIONS);
  698. +               player.removeRequest(request.getClass());
  699. +               client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  700. +               return;
  701. +           }
  702. +          
  703. +           final EnchantResultType resultType = scrollTemplate.calculateSuccess(player, item, supportTemplate);
  704. +           switch (resultType)
  705. +           {
  706. +               case ERROR:
  707. +               {
  708. +                   client.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITIONS);
  709. +                   player.removeRequest(request.getClass());
  710. +                   client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  711. +                   break;
  712. +               }
  713. +               case SUCCESS:
  714. +               {
  715. +                   final Item it = item.getItem();
  716. +                   // Increase enchant level only if scroll's base template has chance, some armors can success over +20 but they shouldn't have increased.
  717. +                   if (scrollTemplate.getChance(player, item) > 0)
  718. +                   {
  719. +                       if (scrollTemplate.isGiant())
  720. +                       {
  721. +                           if (((supportTemplate != null) && (supportTemplate.getId() == 23785)) || ((supportTemplate != null) && (supportTemplate.getId() == 23786))) // Lesser Giant's Lucky Enchant Stones. Increase from +2 to +4
  722. +                           {
  723. +                               item.setEnchantLevel(Math.min(item.getEnchantLevel() + 2 + Rnd.get(3), scrollTemplate.getMaxEnchantLevel()));
  724. +                           }
  725. +                           else
  726. +                           {
  727. +                               item.setEnchantLevel(Math.min(item.getEnchantLevel() + 1 + Rnd.get(3), scrollTemplate.getMaxEnchantLevel()));
  728. +                           }
  729. +                       }
  730. +                       else
  731. +                       {
  732. +                           item.setEnchantLevel(item.getEnchantLevel() + 1);
  733. +                       }
  734. +                       item.updateDatabase();
  735. +                   }
  736. +                   client.sendPacket(new EnchantResult(EnchantResult.SUCCESS, item));
  737. +                  
  738. +                   if (Config.LOG_ITEM_ENCHANTS)
  739. +                   {
  740. +                       if (item.getEnchantLevel() > 0)
  741. +                       {
  742. +                           if (support == null)
  743. +                           {
  744. +                               LOGGER_ENCHANT.info("Success, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  745. +                           }
  746. +                           else
  747. +                           {
  748. +                               LOGGER_ENCHANT.info("Success, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  749. +                           }
  750. +                       }
  751. +                       else if (support == null)
  752. +                       {
  753. +                           LOGGER_ENCHANT.info("Success, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  754. +                       }
  755. +                       else
  756. +                       {
  757. +                           LOGGER_ENCHANT.info("Success, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  758. +                       }
  759. +                   }
  760. +                  
  761. +                   // announce the success
  762. +                   final int minEnchantAnnounce = item.isArmor() ? 10 : 15;
  763. +                   final int maxEnchantAnnounce = item.isArmor() ? 0 : 30;
  764. +                   if ((item.getEnchantLevel() >= minEnchantAnnounce) || (item.getEnchantLevel() == maxEnchantAnnounce))
  765. +                   {
  766. +                       final SystemMessage sm = new SystemMessage(SystemMessageId.C1_HAS_SUCCESSFULLY_ENCHANTED_A_S2_S3);
  767. +                       sm.addString(player.getName());
  768. +                       sm.addInt(item.getEnchantLevel());
  769. +                       sm.addItemName(item);
  770. +                       player.broadcastPacket(sm);
  771. +                       player.broadcastPacket(new ExItemAnnounce(item, player));
  772. +                      
  773. +                       final Skill skill = CommonSkill.FIREWORK.getSkill();
  774. +                       if (skill != null)
  775. +                       {
  776. +                           player.broadcastPacket(new MagicSkillUse(player, player, skill.getId(), skill.getLevel(), skill.getHitTime(), skill.getReuseDelay()));
  777. +                       }
  778. +                   }
  779. +                  
  780. +                   if (item.isEquipped())
  781. +                   {
  782. +                       if (item.isArmor())
  783. +                       {
  784. +                           it.forEachSkill(ItemSkillType.ON_ENCHANT, holder ->
  785. +                           {
  786. +                               // add skills bestowed from +4 armor
  787. +                               if (item.getEnchantLevel() >= holder.getValue())
  788. +                               {
  789. +                                   player.addSkill(holder.getSkill(), false);
  790. +                                   player.sendSkillList();
  791. +                               }
  792. +                           });
  793. +                       }
  794. +                       player.broadcastUserInfo(); // update user info
  795. +                   }
  796. +                   break;
  797. +               }
  798. +               case FAILURE:
  799. +               {
  800. +                   if (scrollTemplate.isSafe())
  801. +                   {
  802. +                       // safe enchant - remain old value
  803. +                       client.sendPacket(SystemMessageId.ENCHANT_FAILED_THE_ENCHANT_VALUE_FOR_THE_CORRESPONDING_ITEM_WILL_BE_EXACTLY_RETAINED);
  804. +                       client.sendPacket(new EnchantResult(EnchantResult.SAFE_FAIL, item));
  805. +                      
  806. +                       if (Config.LOG_ITEM_ENCHANTS)
  807. +                       {
  808. +                           if (item.getEnchantLevel() > 0)
  809. +                           {
  810. +                               if (support == null)
  811. +                               {
  812. +                                   LOGGER_ENCHANT.info("Safe Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  813. +                               }
  814. +                               else
  815. +                               {
  816. +                                   LOGGER_ENCHANT.info("Safe Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  817. +                               }
  818. +                           }
  819. +                           else if (support == null)
  820. +                           {
  821. +                               LOGGER_ENCHANT.info("Safe Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  822. +                           }
  823. +                           else
  824. +                           {
  825. +                               LOGGER_ENCHANT.info("Safe Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  826. +                           }
  827. +                       }
  828. +                   }
  829. +                   else
  830. +                   {
  831. +                       // unequip item on enchant failure to avoid item skills stack
  832. +                       if (item.isEquipped())
  833. +                       {
  834. +                           if (item.getEnchantLevel() > 0)
  835. +                           {
  836. +                               final SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2_HAS_BEEN_UNEQUIPPED);
  837. +                               sm.addInt(item.getEnchantLevel());
  838. +                               sm.addItemName(item);
  839. +                               client.sendPacket(sm);
  840. +                           }
  841. +                           else
  842. +                           {
  843. +                               final SystemMessage sm = new SystemMessage(SystemMessageId.S1_HAS_BEEN_UNEQUIPPED);
  844. +                               sm.addItemName(item);
  845. +                               client.sendPacket(sm);
  846. +                           }
  847. +                          
  848. +                           final ItemInstance[] unequiped = player.getInventory().unEquipItemInSlotAndRecord(item.getLocationSlot());
  849. +                           for (ItemInstance itm : unequiped)
  850. +                           {
  851. +                               iu.addModifiedItem(itm);
  852. +                           }
  853. +                          
  854. +                           player.sendInventoryUpdate(iu);
  855. +                           player.broadcastUserInfo();
  856. +                       }
  857. +                      
  858. +                       if (scrollTemplate.isBlessed() || ((supportTemplate != null) && supportTemplate.isBlessed()))
  859. +                       {
  860. +                           // blessed enchant - clear enchant value
  861. +                           client.sendPacket(SystemMessageId.THE_BLESSED_ENCHANT_FAILED_THE_ENCHANT_VALUE_OF_THE_ITEM_BECAME_0);
  862. +                          
  863. +                           item.setEnchantLevel(0);
  864. +                           item.updateDatabase();
  865. +                           client.sendPacket(new EnchantResult(EnchantResult.BLESSED_FAIL, 0, 0));
  866. +                          
  867. +                           if (Config.LOG_ITEM_ENCHANTS)
  868. +                           {
  869. +                               if (item.getEnchantLevel() > 0)
  870. +                               {
  871. +                                   if (support == null)
  872. +                                   {
  873. +                                       LOGGER_ENCHANT.info("Blessed Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  874. +                                   }
  875. +                                   else
  876. +                                   {
  877. +                                       LOGGER_ENCHANT.info("Blessed Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  878. +                                   }
  879. +                               }
  880. +                               else if (support == null)
  881. +                               {
  882. +                                   LOGGER_ENCHANT.info("Blessed Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  883. +                               }
  884. +                               else
  885. +                               {
  886. +                                   LOGGER_ENCHANT.info("Blessed Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  887. +                               }
  888. +                           }
  889. +                       }
  890. +                       else
  891. +                       {
  892. +                           // enchant failed, destroy item
  893. +                           final int crystalId = item.getItem().getCrystalItemId();
  894. +                           int count = item.getCrystalCount() - ((item.getItem().getCrystalCount() + 1) / 2);
  895. +                           if (count < 1)
  896. +                           {
  897. +                               count = 1;
  898. +                           }
  899. +                          
  900. +                           if (player.getInventory().destroyItem("Enchant", item, player, null) == null)
  901. +                           {
  902. +                               // unable to destroy item, cheater ?
  903. +                               Util.handleIllegalPlayerAction(player, "Unable to delete item on enchant failure from player " + player.getName() + ", possible cheater !", Config.DEFAULT_PUNISH);
  904. +                               player.removeRequest(request.getClass());
  905. +                               client.sendPacket(new EnchantResult(EnchantResult.ERROR, 0, 0));
  906. +                              
  907. +                               if (Config.LOG_ITEM_ENCHANTS)
  908. +                               {
  909. +                                   if (item.getEnchantLevel() > 0)
  910. +                                   {
  911. +                                       if (support == null)
  912. +                                       {
  913. +                                           LOGGER_ENCHANT.info("Unable to destroy, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  914. +                                       }
  915. +                                       else
  916. +                                       {
  917. +                                           LOGGER_ENCHANT.info("Unable to destroy, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  918. +                                       }
  919. +                                   }
  920. +                                   else if (support == null)
  921. +                                   {
  922. +                                       LOGGER_ENCHANT.info("Unable to destroy, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  923. +                                   }
  924. +                                   else
  925. +                                   {
  926. +                                       LOGGER_ENCHANT.info("Unable to destroy, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  927. +                                   }
  928. +                               }
  929. +                               return;
  930. +                           }
  931. +                          
  932. +                           World.getInstance().removeObject(item);
  933. +                           ItemInstance crystals = null;
  934. +                           if (crystalId != 0)
  935. +                           {
  936. +                               crystals = player.getInventory().addItem("Enchant", crystalId, count, player, item);
  937. +                              
  938. +                               final SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S);
  939. +                               sm.addItemName(crystals);
  940. +                               sm.addLong(count);
  941. +                               client.sendPacket(sm);
  942. +                           }
  943. +                          
  944. +                           if (!Config.FORCE_INVENTORY_UPDATE)
  945. +                           {
  946. +                               if (crystals != null)
  947. +                               {
  948. +                                   iu.addItem(crystals);
  949. +                               }
  950. +                           }
  951. +                          
  952. +                           if (crystalId == 0)
  953. +                           {
  954. +                               client.sendPacket(new EnchantResult(EnchantResult.NO_CRYSTAL, 0, 0));
  955. +                           }
  956. +                           else
  957. +                           {
  958. +                               client.sendPacket(new EnchantResult(EnchantResult.FAIL, crystalId, count));
  959. +                           }
  960. +                          
  961. +                           if (Config.LOG_ITEM_ENCHANTS)
  962. +                           {
  963. +                               if (item.getEnchantLevel() > 0)
  964. +                               {
  965. +                                   if (support == null)
  966. +                                   {
  967. +                                       LOGGER_ENCHANT.info("Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  968. +                                   }
  969. +                                   else
  970. +                                   {
  971. +                                       LOGGER_ENCHANT.info("Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", +" + item.getEnchantLevel() + " " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  972. +                                   }
  973. +                               }
  974. +                               else if (support == null)
  975. +                               {
  976. +                                   LOGGER_ENCHANT.info("Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "]");
  977. +                               }
  978. +                               else
  979. +                               {
  980. +                                   LOGGER_ENCHANT.info("Fail, Character:" + player.getName() + " [" + player.getObjectId() + "] Account:" + player.getAccountName() + " IP:" + player.getIPAddress() + ", " + item.getName() + "(" + item.getCount() + ") [" + item.getObjectId() + "], " + scroll.getName() + "(" + scroll.getCount() + ") [" + scroll.getObjectId() + "], " + support.getName() + "(" + support.getCount() + ") [" + support.getObjectId() + "]");
  981. +                               }
  982. +                           }
  983. +                       }
  984. +                   }
  985. +                   break;
  986. +               }
  987. +           }
  988. +          
  989. +           player.sendItemList();
  990. +          
  991. +           request.setProcessing(false);
  992. +           player.broadcastUserInfo(UserInfoType.ENCHANTLEVEL);
  993. +       }
  994. +   }
  995. +}
  996. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement