Parcourir la source

More Quest work and cleanup. Backwards compatible. No datapack change is necessary, though future DP update is recommended.
State class is working its way towards deprecation
Removing questDrops completely. Those are not used from quests at all. Quest drops are handled by scripts in onKill.
Removing registration of dropList from State; adding registration of quest items in Quest, used for auto-removal of quest items from inventories when exiting/aborting a quest.
Removing "junk" from the QuestList packet. What was claimed to be a list of quest items is not it. The packet IS larger than its current description dictates, but its current implementation works just as well as before. Whatever the remaining of the packet holds is obviously not important enough and definitely not related with the quest's item counts (this change will make the packet creation a lot faster, too).

Fulminus il y a 17 ans
Parent
commit
074b7e865f

+ 0 - 17
L2_GameServer_It/java/net/sf/l2j/gameserver/model/L2Attackable.java

@@ -1244,23 +1244,6 @@ public class L2Attackable extends L2NpcInstance
 
          int levelModifier = calculateLevelModifierForDrop(player);          // level modifier in %'s (will be subtracted from drop chance)
 
-         // Add Quest drops to the table containing all possible drops of this L2Attackable
-         FastList<L2DropData> questDrops = new FastList<L2DropData>();
-         player.fillQuestDrops(this, questDrops);
-
-         // First, throw possible quest drops of this L2Attackable
-         for (L2DropData drop : questDrops)
-         {
-             if (drop == null) continue;
-
-             RewardItem item = calculateRewardItem(player, drop, levelModifier, false);
-             if (item == null) continue;
-
-             // Check if the autoLoot mode is active
-             if (Config.AUTO_LOOT) player.doAutoLoot(this, item); // Give this or these Item(s) to the L2PcInstance that has killed the L2Attackable
-             else DropItem(player, item); // drop the item on the ground
-         }
-
          // Check the drop of a cursed weapon
          if (levelModifier == 0 && player.getLevel() > 20) // Not deep blue mob
          	CursedWeaponsManager.getInstance().checkDrop(this, player);

+ 0 - 13
L2_GameServer_It/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java

@@ -1133,19 +1133,6 @@ public final class L2PcInstance extends L2PlayableInstance
 		_questNpcObject = npcId;
 	}
 
