HellboundPointData.java 4.5 KB

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