Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/L2J_Mobius_C6_Interlude/.gitignore b/L2J_Mobius_C6_Interlude/.gitignore
- new file mode 100644
- index 0000000..ae3c172
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/.gitignore
- @@ -0,0 +1 @@
- +/bin/
- diff --git a/L2J_Mobius_C6_Interlude/java/Base/ComboBox/ComboBox.java b/L2J_Mobius_C6_Interlude/java/Base/ComboBox/ComboBox.java
- new file mode 100644
- index 0000000..21709b6
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/Base/ComboBox/ComboBox.java
- @@ -0,0 +1,79 @@
- +/*
- + * 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 Base.ComboBox;
- +
- +import java.util.ArrayList;
- +import java.util.List;
- +
- +import org.l2jmobius.gameserver.model.StatSet;
- +
- +/**
- + * @author Rouxy
- + */
- +public class ComboBox
- +{
- + private int id;
- + private List<StatSet> items = new ArrayList<>();
- +
- + public ComboBox(int id, List<StatSet> items)
- + {
- + this.id = id;
- + this.setItems(items);
- + }
- +
- + public List<ComboBoxItem> getComboBoxItems()
- + {
- +
- + List<ComboBoxItem> comboItems = new ArrayList<>();
- + for (StatSet item : items)
- + {
- + comboItems.add(new ComboBoxItem(item.getInt("itemId"), item.getInt("amount"), item.getInt("enchantLevel"), item.getDouble("chance")));
- + }
- + return comboItems;
- + }
- +
- + /**
- + * @return the id
- + */
- + public int getId()
- + {
- + return id;
- + }
- +
- + /**
- + * @param id the id to set
- + */
- + public void setId(int id)
- + {
- + this.id = id;
- + }
- +
- + /**
- + * @return the items
- + */
- + public List<StatSet> getItems()
- + {
- + return items;
- + }
- +
- + /**
- + * @param items the items to set
- + */
- + public void setItems(List<StatSet> items)
- + {
- + this.items = items;
- + }
- +
- +}
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/Base/ComboBox/ComboBoxData.java b/L2J_Mobius_C6_Interlude/java/Base/ComboBox/ComboBoxData.java
- new file mode 100644
- index 0000000..0a8969c
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/Base/ComboBox/ComboBoxData.java
- @@ -0,0 +1,135 @@
- +/*
- + * 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 Base.ComboBox;
- +
- +import java.io.File;
- +import java.util.ArrayList;
- +import java.util.HashMap;
- +import java.util.List;
- +import java.util.Map;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +import org.w3c.dom.Node;
- +
- +import org.l2jmobius.gameserver.data.ItemTable;
- +import org.l2jmobius.gameserver.model.StatSet;
- +
- +import Base.XML.XMLDocument;
- +
- +/**
- + * @author Rouxy
- + */
- +public class ComboBoxData extends XMLDocument
- +{
- + private Map<Integer, ComboBox> comboBoxes = new HashMap<>();
- +
- + public ComboBoxData()
- + {
- + load();
- + }
- +
- + public static ComboBoxData getInstance()
- + {
- + return SingleTonHolder._instance;
- + }
- +
- + private static class SingleTonHolder
- + {
- + protected static final ComboBoxData _instance = new ComboBoxData();
- + }
- +
- + @Override
- + protected void load()
- + {
- + loadDocument("./data/xml/ComboBoxes.xml");
- + LOG.info("ComboBoxData: Loaded " + comboBoxes.size() + " Comboboxes.");
- + }
- +
- + @Override
- + protected void parseDocument(Document doc, File f)
- + {
- + try
- + {
- +
- + // First element is never read.
- + final Node n = doc.getFirstChild();
- +
- + for (Node o = n.getFirstChild(); o != null; o = o.getNextSibling())
- + {
- + if (!"ComboBox".equalsIgnoreCase(o.getNodeName()))
- + {
- + continue;
- + }
- +
- + NamedNodeMap attrs = o.getAttributes();
- + ComboBox comboBox = null;
- + List<StatSet> items = new ArrayList<>();
- +
- + final int id = Integer.parseInt(attrs.getNamedItem("ID").getNodeValue());
- +
- + for (Node d = o.getFirstChild(); d != null; d = d.getNextSibling())
- + {
- + if (!"item".equalsIgnoreCase(d.getNodeName()))
- + {
- + continue;
- + }
- +
- + attrs = d.getAttributes();
- + StatSet item = new StatSet();
- +
- + item.set("itemId", Integer.parseInt(attrs.getNamedItem("itemId").getNodeValue()));
- + item.set("amount", Integer.parseInt(attrs.getNamedItem("amount").getNodeValue()));
- + item.set("enchantLevel", Integer.parseInt(attrs.getNamedItem("enchantLevel").getNodeValue()));
- + item.set("chance", Integer.parseInt(attrs.getNamedItem("chance").getNodeValue()));
- + if (ItemTable.getInstance().getTemplate(item.getInt("itemId")) != null)
- + {
- + items.add(item);
- + }
- + else
- + {
- + LOG.warning("Item Id: " + item.getInt("itemId") + " is an invalid item for combo box ID: " + id + ".");
- + }
- + comboBox = new ComboBox(id, items);
- +
- + }
- + comboBoxes.put(id, comboBox);
- + }
- + }
- + catch (Exception e)
- + {
- + LOG.warning("ComboBox Data: Error while creating table: " + e);
- + e.printStackTrace();
- + }
- + }
- +
- + public void clear()
- + {
- + comboBoxes.clear();
- + comboBoxes = new HashMap<>();
- + }
- +
- + public void reload()
- + {
- + clear();
- + load();
- + }
- +
- + public ComboBox getComboBoxById(int id)
- + {
- + return comboBoxes.get(id);
- + }
- +
- +}
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/Base/ComboBox/ComboBoxItem.java b/L2J_Mobius_C6_Interlude/java/Base/ComboBox/ComboBoxItem.java
- new file mode 100644
- index 0000000..d3edbc1
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/Base/ComboBox/ComboBoxItem.java
- @@ -0,0 +1,93 @@
- +/*
- + * 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 Base.ComboBox;
- +
- +/**
- + * @author Rouxy
- + */
- +public class ComboBoxItem
- +{
- + private int enchantLevel;
- + private int amount;
- + private int id;
- + private double chance;
- +
- + public ComboBoxItem(int id, int amount, int enchantLevel, double chance)
- + {
- + this.id = id;
- + this.enchantLevel = enchantLevel;
- + this.amount = amount;
- + this.chance = chance;
- + }
- +
- + /**
- + * @return the enchantLevel
- + */
- + public int getEnchantLevel()
- + {
- + return enchantLevel;
- + }
- +
- + /**
- + * @param enchantLevel the enchantLevel to set
- + */
- + public void setEnchantLevel(int enchantLevel)
- + {
- + this.enchantLevel = enchantLevel;
- + }
- +
- + /**
- + * @return the amount
- + */
- + public int getAmount()
- + {
- + return amount;
- + }
- +
- + /**
- + * @param amount the amount to set
- + */
- + public void setAmount(int amount)
- + {
- + this.amount = amount;
- + }
- +
- + /**
- + * @return the id
- + */
- + public int getId()
- + {
- + return id;
- + }
- +
- + /**
- + * @param id the id to set
- + */
- + public void setId(int id)
- + {
- + this.id = id;
- + }
- +
- + public double getChance()
- + {
- + return chance;
- + }
- +
- + public void setChance(double chance)
- + {
- + this.chance = chance;
- + }
- +
- +}
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/Base/XML/XMLDocument.java b/L2J_Mobius_C6_Interlude/java/Base/XML/XMLDocument.java
- new file mode 100644
- index 0000000..756a5ee
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/Base/XML/XMLDocument.java
- @@ -0,0 +1,119 @@
- +package Base.XML;
- +
- +import java.io.File;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import javax.xml.parsers.DocumentBuilderFactory;
- +import javax.xml.transform.OutputKeys;
- +import javax.xml.transform.Transformer;
- +import javax.xml.transform.TransformerException;
- +import javax.xml.transform.TransformerFactory;
- +import javax.xml.transform.dom.DOMSource;
- +import javax.xml.transform.stream.StreamResult;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +import org.w3c.dom.Node;
- +
- +import org.l2jmobius.gameserver.model.StatSet;
- +
- +/**
- + * An XML document, relying on a static and single DocumentBuilderFactory.
- + */
- +public abstract class XMLDocument
- +{
- + protected static final Logger LOG = Logger.getLogger(XMLDocument.class.getName());
- +
- + protected Document document;
- +
- + private static final DocumentBuilderFactory BUILDER;
- + static
- + {
- + BUILDER = DocumentBuilderFactory.newInstance();
- + BUILDER.setValidating(false);
- + BUILDER.setIgnoringComments(true);
- + }
- +
- + abstract protected void load();
- +
- + abstract protected void parseDocument(Document doc, File f);
- +
- + public void loadDocument(String filePath)
- + {
- + loadDocument(new File(filePath));
- + }
- +
- + public void writeDocument(Document doc, String fileName)
- + {
- + try
- + {
- + TransformerFactory transformerFactory = TransformerFactory.newInstance();
- + Transformer transformer = transformerFactory.newTransformer();
- + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- + transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- +
- + DOMSource source = new DOMSource(doc);
- + StreamResult result = new StreamResult(new File(fileName));
- +
- + transformer.transform(source, result);
- + LOG.info("XML file saved to " + fileName);
- + }
- + catch (TransformerException e)
- + {
- + LOG.warning("Error saving XML file: " + e.getMessage());
- + }
- + }
- +
- + /**
- + * Parse an entire directory or file if found.
- + * @param file
- + */
- + public void loadDocument(File file)
- + {
- + if (!file.exists())
- + {
- + LOG.severe("The following file or directory doesn't exist: " + file.getName());
- + return;
- + }
- +
- + if (file.isDirectory())
- + {
- + for (File f : file.listFiles())
- + {
- + loadDocument(f);
- + }
- + }
- + else if (file.isFile())
- + {
- + try
- + {
- + parseDocument(BUILDER.newDocumentBuilder().parse(file), file);
- + }
- + catch (Exception e)
- + {
- + LOG.log(Level.SEVERE, "Error loading XML file " + file.getName(), e);
- + }
- + }
- + }
- +
- + public Document getDocument()
- + {
- + return document;
- + }
- +
- + /**
- + * This method parses the content of a NamedNodeMap and feed the given StatsSet.
- + * @param attrs : The NamedNodeMap to parse.
- + * @param set : The StatsSet to feed.
- + */
- + public static void parseAndFeed(NamedNodeMap attrs, StatSet set)
- + {
- + for (int i = 0; i < attrs.getLength(); i++)
- + {
- + final Node attr = attrs.item(i);
- + set.set(attr.getNodeName(), attr.getNodeValue());
- + }
- + }
- +}
- diff --git a/L2J_Mobius_C6_Interlude/java/Base/XML/XMLDocumentFactory.java b/L2J_Mobius_C6_Interlude/java/Base/XML/XMLDocumentFactory.java
- new file mode 100644
- index 0000000..9594e19
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/Base/XML/XMLDocumentFactory.java
- @@ -0,0 +1,74 @@
- +package Base.XML;
- +
- +import java.io.File;
- +
- +import javax.xml.parsers.DocumentBuilder;
- +import javax.xml.parsers.DocumentBuilderFactory;
- +
- +import org.w3c.dom.Document;
- +
- +/**
- + * @author Forsaiken
- + */
- +public final class XMLDocumentFactory
- +{
- + public static final XMLDocumentFactory getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private final DocumentBuilder _builder;
- +
- + protected XMLDocumentFactory() throws Exception
- + {
- + try
- + {
- + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- + factory.setValidating(false);
- + factory.setIgnoringComments(true);
- +
- + _builder = factory.newDocumentBuilder();
- + }
- + catch (Exception e)
- + {
- + throw new Exception("Failed initializing", e);
- + }
- + }
- +
- + public final Document loadDocument(final String filePath) throws Exception
- + {
- + return loadDocument(new File(filePath));
- + }
- +
- + public final Document loadDocument(final File file) throws Exception
- + {
- + if (!file.exists() || !file.isFile())
- + {
- + throw new Exception("File: " + file.getAbsolutePath() + " doesn't exist and/or is not a file.");
- + }
- +
- + return _builder.parse(file);
- + }
- +
- + public final Document newDocument()
- + {
- + return _builder.newDocument();
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final XMLDocumentFactory _instance;
- +
- + static
- + {
- + try
- + {
- + _instance = new XMLDocumentFactory();
- + }
- + catch (Exception e)
- + {
- + throw new ExceptionInInitializerError(e);
- + }
- + }
- + }
- +}
- \ No newline at end of file
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
- index 0aff7d1..67ff047 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
- @@ -128,6 +130,8 @@
- import org.l2jmobius.gameserver.taskmanager.TaskManager;
- import org.l2jmobius.gameserver.ui.Gui;
- +import Base.ComboBox.ComboBoxData;
- +
- public class GameServer
- {
- private static final Logger LOGGER = Logger.getLogger(GameServer.class.getName());
- @@ -339,6 +343,9 @@
- printSection("Access Levels");
- AdminData.getInstance();
- + printSection("ComboBox Data");
- + ComboBoxData.getInstance();
- +
- printSection("Handlers");
- ItemHandler.getInstance();
- SkillHandler.getInstance();
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/ItemHandler.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/ItemHandler.java
- index 6af36f0..b86f23f 100644
- --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/ItemHandler.java
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/ItemHandler.java
- @@ -30,6 +30,7 @@
- import org.l2jmobius.gameserver.handler.itemhandlers.CharChangePotions;
- import org.l2jmobius.gameserver.handler.itemhandlers.ChestKey;
- import org.l2jmobius.gameserver.handler.itemhandlers.ChristmasTree;
- +import org.l2jmobius.gameserver.handler.itemhandlers.ComboBoxHandler;
- import org.l2jmobius.gameserver.handler.itemhandlers.CrystalCarol;
- import org.l2jmobius.gameserver.handler.itemhandlers.Crystals;
- import org.l2jmobius.gameserver.handler.itemhandlers.CustomPotions;
- @@ -106,6 +107,7 @@
- registerItemHandler(new Maps());
- registerItemHandler(new MercTicket());
- registerItemHandler(new MOSKey());
- + registerItemHandler(new ComboBoxHandler());
- registerItemHandler(new MysteryPotion());
- registerItemHandler(new Nectar());
- registerItemHandler(new NobleCustomItem());
- diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/itemhandlers/ComboBoxHandler.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/itemhandlers/ComboBoxHandler.java
- new file mode 100644
- index 0000000..9f88f55
- --- /dev/null
- +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/itemhandlers/ComboBoxHandler.java
- @@ -0,0 +1,241 @@
- +/*
- + * 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 org.l2jmobius.gameserver.handler.itemhandlers;
- +
- +import org.l2jmobius.commons.util.Rnd;
- +import org.l2jmobius.gameserver.handler.IItemHandler;
- +import org.l2jmobius.gameserver.instancemanager.IdManager;
- +import org.l2jmobius.gameserver.model.actor.Playable;
- +import org.l2jmobius.gameserver.model.actor.Player;
- +import org.l2jmobius.gameserver.model.item.instance.Item;
- +
- +import Base.ComboBox.ComboBox;
- +import Base.ComboBox.ComboBoxData;
- +import Base.ComboBox.ComboBoxItem;
- +
- +/**
- + * @author Rouxy
- + */
- +public class ComboBoxHandler implements IItemHandler
- +{
- +
- + private static final int ITEM_IDS[] =
- + {
- + 19000,
- + 19001,
- + 19002,
- + 19003,
- + 19004,
- + 19005,
- + 19006,
- + 19007,
- + 19008,
- + 19009,
- + 19010,
- + 19011,
- + 19012,
- + 19013,
- + 19014,
- + 19015,
- + 19016,
- + 19017,
- + 19018,
- + 19019,
- + 19020,
- + 19021,
- + 19022,
- + 19023,
- + 19024,
- + 19025,
- + 19026,
- + 19027,
- + 19028,
- + 19029,
- + 19030,
- + 19031,
- + 19033,
- + 19034,
- + 19035,
- + 19036,
- + 19037,
- + 19038,
- + 19039,
- + 19040,
- + 19041,
- + 19042,
- + 19043,
- + 19044,
- + 19045,
- + 19046,
- + 19047,
- + 19048,
- + 19049,
- + 19050,
- + 19051,
- + 19052,
- + 19053,
- + 19054,
- + 19055,
- + 19056,
- + 19057,
- + 19058,
- + 19059,
- + 19060,
- + 19061,
- + 19062,
- + 19063,
- + 19064,
- + 19065,
- + 19066,
- + 19067,
- + 19068,
- + 19069,
- + 19070,
- + 19071,
- + 19072,
- + 19073,
- + 19074,
- + 19075,
- + 19076,
- + 19077,
- + 19078,
- + 19079,
- + 19080,
- + 19081,
- + 19082,
- + 19083,
- + 19084,
- + 19085,
- + 19086,
- + 19087,
- + 19088,
- + 19089,
- + 19090,
- + 19091,
- + 19092,
- + 19093,
- + 19094,
- + 19095,
- + 19096,
- + 19097,
- + 19098,
- + 19099,
- + 19100,
- + 19101,
- + 19102,
- + 19103,
- + 19104,
- + 19105,
- + 19106,
- + 19107,
- + 19108,
- + 19109,
- + 19110,
- + 19111,
- + 19112,
- + 19113,
- + 19114,
- + 19115,
- + 19116,
- + 19117,
- + 19118,
- + 19119,
- + 19120,
- + 19121,
- + 19122,
- + 19123,
- + 19124,
- + 19125,
- + 19126,
- + 19127,
- + 19128,
- + 19129,
- + 19130,
- + 19131,
- + 19132,
- + 19133,
- + 19134,
- + 19135,
- + 19136,
- + 19137,
- + 19138,
- + 19139,
- + 19140,
- + 19141,
- + 15020,
- + 29142
- +
- + };
- +
- + @Override
- + public void useItem(Playable playable, Item item)
- + {
- + if (!(playable instanceof Player))
- + {
- + return;
- + }
- +
- + final Player activeChar = (Player) playable;
- + final int itemId = item.getItemId();
- +
- + ComboBox comboBox = ComboBoxData.getInstance().getComboBoxById(itemId);
- + if (comboBox != null)
- + {
- + Item toGive = null;
- + for (ComboBoxItem boxItem : comboBox.getComboBoxItems())
- + {
- + toGive = new Item(IdManager.getInstance().getNextId(), boxItem.getId());
- + int random = Rnd.get(100);
- + if (random < boxItem.getChance())
- + {
- + if (!toGive.isStackable())
- + {
- + toGive.setEnchantLevel(boxItem.getEnchantLevel());
- + activeChar.addItem("ComboBox", toGive, activeChar, true);
- +
- + }
- + else
- + {
- + activeChar.addItem("ComboBox", boxItem.getId(), boxItem.getAmount(), activeChar, true);
- + }
- +
- + }
- + else
- + {
- + activeChar.sendMessage("You were out of luck opening the item " + toGive.getName());
- + }
- + activeChar.sendMessage(toGive.getName() + " chance: " + boxItem.getChance());
- +
- + }
- +
- + activeChar.sendMessage("You used a combo box type item!");
- + }
- + else
- + {
- + activeChar.sendMessage("This Combo box expired or is invalid!");
- + }
- +
- + playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
- + }
- +
- + @Override
- + public int[] getItemIds()
- + {
- + return ITEM_IDS;
- + }
- +
- +}
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement