HellboundPointData.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 hellbound;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import org.w3c.dom.Document;
  23. import org.w3c.dom.NamedNodeMap;
  24. import org.w3c.dom.Node;
  25. import com.l2jserver.util.data.xml.IXmlReader;
  26. /**
  27. * Point data parser.
  28. * @author Zoey76
  29. */
  30. public final class HellboundPointData implements IXmlReader
  31. {
  32. private final Map<Integer, int[]> _pointsInfo = new HashMap<>();
  33. public HellboundPointData()
  34. {
  35. load();
  36. }
  37. @Override
  38. public void load()
  39. {
  40. _pointsInfo.clear();
  41. parseDatapackFile("data/scripts/hellbound/hellboundTrustPoints.xml");
  42. LOGGER.info("{}: Loaded {} trust point reward data.", getClass().getSimpleName(), _pointsInfo.size());
  43. }
  44. @Override
  45. public void parseDocument(Document doc)
  46. {
  47. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  48. {
  49. if ("list".equals(n.getNodeName()))
  50. {
  51. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  52. {
  53. parsePoint(d);
  54. }
  55. }
  56. }
  57. }
  58. /**
  59. * Parses the point.
  60. * @param d the node to parse
  61. */
  62. private void parsePoint(Node d)
  63. {
  64. if ("npc".equals(d.getNodeName()))
  65. {
  66. NamedNodeMap attrs = d.getAttributes();
  67. Node att = attrs.getNamedItem("id");
  68. if (att == null)
  69. {
  70. LOGGER.error("{}: Missing NPC ID, skipping record!", getClass().getSimpleName());
  71. return;
  72. }
  73. final int npcId = Integer.parseInt(att.getNodeValue());
  74. att = attrs.getNamedItem("points");
  75. if (att == null)
  76. {
  77. LOGGER.error("{}: Missing reward point info for NPC ID {}, skipping record", getClass().getSimpleName(), npcId);
  78. return;
  79. }
  80. final int points = Integer.parseInt(att.getNodeValue());
  81. att = attrs.getNamedItem("minHellboundLvl");
  82. if (att == null)
  83. {
  84. LOGGER.error("{}: Missing minHellboundLvl info for NPC ID {}, skipping record!", getClass().getSimpleName());
  85. return;
  86. }
  87. final int minHbLvl = Integer.parseInt(att.getNodeValue());
  88. att = attrs.getNamedItem("maxHellboundLvl");
  89. if (att == null)
  90. {
  91. LOGGER.error("{}: Missing maxHellboundLvl info for NPC ID {}, skipping record!", getClass().getSimpleName(), npcId);
  92. return;
  93. }
  94. final int maxHbLvl = Integer.parseInt(att.getNodeValue());
  95. att = attrs.getNamedItem("lowestTrustLimit");
  96. final int lowestTrustLimit = (att == null) ? 0 : Integer.parseInt(att.getNodeValue());
  97. _pointsInfo.put(npcId, new int[]
  98. {
  99. points,
  100. minHbLvl,
  101. maxHbLvl,
  102. lowestTrustLimit
  103. });
  104. }
  105. }
  106. /**
  107. * Gets all the points data.
  108. * @return the points data
  109. */
  110. public Map<Integer, int[]> getPointsInfo()
  111. {
  112. return _pointsInfo;
  113. }
  114. /**
  115. * Gets the points amount for an specific NPC ID.
  116. * @param npcId the NPC ID
  117. * @return the points for an specific NPC ID
  118. */
  119. public int getPointsAmount(int npcId)
  120. {
  121. return _pointsInfo.get(npcId)[0];
  122. }
  123. /**
  124. * Get the minimum Hellbound level for the given NPC ID.
  125. * @param npcId the NPC ID
  126. * @return the minimum Hellbound level for the given NPC ID
  127. */
  128. public int getMinHbLvl(int npcId)
  129. {
  130. return _pointsInfo.get(npcId)[1];
  131. }
  132. /**
  133. * Get the maximum Hellbound level for the given NPC ID.
  134. * @param npcId the NPC ID
  135. * @return the maximum Hellbound level for the given NPC ID
  136. */
  137. public int getMaxHbLvl(int npcId)
  138. {
  139. return _pointsInfo.get(npcId)[2];
  140. }
  141. /**
  142. * Get the lowest trust limit for the given NPC ID.
  143. * @param npcId the NPC ID
  144. * @return the lowest trust limit for the given NPC ID
  145. */
  146. public int getLowestTrustLimit(int npcId)
  147. {
  148. return _pointsInfo.get(npcId)[3];
  149. }
  150. public static HellboundPointData getInstance()
  151. {
  152. return SingletonHolder.INSTANCE;
  153. }
  154. private static class SingletonHolder
  155. {
  156. protected static final HellboundPointData INSTANCE = new HellboundPointData();
  157. }
  158. }