FishingMonstersData.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.HashMap;
  21. import java.util.Map;
  22. import org.w3c.dom.NamedNodeMap;
  23. import org.w3c.dom.Node;
  24. import com.l2jserver.gameserver.engines.DocumentParser;
  25. import com.l2jserver.gameserver.model.StatsSet;
  26. import com.l2jserver.gameserver.model.fishing.L2FishingMonster;
  27. /**
  28. * This class holds the Fishing Monsters information.
  29. * @author nonom
  30. */
  31. public final class FishingMonstersData extends DocumentParser
  32. {
  33. private static final Map<Integer, L2FishingMonster> _fishingMonstersData = new HashMap<>();
  34. /**
  35. * Instantiates a new fishing monsters data.
  36. */
  37. protected FishingMonstersData()
  38. {
  39. load();
  40. }
  41. @Override
  42. public void load()
  43. {
  44. _fishingMonstersData.clear();
  45. parseDatapackFile("data/stats/fishing/fishingMonsters.xml");
  46. _log.info(getClass().getSimpleName() + ": Loaded " + _fishingMonstersData.size() + " Fishing Monsters.");
  47. }
  48. @Override
  49. protected void parseDocument()
  50. {
  51. NamedNodeMap attrs;
  52. Node att;
  53. L2FishingMonster fishingMonster;
  54. StatsSet set;
  55. for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
  56. {
  57. if ("list".equalsIgnoreCase(n.getNodeName()))
  58. {
  59. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  60. {
  61. if ("fishingMonster".equalsIgnoreCase(d.getNodeName()))
  62. {
  63. attrs = d.getAttributes();
  64. set = new StatsSet();
  65. for (int i = 0; i < attrs.getLength(); i++)
  66. {
  67. att = attrs.item(i);
  68. set.set(att.getNodeName(), att.getNodeValue());
  69. }
  70. fishingMonster = new L2FishingMonster(set);
  71. _fishingMonstersData.put(fishingMonster.getFishingMonsterId(), fishingMonster);
  72. }
  73. }
  74. }
  75. }
  76. }
  77. /**
  78. * Gets the fishing monster.
  79. * @param lvl the fisherman level
  80. * @return a fishing monster given the fisherman level
  81. */
  82. public L2FishingMonster getFishingMonster(int lvl)
  83. {
  84. for (L2FishingMonster fishingMonster : _fishingMonstersData.values())
  85. {
  86. if ((lvl >= fishingMonster.getUserMinLevel()) && (lvl <= fishingMonster.getUserMaxLevel()))
  87. {
  88. return fishingMonster;
  89. }
  90. }
  91. return null;
  92. }
  93. /**
  94. * Gets the fishing monster by Id.
  95. * @param id the fishing monster Id
  96. * @return the fishing monster by Id
  97. */
  98. public L2FishingMonster getFishingMonsterById(int id)
  99. {
  100. if (_fishingMonstersData.containsKey(id))
  101. {
  102. return _fishingMonstersData.get(id);
  103. }
  104. return null;
  105. }
  106. /**
  107. * Gets the single instance of FishingMonsterData.
  108. * @return single instance of FishingMonsterData
  109. */
  110. public static FishingMonstersData getInstance()
  111. {
  112. return SingletonHolder._instance;
  113. }
  114. private static class SingletonHolder
  115. {
  116. protected static final FishingMonstersData _instance = new FishingMonstersData();
  117. }
  118. }