浏览代码

Fixes #1116 by Kreastr
Now if client requests to change weapon while auto attack, server will schedule a new task to change the weapon that will be run at the end of the strike.
Check this thread for further information http://www.l2jserver.com/forum/thread.php?threadid=30257
Thank you to all people that has tested this and updated to latest revs as well.

DrHouse 16 年之前
父节点
当前提交
ce3062f7c7
共有 1 个文件被更改,包括 112 次插入3 次删除
  1. 112 3
      L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/UseItem.java

+ 112 - 3
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/UseItem.java

@@ -36,6 +36,8 @@ import net.sf.l2j.gameserver.templates.L2ArmorType;
 import net.sf.l2j.gameserver.templates.L2Item;
 import net.sf.l2j.gameserver.templates.L2Weapon;
 import net.sf.l2j.gameserver.templates.L2WeaponType;
+import net.sf.l2j.gameserver.GameTimeController;
+import net.sf.l2j.gameserver.ThreadPoolManager;
 import net.sf.l2j.gameserver.util.FloodProtector;
 
 /**
@@ -50,6 +52,110 @@ public final class UseItem extends L2GameClientPacket
 
 	private int _objectId;
 
+	/** Weapon Equip Task */
+	public class WeaponEquipTask implements Runnable
+	{
+		L2ItemInstance item;
+		L2PcInstance activeChar;
+		public WeaponEquipTask(L2ItemInstance it, L2PcInstance character){
+			item = it;
+			activeChar = character;
+		}
+		public void run()
+		{
+			//If character is still engaged in strike we should not change weapon
+			if (activeChar.isAttackingNow())
+				return;
+            // Equip or unEquip
+            L2ItemInstance[] items = null;
+            boolean isEquiped = item.isEquipped();
+            SystemMessage sm = null;
+            L2ItemInstance old = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LRHAND);
+            if (old == null)
+            	old = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
+
+            activeChar.checkSSMatch(item, old);
+
+            if (isEquiped)
+            {
+	            if (item.getEnchantLevel() > 0)
+	            {
+	            	sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
+	            	sm.addNumber(item.getEnchantLevel());
+	            	sm.addItemName(item);
+	            }
+	            else
+	            {
+		            sm = new SystemMessage(SystemMessageId.S1_DISARMED);
+		            sm.addItemName(item);
+	            }
+	            activeChar.sendPacket(sm);
+
+	            int slot = activeChar.getInventory().getSlotFromItem(item);
+            	items = activeChar.getInventory().unEquipItemInBodySlotAndRecord(slot);
+            }
+            else
+            {
+            	int tempBodyPart = item.getItem().getBodyPart();
+            	L2ItemInstance tempItem = activeChar.getInventory().getPaperdollItemByL2ItemId(tempBodyPart);
+
+            	//check if the item replaces a wear-item
+            	if (tempItem != null && tempItem.isWear())
+            	{
+            		// dont allow an item to replace a wear-item
+            		return;
+            	}
+            	else if (tempBodyPart == 0x4000) // left+right hand equipment
+            	{
+            		// this may not remove left OR right hand equipment
+            		tempItem = activeChar.getInventory().getPaperdollItem(7);
+            		if (tempItem != null && tempItem.isWear()) return;
+
+            		tempItem = activeChar.getInventory().getPaperdollItem(8);
+            		if (tempItem != null && tempItem.isWear()) return;
+            	}
+            	else if (tempBodyPart == 0x8000) // fullbody armor
+            	{
+            		// this may not remove chest or leggins
+            		tempItem = activeChar.getInventory().getPaperdollItem(10);
+            		if (tempItem != null && tempItem.isWear()) return;
+
+            		tempItem = activeChar.getInventory().getPaperdollItem(11);
+            		if (tempItem != null && tempItem.isWear()) return;
+            	}
+
+				if (item.getEnchantLevel() > 0)
+				{
+					sm = new SystemMessage(SystemMessageId.S1_S2_EQUIPPED);
+					sm.addNumber(item.getEnchantLevel());
+					sm.addItemName(item);
+				}
+				else
+				{
+					sm = new SystemMessage(SystemMessageId.S1_EQUIPPED);
+					sm.addItemName(item);
+				}
+				activeChar.sendPacket(sm);
+
+				items = activeChar.getInventory().equipItemAndRecord(item);
+
+	            // Consume mana - will start a task if required; returns if item is not a shadow item
+	            item.decreaseMana(false);
+            }
+            sm = null;
+
+            activeChar.refreshExpertisePenalty();
+
+			if (item.getItem().getType2() == L2Item.TYPE2_WEAPON)
+				activeChar.checkIfWeaponIsAllowed();
+
+			InventoryUpdate iu = new InventoryUpdate();
+			iu.addItems(Arrays.asList(items));
+			activeChar.sendPacket(iu);
+			activeChar.broadcastUserInfo();
+		}
+	}	
+	
 	@Override
 	protected void readImpl()
 	{
@@ -278,10 +384,10 @@ public final class UseItem extends L2GameClientPacket
                     		return;
                     	}
                     	
-                        if ((activeChar.isAttackingNow() || activeChar.isMounted()))
+                        if (activeChar.isMounted())
                         	return;
                         
-                        
+                       
                         if (activeChar.isDisarmed())
                         {
                             activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION));
@@ -528,7 +634,10 @@ public final class UseItem extends L2GameClientPacket
                 {
                     return;
                 }
-
+                if (activeChar.isAttackingNow()){
+                	ThreadPoolManager.getInstance().scheduleGeneral( new WeaponEquipTask(item,activeChar), (activeChar.getAttackEndTime()-GameTimeController.getGameTicks())*GameTimeController.MILLIS_IN_TICK);
+                	return;
+                }
                 // Equip or unEquip
                 L2ItemInstance[] items = null;
                 boolean isEquiped = item.isEquipped();