CharTemplateTable.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (C) 2004-2014 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.datatables;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.logging.Logger;
  25. import org.w3c.dom.NamedNodeMap;
  26. import org.w3c.dom.Node;
  27. import com.l2jserver.gameserver.engines.DocumentParser;
  28. import com.l2jserver.gameserver.model.Location;
  29. import com.l2jserver.gameserver.model.StatsSet;
  30. import com.l2jserver.gameserver.model.actor.templates.L2PcTemplate;
  31. import com.l2jserver.gameserver.model.base.ClassId;
  32. /**
  33. * This will be reworked Soon(tm).
  34. * @author Forsaiken, Zoey76, GKR
  35. */
  36. public final class CharTemplateTable extends DocumentParser
  37. {
  38. private static final Logger _log = Logger.getLogger(CharTemplateTable.class.getName());
  39. private static final Map<ClassId, L2PcTemplate> _charTemplates = new HashMap<>();
  40. private int _dataCount = 0;
  41. protected CharTemplateTable()
  42. {
  43. load();
  44. }
  45. @Override
  46. public void load()
  47. {
  48. _charTemplates.clear();
  49. parseDatapackDirectory("data/stats/chars/baseStats", false);
  50. _log.info(getClass().getSimpleName() + ": Loaded " + _charTemplates.size() + " character templates.");
  51. _log.info(getClass().getSimpleName() + ": Loaded " + _dataCount + " level up gain records.");
  52. }
  53. @Override
  54. protected void parseDocument()
  55. {
  56. NamedNodeMap attrs;
  57. int classId = 0;
  58. for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
  59. {
  60. if ("list".equalsIgnoreCase(n.getNodeName()))
  61. {
  62. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  63. {
  64. if ("classId".equalsIgnoreCase(d.getNodeName()))
  65. {
  66. classId = Integer.parseInt(d.getTextContent());
  67. }
  68. else if ("staticData".equalsIgnoreCase(d.getNodeName()))
  69. {
  70. StatsSet set = new StatsSet();
  71. set.set("classId", classId);
  72. List<Location> creationPoints = new ArrayList<>();
  73. for (Node nd = d.getFirstChild(); nd != null; nd = nd.getNextSibling())
  74. {
  75. // Skip odd nodes
  76. if (nd.getNodeName().equals("#text"))
  77. {
  78. continue;
  79. }
  80. if (nd.getChildNodes().getLength() > 1)
  81. {
  82. for (Node cnd = nd.getFirstChild(); cnd != null; cnd = cnd.getNextSibling())
  83. {
  84. // use L2CharTemplate(superclass) fields for male collision height and collision radius
  85. if (nd.getNodeName().equalsIgnoreCase("collisionMale"))
  86. {
  87. if (cnd.getNodeName().equalsIgnoreCase("radius"))
  88. {
  89. set.set("collision_radius", cnd.getTextContent());
  90. }
  91. else if (cnd.getNodeName().equalsIgnoreCase("height"))
  92. {
  93. set.set("collision_height", cnd.getTextContent());
  94. }
  95. }
  96. if ("node".equalsIgnoreCase(cnd.getNodeName()))
  97. {
  98. attrs = cnd.getAttributes();
  99. creationPoints.add(new Location(parseInteger(attrs, "x"), parseInteger(attrs, "y"), parseInteger(attrs, "z")));
  100. }
  101. else if ("walk".equalsIgnoreCase(cnd.getNodeName()))
  102. {
  103. set.set("baseWalkSpd", cnd.getTextContent());
  104. }
  105. else if ("run".equalsIgnoreCase(cnd.getNodeName()))
  106. {
  107. set.set("baseRunSpd", cnd.getTextContent());
  108. }
  109. else if ("slowSwim".equals(cnd.getNodeName()))
  110. {
  111. set.set("baseSwimWalkSpd", cnd.getTextContent());
  112. }
  113. else if ("fastSwim".equals(cnd.getNodeName()))
  114. {
  115. set.set("baseSwimRunSpd", cnd.getTextContent());
  116. }
  117. else if (!cnd.getNodeName().equals("#text"))
  118. {
  119. set.set((nd.getNodeName() + cnd.getNodeName()), cnd.getTextContent());
  120. }
  121. }
  122. }
  123. else
  124. {
  125. set.set(nd.getNodeName(), nd.getTextContent());
  126. }
  127. }
  128. // calculate total pdef and mdef from parts
  129. set.set("basePDef", (set.getInt("basePDefchest", 0) + set.getInt("basePDeflegs", 0) + set.getInt("basePDefhead", 0) + set.getInt("basePDeffeet", 0) + set.getInt("basePDefgloves", 0) + set.getInt("basePDefunderwear", 0) + set.getInt("basePDefcloak", 0)));
  130. set.set("baseMDef", (set.getInt("baseMDefrear", 0) + set.getInt("baseMDeflear", 0) + set.getInt("baseMDefrfinger", 0) + set.getInt("baseMDefrfinger", 0) + set.getInt("baseMDefneck", 0)));
  131. _charTemplates.put(ClassId.getClassId(classId), new L2PcTemplate(set, creationPoints));
  132. }
  133. else if ("lvlUpgainData".equalsIgnoreCase(d.getNodeName()))
  134. {
  135. for (Node lvlNode = d.getFirstChild(); lvlNode != null; lvlNode = lvlNode.getNextSibling())
  136. {
  137. if ("level".equalsIgnoreCase(lvlNode.getNodeName()))
  138. {
  139. attrs = lvlNode.getAttributes();
  140. int level = parseInteger(attrs, "val");
  141. for (Node valNode = lvlNode.getFirstChild(); valNode != null; valNode = valNode.getNextSibling())
  142. {
  143. String nodeName = valNode.getNodeName();
  144. if ((nodeName.startsWith("hp") || nodeName.startsWith("mp") || nodeName.startsWith("cp")) && _charTemplates.containsKey(ClassId.getClassId(classId)))
  145. {
  146. _charTemplates.get(ClassId.getClassId(classId)).setUpgainValue(nodeName, level, Double.parseDouble(valNode.getTextContent()));
  147. _dataCount++;
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
  155. }
  156. }
  157. public L2PcTemplate getTemplate(final ClassId classId)
  158. {
  159. return _charTemplates.get(classId);
  160. }
  161. public L2PcTemplate getTemplate(final int classId)
  162. {
  163. return _charTemplates.get(ClassId.getClassId(classId));
  164. }
  165. public static final CharTemplateTable getInstance()
  166. {
  167. return SingletonHolder._instance;
  168. }
  169. private static class SingletonHolder
  170. {
  171. protected static final CharTemplateTable _instance = new CharTemplateTable();
  172. }
  173. }