ExperienceTable.java 3.0 KB

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