EnchantItemData.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.datatables;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. import org.w3c.dom.Document;
  21. import org.w3c.dom.NamedNodeMap;
  22. import org.w3c.dom.Node;
  23. import com.l2jserver.gameserver.engines.DocumentParser;
  24. import com.l2jserver.gameserver.model.EnchantItem;
  25. import com.l2jserver.gameserver.model.EnchantScroll;
  26. import com.l2jserver.gameserver.model.StatsSet;
  27. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  28. /**
  29. * @author UnAfraid
  30. */
  31. public class EnchantItemData extends DocumentParser
  32. {
  33. public static final Map<Integer, EnchantScroll> _scrolls = new HashMap<>();
  34. public static final Map<Integer, EnchantItem> _supports = new HashMap<>();
  35. public EnchantItemData()
  36. {
  37. load();
  38. }
  39. @Override
  40. public void load()
  41. {
  42. _scrolls.clear();
  43. _supports.clear();
  44. parseDatapackFile("data/enchantData.xml");
  45. _log.info(getClass().getSimpleName() + ": Loaded " + _scrolls.size() + " Enchant Scrolls.");
  46. _log.info(getClass().getSimpleName() + ": Loaded " + _supports.size() + " Support Items.");
  47. }
  48. @Override
  49. protected void parseDocument(Document doc)
  50. {
  51. StatsSet set;
  52. Node att;
  53. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  54. {
  55. if ("list".equalsIgnoreCase(n.getNodeName()))
  56. {
  57. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  58. {
  59. if ("enchant".equalsIgnoreCase(d.getNodeName()))
  60. {
  61. NamedNodeMap attrs = d.getAttributes();
  62. set = new StatsSet();
  63. for (int i = 0; i < attrs.getLength(); i++)
  64. {
  65. att = attrs.item(i);
  66. set.set(att.getNodeName(), att.getNodeValue());
  67. }
  68. List<Integer> items = new ArrayList<Integer>();
  69. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  70. {
  71. if ("item".equalsIgnoreCase(cd.getNodeName()))
  72. {
  73. items.add(parseInt(cd.getAttributes(), "id"));
  74. }
  75. }
  76. EnchantScroll item = new EnchantScroll(set, items);
  77. _scrolls.put(item.getScrollId(), item);
  78. }
  79. else if ("support".equalsIgnoreCase(d.getNodeName()))
  80. {
  81. NamedNodeMap attrs = d.getAttributes();
  82. set = new StatsSet();
  83. for (int i = 0; i < attrs.getLength(); i++)
  84. {
  85. att = attrs.item(i);
  86. set.set(att.getNodeName(), att.getNodeValue());
  87. }
  88. List<Integer> items = new ArrayList<Integer>();
  89. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  90. {
  91. if ("item".equalsIgnoreCase(cd.getNodeName()))
  92. {
  93. items.add(parseInt(cd.getAttributes(), "id"));
  94. }
  95. }
  96. EnchantItem item = new EnchantItem(set, items);
  97. _supports.put(item.getScrollId(), item);
  98. }
  99. }
  100. }
  101. }
  102. }
  103. /**
  104. * @param scroll
  105. * @return enchant template for scroll
  106. */
  107. public final EnchantScroll getEnchantScroll(L2ItemInstance scroll)
  108. {
  109. return _scrolls.get(scroll.getItemId());
  110. }
  111. /**
  112. * @param item
  113. * @return enchant template for support item
  114. */
  115. public final EnchantItem getSupportItem(L2ItemInstance item)
  116. {
  117. return _supports.get(item.getItemId());
  118. }
  119. public static final EnchantItemData getInstance()
  120. {
  121. return SingletonHolder._instance;
  122. }
  123. private static class SingletonHolder
  124. {
  125. protected static final EnchantItemData _instance = new EnchantItemData();
  126. }
  127. }