FishingMonstersData.java 3.5 KB

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