PlayerXpPercentLostData.java 2.5 KB

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