PlayerXpPercentLostData.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.Arrays;
  21. import org.w3c.dom.Document;
  22. import org.w3c.dom.NamedNodeMap;
  23. import org.w3c.dom.Node;
  24. import com.l2jserver.util.data.xml.IXmlReader;
  25. /**
  26. * This class holds the Player Xp Percent Lost Data for each level for players.
  27. * @author Zealar
  28. */
  29. public final class PlayerXpPercentLostData implements IXmlReader
  30. {
  31. private final int _maxlevel = ExperienceData.getInstance().getMaxLevel();
  32. private final double[] _playerXpPercentLost = new double[_maxlevel + 1];
  33. protected PlayerXpPercentLostData()
  34. {
  35. Arrays.fill(_playerXpPercentLost, 1.);
  36. load();
  37. }
  38. @Override
  39. public void load()
  40. {
  41. parseDatapackFile("data/stats/chars/playerXpPercentLost.xml");
  42. }
  43. @Override
  44. public void parseDocument(Document doc)
  45. {
  46. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  47. {
  48. if ("list".equalsIgnoreCase(n.getNodeName()))
  49. {
  50. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  51. {
  52. if ("xpLost".equalsIgnoreCase(d.getNodeName()))
  53. {
  54. NamedNodeMap attrs = d.getAttributes();
  55. _playerXpPercentLost[parseInteger(attrs, "level")] = parseDouble(attrs, "val");
  56. }
  57. }
  58. }
  59. }
  60. }
  61. public double getXpPercent(final int level)
  62. {
  63. if (level > _maxlevel)
  64. {
  65. LOGGER.warn("Require to high level inside PlayerXpPercentLostData ({})", level);
  66. return _playerXpPercentLost[_maxlevel];
  67. }
  68. return _playerXpPercentLost[level];
  69. }
  70. /**
  71. * Gets the single instance of PlayerXpPercentLostData.
  72. * @return single instance of PlayerXpPercentLostData.
  73. */
  74. public static PlayerXpPercentLostData getInstance()
  75. {
  76. return SingletonHolder._instance;
  77. }
  78. private static class SingletonHolder
  79. {
  80. protected static final PlayerXpPercentLostData _instance = new PlayerXpPercentLostData();
  81. }
  82. }