ArmorSetsData.java 5.0 KB

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