ArmorSetsTable.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 java.util.logging.Level;
  20. import org.w3c.dom.Document;
  21. import org.w3c.dom.NamedNodeMap;
  22. import org.w3c.dom.Node;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.engines.DocumentParser;
  25. import com.l2jserver.gameserver.model.L2ArmorSet;
  26. import com.l2jserver.gameserver.model.holders.SkillHolder;
  27. /**
  28. * @author godson, Luno, UnAfraid
  29. */
  30. public final class ArmorSetsTable extends DocumentParser
  31. {
  32. private final Map<Integer, L2ArmorSet> _armorSets = new HashMap<>();
  33. private ArmorSetsTable()
  34. {
  35. load();
  36. }
  37. private void load()
  38. {
  39. _armorSets.clear();
  40. parseDirectory(new File(Config.DATAPACK_ROOT, "data/stats/armorsets"));
  41. _log.log(Level.INFO, getClass().getSimpleName() + ": Loaded " + _armorSets.size() + " Armor sets.");
  42. }
  43. @Override
  44. protected void parseDocument(Document doc)
  45. {
  46. NamedNodeMap attrs;
  47. L2ArmorSet set;
  48. for (Node n = doc.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. // TODO: Implement me
  116. break;
  117. }
  118. case "dex":
  119. {
  120. // TODO: Implement me
  121. break;
  122. }
  123. case "str":
  124. {
  125. // TODO: Implement me
  126. break;
  127. }
  128. case "men":
  129. {
  130. // TODO: Implement me
  131. break;
  132. }
  133. case "wit":
  134. {
  135. // TODO: Implement me
  136. break;
  137. }
  138. case "int":
  139. {
  140. // TODO: Implement me
  141. break;
  142. }
  143. }
  144. }
  145. _armorSets.put(set.getChestId(), set);
  146. }
  147. }
  148. }
  149. }
  150. }
  151. /**
  152. * @param chestId the chest Id to verify.
  153. * @return {@code true} if the chest Id belongs to a registered armor set, {@code false} otherwise.
  154. */
  155. public boolean isArmorSet(int chestId)
  156. {
  157. return _armorSets.containsKey(chestId);
  158. }
  159. /**
  160. * @param chestId the chest Id identifying the armor set.
  161. * @return the armor set associated to the give chest Id.
  162. */
  163. public L2ArmorSet getSet(int chestId)
  164. {
  165. return _armorSets.get(chestId);
  166. }
  167. public static ArmorSetsTable getInstance()
  168. {
  169. return SingletonHolder._instance;
  170. }
  171. @SuppressWarnings("synthetic-access")
  172. private static class SingletonHolder
  173. {
  174. protected static final ArmorSetsTable _instance = new ArmorSetsTable();
  175. }
  176. }