Dropped faenor script support.

This commit is contained in:
MobiusDev 2016-03-01 10:45:16 +00:00
parent 26cf2291ff
commit 56c8b7288a
7 changed files with 0 additions and 472 deletions

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Event ID="Valentines Event" Active="14 Feb 2005-16 Feb 2005" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/faenor.xsd">
<Droplist>
<AllDrop Items="4209-4217" Count="1,1" Chance="5%" />
</Droplist>
<EventEnd>
<Take From="AllPlayers">
<Item ItemID="4209-4217" />
</Take>
</EventEnd>
<Message Type="OnJoin" Msg="Valentine's Event:\nCollect all 9 Hearts Blocks to recieve a reward!!\n(Quest Item.. All monster's have a chance to drop.)" />
<Npc ID="12371">
<Condition>
<Inventory Items="4209-4217" Count="1" Operation=">=" />
</Condition>
<Give>
<Item ItemID="4625" Count="1" />
<Item ItemID="1540" Count="10" />
<Item ItemID="728" Count="10" />
</Give>
<SystemMessage Msg="Congratulations. Receive your prize." />
<Take>
<Item Items="4209-4217" Count="1" Type="OfEach" />
</Take>
</Npc>
</Event>

View File

@ -145,7 +145,6 @@ import com.l2jmobius.gameserver.model.olympiad.Olympiad;
import com.l2jmobius.gameserver.network.L2GameClient; import com.l2jmobius.gameserver.network.L2GameClient;
import com.l2jmobius.gameserver.network.L2GamePacketHandler; import com.l2jmobius.gameserver.network.L2GamePacketHandler;
import com.l2jmobius.gameserver.pathfinding.PathFinding; import com.l2jmobius.gameserver.pathfinding.PathFinding;
import com.l2jmobius.gameserver.script.faenor.FaenorScriptEngine;
import com.l2jmobius.gameserver.scripting.L2ScriptEngineManager; import com.l2jmobius.gameserver.scripting.L2ScriptEngineManager;
import com.l2jmobius.gameserver.taskmanager.KnownListUpdateTaskManager; import com.l2jmobius.gameserver.taskmanager.KnownListUpdateTaskManager;
import com.l2jmobius.gameserver.taskmanager.TaskManager; import com.l2jmobius.gameserver.taskmanager.TaskManager;
@ -370,9 +369,6 @@ public final class GameServer
MonsterRace.getInstance(); MonsterRace.getInstance();
AutoSpawnHandler.getInstance(); AutoSpawnHandler.getInstance();
FaenorScriptEngine.getInstance();
// Init of a cursed weapon manager
_log.info("AutoSpawnHandler: Loaded " + AutoSpawnHandler.getInstance().size() + " handlers in total."); _log.info("AutoSpawnHandler: Loaded " + AutoSpawnHandler.getInstance().size() + " handlers in total.");
if (Config.L2JMOD_ALLOW_WEDDING) if (Config.L2JMOD_ALLOW_WEDDING)

View File

