ExperienceTable.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. _expTable.clear();
  34. parseDatapackFile("data/stats/experience.xml");
  35. _log.info(getClass().getSimpleName() + ": Loaded " + _expTable.size() + " levels.");
  36. _log.info(getClass().getSimpleName() + ": Max Player Level is: " + (MAX_LEVEL - 1));
  37. _log.info(getClass().getSimpleName() + ": Max Pet Level is: " + (MAX_PET_LEVEL - 1));
  38. }
  39. @Override
  40. protected void parseDocument(Document doc)
  41. {
  42. final Node table = doc.getFirstChild();
  43. final NamedNodeMap tableAttr = table.getAttributes();
  44. MAX_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxLevel").getNodeValue()) + 1);
  45. MAX_PET_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxPetLevel").getNodeValue()) + 1);
  46. NamedNodeMap attrs;
  47. for (Node n = table.getFirstChild(); n != null; n = n.getNextSibling())
  48. {
  49. if ("experience".equals(n.getNodeName()))
  50. {
  51. attrs = n.getAttributes();
  52. _expTable.put(parseInteger(attrs, "level"), parseLong(attrs, "tolevel"));
  53. }
  54. }
  55. }
  56. /**
  57. * @param level the level required.
  58. * @return the experience points required to reach the given level.
  59. */
  60. public long getExpForLevel(int level)
  61. {
  62. return _expTable.get(level);
  63. }
  64. /**
  65. * @return the maximum level acquirable by a player.
  66. */
  67. public byte getMaxLevel()
  68. {
  69. return MAX_LEVEL;
  70. }
  71. /**
  72. * @return the maximum level acquirable by a pet.
  73. */
  74. public byte getMaxPetLevel()
  75. {
  76. return MAX_PET_LEVEL;
  77. }
  78. public static ExperienceTable getInstance()
  79. {
  80. return SingletonHolder._instance;
  81. }
  82. private static class SingletonHolder
  83. {
  84. protected static final ExperienceTable _instance = new ExperienceTable();
  85. }
  86. }