ExperienceData.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2004-2015 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.data.xml.impl;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import org.w3c.dom.Document;
  23. import org.w3c.dom.NamedNodeMap;
  24. import org.w3c.dom.Node;
  25. import com.l2jserver.util.data.xml.IXmlReader;
  26. /**
  27. * This class holds the Experience points for each level for players and pets.
  28. * @author mrTJO
  29. */
  30. public final class ExperienceData implements IXmlReader
  31. {
  32. private final Map<Integer, Long> _expTable = new HashMap<>();
  33. private byte MAX_LEVEL;
  34. private byte MAX_PET_LEVEL;
  35. /**
  36. * Instantiates a new experience table.
  37. */
  38. protected ExperienceData()
  39. {
  40. load();
  41. }
  42. @Override
  43. public void load()
  44. {
  45. _expTable.clear();
  46. parseDatapackFile("data/stats/experience.xml");
  47. LOGGER.info("{}: Loaded {} levels.", getClass().getSimpleName(), _expTable.size());
  48. LOGGER.info("{}: Max Player Level is: {}", getClass().getSimpleName(), (MAX_LEVEL - 1));
  49. LOGGER.info("{}: Max Pet Level is: {}", getClass().getSimpleName(), (MAX_PET_LEVEL - 1));
  50. }
  51. @Override
  52. public void parseDocument(Document doc)
  53. {
  54. final Node table = doc.getFirstChild();
  55. final NamedNodeMap tableAttr = table.getAttributes();
  56. MAX_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxLevel").getNodeValue()) + 1);
  57. MAX_PET_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxPetLevel").getNodeValue()) + 1);
  58. for (Node n = table.getFirstChild(); n != null; n = n.getNextSibling())
  59. {
  60. if ("experience".equals(n.getNodeName()))
  61. {
  62. NamedNodeMap 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 ExperienceData getInstance()
  97. {
  98. return SingletonHolder._instance;
  99. }
  100. private static class SingletonHolder
  101. {
  102. protected static final ExperienceData _instance = new ExperienceData();
  103. }
  104. }