浏览代码

Old fix for finishing cast with a different weapon than
what it was started with. Partially by Kreastr.

Sami 16 年之前
父节点
当前提交
615eabfcca

+ 1 - 1
L2_GameServer/java/net/sf/l2j/gameserver/model/L2Character.java

@@ -3791,7 +3791,7 @@ public abstract class L2Character extends L2Object
 	/**
 	 * Return True if the L2Character is casting.<BR><BR>
 	 */
-	public final boolean isCastingNow()
+	public synchronized final boolean isCastingNow()
 	{
 		return _castEndTime > GameTimeController.getGameTicks();
 	}

+ 94 - 1
L2_GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java

@@ -17,6 +17,7 @@ package net.sf.l2j.gameserver.model.actor.instance;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -1952,6 +1953,98 @@ public final class L2PcInstance extends L2PlayableInstance
 		}
     }
 
+    public synchronized void useEquippableItem(L2ItemInstance item, boolean abortAttack)
+	{
+		// Equip or unEquip
+        L2ItemInstance[] items = null;
+        boolean isEquiped = item.isEquipped();
+        SystemMessage sm = null;
+        L2ItemInstance old = getInventory().getPaperdollItem(Inventory.PAPERDOLL_LRHAND);
+        if (old == null)
+        	old = getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
+
+        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);
+            }
+            sendPacket(sm);
+
+            int slot = getInventory().getSlotFromItem(item);
+        	items = getInventory().unEquipItemInBodySlotAndRecord(slot);
+        }
+        else
+        {
+        	int tempBodyPart = item.getItem().getBodyPart();
+        	L2ItemInstance tempItem = 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 = getInventory().getPaperdollItem(7);
+        		if (tempItem != null && tempItem.isWear()) return;
+
+        		tempItem = getInventory().getPaperdollItem(8);
+        		if (tempItem != null && tempItem.isWear()) return;
+        	}
+        	else if (tempBodyPart == 0x8000) // fullbody armor
+        	{
+        		// this may not remove chest or leggins
+        		tempItem = getInventory().getPaperdollItem(10);
+        		if (tempItem != null && tempItem.isWear()) return;
+
+        		tempItem = 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);
+			}
+			sendPacket(sm);
+
+			items = getInventory().equipItemAndRecord(item);
+
+            // Consume mana - will start a task if required; returns if item is not a shadow item
+            item.decreaseMana(false);
+        }
+        sm = null;
+
+        refreshExpertisePenalty();
+
+		if (item.getItem().getType2() == L2Item.TYPE2_WEAPON)
+			checkIfWeaponIsAllowed();
+
+		InventoryUpdate iu = new InventoryUpdate();
+		iu.addItems(Arrays.asList(items));
+		sendPacket(iu);
+		if (abortAttack) abortAttack();
+		broadcastUserInfo();		
+	}
+    
 	/**
 	 * Return the the PvP Kills of the L2PcInstance (Number of player killed during a PvP).<BR><BR>
 	 */
@@ -7714,7 +7807,7 @@ public final class L2PcInstance extends L2PlayableInstance
 	 * @param dontMove used to prevent movement, if not in range
 	 *
 	 */
-	public void useMagic(L2Skill skill, boolean forceUse, boolean dontMove)
+	public synchronized void useMagic(L2Skill skill, boolean forceUse, boolean dontMove)
 	{
         // Check if the skill is active
         if (skill.isPassive())

+ 2 - 175
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/UseItem.java

@@ -14,7 +14,6 @@
  */
 package net.sf.l2j.gameserver.network.clientpackets;
 
-import java.util.Arrays;
 import java.util.logging.Logger;
 
 import net.sf.l2j.Config;
@@ -28,7 +27,6 @@ import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
 import net.sf.l2j.gameserver.model.base.Race;
 import net.sf.l2j.gameserver.network.SystemMessageId;
 import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
-import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
 import net.sf.l2j.gameserver.network.serverpackets.ItemList;
 import net.sf.l2j.gameserver.network.serverpackets.ShowCalculator;
 import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
@@ -67,92 +65,7 @@ public final class UseItem extends L2GameClientPacket
 			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();
+			activeChar.useEquippableItem(item, false);
 		}
 	}	
 	
@@ -639,93 +552,7 @@ public final class UseItem extends L2GameClientPacket
                 	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.abortAttack();
-				activeChar.broadcastUserInfo();
+                activeChar.useEquippableItem(item, true);
 			}
 			else
 			{