ソースを参照

BETA: More OOP version of [6294].
* All NPC should have the ability to drop items, not only those that can be attacked.
* Avoids duplicated code.
* Gives all NPCs the ability to drop.

Zoey76 11 年 前
コミット
21408a9c01

+ 0 - 63
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/L2Attackable.java

@@ -26,7 +26,6 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 
 import com.l2jserver.Config;
-import com.l2jserver.gameserver.ItemsAutoDestroy;
 import com.l2jserver.gameserver.SevenSigns;
 import com.l2jserver.gameserver.ThreadPoolManager;
 import com.l2jserver.gameserver.ai.CtrlEvent;
@@ -66,7 +65,6 @@ import com.l2jserver.gameserver.model.holders.ItemHolder;
 import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
 import com.l2jserver.gameserver.model.items.L2Item;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
-import com.l2jserver.gameserver.model.items.type.L2EtcItemType;
 import com.l2jserver.gameserver.model.quest.Quest;
 import com.l2jserver.gameserver.model.skills.L2Skill;
 import com.l2jserver.gameserver.model.stats.Stats;
@@ -1695,67 +1693,6 @@ public class L2Attackable extends L2Npc
 		}
 	}
 	
-	/**
-	 * Drops an item.
-	 * @param player the last attacker or main damage dealer
-	 * @param itemId the item ID
-	 * @param itemCount the item count
-	 * @return the dropped item
-	 */
-	public L2ItemInstance dropItem(L2PcInstance player, int itemId, long itemCount)
-	{
-		int randDropLim = 70;
-		
-		L2ItemInstance ditem = null;
-		for (int i = 0; i < itemCount; i++)
-		{
-			// Randomize drop position
-			int newX = (getX() + Rnd.get((randDropLim * 2) + 1)) - randDropLim;
-			int newY = (getY() + Rnd.get((randDropLim * 2) + 1)) - randDropLim;
-			int newZ = Math.max(getZ(), player.getZ()) + 20; // TODO: temp hack, do something nicer when we have geodatas
-			
-			if (ItemTable.getInstance().getTemplate(itemId) != null)
-			{
-				// Init the dropped L2ItemInstance and add it in the world as a visible object at the position where mob was last
-				ditem = ItemTable.getInstance().createItem("Loot", itemId, itemCount, player, this);
-				ditem.getDropProtection().protect(player);
-				ditem.dropMe(this, newX, newY, newZ);
-				
-				// Add drop to auto destroy item task
-				if (!Config.LIST_PROTECTED_ITEMS.contains(itemId))
-				{
-					if (((Config.AUTODESTROY_ITEM_AFTER > 0) && (ditem.getItemType() != L2EtcItemType.HERB)) || ((Config.HERB_AUTO_DESTROY_TIME > 0) && (ditem.getItemType() == L2EtcItemType.HERB)))
-					{
-						ItemsAutoDestroy.getInstance().addItem(ditem);
-					}
-				}
-				ditem.setProtected(false);
-				
-				// If stackable, end loop as entire count is included in 1 instance of item
-				if (ditem.isStackable() || !Config.MULTIPLE_ITEM_DROP)
-				{
-					break;
-				}
-			}
-			else
-			{
-				_log.log(Level.SEVERE, "Item doesn't exist so cannot be dropped. Item ID: " + itemId);
-			}
-		}
-		return ditem;
-	}
-	
-	/**
-	 * Method overload for {@link L2Attackable#dropItem(L2PcInstance, int, long)}
-	 * @param player the last attacker or main damage dealer
-	 * @param item the item holder
-	 * @return the dropped item
-	 */
-	public L2ItemInstance dropItem(L2PcInstance player, ItemHolder item)
-	{
-		return dropItem(player, item.getId(), item.getCount());
-	}
-	
 	/**
 	 * @return the active weapon of this L2Attackable (= null).
 	 */

+ 71 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/L2Npc.java

@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.logging.Level;
 
 import com.l2jserver.Config;
+import com.l2jserver.gameserver.ItemsAutoDestroy;
 import com.l2jserver.gameserver.SevenSigns;
 import com.l2jserver.gameserver.SevenSignsFestival;
 import com.l2jserver.gameserver.ThreadPoolManager;
