DocumentBase.java 40 KB

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