EnchantItemData.java 4.3 KB

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