@@ -67,9 +68,11 @@ import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
 import com.l2jserver.gameserver.model.entity.Castle;
 import com.l2jserver.gameserver.model.entity.Fort;
 import com.l2jserver.gameserver.model.entity.clanhall.SiegableHall;
+import com.l2jserver.gameserver.model.holders.ItemHolder;
 import com.l2jserver.gameserver.model.items.L2Item;
 import com.l2jserver.gameserver.model.items.L2Weapon;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
+import com.l2jserver.gameserver.model.items.type.L2EtcItemType;
 import com.l2jserver.gameserver.model.olympiad.Olympiad;
 import com.l2jserver.gameserver.model.quest.Quest;
 import com.l2jserver.gameserver.model.skills.L2Skill;
@@ -97,6 +100,8 @@ public class L2Npc extends L2Character
 {
 	/** The interaction distance of the L2NpcInstance(is used as offset in MovetoLocation method) */
 	public static final int INTERACTION_DISTANCE = 150;
+	/** Maximum distance where the drop may appear given this NPC position. */
+	public static final int RANDOM_ITEM_DROP_LIMIT = 70;
 	/** The L2Spawn object that manage this L2NpcInstance */
 	private L2Spawn _spawn;
 	/** The flag to specify if this L2NpcInstance is busy */
@@ -1949,4 +1954,70 @@ public class L2Npc extends L2Character
 	{
 		return CategoryData.getInstance().isInCategory(type, getId());
 	}
+	
+	/**
+	 * Drops an item.
+	 * @param player the last attacker or main damage dealer
+	 * @param itemId the item ID
+	 * @param itemCount the item count
+	 * @return the dropped item
+	 */
+	public L2ItemInstance dropItem(L2PcInstance player, int itemId, long itemCount)
+	{
+		L2ItemInstance item = null;
+		for (int i = 0; i < itemCount; i++)
+		{
+			// Randomize drop position.
+			final int newX = (getX() + Rnd.get((RANDOM_ITEM_DROP_LIMIT * 2) + 1)) - RANDOM_ITEM_DROP_LIMIT;
+			final int newY = (getY() + Rnd.get((RANDOM_ITEM_DROP_LIMIT * 2) + 1)) - RANDOM_ITEM_DROP_LIMIT;
+			final int newZ = getZ() + 20;
+			
+			if (ItemTable.getInstance().getTemplate(itemId) == null)
+			{
+				_log.log(Level.SEVERE, "Item doesn't exist so cannot be dropped. Item ID: " + itemId + " Quest: " + getName());
+				return null;
+			}
+			
+			item = ItemTable.getInstance().createItem("Loot", itemId, itemCount, player, this);
+			if (item == null)
+			{
+				return null;
+			}
+			
+			if (player != null)
+			{
+				item.getDropProtection().protect(player);
+			}
+			
+			item.dropMe(this, newX, newY, newZ);
+			
+			// Add drop to auto destroy item task.
+			if (!Config.LIST_PROTECTED_ITEMS.contains(itemId))
+			{
+				if (((Config.AUTODESTROY_ITEM_AFTER > 0) && (item.getItemType() != L2EtcItemType.HERB)) || ((Config.HERB_AUTO_DESTROY_TIME > 0) && (item.getItemType() == L2EtcItemType.HERB)))
+				{
+					ItemsAutoDestroy.getInstance().addItem(item);
+				}
+			}
+			item.setProtected(false);
+			
+			// If stackable, end loop as entire count is included in 1 instance of item.
+			if (item.isStackable() || !Config.MULTIPLE_ITEM_DROP)
+			{
+				break;
+			}
+		}
+		return item;
+	}
+	
+	/**
+	 * Method overload for {@link L2Attackable#dropItem(L2PcInstance, int, long)}
+	 * @param player the last attacker or main damage dealer
+	 * @param item the item holder
+	 * @return the dropped item
+	 */
+	public L2ItemInstance dropItem(L2PcInstance player, ItemHolder item)
+	{
+		return dropItem(player, item.getId(), item.getCount());
+	}
 }

+ 0 - 54
L2J_Server_BETA/java/com/l2jserver/gameserver/model/quest/Quest.java

@@ -37,7 +37,6 @@ import java.util.logging.Logger;
 import com.l2jserver.Config;
 import com.l2jserver.L2DatabaseFactory;
 import com.l2jserver.gameserver.GameTimeController;
