ArmorSetsData.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.io.File;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import org.w3c.dom.Document;
  20. import org.w3c.dom.NamedNodeMap;
  21. import org.w3c.dom.Node;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.engines.DocumentParser;
  24. import com.l2jserver.gameserver.model.L2ArmorSet;
  25. import com.l2jserver.gameserver.model.holders.SkillHolder;
  26. /**
  27. * @author godson, Luno, UnAfraid
  28. */
  29. public final class ArmorSetsData extends DocumentParser
  30. {
  31. private static final Map<Integer, L2ArmorSet> _armorSets = new HashMap<>();
  32. protected ArmorSetsData()
  33. {
  34. _armorSets.clear();
  35. parseDirectory(new File(Config.DATAPACK_ROOT, "data/stats/armorsets"));
  36. _log.info(getClass().getSimpleName() + ": Loaded " + _armorSets.size() + " Armor sets.");
  37. }
  38. @Override
  39. protected void parseDocument(Document doc)
  40. {
  41. NamedNodeMap attrs;
  42. L2ArmorSet set;
  43. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  44. {
  45. if ("list".equalsIgnoreCase(n.getNodeName()))
  46. {
  47. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  48. {
  49. if ("set".equalsIgnoreCase(d.getNodeName()))
  50. {
  51. set = new L2ArmorSet();
  52. for (Node a = d.getFirstChild(); a != null; a = a.getNextSibling())
  53. {
  54. attrs = a.getAttributes();
  55. switch (a.getNodeName())
  56. {
  57. case "chest":
  58. {
  59. set.addChest(parseInt(attrs, "id"));
  60. break;
  61. }
  62. case "feet":
  63. {
  64. set.addFeet(parseInt(attrs, "id"));
  65. break;
  66. }
  67. case "gloves":
  68. {
  69. set.addGloves(parseInt(attrs, "id"));
  70. break;
  71. }
  72. case "head":
  73. {
  74. set.addHead(parseInt(attrs, "id"));
  75. break;
  76. }
  77. case "legs":
  78. {
  79. set.addLegs(parseInt(attrs, "id"));
  80. break;
  81. }
  82. case "shield":
  83. {
  84. set.addShield(parseInt(attrs, "id"));
  85. break;
  86. }
  87. case "skill":
  88. {
  89. int skillId = parseInt(attrs, "id");
  90. int skillLevel = parseInt(attrs, "level");
  91. set.addSkill(new SkillHolder(skillId, skillLevel));
  92. break;
  93. }
  94. case "shield_skill":
  95. {
  96. int skillId = parseInt(attrs, "id");
  97. int skillLevel = parseInt(attrs, "level");
  98. set.addShieldSkill(new SkillHolder(skillId, skillLevel));
  99. break;
  100. }
  101. case "enchant6skill":
  102. {
  103. int skillId = parseInt(attrs, "id");
  104. int skillLevel = parseInt(attrs, "level");
  105. set.addEnchant6Skill(new SkillHolder(skillId, skillLevel));
  106. break;
  107. }
  108. case "con":
  109. {
  110. set.addCon(parseInt(attrs, "val"));
  111. break;
  112. }
  113. case "dex":
  114. {
  115. set.addDex(parseInt(attrs, "val"));
  116. break;
  117. }
  118. case "str":
  119. {
  120. set.addStr(parseInt(attrs, "val"));
  121. break;
  122. }
  123. case "men":
  124. {
  125. set.addMen(parseInt(attrs, "val"));
  126. break;
  127. }
  128. case "wit":
  129. {
  130. set.addWit(parseInt(attrs, "val"));
  131. break;
  132. }
  133. case "int":
  134. {
  135. set.addInt(parseInt(attrs, "val"));
  136. break;
  137. }
  138. }
  139. }
  140. _armorSets.put(set.getChestId(), set);
  141. }
  142. }
  143. }
  144. }
  145. }
  146. /**
  147. * @param chestId the chest Id to verify.
  148. * @return {@code true} if the chest Id belongs to a registered armor set, {@code false} otherwise.
  149. */
  150. public boolean isArmorSet(int chestId)
  151. {
  152. return _armorSets.containsKey(chestId);
  153. }
  154. /**
  155. * @param chestId the chest Id identifying the armor set.
  156. * @return the armor set associated to the give chest Id.
  157. */
  158. public L2ArmorSet getSet(int chestId)
  159. {
  160. return _armorSets.get(chestId);
  161. }
  162. public static ArmorSetsData getInstance()
  163. {
  164. return SingletonHolder._instance;
  165. }
  166. private static class SingletonHolder
  167. {
  168. protected static final ArmorSetsData _instance = new ArmorSetsData();
  169. }
  170. }