Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P Orionwins
- diff --git a/src/Base/XML/XMLDocument.java b/src/Base/XML/XMLDocument.java
- new file mode 100644
- index 0000000..2e9bb7a
- --- /dev/null
- +++ b/src/Base/XML/XMLDocument.java
- @@ -0,0 +1,137 @@
- +package Base.XML;
- +
- +import java.io.File;
- +import java.util.function.Consumer;
- +import java.util.function.Predicate;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import javax.xml.parsers.DocumentBuilderFactory;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +import org.w3c.dom.Node;
- +import org.w3c.dom.NodeList;
- +
- +import l2jorion.game.templates.StatsSet;
- +
- +/**
- + * An XML document, relying on a static and single DocumentBuilderFactory.
- + */
- +public abstract class XMLDocument
- +{
- + protected static final Logger LOG = Logger.getLogger(XMLDocument.class.getName());
- +
- + 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));
- + }
- +
- + /**
- + * 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 void forEach(Node node, Consumer<Node> action)
- + {
- + forEach(node, a -> true, action);
- + }
- +
- + public void forEach(Node node, String nodeName, Consumer<Node> action)
- + {
- + forEach(node, innerNode ->
- + {
- + if (nodeName.contains("|"))
- + {
- + final String[] nodeNames = nodeName.split("\\|");
- + for (String name : nodeNames)
- + {
- + if (!name.isEmpty() && name.equals(innerNode.getNodeName()))
- + {
- + return true;
- + }
- + }
- + return false;
- + }
- + return nodeName.equals(innerNode.getNodeName());
- + }, action);
- + }
- +
- + public void forEach(Node node, Predicate<Node> filter, Consumer<Node> action)
- + {
- + final NodeList list = node.getChildNodes();
- + for (int i = 0; i < list.getLength(); i++)
- + {
- + final Node targetNode = list.item(i);
- + if (filter.test(targetNode))
- + {
- + action.accept(targetNode);
- + }
- + }
- + }
- +
- + public StatsSet parseAttributes(Node node)
- + {
- + final NamedNodeMap attrs = node.getAttributes();
- + final StatsSet map = new StatsSet();
- + for (int i = 0; i < attrs.getLength(); i++)
- + {
- + final Node att = attrs.item(i);
- + map.set(att.getNodeName(), att.getNodeValue());
- + }
- + return map;
- + }
- +
- + /**
- + * 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, StatsSet set)
- + {
- + for (int i = 0; i < attrs.getLength(); i++)
- + {
- + final Node attr = attrs.item(i);
- + set.set(attr.getNodeName(), attr.getNodeValue());
- + }
- + }
- +}
- \ No newline at end of file
- diff --git files/game/data/xml/ComboBoxes.xml files/game/data/xml/ComboBoxes.xml
- new file mode 100644
- index 0000000..502a60b
- --- /dev/null
- +++ files/game/data/xml/ComboBoxes.xml
- @@ -0,0 +1,27 @@
- +<?xml version="1.0" encoding="utf-8"?>
- +<ComboBoxes>
- + <ComboBox ID="19000"> <!-- Mage Starter Pack-->
- + <item itemId="177" amount="1" enchantLevel="0" chance="70"/>
- + <item itemId="1101" amount="1" enchantLevel="0" chance="80"/>
- + <item itemId="1104" amount="1" enchantLevel="0" chance="80"/>
- + <item itemId="908" amount="1" enchantLevel="0" chance="80"/>
- + <item itemId="115" amount="1" enchantLevel="0" chance="80"/>
- + <item itemId="115" amount="1" enchantLevel="0" chance="80"/>
- + <item itemId="877" amount="1" enchantLevel="0" chance="80"/>
- + <item itemId="877" amount="1" enchantLevel="0" chance="80"/>
- + <item itemId="3948" amount="2000" enchantLevel="0" chance="80"/>
- + </ComboBox>
- + <ComboBox ID="19001"> <!-- Fighter Starter Pack-->
- + <item itemId="68" amount="1" enchantLevel="0" chance="0"/>
- + <item itemId="711" amount="1" enchantLevel="0" chance="0"/>
- + <item itemId="715" amount="1" enchantLevel="0" chance="0"/>
- + <item itemId="908" amount="1" enchantLevel="0" chance="0"/>
- + <item itemId="115" amount="1" enchantLevel="0" chance="0"/>
- + <item itemId="115" amount="1" enchantLevel="0" chance="0"/>
- + <item itemId="877" amount="1" enchantLevel="0" chance="0"/>
- + <item itemId="877" amount="1" enchantLevel="0" chance="0"/>
- + <item itemId="1463" amount="2500" enchantLevel="0" chance="0"/>
- + </ComboBox>
- +
- +
- +</ComboBoxes>
- diff --git src/Base/ComboBox/ComboBox.java src/Base/ComboBox/ComboBox.java
- new file mode 100644
- index 0000000..5a1bdb5
- --- /dev/null
- +++ src/Base/ComboBox/ComboBox.java
- @@ -0,0 +1,65 @@
- +package Base.ComboBox;
- +
- +import java.util.ArrayList;
- +import java.util.List;
- +
- +import Base.util.StatsSet;
- +
- +/**
- + * @author Rouxy
- + */
- +public class ComboBox
- +{
- + private int id;
- + private List<StatsSet> items = new ArrayList<>();
- +
- + public ComboBox(int id, List<StatsSet> items)
- + {
- + this.id = id;
- + this.setItems(items);
- + }
- +
- + public List<ComboBoxItem> getComboBoxItems()
- + {
- +
- + List<ComboBoxItem> comboItems = new ArrayList<>();
- + for (StatsSet item : items)
- + {
- + comboItems.add(new ComboBoxItem(item.getInteger("itemId"), item.getInteger("amount"), item.getInteger("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<StatsSet> getItems()
- + {
- + return items;
- + }
- +
- + /**
- + * @param items the items to set
- + */
- + public void setItems(List<StatsSet> items)
- + {
- + this.items = items;
- + }
- +
- +}
- diff --git src/Base/ComboBox/ComboBoxItem.java src/Base/ComboBox/ComboBoxItem.java
- new file mode 100644
- index 0000000..0a4bba0
- --- /dev/null
- +++ src/Base/ComboBox/ComboBoxItem.java
- @@ -0,0 +1,79 @@
- +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;
- + }
- +
- +}
- diff --git src/Base/ComboBox/Data/ComboBoxData.java src/Base/ComboBox/Data/ComboBoxData.java
- new file mode 100644
- index 0000000..d74469e
- --- /dev/null
- +++ src/Base/ComboBox/Data/ComboBoxData.java
- @@ -0,0 +1,121 @@
- +package Base.ComboBox.Data;
- +
- +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 Base.ComboBox.ComboBox;
- +import Base.data.XMLDocument;
- +import Base.util.StatsSet;
- +import l2jwins.game.datatables.sql.ItemTable;
- +
- +/**
- + * @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<StatsSet> 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();
- + StatsSet item = new StatsSet();
- +
- + 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.getInteger("itemId")) != null)
- + {
- + items.add(item);
- + }
- + else
- + {
- + LOG.warning("Item Id: " + item.getInteger("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);
- + }
- +
- +}
- diff --git src/l2jwins/game/GameServer.java src/l2jwins/game/GameServer.java
- index f7ad5fa..b8a251c 100644
- --- src/l2jwins/game/GameServer.java
- +++ src/l2jwins/game/GameServer.java
- @@ -12,6 +12,7 @@
- import java.util.logging.LogManager;
- import Base.ClanStrongold.ClanStrongholdDeviceSpawner;
- +import Base.ComboBox.Data.ComboBoxData;
- import Base.Instance.InstanceManager;
- import Base.Rank.RankManager;
- import Base.Rank.RankingSkillBonuses;
- @@ -548,6 +549,9 @@
- HistoriasTable.getInstance();
- + Util.printSection("ComboBox Data");
- + ComboBoxData.getInstance();
- +
- Util.printSection("Handlers");
- ItemHandler.getInstance();
- SkillHandler.getInstance();
- diff --git src/l2jwins/game/handler/ItemHandler.java src/l2jwins/game/handler/ItemHandler.java
- index ed8f801..21fb2c8 100644
- --- src/l2jwins/game/handler/ItemHandler.java
- +++ src/l2jwins/game/handler/ItemHandler.java
- @@ -21,6 +21,7 @@
- import l2jwins.game.handler.item.ClanPointCustomItem;
- import l2jwins.game.handler.item.ClanReputationItem;
- import l2jwins.game.handler.item.ClanSkillsCustomItem;
- +import l2jwins.game.handler.item.ComboBoxHandler;
- import l2jwins.game.handler.item.CrystalCarol;
- import l2jwins.game.handler.item.Crystals;
- import l2jwins.game.handler.item.CustomItemForFighter;
- @@ -131,6 +132,7 @@
- registerItemHandler(new PremiumCustom30DaysItem());
- registerItemHandler(new PremiumCustom365DaysItem());
- registerItemHandler(new MOSKey());
- + registerItemHandler(new ComboBoxHandler());
- registerItemHandler(new BreakingArrow());
- registerItemHandler(new ChristmasTree());
- registerItemHandler(new Crystals());
- diff --git src/l2jwins/game/handler/item/ComboBoxHandler.java src/l2jwins/game/handler/item/ComboBoxHandler.java
- new file mode 100644
- index 0000000..320578d
- --- /dev/null
- +++ src/l2jwins/game/handler/item/ComboBoxHandler.java
- @@ -0,0 +1,223 @@
- +package l2jwins.game.handler.item;
- +
- +import Base.ComboBox.ComboBox;
- +import Base.ComboBox.ComboBoxItem;
- +import Base.ComboBox.Data.ComboBoxData;
- +import l2jwins.game.handler.IItemHandler;
- +import l2jwins.game.idfactory.IdFactory;
- +import l2jwins.game.model.actor.instance.L2ItemInstance;
- +import l2jwins.game.model.actor.instance.L2PcInstance;
- +import l2jwins.game.model.actor.instance.L2PlayableInstance;
- +import l2jwins.util.random.Rnd;
- +
- +/**
- + * @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(L2PlayableInstance playable, L2ItemInstance item)
- + {
- + if (!(playable instanceof L2PcInstance))
- + {
- + return;
- + }
- +
- + final L2PcInstance activeChar = (L2PcInstance) playable;
- + final int itemId = item.getItemId();
- +
- + ComboBox comboBox = ComboBoxData.getInstance().getComboBoxById(itemId);
- + if (comboBox != null)
- + {
- + L2ItemInstance toGive = null;
- + for (ComboBoxItem boxItem : comboBox.getComboBoxItems())
- + {
- + toGive = new L2ItemInstance(IdFactory.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;
- + }
- +
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement