DocumentBase.java 41 KB

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