2
0

OptionsData.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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.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. _data.clear();
  47. parseDatapackDirectory("data/stats/options", false);
  48. _log.log(Level.INFO, getClass().getSimpleName() + ": Loaded: " + _data.size() + " Options.");
  49. }
  50. @Override
  51. protected void parseDocument()
  52. {
  53. int id;
  54. Options op;
  55. for (Node n = getCurrentDocument().getFirstChild(); n != null; n = n.getNextSibling())
  56. {
  57. if ("list".equalsIgnoreCase(n.getNodeName()))
  58. {
  59. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  60. {
  61. if ("option".equalsIgnoreCase(d.getNodeName()))
  62. {
  63. id = parseInteger(d.getAttributes(), "id");
  64. op = new Options(id);
  65. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  66. {
  67. switch (cd.getNodeName())
  68. {
  69. case "for":
  70. {
  71. for (Node fd = cd.getFirstChild(); fd != null; fd = fd.getNextSibling())
  72. {
  73. switch (fd.getNodeName())
  74. {
  75. case "add":
  76. {
  77. parseFuncs(fd.getAttributes(), "Add", op);
  78. break;
  79. }
  80. case "mul":
  81. {
  82. parseFuncs(fd.getAttributes(), "Mul", op);
  83. break;
  84. }
  85. case "basemul":
  86. {
  87. parseFuncs(fd.getAttributes(), "BaseMul", op);
  88. break;
  89. }
  90. case "sub":
  91. {
  92. parseFuncs(fd.getAttributes(), "Sub", op);
  93. break;
  94. }
  95. case "div":
  96. {
  97. parseFuncs(fd.getAttributes(), "Div", op);
  98. break;
  99. }
  100. case "set":
  101. {
  102. parseFuncs(fd.getAttributes(), "Set", op);
  103. break;
  104. }
  105. }
  106. }
  107. break;
  108. }
  109. case "active_skill":
  110. {
  111. op.setActiveSkill(new SkillHolder(parseInteger(cd.getAttributes(), "id"), parseInteger(cd.getAttributes(), "level")));
  112. break;
  113. }
  114. case "passive_skill":
  115. {
  116. op.setPassiveSkill(new SkillHolder(parseInteger(cd.getAttributes(), "id"), parseInteger(cd.getAttributes(), "level")));
  117. break;
  118. }
  119. case "attack_skill":
  120. {
  121. op.addActivationSkill(new OptionsSkillHolder(parseInteger(cd.getAttributes(), "id"), parseInteger(cd.getAttributes(), "level"), parseDouble(cd.getAttributes(), "chance"), OptionsSkillType.ATTACK));
  122. break;
  123. }
  124. case "magic_skill":
  125. {
  126. op.addActivationSkill(new OptionsSkillHolder(parseInteger(cd.getAttributes(), "id"), parseInteger(cd.getAttributes(), "level"), parseDouble(cd.getAttributes(), "chance"), OptionsSkillType.MAGIC));
  127. break;
  128. }
  129. case "critical_skill":
  130. {
  131. op.addActivationSkill(new OptionsSkillHolder(parseInteger(cd.getAttributes(), "id"), parseInteger(cd.getAttributes(), "level"), parseDouble(cd.getAttributes(), "chance"), OptionsSkillType.CRITICAL));
  132. break;
  133. }
  134. }
  135. }
  136. _data.put(op.getId(), op);
  137. }
  138. }
  139. }
  140. }
  141. }
  142. private void parseFuncs(NamedNodeMap attrs, String func, Options op)
  143. {
  144. Stats stat = Stats.valueOfXml(parseString(attrs, "stat"));
  145. int ord = Integer.decode(parseString(attrs, "order"));
  146. double val = parseDouble(attrs, "val");
  147. op.addFunc(new FuncTemplate(null, null, func, stat, ord, new LambdaConst(val)));
  148. }
  149. public Options getOptions(int id)
  150. {
  151. return _data.get(id);
  152. }
  153. /**
  154. * Gets the single instance of OptionsData.
  155. * @return single instance of OptionsData
  156. */
  157. public static final OptionsData getInstance()
  158. {
  159. return SingletonHolder._instance;
  160. }
  161. private static class SingletonHolder
  162. {
  163. protected static final OptionsData _instance = new OptionsData();
  164. }
  165. }