Chronicle 4 branch.

This commit is contained in:
MobiusDev
2017-07-19 21:24:06 +00:00
parent 9a69bec286
commit 3a0bf3539a
13496 changed files with 641683 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
/*
* 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;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
/**
* @author Luis Arias
*/
public class DateRange
{
private final Date startDate, endDate;
public DateRange(Date from, Date to)
{
startDate = from;
endDate = to;
}
public static DateRange parse(String dateRange, DateFormat format)
{
final String[] date = dateRange.split("-");
if (date.length == 2)
{
try
{
final Date start = format.parse(date[0]);
final Date end = format.parse(date[1]);
return new DateRange(start, end);
}
catch (final ParseException e)
{
System.err.println("Invalid Date Format.");
e.printStackTrace();
}
}
return new DateRange(null, null);
}
public boolean isValid()
{
return (startDate == null) || (endDate == null);
}
public boolean isWithinRange(Date date)
{
return date.after(startDate) && date.before(endDate);
}
public Date getEndDate()
{
return endDate;
}
public Date getStartDate()
{
return startDate;
}
}

View File

@@ -0,0 +1,70 @@
/*
* 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;
import com.l2jmobius.gameserver.Announcements;
import com.l2jmobius.gameserver.GameTimeController;
import com.l2jmobius.gameserver.RecipeController;
import com.l2jmobius.gameserver.datatables.CharNameTable;
import com.l2jmobius.gameserver.datatables.CharTemplateTable;
import com.l2jmobius.gameserver.datatables.ClanTable;
import com.l2jmobius.gameserver.datatables.ItemTable;
import com.l2jmobius.gameserver.datatables.LevelUpData;
import com.l2jmobius.gameserver.datatables.MapRegionTable;
import com.l2jmobius.gameserver.datatables.NpcTable;
import com.l2jmobius.gameserver.datatables.SkillTable;
import com.l2jmobius.gameserver.datatables.SkillTreeTable;
import com.l2jmobius.gameserver.datatables.SpawnTable;
import com.l2jmobius.gameserver.datatables.TeleportLocationTable;
import com.l2jmobius.gameserver.idfactory.IdFactory;
import com.l2jmobius.gameserver.model.L2World;
/**
* @author Luis Arias TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
*/
public interface EngineInterface
{
// * keep the references of Singletons to prevent garbage collection
public CharNameTable _charNametable = CharNameTable.getInstance();
public IdFactory _idFactory = IdFactory.getInstance();
public ItemTable _itemTable = ItemTable.getInstance();
public SkillTable _skillTable = SkillTable.getInstance();
public RecipeController _recipeController = RecipeController.getInstance();
public SkillTreeTable _skillTreeTable = SkillTreeTable.getInstance();
public CharTemplateTable _charTemplates = CharTemplateTable.getInstance();
public ClanTable _clanTable = ClanTable.getInstance();
public NpcTable _npcTable = NpcTable.getInstance();
public TeleportLocationTable _teleTable = TeleportLocationTable.getInstance();
public LevelUpData _levelUpData = LevelUpData.getInstance();
public L2World _world = L2World.getInstance();
public SpawnTable _spawnTable = SpawnTable.getInstance();
public GameTimeController _gameTimeController = GameTimeController.getInstance();
public Announcements _announcements = Announcements.getInstance();
public MapRegionTable _mapRegions = MapRegionTable.getInstance();
public void addQuestDrop(int npcID, int itemID, int min, int max, int chance, String questID, String[] states);
public void addEventDrop(int[] items, int[] count, double chance, DateRange range);
public void onPlayerLogin(String[] message, DateRange range);
}

View File

