Index: D:/L2Workspaces/L2jIncSVN-N/L2jt1/java/net/sf/l2j/gameserver/handler/itemhandlers/ShadowBox.java =================================================================== --- D:/L2Workspaces/L2jIncSVN-N/L2jt1/java/net/sf/l2j/gameserver/handler/itemhandlers/ShadowBox.java (revision 0) +++ D:/L2Workspaces/L2jIncSVN-N/L2jt1/java/net/sf/l2j/gameserver/handler/itemhandlers/ShadowBox.java (revision 0) @@ -0,0 +1,140 @@ +/* + * 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 . + */ + +/** + * @author Forsaiken + */ + +package net.sf.l2j.gameserver.handler.itemhandlers; + +import java.io.File; +import java.util.logging.Logger; + +import javax.xml.parsers.DocumentBuilderFactory; + +import net.sf.l2j.Config; +import net.sf.l2j.gameserver.handler.IItemHandler; +import net.sf.l2j.gameserver.model.L2ItemInstance; +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; +import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance; +import net.sf.l2j.gameserver.network.SystemMessageId; +import net.sf.l2j.gameserver.serverpackets.ItemList; +import net.sf.l2j.gameserver.serverpackets.SystemMessage; +import net.sf.l2j.util.L2FastList; +import net.sf.l2j.util.L2FastMap; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +public class ShadowBox implements IItemHandler +{ + private static final Logger _log = Logger.getLogger(ShadowBox.class.getName()); + + private int[] _itemIds = new int[0]; + + private final L2FastMap> _shadowBoxes; + + public ShadowBox() + { + _shadowBoxes = new L2FastMap>(); + + try + { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setValidating(false); + factory.setIgnoringComments(true); + + File file = new File(Config.DATAPACK_ROOT+"/data/shadowBoxes.xml"); + if (!file.exists()) + return; + + Document doc = factory.newDocumentBuilder().parse(file); + + for (Node n=doc.getFirstChild(); n != null; n = n.getNextSibling()) + { + if ("list".equalsIgnoreCase(n.getNodeName())) + { + for (Node d=n.getFirstChild(); d != null; d = d.getNextSibling()) + { + if ("item".equalsIgnoreCase(d.getNodeName())) + { + NamedNodeMap attrs = d.getAttributes(); + int id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue()); + + L2FastList items = new L2FastList(); + + for (Node cd=d.getFirstChild(); cd != null; cd = cd.getNextSibling()) + { + if ("itemId".equalsIgnoreCase(cd.getNodeName())) + { + attrs = cd.getAttributes(); + items.add(Integer.parseInt(attrs.getNamedItem("val").getNodeValue())); + } + } + + _shadowBoxes.put(id, items); + } + } + } + } + + _itemIds = new int[_shadowBoxes.size()]; + int i = 0; + for (int j : _shadowBoxes.keySet()) + { + _itemIds[i] = j; + i++; + } + } + catch (Exception e) + { + _log.warning("ShadowBox: Error parsing shadowBoxes file."+ e); + return ; + } + + _log.info("ShadowBox: Loaded "+_shadowBoxes.size()+ " Boxes."); + } + + @Override + public void useItem(L2PlayableInstance playable, L2ItemInstance item) + { + if (!(playable instanceof L2PcInstance)) + return; + + L2PcInstance activeChar = (L2PcInstance)playable; + + if (!_shadowBoxes.containsKey(item.getItem())) + return; + + activeChar.getInventory().destroyItem("Extract", item, activeChar, null); + + for (int itemToCreateId : _shadowBoxes.get(item.getItemId())) + { + activeChar.getInventory().addItem("Extract", itemToCreateId, 1, activeChar, item); + SystemMessage sm = new SystemMessage(SystemMessageId.EARNED_ITEM); + sm.addItemName(itemToCreateId); + activeChar.sendPacket(sm); + } + ItemList playerUI = new ItemList(activeChar, false); + activeChar.sendPacket(playerUI); + } + + @Override + public int[] getItemIds() + { + return _itemIds; + } +} \ No newline at end of file