-	/**
-	 * Add Quest drops to the table containing all possible drops of a L2NpcInstance.<BR><BR>
-	 *
-	 * @param npc The L2NpcInstance killed by the L2PcInstance
-	 * @param drops The table containing all possible drops of the L2NpcInstance
-	 *
-	 */
-	public void fillQuestDrops(L2NpcInstance npc, List<L2DropData> drops)
-	{
-		for (QuestState qs : _quests.values())
-			qs.fillQuestDrops(npc, drops);
-	}
-
 	/**
 	 * Return the QuestState object corresponding to the quest name.<BR><BR>
 	 *

+ 13 - 0
L2_GameServer_It/java/net/sf/l2j/gameserver/model/quest/Quest.java

@@ -67,6 +67,7 @@ public abstract class Quest
 	private final String _descr;
     private State _initialState;
     private Map<String, State> _states;
+    private FastList<Integer> _questItemIds;
 
 	/**
 	 * Return collection view of the values contains in the allEventS
@@ -1066,4 +1067,16 @@ public abstract class Quest
           
         return null;
     }
+    
+    public void registerItem(int itemId)
+    {
+    	if (_questItemIds == null)
+    		_questItemIds = new FastList<Integer>();
+    	_questItemIds.add(itemId);
+    }
+    
+    public FastList<Integer> getRegisteredItemIds()
+    {
+    	return _questItemIds;
+    }
 }

+ 0 - 92
L2_GameServer_It/java/net/sf/l2j/gameserver/model/quest/QuestDropInfo.java

@@ -1,92 +0,0 @@
-/* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * http://www.gnu.org/copyleft/gpl.html
- */
-package net.sf.l2j.gameserver.model.quest;
-
-import java.util.List;
-
-import javolution.util.FastList;
-import net.sf.l2j.gameserver.model.L2DropData;
-import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
-
-/**
- * @author XaKa
- *
- */
-public class QuestDropInfo
-{
-	public class DropInfo
-	{
-		public int	dropItemID;
-		public int	dropItemObjID;
-		public int	dropItemCount;
-
-		/**
-		 * Constructor of DropInfo that initialzes class variables
-		 * @param itemID : int designating the ID of the item
-		 * @param itemCount : int designating the quantity of items needed for quest
-		 * @param itemObjID : int designating the ID of the item in the inventory of the player
-		 */
-		public DropInfo(int itemID, int itemCount, int itemObjID)
-		{
-			dropItemID		= itemID;
-			dropItemObjID	= itemObjID;
-			dropItemCount	= itemCount;
-		}
-	}
-
-	public List<DropInfo> dropList;
-
-	/**
-	 * Add informations for dropped items in the inventory of the player.
-	 * @param pcInstance : L2PcInstance designating the player
-	 * @param questName : String designating the name of the quest
-	 */
-	public QuestDropInfo(L2PcInstance pcInstance, String questName)
-	{
-		// Get the QuestState and the State from the name of the quest
-		QuestState	questState		= pcInstance.getQuestState(questName);
-		dropList = new FastList<DropInfo>();
-		if (questState == null)
-		    return;
-
-		if (questState.getDrops() != null)
-        {
-			for(List<L2DropData> questDrop : questState.getDrops().values())
-			{
-				// Get drops given by the mob
-                if(questDrop == null)
-                    continue;
-
-                // Go through all drops of the mob
-    			for(L2DropData dropInfo : questDrop)
-    			{
-    				int dropID 		= dropInfo.getItemId();
-    				int dropObjID	= 0;
-    				int dropCount	= questState.getQuestItemsCount(dropID);
-    				//If player doesn't have this quest item(doesn't kill need npc? or other) then skip it
-    				if(pcInstance.getInventory().getItemByItemId(dropID) == null)
-    					continue;
-
-    				dropObjID = pcInstance.getInventory().getItemByItemId(dropID).getObjectId();
-    				// Add info for the dropped item in the player's inventory
-    				dropList.add(new DropInfo(dropID, dropCount, dropObjID));
-    			}
-            }
-		}
-	}
-}

+ 7 - 162
L2_GameServer_It/java/net/sf/l2j/gameserver/model/quest/QuestState.java

@@ -18,8 +18,6 @@
  */
 package net.sf.l2j.gameserver.model.quest;
 
-import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
 
@@ -65,9 +63,6 @@ public final class QuestState
 	/** List of couples (variable for quest,value of the variable for quest) */
 	private Map<String, String> _vars;
 
-	/** List of drops needed for quest according to the mob */
-	private Map<Integer, List<L2DropData>> _drops;
-
     /** Boolean flag letting QuestStateManager know to exit quest when cleaning up */
     private boolean _isExitQuestOnCleanUp = false;
 
@@ -95,18 +90,6 @@ public final class QuestState
 		_isCompleted = completed;
 		// set the state of the quest
 		_state = state;
-
-		// add drops from state of the quest
-		if (state != null && !isCompleted())
-        {
-			Map<Integer, List<L2DropData>> new_drops = state.getDrops();
-
-			if (new_drops != null)
-            {
-				_drops = new FastMap<Integer, List<L2DropData>>();
-				_drops.putAll(new_drops);
-			}
-		}
     }
 
     public String getQuestName()
@@ -140,15 +123,6 @@ public final class QuestState
 		return _state;
 	}
 