@@ -0,0 +1,100 @@
/*
* 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;
import javax.script.ScriptContext;
import com.l2jmobius.gameserver.scripting.L2ScriptEngineManager;
public class Expression
{
private final ScriptContext context;
@SuppressWarnings("unused")
private final String lang;
@SuppressWarnings("unused")
private final String code;
public static Object eval(String lang, String code)
{
try
{
return L2ScriptEngineManager.getInstance().eval(lang, code);
}
catch (final Exception e)
{
e.printStackTrace();
return null;
}
}
public static Object eval(ScriptContext context, String lang, String code)
{
try
{
return L2ScriptEngineManager.getInstance().eval(lang, code, context);
}
catch (final Exception e)
{
e.printStackTrace();
return null;
}
}
public static Expression create(ScriptContext context, String lang, String code)
{
try
{
return new Expression(context, lang, code);
}
catch (final Exception e)
{
e.printStackTrace();
return null;
}
}
private Expression(ScriptContext pContext, String pLang, String pCode)
{
context = pContext;
lang = pLang;
code = pCode;
}
public <T> void addDynamicVariable(String name, T value, Class<T> type)
{
try
{
context.setAttribute(name, value, ScriptContext.ENGINE_SCOPE);
}
catch (final Exception e)
{
e.printStackTrace();
}
}
public void removeDynamicVariable(String name)
{
try
{
context.removeAttribute(name, ScriptContext.ENGINE_SCOPE);
}
catch (final Exception e)
{
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,68 @@
/*
* 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;
/**
* @author Luis Arias
*/
public class IntList
{
public static int[] parse(String range)
{
if (range.contains("-"))
{
return getIntegerRange(range.split("-"));
}
else if (range.contains(","))
{
return getIntegerList(range.split(","));
}
final int[] list =
{
getInt(range)
};
return list;
}
private static int getInt(String number)
{
return Integer.parseInt(number);
}
private static int[] getIntegerList(String[] numbers)
{
final int[] list = new int[numbers.length];
for (int i = 0; i < list.length; i++)
{
list[i] = getInt(numbers[i]);
}
return list;
}
private static int[] getIntegerRange(String[] numbers)
{
final int min = getInt(numbers[0]);
final int max = getInt(numbers[1]);
final int[] list = new int[(max - min) + 1];
for (int i = 0; i < list.length; i++)
{
list[i] = min + i;
}
return list;
}
}

View File

@@ -0,0 +1,29 @@
/*
* 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;
import javax.script.ScriptContext;
import org.w3c.dom.Node;
/**
* @author Luis Arias
*/
public abstract class Parser
{
public abstract void parseScript(Node node, ScriptContext context);
}

View File

