ArmorSetsData.java 4.9 KB

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