FishingMonstersData.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.datatables;
  16. import java.util.HashMap;
  17. import java.util.Map;
  18. import org.w3c.dom.NamedNodeMap;
  19. import org.w3c.dom.Node;
  20. import com.l2jserver.gameserver.engines.DocumentParser;
  21. import com.l2jserver.gameserver.model.StatsSet;
  22. import com.l2jserver.gameserver.model.fishing.L2FishingMonster;
  23. /**
  24. * This class holds the Fishing Monsters information.
  25. * @author nonom
  26. */
  27. public final class FishingMonstersData extends DocumentParser
  28. {
  29. private static final Map<Integer, L2FishingMonster> _fishingMonstersData = new HashMap<>();
  30. /**
  31. * Instantiates a new fishing monsters data.
  32. */
  33. protected FishingMonstersData()
  34. {
  35. load();
  36. }
  37. @Override
  38. public void load()
  39. {
  40. _fishingMonstersData.clear();
  41. parseDatapackFile("data/stats/fishing/fishingMonsters.xml");
  42. _log.info(getClass().getSimpleName() + ": Loaded " + _fishingMonstersData.size() + " Fishing Monsters.");
  43. }
  44. @Override
  45. protected void parseDocument()
  46. {
  47. NamedNodeMap attrs;
  48. Node att;
  49. L2FishingMonster fishingMonster;
  50. StatsSet set;
  51. for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
  52. {
  53. if ("list".equalsIgnoreCase(n.getNodeName()))
  54. {
  55. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  56. {
  57. if ("fishingMonster".equalsIgnoreCase(d.getNodeName()))
  58. {
  59. attrs = d.getAttributes();
  60. set = new StatsSet();
  61. for (int i = 0; i < attrs.getLength(); i++)
  62. {
  63. att = attrs.item(i);
  64. set.set(att.getNodeName(), att.getNodeValue());
  65. }
  66. fishingMonster = new L2FishingMonster(set);
  67. _fishingMonstersData.put(fishingMonster.getFishingMonsterId(), fishingMonster);
  68. }
  69. }
  70. }
  71. }
  72. }
  73. /**
  74. * Gets the fishing monster.
  75. * @param lvl the fisherman level
  76. * @return a fishing monster given the fisherman level
  77. */
  78. public L2FishingMonster getFishingMonster(int lvl)
  79. {
  80. for (L2FishingMonster fishingMonster : _fishingMonstersData.values())
  81. {
  82. if ((lvl >= fishingMonster.getUserMinLevel()) && (lvl <= fishingMonster.getUserMaxLevel()))
  83. {
  84. return fishingMonster;
  85. }
  86. }
  87. return null;
  88. }
  89. /**
  90. * Gets the fishing monster by Id.
  91. * @param id the fishing monster Id
  92. * @return the fishing monster by Id
  93. */
  94. public L2FishingMonster getFishingMonsterById(int id)
  95. {
  96. if (_fishingMonstersData.containsKey(id))
  97. {
  98. return _fishingMonstersData.get(id);
  99. }
  100. return null;
  101. }
  102. /**
  103. * Gets the single instance of FishingMonsterData.
  104. * @return single instance of FishingMonsterData
  105. */
  106. public static FishingMonstersData getInstance()
  107. {
  108. return SingletonHolder._instance;
  109. }
  110. private static class SingletonHolder
  111. {
  112. protected static final FishingMonstersData _instance = new FishingMonstersData();
  113. }
  114. }