ExperienceTable.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.HashMap;
  17. import java.util.Map;
  18. import org.w3c.dom.NamedNodeMap;
  19. import org.w3c.dom.Node;
  20. import com.l2jserver.gameserver.engines.DocumentParser;
  21. /**
  22. * This class holds the Experience points for each level for players and pets.
  23. * @author mrTJO
  24. */
  25. public final class ExperienceTable extends DocumentParser
  26. {
  27. private final Map<Integer, Long> _expTable = new HashMap<>();
  28. private byte MAX_LEVEL;
  29. private byte MAX_PET_LEVEL;
  30. /**
  31. * Instantiates a new experience table.
  32. */
  33. protected ExperienceTable()
  34. {
  35. load();
  36. }
  37. @Override
  38. public void load()
  39. {
  40. _expTable.clear();
  41. parseDatapackFile("data/stats/experience.xml");
  42. _log.info(getClass().getSimpleName() + ": Loaded " + _expTable.size() + " levels.");
  43. _log.info(getClass().getSimpleName() + ": Max Player Level is: " + (MAX_LEVEL - 1));
  44. _log.info(getClass().getSimpleName() + ": Max Pet Level is: " + (MAX_PET_LEVEL - 1));
  45. }
  46. @Override
  47. protected void parseDocument()
  48. {
  49. final Node table = getCurrentDocument().getFirstChild();
  50. final NamedNodeMap tableAttr = table.getAttributes();
  51. MAX_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxLevel").getNodeValue()) + 1);
  52. MAX_PET_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxPetLevel").getNodeValue()) + 1);
  53. NamedNodeMap attrs;
  54. for (Node n = table.getFirstChild(); n != null; n = n.getNextSibling())
  55. {
  56. if ("experience".equals(n.getNodeName()))
  57. {
  58. attrs = n.getAttributes();
  59. _expTable.put(parseInteger(attrs, "level"), parseLong(attrs, "tolevel"));
  60. }
  61. }
  62. }
  63. /**
  64. * Gets the exp for level.
  65. * @param level the level required.
  66. * @return the experience points required to reach the given level.
  67. */
  68. public long getExpForLevel(int level)
  69. {
  70. return _expTable.get(level);
  71. }
  72. /**
  73. * Gets the max level.
  74. * @return the maximum level acquirable by a player.
  75. */
  76. public byte getMaxLevel()
  77. {
  78. return MAX_LEVEL;
  79. }
  80. /**
  81. * Gets the max pet level.
  82. * @return the maximum level acquirable by a pet.
  83. */
  84. public byte getMaxPetLevel()
  85. {
  86. return MAX_PET_LEVEL;
  87. }
  88. /**
  89. * Gets the single instance of ExperienceTable.
  90. * @return single instance of ExperienceTable
  91. */
  92. public static ExperienceTable getInstance()
  93. {
  94. return SingletonHolder._instance;
  95. }
  96. private static class SingletonHolder
  97. {
  98. protected static final ExperienceTable _instance = new ExperienceTable();
  99. }
  100. }