OptionsData.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (C) 2004-2013 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.HashMap;
  21. import java.util.Map;
  22. import java.util.logging.Level;
  23. import org.w3c.dom.NamedNodeMap;
  24. import org.w3c.dom.Node;
  25. import com.l2jserver.gameserver.engines.DocumentParser;
  26. import com.l2jserver.gameserver.model.holders.SkillHolder;
  27. import com.l2jserver.gameserver.model.options.Options;
  28. import com.l2jserver.gameserver.model.options.OptionsSkillHolder;
  29. import com.l2jserver.gameserver.model.options.OptionsSkillType;
  30. import com.l2jserver.gameserver.model.skills.funcs.FuncTemplate;
  31. import com.l2jserver.gameserver.model.skills.funcs.LambdaConst;
  32. import com.l2jserver.gameserver.model.stats.Stats;
  33. /**
  34. * @author UnAfraid
  35. */
  36. public class OptionsData extends DocumentParser
  37. {
  38. private final Map<Integer, Options> _data = new HashMap<>();
  39. protected OptionsData()
  40. {
  41. load();
  42. }
  43. @Override
  44. public synchronized void load()
  45. {
  46. parseDirectory("data/stats/options");
  47. _log.log(Level.INFO, getClass().getSimpleName() + ": Loaded: " + _data.size() + " Options.");
  48. }
  49. @Override
  50. protected void parseDocument()
  51. {
  52. int id;
  53. Options op;
  54. for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
  55. {
  56. if ("list".equalsIgnoreCase(n.getNodeName()))
  57. {
  58. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  59. {
  60. if ("option".equalsIgnoreCase(d.getNodeName()))
  61. {
  62. id = parseInt(d.getAttributes(), "id");
  63. op = new Options(id);
  64. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  65. {
  66. switch (cd.getNodeName())
  67. {
  68. case "for":
  69. {
  70. for (Node fd = cd.getFirstChild(); fd != null; fd = fd.getNextSibling())
  71. {
  72. switch (fd.getNodeName())
  73. {
  74. case "add":
  75. {
  76. parseFuncs(fd.getAttributes(), "Add", op);
  77. break;
  78. }
  79. case "mul":
  80. {
  81. parseFuncs(fd.getAttributes(), "Mul", op);
  82. break;
  83. }
  84. case "basemul":
  85. {
  86. parseFuncs(fd.getAttributes(), "BaseMul", op);
  87. break;
  88. }
  89. case "sub":
  90. {
  91. parseFuncs(fd.getAttributes(), "Sub", op);
  92. break;
  93. }
  94. case "div":
  95. {
  96. parseFuncs(fd.getAttributes(), "Div", op);
  97. break;
  98. }
  99. case "set":
  100. {
  101. parseFuncs(fd.getAttributes(), "Set", op);
  102. break;
  103. }
  104. }
  105. }
  106. break;
  107. }
  108. case "active_skill":
  109. {
  110. op.setActiveSkill(new SkillHolder(parseInt(cd.getAttributes(), "id"), parseInt(cd.getAttributes(), "level")));
  111. break;
  112. }
  113. case "passive_skill":
  114. {
  115. op.setPassiveSkill(new SkillHolder(parseInt(cd.getAttributes(), "id"), parseInt(cd.getAttributes(), "level")));
  116. break;
  117. }
  118. case "attack_skill":
  119. {
  120. op.addActivationSkill(new OptionsSkillHolder(parseInt(cd.getAttributes(), "id"), parseInt(cd.getAttributes(), "level"), parseDouble(cd.getAttributes(), "chance"), OptionsSkillType.ATTACK));
  121. break;
  122. }
  123. case "magic_skill":
  124. {
  125. op.addActivationSkill(new OptionsSkillHolder(parseInt(cd.getAttributes(), "id"), parseInt(cd.getAttributes(), "level"), parseDouble(cd.getAttributes(), "chance"), OptionsSkillType.MAGIC));
  126. break;
  127. }
  128. case "critical_skill":
  129. {
  130. op.addActivationSkill(new OptionsSkillHolder(parseInt(cd.getAttributes(), "id"), parseInt(cd.getAttributes(), "level"), parseDouble(cd.getAttributes(), "chance"), OptionsSkillType.CRITICAL));
  131. break;
  132. }
  133. }
  134. }
  135. _data.put(op.getId(), op);
  136. }
  137. }
  138. }
  139. }
  140. }
  141. private void parseFuncs(NamedNodeMap attrs, String func, Options op)
  142. {
  143. Stats stat = Stats.valueOfXml(parseString(attrs, "stat"));
  144. int ord = Integer.decode(parseString(attrs, "order"));
  145. double val = parseDouble(attrs, "val");
  146. op.addFunc(new FuncTemplate(null, null, func, stat, ord, new LambdaConst(val)));
  147. }
  148. public Options getOptions(int id)
  149. {
  150. return _data.get(id);
  151. }
  152. /**
  153. * Gets the single instance of OptionsData.
  154. * @return single instance of OptionsData
  155. */
  156. public static final OptionsData getInstance()
  157. {
  158. return SingletonHolder._instance;
  159. }
  160. private static class SingletonHolder
  161. {
  162. protected static final OptionsData _instance = new OptionsData();
  163. }
  164. }