KarmaData.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. parseDatapackFile("data/stats/chars/pcKarmaIncrease.xml");
  40. _log.log(Level.INFO, getClass().getSimpleName() + ": Loaded " + _karmaTable.size() + " karma modifiers.");
  41. }
  42. @Override
  43. protected void parseDocument()
  44. {
  45. NamedNodeMap attrs;
  46. for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
  47. {
  48. if ("pcKarmaIncrease".equalsIgnoreCase(n.getNodeName()))
  49. {
  50. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  51. {
  52. if ("increase".equalsIgnoreCase(d.getNodeName()))
  53. {
  54. attrs = d.getAttributes();
  55. _karmaTable.put(parseInt(attrs, "lvl"), parseDouble(attrs, "val"));
  56. }
  57. }
  58. }
  59. }
  60. }
  61. /**
  62. * @param level
  63. * @return {@code double} modifier used to calculate karma lost upon death.
  64. */
  65. public double getMultiplier(int level)
  66. {
  67. return _karmaTable.get(level);
  68. }
  69. /**
  70. * Gets the single instance of KarmaData.
  71. * @return single instance of KarmaData
  72. */
  73. public static KarmaData getInstance()
  74. {
  75. return SingletonHolder._instance;
  76. }
  77. private static class SingletonHolder
  78. {
  79. protected static final KarmaData _instance = new KarmaData();
  80. }
  81. }