@ -18,14 +18,11 @@ package com.l2jmobius.gameserver.script;
import java.util.Hashtable; import java.util.Hashtable;
import com.l2jmobius.gameserver.script.faenor.FaenorInterface;
/** /**
* @author Luis Arias * @author Luis Arias
*/ */
public class ScriptEngine public class ScriptEngine
{ {
protected EngineInterface _utils = FaenorInterface.getInstance();
public static final Hashtable<String, ParserFactory> parserFactories = new Hashtable<>(); public static final Hashtable<String, ParserFactory> parserFactories = new Hashtable<>();
protected static Parser createParser(String name) throws ParserNotCreatedException protected static Parser createParser(String name) throws ParserNotCreatedException

View File

@ -1,138 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.script.faenor;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptContext;
import org.w3c.dom.Node;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.script.DateRange;
import com.l2jmobius.gameserver.script.IntList;
import com.l2jmobius.gameserver.script.Parser;
import com.l2jmobius.gameserver.script.ParserFactory;
import com.l2jmobius.gameserver.script.ScriptEngine;
/**
* @author Luis Arias
*/
public class FaenorEventParser extends FaenorParser
{
static Logger _log = Logger.getLogger(FaenorEventParser.class.getName());
private DateRange _eventDates = null;
@Override
public void parseScript(final Node eventNode, ScriptContext context)
{
final String ID = attribute(eventNode, "ID");
_eventDates = DateRange.parse(attribute(eventNode, "Active"), DATE_FORMAT);
final Date currentDate = new Date();
if (_eventDates.getEndDate().before(currentDate))
{
_log.info("Event ID: (" + ID + ") has passed... Ignored.");
return;
}
if (_eventDates.getStartDate().after(currentDate))
{
_log.info("Event ID: (" + ID + ") is not active yet... Ignored.");
ThreadPoolManager.getInstance().scheduleGeneral(() -> parseEventDropAndMessage(eventNode), _eventDates.getStartDate().getTime() - currentDate.getTime());
return;
}
parseEventDropAndMessage(eventNode);
}
protected void parseEventDropAndMessage(Node eventNode)
{
for (Node node = eventNode.getFirstChild(); node != null; node = node.getNextSibling())
{
if (isNodeName(node, "DropList"))
{
parseEventDropList(node);
}
else if (isNodeName(node, "Message"))
{
parseEventMessage(node);
}
}
}
private void parseEventMessage(Node sysMsg)
{
try
{
final String type = attribute(sysMsg, "Type");
final String message = attribute(sysMsg, "Msg");
if (type.equalsIgnoreCase("OnJoin"))
{
_bridge.onPlayerLogin(message, _eventDates);
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "Error in event parser: " + e.getMessage(), e);
}
}
private void parseEventDropList(Node dropList)
{
for (Node node = dropList.getFirstChild(); node != null; node = node.getNextSibling())
{
if (isNodeName(node, "AllDrop"))
{
parseEventDrop(node);
}
}
}
private void parseEventDrop(Node drop)
{
try
{
final int[] items = IntList.parse(attribute(drop, "Items"));
final int[] count = IntList.parse(attribute(drop, "Count"));
final double chance = getPercent(attribute(drop, "Chance"));
_bridge.addEventDrop(items, count, chance, _eventDates);
}
catch (Exception e)
{
_log.log(Level.WARNING, "ERROR(parseEventDrop):" + e.getMessage(), e);
}
}
static class FaenorEventParserFactory extends ParserFactory
{
@Override
public Parser create()
{
return (new FaenorEventParser());
}
}
static
{
ScriptEngine.parserFactories.put(getParserName("Event"), new FaenorEventParserFactory());
}
}

View File

@ -1,61 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.script.faenor;
import java.util.List;
import java.util.logging.Logger;
import com.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
import com.l2jmobius.gameserver.datatables.EventDroplist;
import com.l2jmobius.gameserver.model.announce.EventAnnouncement;
import com.l2jmobius.gameserver.script.DateRange;
import com.l2jmobius.gameserver.script.EngineInterface;
/**
* @author Luis Arias
*/
public class FaenorInterface implements EngineInterface
{
protected static final Logger _log = Logger.getLogger(FaenorInterface.class.getName());
public static FaenorInterface getInstance()
{
return SingletonHolder._instance;
}
public List<?> getAllPlayers()
{
return null;
}
@Override
public void addEventDrop(int[] items, int[] count, double chance, DateRange range)
{
EventDroplist.getInstance().addGlobalDrop(items, count, (int) (chance * 1000000), range);
}
@Override
public void onPlayerLogin(String message, DateRange validDateRange)
{
AnnouncementsTable.getInstance().addAnnouncement(new EventAnnouncement(validDateRange, message));
}
private static class SingletonHolder
{
protected static final FaenorInterface _instance = new FaenorInterface();
}
}

View File

@ -1,134 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.script.faenor;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import javax.script.ScriptContext;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.l2jmobius.gameserver.script.Parser;
/**
* @author Luis Arias
*/
public abstract class FaenorParser extends Parser
{
protected static FaenorInterface _bridge = FaenorInterface.getInstance();
protected final DateFormat DATE_FORMAT = new SimpleDateFormat("dd MMM yyyy", Locale.US);
/*
* UTILITY FUNCTIONS
*/
public static String attribute(Node node, String attributeName)
{
return attribute(node, attributeName, null);
}
public static String element(Node node, String elementName)
{
return element(node, elementName, null);
}
public static String attribute(Node node, String attributeName, String defaultValue)
{
try
{
return node.getAttributes().getNamedItem(attributeName).getNodeValue();
}
catch (Exception e)
{
if (defaultValue != null)
{
return defaultValue;
}
throw new NullPointerException(e.getMessage());
}
}
public static String element(Node parentNode, String elementName, String defaultValue)
{
try
{
final NodeList list = parentNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++)
{
final Node node = list.item(i);
if (node.getNodeName().equalsIgnoreCase(elementName))
{
return node.getTextContent();
}
}
}
catch (Exception e)
{
}
if (defaultValue != null)
{
return defaultValue;
}
throw new NullPointerException();
}
public static boolean isNodeName(Node node, String name)
{
return node.getNodeName().equalsIgnoreCase(name);
}
public Date getDate(String date) throws ParseException
{
return DATE_FORMAT.parse(date);
}
public static double getPercent(String percent)
{
return (Double.parseDouble(percent.split("%")[0]) / 100.0);
}
protected static int getInt(String number)
{
return Integer.parseInt(number);
}
protected static double getDouble(String number)
{
return Double.parseDouble(number);
}
protected static float getFloat(String number)
{
return Float.parseFloat(number);
}
protected static String getParserName(String name)
{
return "faenor.Faenor" + name + "Parser";
}
/**
* @param node
* @param context
*/
@Override
public abstract void parseScript(Node node, ScriptContext context);
}

View File

@ -1,106 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.script.faenor;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptContext;
import org.w3c.dom.Node;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.script.Parser;
import com.l2jmobius.gameserver.script.ParserNotCreatedException;
import com.l2jmobius.gameserver.script.ScriptDocument;
import com.l2jmobius.gameserver.script.ScriptEngine;
import com.l2jmobius.util.file.filter.XMLFilter;
/**
* @author Luis Arias
*/
public class FaenorScriptEngine extends ScriptEngine
{
private static final Logger _log = Logger.getLogger(FaenorScriptEngine.class.getName());
public static final String PACKAGE_DIRECTORY = "faenor/";
protected FaenorScriptEngine()
{
final File packDirectory = new File(Config.DATAPACK_ROOT, PACKAGE_DIRECTORY);
final File[] files = packDirectory.listFiles(new XMLFilter());
if (files != null)
{
for (File file : files)
{
try (InputStream in = new FileInputStream(file))
{
parseScript(new ScriptDocument(file.getName(), in), null);
}
catch (IOException e)
{
_log.log(Level.WARNING, e.getMessage(), e);
}
}
}
}
public void parseScript(ScriptDocument script, ScriptContext context)
{
final Node node = script.getDocument().getFirstChild();
final String parserClass = "faenor.Faenor" + node.getNodeName() + "Parser";
Parser parser = null;
try
{
parser = createParser(parserClass);
}
catch (ParserNotCreatedException e)
{
_log.log(Level.WARNING, "ERROR: No parser registered for Script: " + parserClass + ": " + e.getMessage(), e);
}
if (parser == null)
{
_log.warning("Unknown Script Type: " + script.getName());
return;
}
try
{
parser.parseScript(node, context);
_log.info(getClass().getSimpleName() + ": Loaded " + script.getName() + " successfully.");
}
catch (Exception e)
{
_log.log(Level.WARNING, "Script Parsing Failed: " + e.getMessage(), e);
}
}
public static FaenorScriptEngine getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final FaenorScriptEngine _instance = new FaenorScriptEngine();
}
}