DocumentBase.java 43 KB

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