ExperienceTable.java 3.0 KB

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