-	/**
-	 * Return list of drops needed for the quest in concordance with mobs
-	 * @return FastMap
-	 */
-	public Map<Integer, List<L2DropData>> getDrops()
-	{
-		return _drops;
-	}
-
 	/**
 	 * Return true if quest completed, false otherwise
 	 * @return boolean
@@ -183,33 +157,6 @@ public final class QuestState
 	 */
 	public Object setState(State state)
     {
-		// remove drops from previous state
-		if (getDrops() != null)
-        {
-			for (Iterator<List<L2DropData>> i = getDrops().values().iterator(); i.hasNext();)
-            {
-				List<L2DropData> lst = i.next();
-
-				for (Iterator<L2DropData> ds = lst.iterator(); ds.hasNext();)
-                {
-					L2DropData d = ds.next();
-					String[] states = d.getStateIDs();
-
-					for (int k=0; k < states.length; k++)
-                    {
-						if (getState().getName().equals(states[k]))
-                        {
-							ds.remove();
-							break;
-						}
-					}
-				}
-
-				if (lst == null || lst.size() == 0)
-					i.remove();
-			}
-		}
-
         // set new state
 		_state = state;
 
@@ -218,20 +165,6 @@ public final class QuestState
 		if(getStateId().equals("Completed")) _isCompleted = true;
 		else _isCompleted = false;
 
-		// add drops from new state
-		if (!isCompleted())
-        {
-			Map<Integer, List<L2DropData>> newDrops = state.getDrops();
-
-			if (newDrops != null)
-            {
-				if (getDrops() == null)
-					_drops = new FastMap<Integer, List<L2DropData>>();
-
-				_drops.putAll(newDrops);
-			}
-		}
-
 		Quest.updateQuestInDb(this);
 		QuestList ql = new QuestList();
 
@@ -471,15 +404,6 @@ public final class QuestState
         return varint;
     }
 
-	public boolean waitsForEvent(String event)
-    {
-		for (String se : getState().getEvents())
-			if (se.equals(event))
-				return true;
-
-        return false;
-	}
-
     /**
      * Add player to get notification of characters death
      * @param character : L2Character of the character to get notification of death
@@ -492,66 +416,6 @@ public final class QuestState
         character.addNotifyQuestOfDeath(this);
     }
 
-	/**
-	 * Add drop to the list of drops for the quest
-	 * @param npcId : int pointing out the NPC given the drop
-	 * @param itemId : int pointing out the ID of the item dropped
-	 * @param chance : int pointing out the chance to get the drop
-	 */
-	public void addQuestDrop(int npcId, int itemId, int chance)
-    {
-		if (getDrops() == null)
-			_drops = new FastMap<Integer, List<L2DropData>>();
-
-		L2DropData d = new L2DropData();
-		d.setItemId(itemId);
-		d.setChance(chance);
-		d.setQuestID(getQuestName());
-		d.addStates(new String[]{getState().getName()});
-		List<L2DropData> lst = getDrops().get(npcId);
-
-		if (lst != null)
-        {
-			lst.add(d);
-		}
-        else
-        {
-			lst = new FastList<L2DropData>();
-			lst.add(d);
-			_drops.put(npcId, lst);
-		}
-	}
-
-	/**
-	 * Clear all drops from the class variable "drops"
-	 */
-	public void clearQuestDrops()
-    {
-		_drops = null;
-	}
-
-	/**
-	 * Add quest drops to the parameter "drops"
-	 * @param npc : L2Attackable killed
-	 * @param drops : List of drops of the L2Attackable
-	 */
-	public void fillQuestDrops(L2NpcInstance npc, List<L2DropData> drops)
-	{
-		if (getDrops() == null)
-			return;
-
-		// Get drops of the NPC recorded in class variable "drops"
-		List<L2DropData> lst = getDrops().get(npc.getTemplate().npcId);
-		// If drops of the NPC in class variable "drops" exist, add them to parameter "drops"
-		if (lst != null)
-			drops.addAll(lst);
-		// Get drops for all NPC recorded in class variable "drops"
-		lst = getDrops().get(0); // all mobs
-		// If drops for all NPC in class variable "drops" exist, add them to parameter "drops"
-		if (lst != null)
-			drops.addAll(lst);
-	}
-
 	/**
 	 * Return the quantity of one sort of item hold by the player
 	 * @param itemId : ID of the item wanted to be count
@@ -923,34 +787,15 @@ public final class QuestState
 
 		// Say quest is completed
 		_isCompleted = true;
-		// Clean drops
-		if (getDrops() != null)
-        {
-			// Go through values of class variable "drops" pointing out mobs that drop for quest
-		    for (Iterator<List<L2DropData>> i = getDrops().values().iterator(); i.hasNext();)
-            {
-		    	List<L2DropData> lst = i.next();
+		// Clean registered quest items
 
-		    	// Go through values of mobs that drop for quest pointing out drops of the mob
-		    	for (Iterator<L2DropData> ds = lst.iterator(); ds.hasNext();)
-                {
-					L2DropData d = ds.next();
-					int itemId = d.getItemId();
-
-					// Get [item from] / [presence of the item in] the inventory of the player
-					L2ItemInstance item = getPlayer().getInventory().getItemByItemId(itemId);
-
-				    	if (item == null || itemId == 57)
-						continue;
-
-					int count = item.getCount();
-					// If player has the item in inventory, destroy it (if not gold)
-
-					getPlayer().destroyItemByItemId("Quest", itemId, count, getPlayer(), true);
-				}
+		FastList<Integer> itemIdList = getQuest().getRegisteredItemIds();
+		if (itemIdList != null)
+		{
+			for (FastList.Node<Integer> n = itemIdList.head(), end = itemIdList.tail(); (n = n.getNext()) != end;) 
+			{
+	    		takeItems(n.getValue().intValue(), -1);
 		    }
-
-		    _drops = null;
 		}
 
 		// If quest is repeatable, delete quest from list of quest of the player and from database (quest CAN be created again => repeatable)

+ 8 - 57
L2_GameServer_It/java/net/sf/l2j/gameserver/model/quest/State.java

@@ -18,12 +18,7 @@
  */
 package net.sf.l2j.gameserver.model.quest;
 
