DocumentBase.java 42 KB

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