Guest User

RequestRefine.java

a guest
Aug 3rd, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.24 KB | None | 0 0
  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.network.clientpackets;
  16.  
  17. import net.sf.l2j.gameserver.datatables.AugmentationData;
  18. import net.sf.l2j.gameserver.model.L2Augmentation;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  21. import net.sf.l2j.gameserver.model.item.kind.Premium;
  22. import net.sf.l2j.gameserver.network.SystemMessageId;
  23. import net.sf.l2j.gameserver.network.serverpackets.ExVariationResult;
  24. import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  25. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  26.  
  27. /**
  28.  * Format:(ch) dddd
  29.  * @author -Wooden-
  30.  */
  31. public final class RequestRefine extends AbstractRefinePacket
  32. {
  33.     private int _targetItemObjId;
  34.     private int _refinerItemObjId;
  35.     private int _gemStoneItemObjId;
  36.     private int _gemStoneCount;
  37.    
  38.     @Override
  39.     protected void readImpl()
  40.     {
  41.         _targetItemObjId = readD();
  42.         _refinerItemObjId = readD();
  43.         _gemStoneItemObjId = readD();
  44.         _gemStoneCount = readD();
  45.     }
  46.    
  47.     @Override
  48.     protected void runImpl()
  49.     {
  50.         final L2PcInstance activeChar = getClient().getActiveChar();
  51.         if (activeChar == null)
  52.         {
  53.             return;
  54.         }
  55.        
  56.         final ItemInstance targetItem = activeChar.getInventory().getItemByObjectId(_targetItemObjId);
  57.         if (targetItem == null)
  58.         {
  59.             activeChar.sendPacket(new ExVariationResult(0, 0, 0));
  60.             activeChar.sendPacket(SystemMessageId.AUGMENTATION_FAILED_DUE_TO_INAPPROPRIATE_CONDITIONS);
  61.             return;
  62.         }
  63.        
  64.         final ItemInstance refinerItem = activeChar.getInventory().getItemByObjectId(_refinerItemObjId);
  65.         if (refinerItem == null)
  66.         {
  67.             activeChar.sendPacket(new ExVariationResult(0, 0, 0));
  68.             activeChar.sendPacket(SystemMessageId.AUGMENTATION_FAILED_DUE_TO_INAPPROPRIATE_CONDITIONS);
  69.             return;
  70.         }
  71.        
  72.         final ItemInstance gemStoneItem = activeChar.getInventory().getItemByObjectId(_gemStoneItemObjId);
  73.         if (gemStoneItem == null)
  74.         {
  75.             activeChar.sendPacket(new ExVariationResult(0, 0, 0));
  76.             activeChar.sendPacket(SystemMessageId.AUGMENTATION_FAILED_DUE_TO_INAPPROPRIATE_CONDITIONS);
  77.             return;
  78.         }
  79.        
  80.         if (!isValid(activeChar, targetItem, refinerItem, gemStoneItem))
  81.         {
  82.             activeChar.sendPacket(new ExVariationResult(0, 0, 0));
  83.             activeChar.sendPacket(SystemMessageId.AUGMENTATION_FAILED_DUE_TO_INAPPROPRIATE_CONDITIONS);
  84.             return;
  85.         }
  86.        
  87.         final LifeStone ls = getLifeStone(refinerItem.getItemId());
  88.         if (ls == null)
  89.         {
  90.             activeChar.sendPacket(new ExVariationResult(0, 0, 0));
  91.             activeChar.sendPacket(SystemMessageId.AUGMENTATION_FAILED_DUE_TO_INAPPROPRIATE_CONDITIONS);
  92.             return;
  93.         }
  94.        
  95.         final int lifeStoneLevel = ls.getLevel();
  96.         final int lifeStoneGrade = ls.getGrade();
  97.         if (_gemStoneCount != getGemStoneCount(targetItem.getItem().getCrystalType()))
  98.         {
  99.             activeChar.sendPacket(new ExVariationResult(0, 0, 0));
  100.             activeChar.sendPacket(SystemMessageId.AUGMENTATION_FAILED_DUE_TO_INAPPROPRIATE_CONDITIONS);
  101.             return;
  102.         }
  103.        
  104.         // unequip item
  105.         if (targetItem.isEquipped())
  106.         {
  107.             ItemInstance[] unequipped = activeChar.getInventory().unEquipItemInSlotAndRecord(targetItem.getLocationSlot());
  108.             InventoryUpdate iu = new InventoryUpdate();
  109.            
  110.             for (ItemInstance itm : unequipped)
  111.             {
  112.                 iu.addModifiedItem(itm);
  113.             }
  114.            
  115.             activeChar.sendPacket(iu);
  116.             activeChar.broadcastUserInfo();
  117.         }
  118.        
  119.         // Consume the life stone
  120.         if (!activeChar.destroyItem("RequestRefine", refinerItem, 1, null, false))
  121.         {
  122.             activeChar.sendPacket(new ExVariationResult(0, 0, 0));
  123.             activeChar.sendPacket(SystemMessageId.AUGMENTATION_FAILED_DUE_TO_INAPPROPRIATE_CONDITIONS);
  124.             return;
  125.         }
  126.        
  127.         // Consume gemstones
  128.         if (!activeChar.destroyItem("RequestRefine", gemStoneItem, _gemStoneCount, null, false))
  129.         {
  130.             activeChar.sendPacket(new ExVariationResult(0, 0, 0));
  131.             activeChar.sendPacket(SystemMessageId.AUGMENTATION_FAILED_DUE_TO_INAPPROPRIATE_CONDITIONS);
  132.             return;
  133.         }
  134.        
  135.         final double premiumMul = activeChar.getPremiumAttribute(Premium.MODIFIER_AUGMENT_CHANCE);
  136.        
  137.         final L2Augmentation aug = AugmentationData.getInstance().generateRandomAugmentation(lifeStoneLevel, lifeStoneGrade, premiumMul);
  138.         targetItem.setAugmentation(aug);
  139.        
  140.         final int stat12 = 0x0000FFFF & aug.getAugmentationId();
  141.         final int stat34 = aug.getAugmentationId() >> 16;
  142.         activeChar.sendPacket(new ExVariationResult(stat12, stat34, 1));
  143.        
  144.         InventoryUpdate iu = new InventoryUpdate();
  145.         iu.addModifiedItem(targetItem);
  146.         activeChar.sendPacket(iu);
  147.        
  148.         StatusUpdate su = new StatusUpdate(activeChar);
  149.         su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
  150.         activeChar.sendPacket(su);
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment