瀏覽代碼

If inventory loaded before player appeared in the world - equipped shadow items does not consume mana.
Added forced scheduling of the mana consumption on load.
Also hero and common items booleans moved into L2Item.

_DS_ 16 年之前
父節點
當前提交
5f4b09df5c

+ 15 - 8
L2_GameServer/java/net/sf/l2j/gameserver/model/L2ItemInstance.java

@@ -704,12 +704,12 @@ public final class L2ItemInstance extends L2Object
     
     public boolean isHeroItem()
     {
-        return ((_itemId >= 6611 && _itemId <= 6621) || (_itemId >= 9388 && _itemId <= 9390) || _itemId == 6842);
+        return _item.isHeroItem();
     }
 
     public boolean isCommonItem()
     {
-        return ((_itemId >= 12006 && _itemId <= 12361) || (_itemId >= 11605 && _itemId <= 12308));
+        return _item.isCommon();
     }
     
     public boolean isOlyRestrictedItem()
@@ -1049,7 +1049,7 @@ public final class L2ItemInstance extends L2Object
 	 */
 	public class ScheduleConsumeManaTask implements Runnable
 	{
-		private L2ItemInstance _shadowItem;
+		private final L2ItemInstance _shadowItem;
 		
 		public ScheduleConsumeManaTask(L2ItemInstance item)
 		{
@@ -1107,7 +1107,7 @@ public final class L2ItemInstance extends L2Object
 		if (_storedInDb) _storedInDb = false;
 		if (resetConsumingMana) _consumingMana = false;
 
-		L2PcInstance player = ((L2PcInstance)L2World.getInstance().findObject(getOwnerId()));
+		final L2PcInstance player = ((L2PcInstance)L2World.getInstance().findObject(getOwnerId()));
 		if (player != null)
 		{
 			SystemMessage sm;
@@ -1189,8 +1189,10 @@ public final class L2ItemInstance extends L2Object
 		}
 	}
 
-	private void scheduleConsumeManaTask()
+	public void scheduleConsumeManaTask()
 	{
+		if (_consumingMana)
+			return;
 		_consumingMana = true;
 		ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleConsumeManaTask(this), MANA_CONSUMPTION_RATE);
 	}
@@ -1354,8 +1356,12 @@ public final class L2ItemInstance extends L2Object
 		inst._mana = manaLeft;
 		inst._time = time;
 		// consume 1 mana
-		if (inst._mana > 0 && inst.getLocation() == ItemLocation.PAPERDOLL)
-		    inst.decreaseMana(false);
+		if (inst.isShadowItem() && inst.isEquipped())
+		{
+			inst.decreaseMana(false);
+			// if player still not loaded and not found in the world - force task creation
+			inst.scheduleConsumeManaTask();
+		}
 
 		// if mana left is 0 return nothing, item already deleted from decreaseMana()
 		if (inst._mana == 0)
@@ -1650,6 +1656,7 @@ public final class L2ItemInstance extends L2Object
     {
     	return _time - System.currentTimeMillis();
     }
+
     public void endOfLife()
     {
     	L2PcInstance player = ((L2PcInstance)L2World.getInstance().findObject(getOwnerId()));
@@ -1707,7 +1714,7 @@ public final class L2ItemInstance extends L2Object
     
     public class ScheduleLifeTimeTask implements Runnable
     {
-    	private L2ItemInstance _limitedItem;
+    	private final L2ItemInstance _limitedItem;
     	
     	public ScheduleLifeTimeTask(L2ItemInstance item)
     	{

+ 26 - 2
L2_GameServer/java/net/sf/l2j/gameserver/templates/item/L2Item.java

@@ -156,7 +156,10 @@ public abstract class L2Item
 	private final boolean _dropable;
 	private final boolean _destroyable;
 	private final boolean _tradeable;
-	
+
+	private final boolean _common;
+	private final boolean _heroItem;
+
 	@SuppressWarnings("unchecked")
 	protected final Enum _type;
 	
@@ -207,6 +210,9 @@ public abstract class L2Item
 		_dropable = set.getBool("dropable", true);
 		_destroyable = set.getBool("destroyable", true);
 		_tradeable = set.getBool("tradeable", true);
+
+		_common = (_itemId >= 12006 && _itemId <= 12361) || (_itemId >= 11605 && _itemId <= 12308);
+		_heroItem = (_itemId >= 6611 && _itemId <= 6621) || (_itemId >= 9388 && _itemId <= 9390) || _itemId == 6842;
 	}
 	
 	/**
@@ -464,7 +470,25 @@ public abstract class L2Item
 	{
 		return _tradeable;
 	}
-	
+
+	/**
+	 * Returns if item is common
+	 * @return boolean
+	 */
+	public final boolean isCommon()
+	{
+		return _common;
+	}
+
+	/**
+	 * Returns if item is hero-only
+	 * @return
+	 */
+	public final boolean isHeroItem()
+	{
+		return _heroItem;
+	}
+
 	/**
 	 * Returns if item is for hatchling
 	 * @return boolean