浏览代码

BETA: Faenor Engine rework (Thanks Tukune)
* Removing zip support
* Source format/cleanup
Note: Requires DP Update

Rumen Nikiforov 13 年之前
父节点
当前提交
feb2bfa69e

+ 2 - 17
L2J_Server_BETA/java/com/l2jserver/gameserver/script/faenor/FaenorEventParser.java

@@ -31,7 +31,6 @@ import com.l2jserver.gameserver.script.ScriptEngine;
 
 
 /**
 /**
  * @author Luis Arias
  * @author Luis Arias
- * 
  */
  */
 public class FaenorEventParser extends FaenorParser
 public class FaenorEventParser extends FaenorParser
 {
 {
@@ -42,10 +41,6 @@ public class FaenorEventParser extends FaenorParser
 	public void parseScript(final Node eventNode, ScriptContext context)
 	public void parseScript(final Node eventNode, ScriptContext context)
 	{
 	{
 		String ID = attribute(eventNode, "ID");
 		String ID = attribute(eventNode, "ID");
-		
-		if (DEBUG)
-			_log.fine("Parsing Event \"" + ID + "\"");
-		
 		_eventDates = DateRange.parse(attribute(eventNode, "Active"), DATE_FORMAT);
 		_eventDates = DateRange.parse(attribute(eventNode, "Active"), DATE_FORMAT);
 		
 		
 		Date currentDate = new Date();
 		Date currentDate = new Date();
@@ -58,7 +53,8 @@ public class FaenorEventParser extends FaenorParser
 		if (_eventDates.getStartDate().after(currentDate))
 		if (_eventDates.getStartDate().after(currentDate))
 		{
 		{
 			_log.info("Event ID: (" + ID + ") is not active yet... Ignored.");
 			_log.info("Event ID: (" + ID + ") is not active yet... Ignored.");
-			ThreadPoolManager.getInstance().scheduleGeneral(new Runnable() {
+			ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
+			{
 				@Override
 				@Override
 				public void run()
 				public void run()
 				{
 				{
@@ -73,10 +69,8 @@ public class FaenorEventParser extends FaenorParser
 	
 	
 	protected void parseEventDropAndMessage(Node eventNode)
 	protected void parseEventDropAndMessage(Node eventNode)
 	{
 	{
-		
 		for (Node node = eventNode.getFirstChild(); node != null; node = node.getNextSibling())
 		for (Node node = eventNode.getFirstChild(); node != null; node = node.getNextSibling())
 		{
 		{
-			
 			if (isNodeName(node, "DropList"))
 			if (isNodeName(node, "DropList"))
 			{
 			{
 				parseEventDropList(node);
 				parseEventDropList(node);
@@ -90,9 +84,6 @@ public class FaenorEventParser extends FaenorParser
 	
 	
 	private void parseEventMessage(Node sysMsg)
 	private void parseEventMessage(Node sysMsg)
 	{
 	{
-		if (DEBUG)
-			_log.fine("Parsing Event Message.");
-		
 		try
 		try
 		{
 		{
 			String type = attribute(sysMsg, "Type");
 			String type = attribute(sysMsg, "Type");
@@ -111,9 +102,6 @@ public class FaenorEventParser extends FaenorParser
 	
 	
 	private void parseEventDropList(Node dropList)
 	private void parseEventDropList(Node dropList)
 	{
 	{
-		if (DEBUG)
-			_log.fine("Parsing Droplist.");
-		
 		for (Node node = dropList.getFirstChild(); node != null; node = node.getNextSibling())
 		for (Node node = dropList.getFirstChild(); node != null; node = node.getNextSibling())
 		{
 		{
 			if (isNodeName(node, "AllDrop"))
 			if (isNodeName(node, "AllDrop"))
@@ -125,9 +113,6 @@ public class FaenorEventParser extends FaenorParser
 	
 	
 	private void parseEventDrop(Node drop)
 	private void parseEventDrop(Node drop)
 	{
 	{
-		if (DEBUG)
-			_log.fine("Parsing Drop.");
-		
 		try
 		try
 		{
 		{
 			int[] items = IntList.parse(attribute(drop, "Items"));
 			int[] items = IntList.parse(attribute(drop, "Items"));

+ 15 - 11
L2J_Server_BETA/java/com/l2jserver/gameserver/script/faenor/FaenorInterface.java

@@ -73,13 +73,13 @@ public class FaenorInterface implements EngineInterface
 	
 	
 	/**
 	/**
 	 * Adds a new Drop to an NPC
 	 * Adds a new Drop to an NPC
-	 * @param npcID 
-	 * @param itemID 
-	 * @param min 
-	 * @param max 
-	 * @param sweep 
-	 * @param chance 
-	 * @throws NullPointerException 
+	 * @param npcID
+	 * @param itemID
+	 * @param min
+	 * @param max
+	 * @param sweep
+	 * @param chance
+	 * @throws NullPointerException
 	 * @see com.l2jserver.gameserver.script.EngineInterface#addQuestDrop(int, int, int, int, int, String, String[])
 	 * @see com.l2jserver.gameserver.script.EngineInterface#addQuestDrop(int, int, int, int, int, String, String[])
 	 */
 	 */
 	public void addDrop(int npcID, int itemID, int min, int max, boolean sweep, int chance) throws NullPointerException
 	public void addDrop(int npcID, int itemID, int min, int max, boolean sweep, int chance) throws NullPointerException
@@ -88,7 +88,9 @@ public class FaenorInterface implements EngineInterface
 		if (npc == null)
 		if (npc == null)
 		{
 		{
 			if (Config.DEBUG)
 			if (Config.DEBUG)
+			{
 				_log.warning("Npc doesnt Exist");
 				_log.warning("Npc doesnt Exist");
+			}
 			throw new NullPointerException();
 			throw new NullPointerException();
 		}
 		}
 		L2DropData drop = new L2DropData();
 		L2DropData drop = new L2DropData();
@@ -101,9 +103,7 @@ public class FaenorInterface implements EngineInterface
 	}
 	}
 	
 	
 	/**
 	/**
-	 * Adds a new drop to an NPC.  If the drop is sweep, it adds it to the NPC's Sweep category
-	 * If the drop is non-sweep, it creates a new category for this drop.
-	 *
+	 * Adds a new drop to an NPC. If the drop is sweep, it adds it to the NPC's Sweep category If the drop is non-sweep, it creates a new category for this drop.
 	 * @param npc
 	 * @param npc
 	 * @param drop
 	 * @param drop
 	 * @param sweep
 	 * @param sweep
@@ -111,7 +111,9 @@ public class FaenorInterface implements EngineInterface
 	public void addDrop(L2NpcTemplate npc, L2DropData drop, boolean sweep)
 	public void addDrop(L2NpcTemplate npc, L2DropData drop, boolean sweep)
 	{
 	{
 		if (sweep)
 		if (sweep)
+		{
 			addDrop(npc, drop, -1);
 			addDrop(npc, drop, -1);
+		}
 		else
 		else
 		{
 		{
 			int maxCategory = -1;
 			int maxCategory = -1;
@@ -119,7 +121,9 @@ public class FaenorInterface implements EngineInterface
 			for (L2DropCategory cat : npc.getDropData())
 			for (L2DropCategory cat : npc.getDropData())
 			{
 			{
 				if (maxCategory < cat.getCategoryType())
 				if (maxCategory < cat.getCategoryType())
+				{
 					maxCategory = cat.getCategoryType();
 					maxCategory = cat.getCategoryType();
+				}
 			}
 			}
 			maxCategory++;
 			maxCategory++;
 			npc.addDropData(drop, maxCategory);
 			npc.addDropData(drop, maxCategory);
@@ -127,7 +131,7 @@ public class FaenorInterface implements EngineInterface
 	}
 	}
 	
 	
 	/**
 	/**
-	 * Adds a new drop to an NPC, in the specified category.  If the category does not exist, it is created.
+	 * Adds a new drop to an NPC, in the specified category. If the category does not exist, it is created.
 	 * @param npc
 	 * @param npc
 	 * @param drop
 	 * @param drop
 	 * @param category
 	 * @param category

+ 10 - 9
L2J_Server_BETA/java/com/l2jserver/gameserver/script/faenor/FaenorParser.java

@@ -29,15 +29,12 @@ import com.l2jserver.gameserver.script.Parser;
 
 
 /**
 /**
  * @author Luis Arias
  * @author Luis Arias
- *
  */
  */
 public abstract class FaenorParser extends Parser
 public abstract class FaenorParser extends Parser
 {
 {
 	protected static FaenorInterface _bridge = FaenorInterface.getInstance();
 	protected static FaenorInterface _bridge = FaenorInterface.getInstance();
 	protected final DateFormat DATE_FORMAT = new SimpleDateFormat("dd MMM yyyy", Locale.US);
 	protected final DateFormat DATE_FORMAT = new SimpleDateFormat("dd MMM yyyy", Locale.US);
 	
 	
-	public final static boolean DEBUG = true;
-	
 	/*
 	/*
 	 * UTILITY FUNCTIONS
 	 * UTILITY FUNCTIONS
 	 */
 	 */
@@ -60,7 +57,9 @@ public abstract class FaenorParser extends Parser
 		catch (Exception e)
 		catch (Exception e)
 		{
 		{
 			if (defaultValue != null)
 			if (defaultValue != null)
+			{
 				return defaultValue;
 				return defaultValue;
+			}
 			throw new NullPointerException(e.getMessage());
 			throw new NullPointerException(e.getMessage());
 		}
 		}
 	}
 	}
@@ -70,9 +69,9 @@ public abstract class FaenorParser extends Parser
 		try
 		try
 		{
 		{
 			NodeList list = parentNode.getChildNodes();
 			NodeList list = parentNode.getChildNodes();
-			for (int i=0; i<list.getLength(); i++)
+			for (int i = 0; i < list.getLength(); i++)
 			{
 			{
-				Node node   = list.item(i);
+				Node node = list.item(i);
 				if (node.getNodeName().equalsIgnoreCase(elementName))
 				if (node.getNodeName().equalsIgnoreCase(elementName))
 				{
 				{
 					return node.getTextContent();
 					return node.getTextContent();
@@ -80,11 +79,13 @@ public abstract class FaenorParser extends Parser
 			}
 			}
 		}
 		}
 		catch (Exception e)
 		catch (Exception e)
-		{}
+		{
+		}
 		if (defaultValue != null)
 		if (defaultValue != null)
+		{
 			return defaultValue;
 			return defaultValue;
+		}
 		throw new NullPointerException();
 		throw new NullPointerException();
-		
 	}
 	}
 	
 	
 	public static boolean isNodeName(Node node, String name)
 	public static boolean isNodeName(Node node, String name)
@@ -119,9 +120,9 @@ public abstract class FaenorParser extends Parser
 	
 	
 	protected static String getParserName(String name)
 	protected static String getParserName(String name)
 	{
 	{
-		return "faenor.Faenor"+name+"Parser";
+		return "faenor.Faenor" + name + "Parser";
 	}
 	}
-
+	
 	/**
 	/**
 	 * @param node
 	 * @param node
 	 * @param context
 	 * @param context

+ 12 - 22
L2J_Server_BETA/java/com/l2jserver/gameserver/script/faenor/FaenorQuestParser.java

@@ -26,45 +26,41 @@ import com.l2jserver.gameserver.script.ScriptEngine;
 
 
 /**
 /**
  * @author Luis Arias
  * @author Luis Arias
- *
  */
  */
 public class FaenorQuestParser extends FaenorParser
 public class FaenorQuestParser extends FaenorParser
 {
 {
 	protected static final Logger _log = Logger.getLogger(FaenorQuestParser.class.getName());
 	protected static final Logger _log = Logger.getLogger(FaenorQuestParser.class.getName());
+	
 	@Override
 	@Override
 	public void parseScript(Node questNode, ScriptContext context)
 	public void parseScript(Node questNode, ScriptContext context)
-	{
-		if (DEBUG)
-			_log.info("Parsing Quest.");
-		
+	{	
 		String questID = attribute(questNode, "ID");
 		String questID = attribute(questNode, "ID");
 		
 		
-		for (Node node = questNode.getFirstChild(); node != null; node = node.getNextSibling()) {
+		for (Node node = questNode.getFirstChild(); node != null; node = node.getNextSibling())
+		{
 			if (isNodeName(node, "DROPLIST"))
 			if (isNodeName(node, "DROPLIST"))
 			{
 			{
 				parseQuestDropList(node.cloneNode(true), questID);
 				parseQuestDropList(node.cloneNode(true), questID);
 			}
 			}
 			else if (isNodeName(node, "DIALOG WINDOWS"))
 			else if (isNodeName(node, "DIALOG WINDOWS"))
 			{
 			{
-				//parseDialogWindows(node.cloneNode(true));
+				// parseDialogWindows(node.cloneNode(true));
 			}
 			}
 			else if (isNodeName(node, "INITIATOR"))
 			else if (isNodeName(node, "INITIATOR"))
 			{
 			{
-				//parseInitiator(node.cloneNode(true));
+				// parseInitiator(node.cloneNode(true));
 			}
 			}
 			else if (isNodeName(node, "STATE"))
 			else if (isNodeName(node, "STATE"))
 			{
 			{
-				//parseState(node.cloneNode(true));
+				// parseState(node.cloneNode(true));
 			}
 			}
 		}
 		}
 	}
 	}
 	
 	
 	private void parseQuestDropList(Node dropList, String questID) throws NullPointerException
 	private void parseQuestDropList(Node dropList, String questID) throws NullPointerException
 	{
 	{
-		if (DEBUG)
-			_log.info("Parsing Droplist.");
-		
-		for (Node node = dropList.getFirstChild(); node != null; node = node.getNextSibling()) {
+		for (Node node = dropList.getFirstChild(); node != null; node = node.getNextSibling())
+		{
 			if (isNodeName(node, "DROP"))
 			if (isNodeName(node, "DROP"))
 			{
 			{
 				parseQuestDrop(node.cloneNode(true), questID);
 				parseQuestDrop(node.cloneNode(true), questID);
@@ -72,11 +68,8 @@ public class FaenorQuestParser extends FaenorParser
 		}
 		}
 	}
 	}
 	
 	
-	private void parseQuestDrop(Node drop, String questID)// throws NullPointerException
-	{
-		if (DEBUG)
-			_log.info("Parsing Drop.");
-		
+	private void parseQuestDrop(Node drop, String questID)
+	{	
 		int npcID;
 		int npcID;
 		int itemID;
 		int itemID;
 		int min;
 		int min;
@@ -97,9 +90,6 @@ public class FaenorQuestParser extends FaenorParser
 			throw new NullPointerException("Incorrect Drop Data");
 			throw new NullPointerException("Incorrect Drop Data");
 		}
 		}
 		
 		
-		if (DEBUG)
-			_log.info("Adding Drop to NpcID: "+npcID);
-		
 		_bridge.addQuestDrop(npcID, itemID, min, max, chance, questID, states);
 		_bridge.addQuestDrop(npcID, itemID, min, max, chance, questID, states);
 	}
 	}
 	
 	
@@ -108,7 +98,7 @@ public class FaenorQuestParser extends FaenorParser
 		@Override
 		@Override
 		public Parser create()
 		public Parser create()
 		{
 		{
-			return(new FaenorQuestParser());
+			return (new FaenorQuestParser());
 		}
 		}
 	}
 	}
 	
 	

+ 12 - 139
L2J_Server_BETA/java/com/l2jserver/gameserver/script/faenor/FaenorScriptEngine.java

@@ -15,14 +15,11 @@
 package com.l2jserver.gameserver.script.faenor;
 package com.l2jserver.gameserver.script.faenor;
 
 
 import java.io.File;
 import java.io.File;
-import java.io.FileFilter;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
+import java.io.InputStream;
 import java.util.logging.Level;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.logging.Logger;
-import java.util.zip.ZipException;
-import java.util.zip.ZipFile;
 
 
 import javax.script.ScriptContext;
 import javax.script.ScriptContext;
 
 
@@ -33,150 +30,37 @@ import com.l2jserver.gameserver.script.Parser;
 import com.l2jserver.gameserver.script.ParserNotCreatedException;
 import com.l2jserver.gameserver.script.ParserNotCreatedException;
 import com.l2jserver.gameserver.script.ScriptDocument;
 import com.l2jserver.gameserver.script.ScriptDocument;
 import com.l2jserver.gameserver.script.ScriptEngine;
 import com.l2jserver.gameserver.script.ScriptEngine;
-import com.l2jserver.gameserver.script.ScriptPackage;
-import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
+import com.l2jserver.util.file.filter.XMLFilter;
 
 
 /**
 /**
  * @author Luis Arias
  * @author Luis Arias
- *
  */
  */
 public class FaenorScriptEngine extends ScriptEngine
 public class FaenorScriptEngine extends ScriptEngine
 {
 {
-	static Logger _log = Logger.getLogger(FaenorScriptEngine.class.getName());
+	private static Logger _log = Logger.getLogger(FaenorScriptEngine.class.getName());
 	public final static String PACKAGE_DIRECTORY = "data/faenor/";
 	public final static String PACKAGE_DIRECTORY = "data/faenor/";
-	public final static boolean DEBUG = true;
-	
-	private LinkedList<ScriptDocument> _scripts;
-	
-	public static FaenorScriptEngine getInstance()
-	{
-		return SingletonHolder._instance;
-	}
 	
 	
 	private FaenorScriptEngine()
 	private FaenorScriptEngine()
 	{
 	{
-		_scripts = new LinkedList<ScriptDocument>();
-		loadPackages();
-		parsePackages();
+		File packDirectory = new File(Config.DATAPACK_ROOT, PACKAGE_DIRECTORY);
 		
 		
-	}
-	
-	public void reloadPackages()
-	{
-		_scripts = new LinkedList<ScriptDocument>();
-		parsePackages();
-	}
-	
-	private void loadPackages()
-	{
-		File packDirectory = new File(Config.DATAPACK_ROOT, PACKAGE_DIRECTORY);//_log.sss(packDirectory.getAbsolutePath());
-		
-		FileFilter fileFilter = new FileFilter() {
-			@Override
-			public boolean accept(File file)
-			{
-				return file.getName().endsWith(".zip");
-			}
-		};
-		
-		File[] files = packDirectory.listFiles(fileFilter);
-		if (files == null)
-			return;
-		ZipFile zipPack;
+		File[] files = packDirectory.listFiles(new XMLFilter());
 		
 		
 		for (File file : files)
 		for (File file : files)
 		{
 		{
-			try
+			try (InputStream in = new FileInputStream(file))
 			{
 			{
-				zipPack = new ZipFile(file);
-			}
-			catch (ZipException e)
-			{
-				_log.log(Level.WARNING, "", e);
-				continue;
-			}
-			catch (IOException e)
-			{
-				_log.log(Level.WARNING, "", e);
-				continue;
-			}
-			
-			ScriptPackage module = new ScriptPackage(zipPack);
-			
-			List<ScriptDocument> scrpts = module.getScriptFiles();
-			for (ScriptDocument script : scrpts)
-			{
-				_scripts.add(script);
-			}
-			try
-			{
-				zipPack.close();
+				parseScript(new ScriptDocument(file.getName(), in), null);
 			}
 			}
 			catch (IOException e)
 			catch (IOException e)
 			{
 			{
+				_log.log(Level.WARNING, e.getMessage(), e);
 			}
 			}
 		}
 		}
-		/*for (ScriptDocument script : scripts)
-		 {
-		 _log.sss("Script: "+script);
-		 }
-		 _log.sss("Sorting");
-		 orderScripts();
-		 for (ScriptDocument script : scripts)
-		 {
-		 _log.sss("Script: "+script);
-		 }*/
-	}
-	
-	public void orderScripts()
-	{
-		if (_scripts.size() > 1)
-		{
-			//ScriptDocument npcInfo = null;
-			
-			for (int i = 0; i < _scripts.size();)
-			{
-				if (_scripts.get(i).getName().contains("NpcStatData"))
-				{
-					_scripts.addFirst(_scripts.remove(i));
-					//scripts.set(i, scripts.get(0));
-					//scripts.set(0, npcInfo);
-				}
-				else
-				{
-					i++;
-				}
-			}
-		}
-	}
-	
-	public void parsePackages()
-	{
-		L2ScriptEngineManager sem = L2ScriptEngineManager.getInstance();
-		ScriptContext context = sem.getScriptContext("beanshell");
-		try
-		{
-			sem.eval("beanshell", "double log1p(double d) { return Math.log1p(d); }");
-			sem.eval("beanshell", "double pow(double d, double p) { return Math.pow(d,p); }");
-			
-			for (ScriptDocument script : _scripts)
-			{
-				parseScript(script, context);
-			}
-		}
-		catch (Exception e)
-		{
-			_log.log(Level.WARNING, "", e);
-		}
 	}
 	}
 	
 	
 	public void parseScript(ScriptDocument script, ScriptContext context)
 	public void parseScript(ScriptDocument script, ScriptContext context)
 	{
 	{
-		if (DEBUG)
-		{
-			_log.fine("Parsing Script: " + script.getName());
-		}
-		
 		Node node = script.getDocument().getFirstChild();
 		Node node = script.getDocument().getFirstChild();
 		String parserClass = "faenor.Faenor" + node.getNodeName() + "Parser";
 		String parserClass = "faenor.Faenor" + node.getNodeName() + "Parser";
 		
 		
@@ -199,7 +83,7 @@ public class FaenorScriptEngine extends ScriptEngine
 		try
 		try
 		{
 		{
 			parser.parseScript(node, context);
 			parser.parseScript(node, context);
-			_log.fine(script.getName() + "Script Sucessfullty Parsed.");
+			_log.info(getClass().getSimpleName() + ": Loaded  " + script.getName() + " Sucessfullty.");
 		}
 		}
 		catch (Exception e)
 		catch (Exception e)
 		{
 		{
@@ -207,20 +91,9 @@ public class FaenorScriptEngine extends ScriptEngine
 		}
 		}
 	}
 	}
 	
 	
-	@Override
-	public String toString()
+	public static FaenorScriptEngine getInstance()
 	{
 	{
-		if (_scripts.isEmpty())
-			return "No Packages Loaded.";
-		
-		StringBuilder out = new StringBuilder();
-		out.append("Script Packages currently loaded:\n");
-		
-		for (ScriptDocument script : _scripts)
-		{
-			out.append(script);
-		}
-		return out.toString();
+		return SingletonHolder._instance;
 	}
 	}
 	
 	
 	@SuppressWarnings("synthetic-access")
 	@SuppressWarnings("synthetic-access")