PlayerTemplateData.java 6.5 KB

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