ExperienceTable.java 2.9 KB

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