@@ -0,0 +1,22 @@
/*
* 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;
public abstract class ParserFactory
{
public abstract Parser create();
}

View File

@@ -0,0 +1,27 @@
/*
* 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;
public class ParserNotCreatedException extends Exception
{
private static final long serialVersionUID = 1L;
public ParserNotCreatedException()
{
super("Parser could not be created!");
}
}

View File

@@ -0,0 +1,91 @@
/*
* 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;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
/**
*
*
*/
public class ScriptDocument
{
private Document document;
private final String _name;
public ScriptDocument(String name, InputStream input)
{
_name = name;
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
{
final DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(input);
}
catch (final SAXException sxe)
{
// Error generated during parsing)
Exception x = sxe;
if (sxe.getException() != null)
{
x = sxe.getException();
}
x.printStackTrace();
}
catch (final ParserConfigurationException pce)
{
// Parser with specified options can't be built
pce.printStackTrace();
}
catch (final IOException ioe)
{
// I/O error
ioe.printStackTrace();
}
}
public Document getDocument()
{
return document;
}
/**
* @return Returns the _name.
*/
public String getName()
{
return _name;
}
@Override
public String toString()
{
return _name;
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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;
import java.util.Hashtable;
import com.l2jmobius.gameserver.script.faenor.FaenorInterface;
/**
* @author Luis Arias TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
*/
public class ScriptEngine
{
protected EngineInterface _utils = new FaenorInterface();
public static Hashtable<String, ParserFactory> parserFactories = new Hashtable<>();
protected static Parser createParser(String name) throws ParserNotCreatedException
{
ParserFactory s = parserFactories.get(name);
if (s == null) // shape not found
{
try
{
Class.forName("com.l2jmobius.gameserver.script." + name);
// By now the static block with no function would
// have been executed if the shape was found.
// the shape is expected to have put its factory
// in the hashtable.
s = parserFactories.get(name);
if (s == null) // if the shape factory is not there even now
{
throw (new ParserNotCreatedException());
}
}
catch (final ClassNotFoundException e)
{
// We'll throw an exception to indicate that
// the shape could not be created
throw (new ParserNotCreatedException());
}
}
return (s.create());
}
}

View File

@@ -0,0 +1,126 @@
/*
* 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;
import java.io.IOException;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javolution.util.FastList;
/**
* @author Luis Arias TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
*/
public class ScriptPackage
{
private final List<ScriptDocument> scriptFiles;
private final List<String> otherFiles;
private final String name;
public ScriptPackage(ZipFile pack)
{
scriptFiles = new FastList<>();
otherFiles = new FastList<>();
name = pack.getName();
addFiles(pack);
}
/**
* @return Returns the otherFiles.
*/
public List<String> getOtherFiles()
{
return otherFiles;
}
/**
* @return Returns the scriptFiles.
*/
public List<ScriptDocument> getScriptFiles()
{
return scriptFiles;
}
/**
* @param pack The scriptFiles to set.
*/
private void addFiles(ZipFile pack)
{
for (final Enumeration<? extends ZipEntry> e = pack.entries(); e.hasMoreElements();)
{
final ZipEntry entry = e.nextElement();
if (entry.getName().endsWith(".xml"))
{
try
{
final ScriptDocument newScript = new ScriptDocument(entry.getName(), pack.getInputStream(entry));
scriptFiles.add(newScript);
}
catch (final IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
else if (!entry.isDirectory())
{
otherFiles.add(entry.getName());
}
}
}
/**
* @return Returns the name.
*/
public String getName()
{
return name;
}
@Override
public String toString()
{
if (getScriptFiles().isEmpty() && getOtherFiles().isEmpty())
{
return "Empty Package.";
}
String out = "Package Name: " + getName() + "\n";
if (!getScriptFiles().isEmpty())
{
out += "Xml Script Files...\n";
for (final ScriptDocument script : getScriptFiles())
{
out += script.getName() + "\n";
}
}
if (!getOtherFiles().isEmpty())
{
out += "Other Files...\n";
for (final String fileName : getOtherFiles())
{
out += fileName + "\n";
}
}
return out;
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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;
/**
* @author -Nemesiss-
*/
public class ShortList
{
public static short[] parse(String range)
{
if (range.contains("-"))
{
return getShortList(range.split("-"));
}
else if (range.contains(","))
{
return getShortList(range.split(","));
}
final short[] list =
{
getShort(range)
};
return list;
}
private static short getShort(String number)
{
return Short.parseShort(number);
}
private static short[] getShortList(String[] numbers)
{
final short[] list = new short[numbers.length];
for (int i = 0; i < list.length; i++)
{
list[i] = getShort(numbers[i]);
}
return list;
}
}

View File

@@ -0,0 +1,166 @@
/*
* 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.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");
if (DEBUG)
{
_log.fine("Parsing Event \"" + 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(new Runnable()
{
@Override
public void run()
{
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)
{
if (DEBUG)
{
_log.fine("Parsing Event Message.");
}
try
{
final String type = attribute(sysMsg, "Type");
final String[] message = attribute(sysMsg, "Msg").split("\n");
if (type.equalsIgnoreCase("OnJoin"))
{
bridge.onPlayerLogin(message, eventDates);
}
}
catch (final Exception e)
{
_log.warning("Error in event parser.");
e.printStackTrace();
}
}
private void parseEventDropList(Node dropList)
{
if (DEBUG)
{
_log.fine("Parsing Droplist.");
}
for (Node node = dropList.getFirstChild(); node != null; node = node.getNextSibling())
{
if (isNodeName(node, "AllDrop"))
{
parseEventDrop(node);
}
}
}
private void parseEventDrop(Node drop)
{
if (DEBUG)
{
_log.fine("Parsing 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 (final Exception e)
{
_log.warning("ERROR(parseEventDrop):" + e.getMessage());
}
}
static class FaenorEventParserFactory extends ParserFactory
{
@Override
public Parser create()
{
return (new FaenorEventParser());
}
}
static
{
ScriptEngine.parserFactories.put(getParserName("Event"), new FaenorEventParserFactory());
}
}

View File

@@ -0,0 +1,221 @@
/*
* 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.Map;
import javax.script.ScriptContext;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.Announcements;
import com.l2jmobius.gameserver.EventDroplist;
import com.l2jmobius.gameserver.model.L2DropCategory;
import com.l2jmobius.gameserver.model.L2DropData;
import com.l2jmobius.gameserver.model.L2PetData;
import com.l2jmobius.gameserver.script.DateRange;
import com.l2jmobius.gameserver.script.EngineInterface;
import com.l2jmobius.gameserver.script.Expression;
import com.l2jmobius.gameserver.templates.L2NpcTemplate;
import javolution.util.FastList;
/**
* @author Luis Arias TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
*/
public class FaenorInterface implements EngineInterface
{
private static FaenorInterface _instance;
public static FaenorInterface getInstance()
{
if (_instance == null)
{
_instance = new FaenorInterface();
}
return _instance;
}
public FaenorInterface()
{
}
/*
* (non-Javadoc)
* @see com.l2jmobius.gameserver.script.EngineInterface#getAllPlayers()
*/
public List<?> getAllPlayers()
{
// TODO Auto-generated method stub
return null;
}
/**
* Adds a new Quest Drop to an NPC
*/
@Override
public void addQuestDrop(int npcID, int itemID, int min, int max, int chance, String questID, String[] states)
{
final L2NpcTemplate npc = _npcTable.getTemplate(npcID);
if (npc == null)
{
throw new NullPointerException();
}
final L2DropData drop = new L2DropData();
drop.setItemId(itemID);
drop.setMinDrop(min);
drop.setMaxDrop(max);
drop.setChance(chance);
drop.setQuestID(questID);
drop.addStates(states);
addDrop(npc, drop, false);
}
/**
* Adds a new Drop to an NPC
* @param npcID
* @param itemID
* @param min
* @param max
* @param sweep
* @param chance
* @throws NullPointerException
*/
public void addDrop(int npcID, int itemID, int min, int max, boolean sweep, int chance) throws NullPointerException
{
final L2NpcTemplate npc = _npcTable.getTemplate(npcID);
if (npc == null)
{
if (Config.DEBUG)
{
System.out.print("Npc doesnt Exist");
}
throw new NullPointerException();
}
final L2DropData drop = new L2DropData();
drop.setItemId(itemID);
drop.setMinDrop(min);
drop.setMaxDrop(max);
drop.setChance(chance);
addDrop(npc, drop, sweep);
}
/**
* 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 drop
* @param sweep
*/
public void addDrop(L2NpcTemplate npc, L2DropData drop, boolean sweep)
{
if (sweep)
{
addDrop(npc, drop, -1);
}
else
{
int maxCategory = -1;
if (npc.getDropData() != null)
{
for (final L2DropCategory cat : npc.getDropData())
{
if (maxCategory < cat.getCategoryType())
{
maxCategory = cat.getCategoryType();
}
}
}
maxCategory++;
npc.addDropData(drop, maxCategory);
}
}
/**
* Adds a new drop to an NPC, in the specified category. If the category does not exist, it is created.
* @param npc
* @param drop
* @param category
*/
public void addDrop(L2NpcTemplate npc, L2DropData drop, int category)
{
npc.addDropData(drop, category);
}
/**
* @param npcID
* @return Returns the _questDrops.
*/
public List<L2DropData> getQuestDrops(int npcID)
{
final L2NpcTemplate npc = _npcTable.getTemplate(npcID);
if (npc == null)
{
return null;
}
final List<L2DropData> questDrops = new FastList<>();
if (npc.getDropData() != null)
{
for (final L2DropCategory cat : npc.getDropData())
{
for (final L2DropData drop : cat.getAllDrops())
{
if (drop.getQuestID() != null)
{
questDrops.add(drop);
}
}
}
}
return questDrops;
}
@Override
public void addEventDrop(int[] items, int[] count, double chance, DateRange range)
{
EventDroplist.getInstance().addGlobalDrop(items, count, (int) (chance * L2DropData.MAX_CHANCE), range);
}
@Override
public void onPlayerLogin(String[] message, DateRange validDateRange)
{
Announcements.getInstance().addEventAnnouncement(validDateRange, message);
}
public void addPetData(ScriptContext context, int petID, int levelStart, int levelEnd, Map<String, String> stats)
{
final L2PetData[] petData = new L2PetData[(levelEnd - levelStart) + 1];
int value = 0;
for (int level = levelStart; level <= levelEnd; level++)
{
petData[level - 1] = new L2PetData();
petData[level - 1].setPetID(petID);
petData[level - 1].setPetLevel(level);
context.setAttribute("level", new Double(level), ScriptContext.ENGINE_SCOPE);
for (final String stat : stats.keySet())
{
value = ((Number) Expression.eval(context, "beanshell", stats.get(stat))).intValue();
petData[level - 1].setStat(stat, value);
}
context.removeAttribute("level", ScriptContext.ENGINE_SCOPE);
}
}
}

View File

@@ -0,0 +1,133 @@
/*
* 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 static DateFormat DATE_FORMAT = new SimpleDateFormat("dd MMM yyyy", Locale.US);
public final static boolean DEBUG = true;
/*
* 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 (final 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 (final Exception e)
{
}
if (defaultValue != null)
{
return defaultValue;
}
throw new NullPointerException();
}
public static boolean isNodeName(Node node, String name)
{
return node.getNodeName().equalsIgnoreCase(name);
}
public static 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";
}
@Override
public abstract void parseScript(Node node, ScriptContext context);
}

View File

@@ -0,0 +1,127 @@
/*
* 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 javax.script.ScriptContext;
import org.w3c.dom.Node;
import com.l2jmobius.gameserver.script.Parser;
import com.l2jmobius.gameserver.script.ParserFactory;
import com.l2jmobius.gameserver.script.ScriptEngine;
/**
* @author Luis Arias
*/
public class FaenorQuestParser extends FaenorParser
{
@Override
public void parseScript(Node questNode, ScriptContext context)
{
if (DEBUG)
{
System.out.println("Parsing Quest.");
}
final String questID = attribute(questNode, "ID");
for (Node node = questNode.getFirstChild(); node != null; node = node.getNextSibling())
{
if (isNodeName(node, "DROPLIST"))
{
parseQuestDropList(node.cloneNode(true), questID);
}
else if (isNodeName(node, "DIALOG WINDOWS"))
{
// parseDialogWindows(node.cloneNode(true));
}
else if (isNodeName(node, "INITIATOR"))
{
// parseInitiator(node.cloneNode(true));
}
else if (isNodeName(node, "STATE"))
{
// parseState(node.cloneNode(true));
}
}
}
private void parseQuestDropList(Node dropList, String questID) throws NullPointerException
{
if (DEBUG)
{
System.out.println("Parsing Droplist.");
}
for (Node node = dropList.getFirstChild(); node != null; node = node.getNextSibling())
{
if (isNodeName(node, "DROP"))
{
parseQuestDrop(node.cloneNode(true), questID);
}
}
}
private void parseQuestDrop(Node drop, String questID)// throws NullPointerException
{
if (DEBUG)
{
System.out.println("Parsing Drop.");
}
int npcID;
int itemID;
int min;
int max;
int chance;
String[] states;
try
{
npcID = getInt(attribute(drop, "NpcID"));
itemID = getInt(attribute(drop, "ItemID"));
min = getInt(attribute(drop, "Min"));
max = getInt(attribute(drop, "Max"));
chance = getInt(attribute(drop, "Chance"));
states = (attribute(drop, "States")).split(",");
}
catch (final NullPointerException e)
{
throw new NullPointerException("Incorrect Drop Data");
}
if (DEBUG)
{
System.out.println("Adding Drop to NpcID: " + npcID);
}
bridge.addQuestDrop(npcID, itemID, min, max, chance, questID, states);
}
static class FaenorQuestParserFactory extends ParserFactory
{
@Override
public Parser create()
{
return (new FaenorQuestParser());
}
}
static
{
ScriptEngine.parserFactories.put(getParserName("Quest"), new FaenorQuestParserFactory());
}
}

View File

@@ -0,0 +1,227 @@
/*
* 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.FileFilter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import javax.script.ScriptContext;
import org.w3c.dom.Node;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.GameServer;
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.gameserver.script.ScriptPackage;
import com.l2jmobius.gameserver.scripting.L2ScriptEngineManager;
/**
* @author Luis Arias
*/
public class FaenorScriptEngine extends ScriptEngine
{
static Logger _log = Logger.getLogger(GameServer.class.getName());
public final static String PACKAGE_DIRECTORY = "data/faenor/";
public final static boolean DEBUG = true;
private static FaenorScriptEngine instance;
private LinkedList<ScriptDocument> scripts;
public static FaenorScriptEngine getInstance()
{
if (instance == null)
{
instance = new FaenorScriptEngine();
}
return instance;
}
private FaenorScriptEngine()
{
scripts = new LinkedList<>();
loadPackages();
parsePackages();
}
public void reloadPackages()
{
scripts = new LinkedList<>();
parsePackages();
}
private void loadPackages()
{
final File packDirectory = new File(Config.DATAPACK_ROOT, PACKAGE_DIRECTORY);// _log.sss(packDirectory.getAbsolutePath());
final FileFilter fileFilter = new FileFilter()
{
@Override
public boolean accept(File file)
{
return file.getName().endsWith(".zip");
}
};
final File[] files = packDirectory.listFiles(fileFilter);
if (files == null)
{
return;
}
ZipFile zipPack;
for (final File file : files)
{
try
{
zipPack = new ZipFile(file);
}
catch (final ZipException e)
{
e.printStackTrace();
continue;
}
catch (final IOException e)
{
e.printStackTrace();
continue;
}
final ScriptPackage module = new ScriptPackage(zipPack);
final List<ScriptDocument> scrpts = module.getScriptFiles();
for (final ScriptDocument script : scrpts)
{
scripts.add(script);
}
try
{
zipPack.close();
}
catch (final IOException e)
{
}
}
}
public void orderScripts()
{
if (scripts.size() > 1)
{
for (int i = 0; i < scripts.size();)
{
if (scripts.get(i).getName().contains("NpcStatData"))
{
scripts.addFirst(scripts.remove(i));
}
else
{
i++;
}
}
}
}
public void parsePackages()
{
final L2ScriptEngineManager sem = L2ScriptEngineManager.getInstance();
final 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 (final ScriptDocument script : scripts)
{
parseScript(script, context);
}
}
catch (final Exception e)
{
e.printStackTrace();
}
}
public void parseScript(ScriptDocument script, ScriptContext context)
{
if (DEBUG)
{
_log.fine("Parsing Script: " + script.getName());
}
final Node node = script.getDocument().getFirstChild();
final String parserClass = "faenor.Faenor" + node.getNodeName() + "Parser";
Parser parser = null;
try
{
parser = createParser(parserClass);
}
catch (final ParserNotCreatedException e)
{
_log.warning("ERROR: No parser registered for Script: " + parserClass);
e.printStackTrace();
}
if (parser == null)
{
_log.warning("Unknown Script Type: " + script.getName());
return;
}
try
{
parser.parseScript(node, context);
_log.fine(script.getName() + "Script Sucessfullty Parsed.");
}
catch (final Exception e)
{
e.printStackTrace();
_log.warning("Script Parsing Failed.");
}
}
@Override
public String toString()
{
if (scripts.isEmpty())
{
return "No Packages Loaded.";
}
String out = "Script Packages currently loaded:\n";
for (final ScriptDocument script : scripts)
{
out += script;
}
return out;
}
}

View File

@@ -0,0 +1,143 @@
/*
* 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.Map;
import java.util.logging.Logger;
import javax.script.ScriptContext;
import org.w3c.dom.Node;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.script.IntList;
import com.l2jmobius.gameserver.script.Parser;
import com.l2jmobius.gameserver.script.ParserFactory;
import com.l2jmobius.gameserver.script.ScriptEngine;
import javolution.util.FastMap;
/**
* @author Luis Arias
*/
public class FaenorWorldDataParser extends FaenorParser
{
static Logger _log = Logger.getLogger(FaenorWorldDataParser.class.getName());
// Script Types
private final static String PET_DATA = "PetData";
@Override
public void parseScript(Node eventNode, ScriptContext context)
{
if (Config.DEBUG)
{
System.out.println("Parsing WorldData");
}
for (Node node = eventNode.getFirstChild(); node != null; node = node.getNextSibling())
{
if (isNodeName(node, PET_DATA))
{
parsePetData(node, context);
}
}
}
public class PetData
{
public int petID;
public int levelStart;
public int levelEnd;
Map<String, String> statValues;
public PetData()
{
statValues = new FastMap<>();
}
}
private void parsePetData(Node petNode, ScriptContext context)
{
final PetData petData = new PetData();
try
{
petData.petID = getInt(attribute(petNode, "ID"));
final int[] levelRange = IntList.parse(attribute(petNode, "Levels"));
petData.levelStart = levelRange[0];
petData.levelEnd = levelRange[1];
for (Node node = petNode.getFirstChild(); node != null; node = node.getNextSibling())
{
if (isNodeName(node, "Stat"))
{
parseStat(node, petData);
}
}
bridge.addPetData(context, petData.petID, petData.levelStart, petData.levelEnd, petData.statValues);
}
catch (final Exception e)
{
petData.petID = -1;
_log.warning("Error in pet Data parser.");
e.printStackTrace();
}
}
private void parseStat(Node stat, PetData petData)
{
// if (Config.DEBUG) System.out.println("Parsing Pet Statistic.");
try
{
final String statName = attribute(stat, "Name");
for (Node node = stat.getFirstChild(); node != null; node = node.getNextSibling())
{
if (isNodeName(node, "Formula"))
{
final String formula = parseForumla(node);
petData.statValues.put(statName, formula);
}
}
}
catch (final Exception e)
{
petData.petID = -1;
System.err.println("ERROR(parseStat):" + e.getMessage());
}
}
private String parseForumla(Node formulaNode)
{
return formulaNode.getTextContent().trim();
}
static class FaenorWorldDataParserFactory extends ParserFactory
{
@Override
public Parser create()
{
return (new FaenorWorldDataParser());
}
}
static
{
ScriptEngine.parserFactories.put(getParserName("WorldData"), new FaenorWorldDataParserFactory());
}
}