KarmaData.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 java.util.logging.Level;
  23. import org.w3c.dom.NamedNodeMap;
  24. import org.w3c.dom.Node;
  25. import com.l2jserver.gameserver.engines.DocumentParser;
  26. /**
  27. * @author UnAfraid
  28. */
  29. public class KarmaData extends DocumentParser
  30. {
  31. private final Map<Integer, Double> _karmaTable = new HashMap<>();
  32. public KarmaData()
  33. {
  34. load();
  35. }
  36. @Override
  37. public synchronized void load()
  38. {
  39. _karmaTable.clear();
  40. parseDatapackFile("data/stats/chars/pcKarmaIncrease.xml");
  41. _log.log(Level.INFO, getClass().getSimpleName() + ": Loaded " + _karmaTable.size() + " karma modifiers.");
  42. }
  43. @Override
  44. protected void parseDocument()
  45. {
  46. NamedNodeMap attrs;
  47. for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
  48. {
  49. if ("pcKarmaIncrease".equalsIgnoreCase(n.getNodeName()))
  50. {
  51. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  52. {
  53. if ("increase".equalsIgnoreCase(d.getNodeName()))
  54. {
  55. attrs = d.getAttributes();
  56. _karmaTable.put(parseInt(attrs, "lvl"), parseDouble(attrs, "val"));
  57. }
  58. }
  59. }
  60. }
  61. }
  62. /**
  63. * @param level
  64. * @return {@code double} modifier used to calculate karma lost upon death.
  65. */
  66. public double getMultiplier(int level)
  67. {
  68. return _karmaTable.get(level);
  69. }
  70. /**
  71. * Gets the single instance of KarmaData.
  72. * @return single instance of KarmaData
  73. */
  74. public static KarmaData getInstance()
  75. {
  76. return SingletonHolder._instance;
  77. }
  78. private static class SingletonHolder
  79. {
  80. protected static final KarmaData _instance = new KarmaData();
  81. }
  82. }