浏览代码

Little fix for [1428]
Previous code worked fine for all cases except those non-quest scripts that actually require a player QuestState. In that case, scripts would not behave correctly at all.
In addition, the reload syntax has been simplified. The admin/gm no longer needs to care about the directory structure in order to use reload.
On the other hand, questNames MUST be unique once again. With 1428 I had attempted to make it compatible with Java mechanics where two classes may have the same name, as long as they are in different folders (for example quests.myScript and ai.myScript is acceptable in Java); however, without gross amounts of DP rework, this seems impossible. Thus, questNames MUST be different EVEN if their paths are different. Thus ai.myScript and quests.myScript won't work because they are both using the questName "myScript". However, one could easily name them as ai.ai_myScript and quests.quests_myScript if necessary ;)

Fulminus 17 年之前
父节点
当前提交
60ddab069d

+ 8 - 5
L2_GameServer_It/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminQuest.java

@@ -52,11 +52,14 @@ public class AdminQuest implements IAdminCommandHandler
             if (activeChar.getAccessLevel() < REQUIRED_LEVEL) return false;
 
         // syntax will either be:
-        // For scripts in the quests folder:  //quest_reload <id>
-        //                                    //quest_reload <questName>
-        // For all scripts (including those in the quests folder):  //quest_reload <path>.<questName>
-        // Example:  //quest_reload village_master.orc_occupation_change_1
-        // Example:  //quest_reload ai.group_template.chests
+        //                           //quest_reload <id>
+        //                           //quest_reload <questName>
+        // The questName MUST start with a non-numeric character for this to work, 
+        // regardless which of the two formats is used.
+        // Example:  //quest_reload orc_occupation_change_1
+        // Example:  //quest_reload chests
+        // Example:  //quest_reload SagasSuperclass
+        // Example:  //quest_reload 12
         if (command.startsWith("admin_quest_reload"))
         {
         	String[] parts = command.split(" ");

+ 4 - 21
L2_GameServer_It/java/net/sf/l2j/gameserver/instancemanager/QuestManager.java

@@ -60,13 +60,10 @@ public class QuestManager
     // Method - Public
     public final boolean reload(String questFolder)
     {
-    	if(questFolder.indexOf('.') < 0)
-    		questFolder = "quests."+questFolder;
-    	
     	Quest q = getQuest(questFolder);
     	if (q!=null)
     		q.saveGlobalData();
-    	return QuestJython.reloadQuest(questFolder);
+    	return QuestJython.reloadQuest(q.getPrefixPath()+questFolder);
     }
     
     /**
@@ -83,7 +80,7 @@ public class QuestManager
     		return false;
     	}
     	q.saveGlobalData();
-    	return QuestJython.reloadQuest("quests."+q.getName());
+    	return QuestJython.reloadQuest(q.getPrefixPath()+q.getName());
     }
     
     // =========================================================
@@ -103,10 +100,7 @@ public class QuestManager
     // Property - Public
     public final Quest getQuest(String name)
     {
-    	if(name.indexOf('.') < 0)
-    		return getQuests().get("quests."+name);
-    	else
-    		return getQuests().get(name);
+		return getQuests().get(name);
     }
 
     public final Quest getQuest(int questId)
@@ -125,20 +119,9 @@ public class QuestManager
     	if (getQuests().containsKey(newQuest.getName()))
 			_log.info("Replaced: "+newQuest.getName()+" with a new version");
     	
-    	// Given the quest instance, create a string representing the path and questName 
-    	// like a simplified version of a canonical class name.  That is, if a script is in 
-    	// DATAPACK_PATH/jscript/quests/abc the result will be quests.abc
-    	// Similarly, for a script in DATAPACK_PATH/jscript/ai/individual/myClass.py
-    	// the result will be ai.individual.myClass
-    	// All quests are to be indexed, processed, and reloaded by this form of pathname.
-    	StringBuffer a = new StringBuffer(newQuest.getClass().getCanonicalName());
-    	a.delete(0, a.indexOf(".jscript.")+9);
-    	a.delete(a.indexOf(newQuest.getClass().getSimpleName()), a.length());
-    	a.append(newQuest.getName());
-
     	// Note: FastMap will replace the old value if the key already exists
     	// so there is no need to explicitly try to remove the old reference.
-    	getQuests().put(a.toString(), newQuest);
+    	getQuests().put(newQuest.getName(), newQuest);
     }
     
     public final FastMap<String, Quest> getQuests()

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

@@ -64,6 +64,7 @@ public abstract class Quest
 
 	private final int _questId;
 	private final String _name;
+	private final String _prefixPath;	// used only for admin_quest_reload
 	private final String _descr;
     private State _initialState;
     private Map<String, State> _states;
@@ -89,6 +90,17 @@ public abstract class Quest
 		_name = name;
 		_descr = descr;
         _states = new FastMap<String, State>();
+        
+    	// Given the quest instance, create a string representing the path and questName 
+    	// like a simplified version of a canonical class name.  That is, if a script is in 
+    	// DATAPACK_PATH/jscript/quests/abc the result will be quests.abc
+    	// Similarly, for a script in DATAPACK_PATH/jscript/ai/individual/myClass.py
+    	// the result will be ai.individual.myClass
+    	// All quests are to be indexed, processed, and reloaded by this form of pathname.
+    	StringBuffer temp = new StringBuffer(getClass().getCanonicalName());
+    	temp.delete(0, temp.indexOf(".jscript.")+9);
+    	temp.delete(temp.indexOf(getClass().getSimpleName()), temp.length());
+    	_prefixPath = temp.toString();
 		if (questId != 0)
 		{
 			QuestManager.getInstance().addQuest(Quest.this);
@@ -187,6 +199,15 @@ public abstract class Quest
 		return _name;
 	}
 	
+	/**
+	 * Return name of the prefix path for the quest, down to the last "."
+	 * For example "quests." or "ai.individual."
+	 * @return String
+	 */
+	public String getPrefixPath() {
+		return _prefixPath;
+	}
+	
 	/**
 	 * Return description of the quest
 	 * @return String