-import com.l2jserver.gameserver.ItemsAutoDestroy;
 import com.l2jserver.gameserver.ThreadPoolManager;
 import com.l2jserver.gameserver.cache.HtmCache;
 import com.l2jserver.gameserver.datatables.DoorTable;
@@ -70,7 +69,6 @@ import com.l2jserver.gameserver.model.interfaces.IPositionable;
 import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
 import com.l2jserver.gameserver.model.items.L2Item;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
-import com.l2jserver.gameserver.model.items.type.L2EtcItemType;
 import com.l2jserver.gameserver.model.olympiad.CompetitionType;
 import com.l2jserver.gameserver.model.quest.AITasks.AggroRangeEnter;
 import com.l2jserver.gameserver.model.quest.AITasks.SeeCreature;
@@ -3525,58 +3523,6 @@ public class Quest extends ManagedScript implements IIdentifiable
 		return check;
 	}
 	
-	/**
-	 * Drops an item given an NPC.
-	 * @param npc the NPC dropping the item
-	 * @param itemId the item ID
-	 * @param itemCount the item count
-	 */
-	public void dropItem(L2Npc npc, int itemId, long itemCount)
-	{
-		for (int i = 0; i < itemCount; i++)
-		{
-			// Randomize drop position.
-			final int newX = (npc.getX() + Rnd.get((70 * 2) + 1)) - 70;
-			final int newY = (npc.getY() + Rnd.get((70 * 2) + 1)) - 70;
-			final int newZ = npc.getZ() + 20;
-			
-			if (ItemTable.getInstance().getTemplate(itemId) == null)
-			{
-				_log.log(Level.SEVERE, "Item doesn't exist so cannot be dropped. Item ID: " + itemId + " Quest: " + getName());
-				return;
-			}
-			
-			final L2ItemInstance item = ItemTable.getInstance().createItem("Loot", itemId, itemCount, null, null);
-			item.dropMe(npc, newX, newY, newZ);
-			
-			// Add drop to auto destroy item task.
-			if (!Config.LIST_PROTECTED_ITEMS.contains(itemId))
-			{
-				if (((Config.AUTODESTROY_ITEM_AFTER > 0) && (item.getItemType() != L2EtcItemType.HERB)) || ((Config.HERB_AUTO_DESTROY_TIME > 0) && (item.getItemType() == L2EtcItemType.HERB)))
-				{
-					ItemsAutoDestroy.getInstance().addItem(item);
-				}
-			}
-			item.setProtected(false);
-			
-			// If stackable, end loop as entire count is included in 1 instance of item.
-			if (item.isStackable() || !Config.MULTIPLE_ITEM_DROP)
-			{
-				break;
-			}
-		}
-	}
-	
-	/**
-	 * Method overload for {@link Quest#dropItem(L2Npc, int, long)}
-	 * @param npc the NPC dropping the item
-	 * @param item the item holder
-	 */
-	public void dropItem(L2Npc npc, ItemHolder item)
-	{
-		dropItem(npc, item.getId(), item.getCount());
-	}
-	
 	/**
 	 * Remove all quest items associated with this quest from the specified player's inventory.
 	 * @param player the player whose quest items to remove

+ 0 - 6
L2J_Server_BETA/java/com/l2jserver/gameserver/model/quest/QuestState.java

@@ -34,7 +34,6 @@ import com.l2jserver.gameserver.enums.QuestType;
 import com.l2jserver.gameserver.instancemanager.QuestManager;
 import com.l2jserver.gameserver.model.actor.L2Character;
 import com.l2jserver.gameserver.model.actor.L2Npc;
-import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.holders.ItemHolder;
 import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
@@ -1202,11 +1201,6 @@ public final class QuestState
 		_player.sendPacket(new TutorialEnableClientEvent(number));
 	}
 	
-	public void dropItem(L2MonsterInstance npc, L2PcInstance player, int itemId, int count)
-	{
-		npc.dropItem(player, itemId, count);
-	}
-	
 	/**
 	 * Set the restart time for the daily quests.<br>
 	 * The time is hardcoded at {@link Quest#getResetHour()} hours, {@link Quest#getResetMinutes()} minutes of the following day.<br>