KarmaData.java 2.4 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.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. * Karma data.
  28. * @author UnAfraid
  29. */
  30. public class KarmaData implements IXmlReader
  31. {
  32. private final Map<Integer, Double> _karmaTable = new HashMap<>();
  33. public KarmaData()
  34. {
  35. load();
  36. }
  37. @Override
  38. public synchronized void load()
  39. {
  40. _karmaTable.clear();
  41. parseDatapackFile("data/stats/chars/pcKarmaIncrease.xml");
  42. LOGGER.info("{}: Loaded {} karma modifiers.", getClass().getSimpleName(), _karmaTable.size());
  43. }
  44. @Override
  45. public void parseDocument(Document doc)
  46. {
  47. for (Node n = doc.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. final NamedNodeMap attrs = d.getAttributes();
  56. _karmaTable.put(parseInteger(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. }