ExperienceTable.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.datatables;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import org.w3c.dom.NamedNodeMap;
  23. import org.w3c.dom.Node;
  24. import com.l2jserver.gameserver.engines.DocumentParser;
  25. /**
  26. * This class holds the Experience points for each level for players and pets.
  27. * @author mrTJO
  28. */
  29. public final class ExperienceTable extends DocumentParser
  30. {
  31. private final Map<Integer, Long> _expTable = new HashMap<>();
  32. private byte MAX_LEVEL;
  33. private byte MAX_PET_LEVEL;
  34. /**
  35. * Instantiates a new experience table.
  36. */
  37. protected ExperienceTable()
  38. {
  39. load();
  40. }
  41. @Override
  42. public void load()
  43. {
  44. _expTable.clear();
  45. parseDatapackFile("data/stats/experience.xml");
  46. _log.info(getClass().getSimpleName() + ": Loaded " + _expTable.size() + " levels.");
  47. _log.info(getClass().getSimpleName() + ": Max Player Level is: " + (MAX_LEVEL - 1));
  48. _log.info(getClass().getSimpleName() + ": Max Pet Level is: " + (MAX_PET_LEVEL - 1));
  49. }
  50. @Override
  51. protected void parseDocument()
  52. {
  53. final Node table = getCurrentDocument().getFirstChild();
  54. final NamedNodeMap tableAttr = table.getAttributes();
  55. MAX_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxLevel").getNodeValue()) + 1);
  56. MAX_PET_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxPetLevel").getNodeValue()) + 1);
  57. NamedNodeMap attrs;
  58. for (Node n = table.getFirstChild(); n != null; n = n.getNextSibling())
  59. {
  60. if ("experience".equals(n.getNodeName()))
  61. {
  62. attrs = n.getAttributes();
  63. _expTable.put(parseInteger(attrs, "level"), parseLong(attrs, "tolevel"));
  64. }
  65. }
  66. }
  67. /**
  68. * Gets the exp for level.
  69. * @param level the level required.
  70. * @return the experience points required to reach the given level.
  71. */
  72. public long getExpForLevel(int level)
  73. {
  74. return _expTable.get(level);
  75. }
  76. /**
  77. * Gets the max level.
  78. * @return the maximum level acquirable by a player.
  79. */
  80. public byte getMaxLevel()
  81. {
  82. return MAX_LEVEL;
  83. }
  84. /**
  85. * Gets the max pet level.
  86. * @return the maximum level acquirable by a pet.
  87. */
  88. public byte getMaxPetLevel()
  89. {
  90. return MAX_PET_LEVEL;
  91. }
  92. /**
  93. * Gets the single instance of ExperienceTable.
  94. * @return single instance of ExperienceTable
  95. */
  96. public static ExperienceTable getInstance()
  97. {
  98. return SingletonHolder._instance;
  99. }
  100. private static class SingletonHolder
  101. {
  102. protected static final ExperienceTable _instance = new ExperienceTable();
  103. }
  104. }