DocumentBase.java 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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.skills;
  16. import java.io.File;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.NoSuchElementException;
  21. import java.util.StringTokenizer;
  22. import java.util.logging.Level;
  23. import java.util.logging.Logger;
  24. import javax.xml.parsers.DocumentBuilderFactory;
  25. import javolution.util.FastMap;
  26. import org.w3c.dom.Document;
  27. import org.w3c.dom.NamedNodeMap;
  28. import org.w3c.dom.Node;
  29. import com.l2jserver.Config;
  30. import com.l2jserver.gameserver.datatables.ItemTable;
  31. import com.l2jserver.gameserver.model.ChanceCondition;
  32. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  33. import com.l2jserver.gameserver.model.L2Skill;
  34. import com.l2jserver.gameserver.model.base.PlayerState;
  35. import com.l2jserver.gameserver.model.base.Race;
  36. import com.l2jserver.gameserver.skills.conditions.Condition;
  37. import com.l2jserver.gameserver.skills.conditions.ConditionChangeWeapon;
  38. import com.l2jserver.gameserver.skills.conditions.ConditionForceBuff;
  39. import com.l2jserver.gameserver.skills.conditions.ConditionGameChance;
  40. import com.l2jserver.gameserver.skills.conditions.ConditionGameTime;
  41. import com.l2jserver.gameserver.skills.conditions.ConditionGameTime.CheckGameTime;
  42. import com.l2jserver.gameserver.skills.conditions.ConditionLogicAnd;
  43. import com.l2jserver.gameserver.skills.conditions.ConditionLogicNot;
  44. import com.l2jserver.gameserver.skills.conditions.ConditionLogicOr;
  45. import com.l2jserver.gameserver.skills.conditions.ConditionMinDistance;
  46. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerActiveEffectId;
  47. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerActiveSkillId;
  48. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerAgathionId;
  49. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerCharges;
  50. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerClassIdRestriction;
  51. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerCloakStatus;
  52. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerCp;
  53. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerFlyMounted;
  54. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerGrade;
  55. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerHasCastle;
  56. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerHasClanHall;
  57. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerHasFort;
  58. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerHasPet;
  59. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerHp;
  60. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerInstanceId;
  61. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerInvSize;
  62. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerIsClanLeader;
  63. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerIsHero;
  64. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerLandingZone;
  65. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerLevel;
  66. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerMp;
  67. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerPkCount;
  68. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerPledgeClass;
  69. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerRace;
  70. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerServitorNpcId;
  71. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerSex;
  72. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerSiegeSide;
  73. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerSouls;
  74. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerState;
  75. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerSubclass;
  76. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerTvTEvent;
  77. import com.l2jserver.gameserver.skills.conditions.ConditionPlayerWeight;
  78. import com.l2jserver.gameserver.skills.conditions.ConditionSiegeZone;
  79. import com.l2jserver.gameserver.skills.conditions.ConditionSkillStats;
  80. import com.l2jserver.gameserver.skills.conditions.ConditionSlotItemId;
  81. import com.l2jserver.gameserver.skills.conditions.ConditionTargetAbnormal;
  82. import com.l2jserver.gameserver.skills.conditions.ConditionTargetActiveEffectId;
  83. import com.l2jserver.gameserver.skills.conditions.ConditionTargetActiveSkillId;
  84. import com.l2jserver.gameserver.skills.conditions.ConditionTargetAggro;
  85. import com.l2jserver.gameserver.skills.conditions.ConditionTargetClassIdRestriction;
  86. import com.l2jserver.gameserver.skills.conditions.ConditionTargetLevel;
  87. import com.l2jserver.gameserver.skills.conditions.ConditionTargetNpcId;
  88. import com.l2jserver.gameserver.skills.conditions.ConditionTargetNpcType;
  89. import com.l2jserver.gameserver.skills.conditions.ConditionTargetPlayable;
  90. import com.l2jserver.gameserver.skills.conditions.ConditionTargetRace;
  91. import com.l2jserver.gameserver.skills.conditions.ConditionTargetRaceId;
  92. import com.l2jserver.gameserver.skills.conditions.ConditionTargetUsesWeaponKind;
  93. import com.l2jserver.gameserver.skills.conditions.ConditionUsingItemType;
  94. import com.l2jserver.gameserver.skills.conditions.ConditionUsingSkill;
  95. import com.l2jserver.gameserver.skills.conditions.ConditionWithSkill;
  96. import com.l2jserver.gameserver.skills.effects.EffectChanceSkillTrigger;
  97. import com.l2jserver.gameserver.skills.funcs.FuncTemplate;
  98. import com.l2jserver.gameserver.skills.funcs.Lambda;
  99. import com.l2jserver.gameserver.skills.funcs.LambdaCalc;
  100. import com.l2jserver.gameserver.skills.funcs.LambdaConst;
  101. import com.l2jserver.gameserver.skills.funcs.LambdaStats;
  102. import com.l2jserver.gameserver.templates.StatsSet;
  103. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  104. import com.l2jserver.gameserver.templates.item.L2ArmorType;
  105. import com.l2jserver.gameserver.templates.item.L2Item;
  106. import com.l2jserver.gameserver.templates.item.L2WeaponType;
  107. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  108. /**
  109. * @author mkizub
  110. */
  111. abstract class DocumentBase
  112. {
  113. static Logger _log = Logger.getLogger(DocumentBase.class.getName());
  114. private File _file;
  115. protected Map<String, String[]> _tables;
  116. DocumentBase(File pFile)
  117. {
  118. _file = pFile;
  119. _tables = new FastMap<String, String[]>();
  120. }
  121. Document parse()
  122. {
  123. Document doc;
  124. try
  125. {
  126. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  127. factory.setValidating(false);
  128. factory.setIgnoringComments(true);
  129. doc = factory.newDocumentBuilder().parse(_file);
  130. }
  131. catch (Exception e)
  132. {
  133. _log.log(Level.SEVERE, "Error loading file " + _file, e);
  134. return null;
  135. }
  136. try
  137. {
  138. parseDocument(doc);
  139. }
  140. catch (Exception e)
  141. {
  142. _log.log(Level.SEVERE, "Error in file " + _file, e);
  143. return null;
  144. }
  145. return doc;
  146. }
  147. protected abstract void parseDocument(Document doc);
  148. protected abstract StatsSet getStatsSet();
  149. protected abstract String getTableValue(String name);
  150. protected abstract String getTableValue(String name, int idx);
  151. protected void resetTable()
  152. {
  153. _tables = new FastMap<String, String[]>();
  154. }
  155. protected void setTable(String name, String[] table)
  156. {
  157. _tables.put(name, table);
  158. }
  159. protected void parseTemplate(Node n, Object template)
  160. {
  161. Condition condition = null;
  162. n = n.getFirstChild();
  163. if (n == null) return;
  164. if ("cond".equalsIgnoreCase(n.getNodeName()))
  165. {
  166. condition = parseCondition(n.getFirstChild(), template);
  167. Node msg = n.getAttributes().getNamedItem("msg");
  168. Node msgId = n.getAttributes().getNamedItem("msgId");
  169. if (condition != null && msg != null)
  170. condition.setMessage(msg.getNodeValue());
  171. else if (condition != null && msgId != null)
  172. {
  173. condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
  174. Node addName = n.getAttributes().getNamedItem("addName");
  175. if (addName != null && Integer.decode(getValue(msgId.getNodeValue(), null)) > 0)
  176. condition.addName();
  177. }
  178. n = n.getNextSibling();
  179. }
  180. for (; n != null; n = n.getNextSibling())
  181. {
  182. if ("add".equalsIgnoreCase(n.getNodeName())) attachFunc(n, template, "Add", condition);
  183. else if ("sub".equalsIgnoreCase(n.getNodeName())) attachFunc(n, template, "Sub", condition);
  184. else if ("mul".equalsIgnoreCase(n.getNodeName())) attachFunc(n, template, "Mul", condition);
  185. else if ("basemul".equalsIgnoreCase(n.getNodeName())) attachFunc(n, template, "BaseMul", condition);
  186. else if ("div".equalsIgnoreCase(n.getNodeName())) attachFunc(n, template, "Div", condition);
  187. else if ("set".equalsIgnoreCase(n.getNodeName())) attachFunc(n, template, "Set", condition);
  188. else if ("enchant".equalsIgnoreCase(n.getNodeName())) attachFunc(n, template, "Enchant", condition);
  189. else if ("enchanthp".equalsIgnoreCase(n.getNodeName())) attachFunc(n, template, "EnchantHp", condition);
  190. //else if ("skill".equalsIgnoreCase(n.getNodeName())) attachSkill(n, template, condition);
  191. else if ("effect".equalsIgnoreCase(n.getNodeName()))
  192. {
  193. if (template instanceof EffectTemplate) throw new RuntimeException("Nested effects");
  194. attachEffect(n, template, condition);
  195. }
  196. }
  197. }
  198. protected void attachFunc(Node n, Object template, String name, Condition attachCond)
  199. {
  200. Stats stat = Stats.valueOfXml(n.getAttributes().getNamedItem("stat").getNodeValue());
  201. String order = n.getAttributes().getNamedItem("order").getNodeValue();
  202. Lambda lambda = getLambda(n, template);
  203. int ord = Integer.decode(getValue(order, template));
  204. Condition applayCond = parseCondition(n.getFirstChild(), template);
  205. FuncTemplate ft = new FuncTemplate(attachCond, applayCond, name, stat, ord, lambda);
  206. if (template instanceof L2Item) ((L2Item) template).attach(ft);
  207. else if (template instanceof L2Skill) ((L2Skill) template).attach(ft);
  208. else if (template instanceof EffectTemplate) ((EffectTemplate) template).attach(ft);
  209. }
  210. protected void attachLambdaFunc(Node n, Object template, LambdaCalc calc)
  211. {
  212. String name = n.getNodeName();
  213. final StringBuilder sb = new StringBuilder(name);
  214. sb.setCharAt(0, Character.toUpperCase(name.charAt(0)));
  215. name = sb.toString();
  216. Lambda lambda = getLambda(n, template);
  217. FuncTemplate ft = new FuncTemplate(null, null, name, null, calc.funcs.length, lambda);
  218. calc.addFunc(ft.getFunc(new Env(), calc));
  219. }
  220. protected void attachEffect(Node n, Object template, Condition attachCond)
  221. {
  222. NamedNodeMap attrs = n.getAttributes();
  223. String name = getValue(attrs.getNamedItem("name").getNodeValue().intern(), template);
  224. /**
  225. * Keep this values as default ones, DP needs it
  226. */
  227. int time = 1;
  228. int count = 1;
  229. if (attrs.getNamedItem("count") != null)
  230. {
  231. count = Integer.decode(getValue(attrs.getNamedItem("count").getNodeValue(), template));
  232. }
  233. if (attrs.getNamedItem("time") != null)
  234. {
  235. time = Integer.decode(getValue(attrs.getNamedItem("time").getNodeValue(),template));
  236. if (Config.ENABLE_MODIFY_SKILL_DURATION)
  237. {
  238. if (Config.SKILL_DURATION_LIST.containsKey(((L2Skill) template).getId()))
  239. {
  240. if (((L2Skill) template).getLevel() < 100)
  241. time = Config.SKILL_DURATION_LIST.get(((L2Skill) template).getId());
  242. else if ((((L2Skill) template).getLevel() >= 100) && (((L2Skill) template).getLevel() < 140))
  243. time += Config.SKILL_DURATION_LIST.get(((L2Skill) template).getId());
  244. else if (((L2Skill) template).getLevel() > 140)
  245. time = Config.SKILL_DURATION_LIST.get(((L2Skill) template).getId());
  246. if (Config.DEBUG)
  247. _log.info("*** Skill " + ((L2Skill) template).getName() + " (" + ((L2Skill) template).getLevel() + ") changed duration to " + time + " seconds.");
  248. }
  249. }
  250. }
  251. else if (((L2Skill) template).getBuffDuration() > 0)
  252. time = ((L2Skill) template).getBuffDuration() / 1000 / count;
  253. boolean self = false;
  254. if (attrs.getNamedItem("self") != null)
  255. {
  256. if (Integer.decode(getValue(attrs.getNamedItem("self").getNodeValue(),template)) == 1)
  257. self = true;
  258. }
  259. boolean icon = true;
  260. if (attrs.getNamedItem("noicon") !=null)
  261. {
  262. if (Integer.decode(getValue(attrs.getNamedItem("noicon").getNodeValue(),template)) == 1)
  263. icon = false;
  264. }
  265. Lambda lambda = getLambda(n, template);
  266. Condition applayCond = parseCondition(n.getFirstChild(), template);
  267. AbnormalEffect abnormal = AbnormalEffect.NULL;
  268. if (attrs.getNamedItem("abnormal") != null)
  269. {
  270. String abn = attrs.getNamedItem("abnormal").getNodeValue();
  271. abnormal = AbnormalEffect.getByName(abn);
  272. }
  273. AbnormalEffect special = AbnormalEffect.NULL;
  274. if (attrs.getNamedItem("special") != null)
  275. {
  276. String spc = attrs.getNamedItem("special").getNodeValue();
  277. special = AbnormalEffect.getByName(spc);
  278. }
  279. AbnormalEffect event = AbnormalEffect.NULL;
  280. if (attrs.getNamedItem("event") != null)
  281. {
  282. String spc = attrs.getNamedItem("event").getNodeValue();
  283. event = AbnormalEffect.getByName(spc);
  284. }
  285. byte abnormalLvl = 0;
  286. String abnormalType = "none";
  287. if (attrs.getNamedItem("abnormalType") != null)
  288. {
  289. abnormalType = attrs.getNamedItem("abnormalType").getNodeValue();
  290. }
  291. if (attrs.getNamedItem("abnormalLvl") != null)
  292. {
  293. abnormalLvl = Byte.parseByte(getValue(attrs.getNamedItem("abnormalLvl").getNodeValue(), template));
  294. }
  295. double effectPower = -1;
  296. if (attrs.getNamedItem("effectPower") != null)
  297. effectPower = Double.parseDouble( getValue(attrs.getNamedItem("effectPower").getNodeValue(), template));
  298. L2SkillType type = null;
  299. if (attrs.getNamedItem("effectType") != null)
  300. {
  301. String typeName = getValue(attrs.getNamedItem("effectType").getNodeValue(), template);
  302. try
  303. {
  304. type = Enum.valueOf(L2SkillType.class, typeName);
  305. }
  306. catch (Exception e)
  307. {
  308. throw new IllegalArgumentException("Not skilltype found for: "+typeName);
  309. }
  310. }
  311. EffectTemplate lt;
  312. final boolean isChanceSkillTrigger = (name == EffectChanceSkillTrigger.class.getName());
  313. int trigId = 0;
  314. if (attrs.getNamedItem("triggeredId") != null)
  315. trigId = Integer.parseInt(getValue(attrs.getNamedItem("triggeredId").getNodeValue(), template));
  316. else if (isChanceSkillTrigger)
  317. throw new NoSuchElementException(name + " requires triggerId");
  318. int trigLvl = 1;
  319. if (attrs.getNamedItem("triggeredLevel") != null)
  320. trigLvl = Integer.parseInt(getValue(attrs.getNamedItem("triggeredLevel").getNodeValue(), template));
  321. String chanceCond = null;
  322. if (attrs.getNamedItem("chanceType") != null)
  323. chanceCond = getValue(attrs.getNamedItem("chanceType").getNodeValue(), template);
  324. else if (isChanceSkillTrigger)
  325. throw new NoSuchElementException(name + " requires chanceType");
  326. int activationChance = -1;
  327. if (attrs.getNamedItem("activationChance") != null)
  328. activationChance = Integer.parseInt(getValue(attrs.getNamedItem("activationChance").getNodeValue(), template));
  329. int activationMinDamage = -1;
  330. if (attrs.getNamedItem("activationMinDamage") != null)
  331. activationMinDamage = Integer.parseInt(getValue(attrs.getNamedItem("activationMinDamage").getNodeValue(), template));
  332. String activationElements = null;
  333. if (attrs.getNamedItem("activationElements") != null)
  334. activationElements = getValue(attrs.getNamedItem("activationElements").getNodeValue(), template);
  335. boolean pvpOnly = false;
  336. if (attrs.getNamedItem("pvpChanceOnly") != null)
  337. pvpOnly = Boolean.parseBoolean(getValue(attrs.getNamedItem("pvpChanceOnly").getNodeValue(), template));
  338. ChanceCondition chance = ChanceCondition.parse(chanceCond, activationChance, activationMinDamage, activationElements, pvpOnly);
  339. if (chance == null && isChanceSkillTrigger)
  340. throw new NoSuchElementException("Invalid chance condition: " + chanceCond + " "
  341. + activationChance);
  342. lt = new EffectTemplate(attachCond, applayCond, name, lambda, count, time, abnormal, special, event, abnormalType, abnormalLvl, icon, effectPower, type, trigId, trigLvl, chance);
  343. parseTemplate(n, lt);
  344. if (template instanceof L2Item)
  345. ((L2Item) template).attach(lt);
  346. else if (template instanceof L2Skill)
  347. {
  348. if (self)
  349. ((L2Skill) template).attachSelf(lt);
  350. else
  351. ((L2Skill) template).attach(lt);
  352. }
  353. }
  354. protected Condition parseCondition(Node n, Object template)
  355. {
  356. while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  357. n = n.getNextSibling();
  358. if (n == null) return null;
  359. if ("and".equalsIgnoreCase(n.getNodeName())) return parseLogicAnd(n, template);
  360. if ("or".equalsIgnoreCase(n.getNodeName())) return parseLogicOr(n, template);
  361. if ("not".equalsIgnoreCase(n.getNodeName())) return parseLogicNot(n, template);
  362. if ("player".equalsIgnoreCase(n.getNodeName())) return parsePlayerCondition(n, template);
  363. if ("target".equalsIgnoreCase(n.getNodeName())) return parseTargetCondition(n, template);
  364. if ("skill".equalsIgnoreCase(n.getNodeName())) return parseSkillCondition(n);
  365. if ("using".equalsIgnoreCase(n.getNodeName())) return parseUsingCondition(n);
  366. if ("game".equalsIgnoreCase(n.getNodeName())) return parseGameCondition(n);
  367. return null;
  368. }
  369. protected Condition parseLogicAnd(Node n, Object template)
  370. {
  371. ConditionLogicAnd cond = new ConditionLogicAnd();
  372. for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
  373. {
  374. if (n.getNodeType() == Node.ELEMENT_NODE) cond.add(parseCondition(n, template));
  375. }
  376. if (cond.conditions == null || cond.conditions.length == 0)
  377. _log.severe("Empty <and> condition in " + _file);
  378. return cond;
  379. }
  380. protected Condition parseLogicOr(Node n, Object template)
  381. {
  382. ConditionLogicOr cond = new ConditionLogicOr();
  383. for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
  384. {
  385. if (n.getNodeType() == Node.ELEMENT_NODE) cond.add(parseCondition(n, template));
  386. }
  387. if (cond.conditions == null || cond.conditions.length == 0)
  388. _log.severe("Empty <or> condition in " + _file);
  389. return cond;
  390. }
  391. protected Condition parseLogicNot(Node n, Object template)
  392. {
  393. for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
  394. {
  395. if (n.getNodeType() == Node.ELEMENT_NODE)
  396. {
  397. return new ConditionLogicNot(parseCondition(n, template));
  398. }
  399. }
  400. _log.severe("Empty <not> condition in " + _file);
  401. return null;
  402. }
  403. protected Condition parsePlayerCondition(Node n, Object template)
  404. {
  405. Condition cond = null;
  406. byte[] forces = new byte[2];
  407. NamedNodeMap attrs = n.getAttributes();
  408. for (int i = 0; i < attrs.getLength(); i++)
  409. {
  410. Node a = attrs.item(i);
  411. if ("race".equalsIgnoreCase(a.getNodeName()))
  412. {
  413. Race race = Race.valueOf(a.getNodeValue());
  414. cond = joinAnd(cond, new ConditionPlayerRace(race));
  415. }
  416. else if ("level".equalsIgnoreCase(a.getNodeName()))
  417. {
  418. int lvl = Integer.decode(getValue(a.getNodeValue(), template));
  419. cond = joinAnd(cond, new ConditionPlayerLevel(lvl));
  420. }
  421. else if ("resting".equalsIgnoreCase(a.getNodeName()))
  422. {
  423. boolean val = Boolean.valueOf(a.getNodeValue());
  424. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.RESTING, val));
  425. }
  426. else if ("flying".equalsIgnoreCase(a.getNodeName()))
  427. {
  428. boolean val = Boolean.valueOf(a.getNodeValue());
  429. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.FLYING, val));
  430. }
  431. else if ("moving".equalsIgnoreCase(a.getNodeName()))
  432. {
  433. boolean val = Boolean.valueOf(a.getNodeValue());
  434. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.MOVING, val));
  435. }
  436. else if ("running".equalsIgnoreCase(a.getNodeName()))
  437. {
  438. boolean val = Boolean.valueOf(a.getNodeValue());
  439. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.RUNNING, val));
  440. }
  441. else if ("behind".equalsIgnoreCase(a.getNodeName()))
  442. {
  443. boolean val = Boolean.valueOf(a.getNodeValue());
  444. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.BEHIND, val));
  445. }
  446. else if ("front".equalsIgnoreCase(a.getNodeName()))
  447. {
  448. boolean val = Boolean.valueOf(a.getNodeValue());
  449. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.FRONT, val));
  450. }
  451. else if ("chaotic".equalsIgnoreCase(a.getNodeName()))
  452. {
  453. boolean val = Boolean.valueOf(a.getNodeValue());
  454. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.CHAOTIC, val));
  455. }
  456. else if ("olympiad".equalsIgnoreCase(a.getNodeName()))
  457. {
  458. boolean val = Boolean.valueOf(a.getNodeValue());
  459. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.OLYMPIAD, val));
  460. }
  461. else if ("ishero".equalsIgnoreCase(a.getNodeName()))
  462. {
  463. boolean val = Boolean.valueOf(a.getNodeValue());
  464. cond = joinAnd(cond, new ConditionPlayerIsHero(val));
  465. }
  466. else if ("hp".equalsIgnoreCase(a.getNodeName()))
  467. {
  468. int hp = Integer.decode(getValue(a.getNodeValue(), null));
  469. cond = joinAnd(cond, new ConditionPlayerHp(hp));
  470. }
  471. else if ("mp".equalsIgnoreCase(a.getNodeName()))
  472. {
  473. int hp = Integer.decode(getValue(a.getNodeValue(), null));
  474. cond = joinAnd(cond, new ConditionPlayerMp(hp));
  475. }
  476. else if ("cp".equalsIgnoreCase(a.getNodeName()))
  477. {
  478. int cp = Integer.decode(getValue(a.getNodeValue(), null));
  479. cond = joinAnd(cond, new ConditionPlayerCp(cp));
  480. }
  481. else if ("grade".equalsIgnoreCase(a.getNodeName()))
  482. {
  483. int expIndex = Integer.decode(getValue(a.getNodeValue(), template));
  484. cond = joinAnd(cond, new ConditionPlayerGrade(expIndex));
  485. }
  486. else if ("pkCount".equalsIgnoreCase(a.getNodeName()))
  487. {
  488. int expIndex = Integer.decode(getValue(a.getNodeValue(), template));
  489. cond = joinAnd(cond, new ConditionPlayerPkCount(expIndex));
  490. }
  491. else if ("siegezone".equalsIgnoreCase(a.getNodeName()))
  492. {
  493. int value = Integer.decode(getValue(a.getNodeValue(), null));
  494. cond = joinAnd(cond, new ConditionSiegeZone(value, true));
  495. }
  496. else if ("siegeside".equalsIgnoreCase(a.getNodeName()))
  497. {
  498. int value = Integer.decode(getValue(a.getNodeValue(), null));
  499. cond = joinAnd(cond, new ConditionPlayerSiegeSide(value));
  500. }
  501. else if ("battle_force".equalsIgnoreCase(a.getNodeName()))
  502. {
  503. forces[0] = Byte.decode(getValue(a.getNodeValue(), null));
  504. }
  505. else if ("spell_force".equalsIgnoreCase(a.getNodeName()))
  506. {
  507. forces[1] = Byte.decode(getValue(a.getNodeValue(), null));
  508. }
  509. else if ("charges".equalsIgnoreCase(a.getNodeName()))
  510. {
  511. int value = Integer.decode(getValue(a.getNodeValue(), template));
  512. cond = joinAnd(cond, new ConditionPlayerCharges(value));
  513. }
  514. else if ("souls".equalsIgnoreCase(a.getNodeName()))
  515. {
  516. int value = Integer.decode(getValue(a.getNodeValue(), template));
  517. cond = joinAnd(cond, new ConditionPlayerSouls(value));
  518. }
  519. else if ("weight".equalsIgnoreCase(a.getNodeName()))
  520. {
  521. int weight = Integer.decode(getValue(a.getNodeValue(), null));
  522. cond = joinAnd(cond, new ConditionPlayerWeight(weight));
  523. }
  524. else if ("invSize".equalsIgnoreCase(a.getNodeName()))
  525. {
  526. int size = Integer.decode(getValue(a.getNodeValue(), null));
  527. cond = joinAnd(cond, new ConditionPlayerInvSize(size));
  528. }
  529. else if ("isClanLeader".equalsIgnoreCase(a.getNodeName()))
  530. {
  531. boolean val = Boolean.valueOf(a.getNodeValue());
  532. cond = joinAnd(cond, new ConditionPlayerIsClanLeader(val));
  533. }
  534. else if ("onTvTEvent".equalsIgnoreCase(a.getNodeName()))
  535. {
  536. boolean val = Boolean.valueOf(a.getNodeValue());
  537. cond = joinAnd(cond, new ConditionPlayerTvTEvent(val));
  538. }
  539. else if ("pledgeClass".equalsIgnoreCase(a.getNodeName()))
  540. {
  541. int pledgeClass = Integer.decode(getValue(a.getNodeValue(), null));
  542. cond = joinAnd(cond, new ConditionPlayerPledgeClass(pledgeClass));
  543. }
  544. else if ("clanHall".equalsIgnoreCase(a.getNodeName()))
  545. {
  546. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  547. ArrayList<Integer> array = new ArrayList<Integer>(st.countTokens());
  548. while (st.hasMoreTokens())
  549. {
  550. String item = st.nextToken().trim();
  551. array.add(Integer.decode(getValue(item, null)));
  552. }
  553. cond = joinAnd(cond, new ConditionPlayerHasClanHall(array));
  554. }
  555. else if ("fort".equalsIgnoreCase(a.getNodeName()))
  556. {
  557. int fort = Integer.decode(getValue(a.getNodeValue(), null));
  558. cond = joinAnd(cond, new ConditionPlayerHasFort(fort));
  559. }
  560. else if ("castle".equalsIgnoreCase(a.getNodeName()))
  561. {
  562. int castle = Integer.decode(getValue(a.getNodeValue(), null));
  563. cond = joinAnd(cond, new ConditionPlayerHasCastle(castle));
  564. }
  565. else if ("sex".equalsIgnoreCase(a.getNodeName()))
  566. {
  567. int sex = Integer.decode(getValue(a.getNodeValue(), null));
  568. cond = joinAnd(cond, new ConditionPlayerSex(sex));
  569. }
  570. else if ("flyMounted".equalsIgnoreCase(a.getNodeName()))
  571. {
  572. boolean val = Boolean.valueOf(a.getNodeValue());
  573. cond = joinAnd(cond, new ConditionPlayerFlyMounted(val));
  574. }
  575. else if ("landingZone".equalsIgnoreCase(a.getNodeName()))
  576. {
  577. boolean val = Boolean.valueOf(a.getNodeValue());
  578. cond = joinAnd(cond, new ConditionPlayerLandingZone(val));
  579. }
  580. else if ("active_effect_id".equalsIgnoreCase(a.getNodeName()))
  581. {
  582. int effect_id = Integer.decode(getValue(a.getNodeValue(), template));
  583. cond = joinAnd(cond, new ConditionPlayerActiveEffectId(effect_id));
  584. }
  585. else if ("active_effect_id_lvl".equalsIgnoreCase(a.getNodeName()))
  586. {
  587. String val = getValue(a.getNodeValue(), template);
  588. int effect_id = Integer.decode(getValue(val.split(",")[0], template));
  589. int effect_lvl = Integer.decode(getValue(val.split(",")[1], template));
  590. cond = joinAnd(cond, new ConditionPlayerActiveEffectId(effect_id, effect_lvl));
  591. }
  592. else if ("active_skill_id".equalsIgnoreCase(a.getNodeName()))
  593. {
  594. int skill_id = Integer.decode(getValue(a.getNodeValue(), template));
  595. cond = joinAnd(cond, new ConditionPlayerActiveSkillId(skill_id));
  596. }
  597. else if ("active_skill_id_lvl".equalsIgnoreCase(a.getNodeName()))
  598. {
  599. String val = getValue(a.getNodeValue(), template);
  600. int skill_id = Integer.decode(getValue(val.split(",")[0], template));
  601. int skill_lvl = Integer.decode(getValue(val.split(",")[1], template));
  602. cond = joinAnd(cond, new ConditionPlayerActiveSkillId(skill_id, skill_lvl));
  603. }
  604. else if ("class_id_restriction".equalsIgnoreCase(a.getNodeName()))
  605. {
  606. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  607. ArrayList<Integer> array = new ArrayList<Integer>(st.countTokens());
  608. while (st.hasMoreTokens())
  609. {
  610. String item = st.nextToken().trim();
  611. array.add(Integer.decode(getValue(item, null)));
  612. }
  613. cond = joinAnd(cond, new ConditionPlayerClassIdRestriction(array));
  614. }
  615. else if ("subclass".equalsIgnoreCase(a.getNodeName()))
  616. {
  617. boolean val = Boolean.valueOf(a.getNodeValue());
  618. cond = joinAnd(cond, new ConditionPlayerSubclass(val));
  619. }
  620. else if ("instanceId".equalsIgnoreCase(a.getNodeName()))
  621. {
  622. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  623. ArrayList<Integer> array = new ArrayList<Integer>(st.countTokens());
  624. while (st.hasMoreTokens())
  625. {
  626. String item = st.nextToken().trim();
  627. array.add(Integer.decode(getValue(item, null)));
  628. }
  629. cond = joinAnd(cond, new ConditionPlayerInstanceId(array));
  630. }
  631. else if ("agathionId".equalsIgnoreCase(a.getNodeName()))
  632. {
  633. int agathionId = Integer.decode(a.getNodeValue());
  634. cond = joinAnd(cond, new ConditionPlayerAgathionId(agathionId));
  635. }
  636. else if ("cloakStatus".equalsIgnoreCase(a.getNodeName()))
  637. {
  638. int val = Integer.valueOf(a.getNodeValue());
  639. cond = joinAnd(cond, new ConditionPlayerCloakStatus(val));
  640. }
  641. else if ("hasPet".equalsIgnoreCase(a.getNodeName()))
  642. {
  643. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  644. ArrayList<Integer> array = new ArrayList<Integer>(st.countTokens());
  645. while (st.hasMoreTokens())
  646. {
  647. String item = st.nextToken().trim();
  648. array.add(Integer.decode(getValue(item, null)));
  649. }
  650. cond = joinAnd(cond, new ConditionPlayerHasPet(array));
  651. }
  652. else if ("servitorNpcId".equalsIgnoreCase(a.getNodeName()))
  653. {
  654. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  655. ArrayList<Integer> array = new ArrayList<Integer>(st.countTokens());
  656. while (st.hasMoreTokens())
  657. {
  658. String item = st.nextToken().trim();
  659. array.add(Integer.decode(getValue(item, null)));
  660. }
  661. cond = joinAnd(cond, new ConditionPlayerServitorNpcId(array));
  662. }
  663. }
  664. if (forces[0] + forces[1] > 0)
  665. cond = joinAnd(cond, new ConditionForceBuff(forces));
  666. if (cond == null) _log.severe("Unrecognized <player> condition in " + _file);
  667. return cond;
  668. }
  669. protected Condition parseTargetCondition(Node n, Object template)
  670. {
  671. Condition cond = null;
  672. NamedNodeMap attrs = n.getAttributes();
  673. for (int i = 0; i < attrs.getLength(); i++)
  674. {
  675. Node a = attrs.item(i);
  676. if ("aggro".equalsIgnoreCase(a.getNodeName()))
  677. {
  678. boolean val = Boolean.valueOf(a.getNodeValue());
  679. cond = joinAnd(cond, new ConditionTargetAggro(val));
  680. }
  681. else if ("siegezone".equalsIgnoreCase(a.getNodeName()))
  682. {
  683. int value = Integer.decode(getValue(a.getNodeValue(), null));
  684. cond = joinAnd(cond, new ConditionSiegeZone(value, false));
  685. }
  686. else if ("level".equalsIgnoreCase(a.getNodeName()))
  687. {
  688. int lvl = Integer.decode(getValue(a.getNodeValue(), template));
  689. cond = joinAnd(cond, new ConditionTargetLevel(lvl));
  690. }
  691. else if ("playable".equalsIgnoreCase(a.getNodeName()))
  692. {
  693. cond = joinAnd(cond, new ConditionTargetPlayable());
  694. }
  695. else if ("class_id_restriction".equalsIgnoreCase(a.getNodeName()))
  696. {
  697. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  698. ArrayList<Integer> array = new ArrayList<Integer>(st.countTokens());
  699. while (st.hasMoreTokens())
  700. {
  701. String item = st.nextToken().trim();
  702. array.add(Integer.decode(getValue(item, null)));
  703. }
  704. cond = joinAnd(cond, new ConditionTargetClassIdRestriction(array));
  705. }
  706. else if ("active_effect_id".equalsIgnoreCase(a.getNodeName()))
  707. {
  708. int effect_id = Integer.decode(getValue(a.getNodeValue(), template));
  709. cond = joinAnd(cond, new ConditionTargetActiveEffectId(effect_id));
  710. }
  711. else if ("active_effect_id_lvl".equalsIgnoreCase(a.getNodeName()))
  712. {
  713. String val = getValue(a.getNodeValue(), template);
  714. int effect_id = Integer.decode(getValue(val.split(",")[0], template));
  715. int effect_lvl = Integer.decode(getValue(val.split(",")[1], template));
  716. cond = joinAnd(cond, new ConditionTargetActiveEffectId(effect_id, effect_lvl));
  717. }
  718. else if ("active_skill_id".equalsIgnoreCase(a.getNodeName()))
  719. {
  720. int skill_id = Integer.decode(getValue(a.getNodeValue(), template));
  721. cond = joinAnd(cond, new ConditionTargetActiveSkillId(skill_id));
  722. }
  723. else if ("active_skill_id_lvl".equalsIgnoreCase(a.getNodeName()))
  724. {
  725. String val = getValue(a.getNodeValue(), template);
  726. int skill_id = Integer.decode(getValue(val.split(",")[0], template));
  727. int skill_lvl = Integer.decode(getValue(val.split(",")[1], template));
  728. cond = joinAnd(cond, new ConditionTargetActiveSkillId(skill_id, skill_lvl));
  729. }
  730. else if ("abnormal".equalsIgnoreCase(a.getNodeName()))
  731. {
  732. int abnormalId = Integer.decode(getValue(a.getNodeValue(), template));
  733. cond = joinAnd(cond, new ConditionTargetAbnormal(abnormalId));
  734. }
  735. else if("mindistance".equalsIgnoreCase(a.getNodeName()))
  736. {
  737. int distance = Integer.decode(getValue(a.getNodeValue(),null));
  738. cond = joinAnd(cond, new ConditionMinDistance(distance*distance));
  739. }
  740. // used for npc race
  741. else if ("race_id".equalsIgnoreCase(a.getNodeName()))
  742. {
  743. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  744. ArrayList<Integer> array = new ArrayList<Integer>(st.countTokens());
  745. while (st.hasMoreTokens())
  746. {
  747. String item = st.nextToken().trim();
  748. array.add(Integer.decode(getValue(item, null)));
  749. }
  750. cond = joinAnd(cond, new ConditionTargetRaceId(array));
  751. }
  752. // used for pc race
  753. else if ("race".equalsIgnoreCase(a.getNodeName()))
  754. {
  755. Race race = Race.valueOf(a.getNodeValue());
  756. cond = joinAnd(cond, new ConditionTargetRace(race));
  757. }
  758. else if ("using".equalsIgnoreCase(a.getNodeName()))
  759. {
  760. int mask = 0;
  761. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  762. while (st.hasMoreTokens())
  763. {
  764. String item = st.nextToken().trim();
  765. for (L2WeaponType wt : L2WeaponType.values())
  766. {
  767. if (wt.toString().equals(item))
  768. {
  769. mask |= wt.mask();
  770. break;
  771. }
  772. }
  773. for (L2ArmorType at : L2ArmorType.values())
  774. {
  775. if (at.toString().equals(item))
  776. {
  777. mask |= at.mask();
  778. break;
  779. }
  780. }
  781. }
  782. cond = joinAnd(cond, new ConditionTargetUsesWeaponKind(mask));
  783. }
  784. else if ("npcId".equalsIgnoreCase(a.getNodeName()))
  785. {
  786. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  787. ArrayList<Integer> array = new ArrayList<Integer>(st.countTokens());
  788. while (st.hasMoreTokens())
  789. {
  790. String item = st.nextToken().trim();
  791. array.add(Integer.decode(getValue(item, null)));
  792. }
  793. cond = joinAnd(cond, new ConditionTargetNpcId(array));
  794. }
  795. else if ("npcType".equalsIgnoreCase(a.getNodeName()))
  796. {
  797. String values = getValue(a.getNodeValue(), template).trim();
  798. String[] valuesSplit = values.split(",");
  799. InstanceType[] types = new InstanceType[valuesSplit.length];
  800. InstanceType type;
  801. for (int j = 0; j < valuesSplit.length; j++)
  802. {
  803. type = Enum.valueOf(InstanceType.class, valuesSplit[j]);
  804. if (type == null)
  805. throw new IllegalArgumentException("Instance type not recognized: "+valuesSplit[j]);
  806. types[j] = type;
  807. }
  808. cond = joinAnd(cond, new ConditionTargetNpcType(types));
  809. }
  810. }
  811. if (cond == null) _log.severe("Unrecognized <target> condition in " + _file);
  812. return cond;
  813. }
  814. protected Condition parseSkillCondition(Node n)
  815. {
  816. NamedNodeMap attrs = n.getAttributes();
  817. Stats stat = Stats.valueOfXml(attrs.getNamedItem("stat").getNodeValue());
  818. return new ConditionSkillStats(stat);
  819. }
  820. protected Condition parseUsingCondition(Node n)
  821. {
  822. Condition cond = null;
  823. NamedNodeMap attrs = n.getAttributes();
  824. for (int i = 0; i < attrs.getLength(); i++)
  825. {
  826. Node a = attrs.item(i);
  827. if ("kind".equalsIgnoreCase(a.getNodeName()))
  828. {
  829. int mask = 0;
  830. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  831. while (st.hasMoreTokens())
  832. {
  833. int old = mask;
  834. String item = st.nextToken().trim();
  835. if (ItemTable._weaponTypes.containsKey(item))
  836. mask |= ItemTable._weaponTypes.get(item).mask();
  837. if (ItemTable._armorTypes.containsKey(item))
  838. mask |= ItemTable._armorTypes.get(item).mask();
  839. if (old == mask)
  840. _log.info("[parseUsingCondition=\"kind\"] Unknown item type name: "+item);
  841. }
  842. cond = joinAnd(cond, new ConditionUsingItemType(mask));
  843. }
  844. else if ("skill".equalsIgnoreCase(a.getNodeName()))
  845. {
  846. int id = Integer.parseInt(a.getNodeValue());
  847. cond = joinAnd(cond, new ConditionUsingSkill(id));
  848. }
  849. else if ("slotitem".equalsIgnoreCase(a.getNodeName()))
  850. {
  851. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ";");
  852. int id = Integer.parseInt(st.nextToken().trim());
  853. int slot = Integer.parseInt(st.nextToken().trim());
  854. int enchant = 0;
  855. if (st.hasMoreTokens()) enchant = Integer.parseInt(st.nextToken().trim());
  856. cond = joinAnd(cond, new ConditionSlotItemId(slot, id, enchant));
  857. }
  858. else if ("weaponChange".equalsIgnoreCase(a.getNodeName()))
  859. {
  860. boolean val = Boolean.valueOf(a.getNodeValue());
  861. cond = joinAnd(cond, new ConditionChangeWeapon(val));
  862. }
  863. }
  864. if (cond == null) _log.severe("Unrecognized <using> condition in " + _file);
  865. return cond;
  866. }
  867. protected Condition parseGameCondition(Node n)
  868. {
  869. Condition cond = null;
  870. NamedNodeMap attrs = n.getAttributes();
  871. for (int i = 0; i < attrs.getLength(); i++)
  872. {
  873. Node a = attrs.item(i);
  874. if ("skill".equalsIgnoreCase(a.getNodeName()))
  875. {
  876. boolean val = Boolean.valueOf(a.getNodeValue());
  877. cond = joinAnd(cond, new ConditionWithSkill(val));
  878. }
  879. if ("night".equalsIgnoreCase(a.getNodeName()))
  880. {
  881. boolean val = Boolean.valueOf(a.getNodeValue());
  882. cond = joinAnd(cond, new ConditionGameTime(CheckGameTime.NIGHT, val));
  883. }
  884. if ("chance".equalsIgnoreCase(a.getNodeName()))
  885. {
  886. int val = Integer.decode(getValue(a.getNodeValue(), null));
  887. cond = joinAnd(cond, new ConditionGameChance(val));
  888. }
  889. }
  890. if (cond == null) _log.severe("Unrecognized <game> condition in " + _file);
  891. return cond;
  892. }
  893. protected void parseTable(Node n)
  894. {
  895. NamedNodeMap attrs = n.getAttributes();
  896. String name = attrs.getNamedItem("name").getNodeValue();
  897. if (name.charAt(0) != '#') throw new IllegalArgumentException("Table name must start with #");
  898. StringTokenizer data = new StringTokenizer(n.getFirstChild().getNodeValue());
  899. List<String> array = new ArrayList<String>(data.countTokens());
  900. while (data.hasMoreTokens())
  901. array.add(data.nextToken());
  902. setTable(name, array.toArray(new String[array.size()]));
  903. }
  904. protected void parseBeanSet(Node n, StatsSet set, Integer level)
  905. {
  906. String name = n.getAttributes().getNamedItem("name").getNodeValue().trim();
  907. String value = n.getAttributes().getNamedItem("val").getNodeValue().trim();
  908. char ch = value.length() == 0 ? ' ' : value.charAt(0);
  909. if (ch == '#' || ch == '-' || Character.isDigit(ch))
  910. set.set(name, String.valueOf(getValue(value, level)));
  911. else
  912. set.set(name, value);
  913. }
  914. protected void setExtractableSkillData(StatsSet set, String value)
  915. {
  916. set.set("capsuled_items_skill", value);
  917. }
  918. protected Lambda getLambda(Node n, Object template)
  919. {
  920. Node nval = n.getAttributes().getNamedItem("val");
  921. if (nval != null)
  922. {
  923. String val = nval.getNodeValue();
  924. if (val.charAt(0) == '#')
  925. { // table by level
  926. return new LambdaConst(Double.parseDouble(getTableValue(val)));
  927. }
  928. else if (val.charAt(0) == '$')
  929. {
  930. if (val.equalsIgnoreCase("$player_level"))
  931. return new LambdaStats(LambdaStats.StatsType.PLAYER_LEVEL);
  932. if (val.equalsIgnoreCase("$target_level"))
  933. return new LambdaStats(LambdaStats.StatsType.TARGET_LEVEL);
  934. if (val.equalsIgnoreCase("$player_max_hp"))
  935. return new LambdaStats(LambdaStats.StatsType.PLAYER_MAX_HP);
  936. if (val.equalsIgnoreCase("$player_max_mp"))
  937. return new LambdaStats(LambdaStats.StatsType.PLAYER_MAX_MP);
  938. // try to find value out of item fields
  939. StatsSet set = getStatsSet();
  940. String field = set.getString(val.substring(1));
  941. if (field != null)
  942. {
  943. return new LambdaConst(Double.parseDouble(getValue(field, template)));
  944. }
  945. // failed
  946. throw new IllegalArgumentException("Unknown value " + val);
  947. }
  948. else
  949. {
  950. return new LambdaConst(Double.parseDouble(val));
  951. }
  952. }
  953. LambdaCalc calc = new LambdaCalc();
  954. n = n.getFirstChild();
  955. while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
  956. n = n.getNextSibling();
  957. if (n == null || !"val".equals(n.getNodeName()))
  958. throw new IllegalArgumentException("Value not specified");
  959. for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
  960. {
  961. if (n.getNodeType() != Node.ELEMENT_NODE) continue;
  962. attachLambdaFunc(n, template, calc);
  963. }
  964. return calc;
  965. }
  966. protected String getValue(String value, Object template)
  967. {
  968. // is it a table?
  969. if (value.charAt(0) == '#')
  970. {
  971. if (template instanceof L2Skill) return getTableValue(value);
  972. else if (template instanceof Integer) return getTableValue(value, ((Integer) template).intValue());
  973. else throw new IllegalStateException();
  974. }
  975. return value;
  976. }
  977. protected Condition joinAnd(Condition cond, Condition c)
  978. {
  979. if (cond == null) return c;
  980. if (cond instanceof ConditionLogicAnd)
  981. {
  982. ((ConditionLogicAnd) cond).add(c);
  983. return cond;
  984. }
  985. ConditionLogicAnd and = new ConditionLogicAnd();
  986. and.add(cond);
  987. and.add(c);
  988. return and;
  989. }
  990. }