-import java.util.List;
-import java.util.Map;
-
-import javolution.util.FastList;
-import javolution.util.FastMap;
-import net.sf.l2j.gameserver.model.L2DropData;
+import net.sf.l2j.gameserver.instancemanager.QuestManager;
 
 /**
  * @author Luis Arias
@@ -32,16 +27,8 @@ import net.sf.l2j.gameserver.model.L2DropData;
  */
 public class State
 {
-	// TODO - Begins
-	/** Prototype of empty String list */
-	private static final String[] _emptyStrList = new String[0];
-	// TODO - End
-
 	/** Name of the quest */
-    /** Quest object associated to the state */
-	private final Quest _quest;
-	private Map<Integer, List<L2DropData>> _drops;
-	private String[] _events = _emptyStrList;
+    private String _questName;
     private String _name;
 
 
@@ -53,7 +40,7 @@ public class State
     public State(String name, Quest quest)
     {
         _name = name;
-		_quest = quest;
+        _questName = quest.getName();
 		quest.addState(this);
     }
 
@@ -64,47 +51,16 @@ public class State
      * @param npcId : int designating the ID of the NPC
      * @param itemId : int designating the ID of the item dropped
      * @param chance : int designating the chance the item dropped
+     * 
+     * DEPRECATING THIS...only the itemId is really needed, and even 
+     * that is only here for backwards compatibility
      */
     public void addQuestDrop(int npcId, int itemId, int chance) {
-        try {
-            if (_drops == null)
-                _drops = new FastMap<Integer, List<L2DropData>>();
-            L2DropData d = new L2DropData();
-            d.setItemId(itemId);
-            d.setChance(chance);
-            d.setQuestID(_quest.getName());
-            d.addStates(new String[]{_name});
-            List<L2DropData> lst = _drops.get(npcId);
-            if (lst != null) {
-                lst.add(d);
-            } else {
-                lst = new FastList<L2DropData>();
-                lst.add(d);
-                _drops.put(npcId, lst);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    	QuestManager.getInstance().getQuest(_questName).registerItem(itemId);
     }
 
     // =========================================================
-    // Proeprty
-
-    /**
-     * Return list of drops at this step/state of the quest.
-     * @return HashMap
-     */
-    Map<Integer, List<L2DropData>> getDrops() {
-        return _drops;
-    }
-
-    /**
-     * Return list of events
-     * @return String[]
-     */
-    String[] getEvents() {
-        return _events;
-    }
+    // Property
 
     /**
      * Return name of the quest
@@ -123,9 +79,4 @@ public class State
 	public String toString() {
         return _name;
     }
-
-    public Quest getQuest()
-    {
-        return _quest;
-    }
 }

+ 0 - 30
L2_GameServer_It/java/net/sf/l2j/gameserver/serverpackets/GMViewQuestList.java

@@ -18,12 +18,8 @@
  */
 package net.sf.l2j.gameserver.serverpackets;
 
-import java.util.List;
-
-import javolution.util.FastList;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
 import net.sf.l2j.gameserver.model.quest.Quest;
-import net.sf.l2j.gameserver.model.quest.QuestDropInfo;
 import net.sf.l2j.gameserver.model.quest.QuestState;
 
 /**
@@ -73,32 +69,6 @@ public class GMViewQuestList extends L2GameServerPacket
 
             writeD(qs.getInt("cond"));   // stage of quest progress
         }
-
-        //Prepare info about all quests
-        List<QuestDropInfo> questDrops = new FastList<QuestDropInfo>();
-        int FullCountDropItems = 0;
-
-        for (Quest q : questList)
-        {
-            QuestDropInfo newQDrop = new QuestDropInfo(_activeChar, q.getName());
-            //Calculate full count drop items
-            FullCountDropItems += newQDrop.dropList.size();
-
-            questDrops.add(newQDrop);
-        }
-
-        writeH(FullCountDropItems);
-
-        for (QuestDropInfo currQDropInfo : questDrops)
-        {
-            for (QuestDropInfo.DropInfo itemDropInfo : currQDropInfo.dropList)
-            {
-                writeD(itemDropInfo.dropItemObjID);
-                writeD(itemDropInfo.dropItemID);
-                writeD(itemDropInfo.dropItemCount);
-                writeD(5); // ??
-            }
-        }
 	}
 
 	/* (non-Javadoc)

+ 0 - 58
L2_GameServer_It/java/net/sf/l2j/gameserver/serverpackets/QuestList.java

@@ -18,12 +18,8 @@
  */
 package net.sf.l2j.gameserver.serverpackets;
 
-import java.util.List;
-
-import javolution.util.FastList;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
 import net.sf.l2j.gameserver.model.quest.Quest;
-import net.sf.l2j.gameserver.model.quest.QuestDropInfo;
 import net.sf.l2j.gameserver.model.quest.QuestState;
 
 
@@ -39,28 +35,6 @@ import net.sf.l2j.gameserver.model.quest.QuestState;
  * 04 01 00 00
  * a2 00 00 00
  *
- * 04 00 		number of quest items
- *
- * 85 45 13 40 	item obj id
- * 36 05 00 00 	item id
- * 02 00 00 00 	count
- * 00 00 		?? bodyslot
- *
- * 23 bd 12 40
- * 86 04 00 00
- * 0a 00 00 00
- * 00 00
- *
- * 1f bd 12 40
- * 5a 04 00 00
- * 09 00 00 00
- * 00 00
- *
- * 1b bd 12 40
- * 5b 04 00 00
- * 39 00 00 00
- * 00 00                                                 .
- *
  * format h (d) h (dddh)   rev 377
  * format h (dd) h (dddd)  rev 417
  *
@@ -102,14 +76,6 @@ public class QuestList extends L2GameServerPacket
 	     * 			4 byte - Quest ID
 	     * 			4 byte - Quest Status
 	     * 		}
-	     * 		2 byte - Number of All Quests Item
-	     * 		for Item in AllQuestsItem
-	     * 		{
-	     * 			4 byte - Item.ObjID
-	     * 			4 byte - Item.ID
-	     * 			4 byte - Item.Count
-	     * 			4 byte - 5
-	     * 		}
 	     * }
 	     *
 	     * NOTE: The following special constructs are true for the 4-byte Quest Status:
@@ -155,30 +121,6 @@ public class QuestList extends L2GameServerPacket
 			else
 				writeD(qs.getInt("cond"));
 		}
-
-		//Prepare info about all quests
-		List<QuestDropInfo> questDrops = new FastList<QuestDropInfo>();
-		int FullCountDropItems = 0;
-		for(Quest q : _quests)
-		{
-			QuestDropInfo newQDrop = new QuestDropInfo(_activeChar, q.getName());
-			//Calculate full count drop items
-			FullCountDropItems += newQDrop.dropList.size();
-
-			questDrops.add(newQDrop);
-		}
-
-		writeH(FullCountDropItems);
-		for(QuestDropInfo currQDropInfo : questDrops)
-		{
-			for(QuestDropInfo.DropInfo itemDropInfo : currQDropInfo.dropList)
-			{
-				writeD(itemDropInfo.dropItemObjID);
-				writeD(itemDropInfo.dropItemID);
-				writeD(itemDropInfo.dropItemCount);
-				writeD(5);							//<<<<---- what is that?
-			}
-		}
 	}
 
 	/* (non-Javadoc)