DocumentBase.java 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  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.ConditionForceBuff;
  40. import com.l2jserver.gameserver.model.conditions.ConditionGameChance;
  41. import com.l2jserver.gameserver.model.conditions.ConditionGameTime;
  42. import com.l2jserver.gameserver.model.conditions.ConditionGameTime.CheckGameTime;
  43. import com.l2jserver.gameserver.model.conditions.ConditionLogicAnd;
  44. import com.l2jserver.gameserver.model.conditions.ConditionLogicNot;
  45. import com.l2jserver.gameserver.model.conditions.ConditionLogicOr;
  46. import com.l2jserver.gameserver.model.conditions.ConditionMinDistance;
  47. import com.l2jserver.gameserver.model.conditions.ConditionPlayerActiveEffectId;
  48. import com.l2jserver.gameserver.model.conditions.ConditionPlayerActiveSkillId;
  49. import com.l2jserver.gameserver.model.conditions.ConditionPlayerAgathionId;
  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. byte[] forces = new byte[2];
  428. NamedNodeMap attrs = n.getAttributes();
  429. for (int i = 0; i < attrs.getLength(); i++)
  430. {
  431. Node a = attrs.item(i);
  432. if ("races".equalsIgnoreCase(a.getNodeName()))
  433. {
  434. final String[] racesVal = a.getNodeValue().split(",");
  435. final Race[] races = new Race[racesVal.length];
  436. for (int r = 0; r < racesVal.length; r++)
  437. {
  438. if (racesVal[r] != null)
  439. {
  440. races[r] = Race.valueOf(racesVal[r]);
  441. }
  442. }
  443. cond = joinAnd(cond, new ConditionPlayerRace(races));
  444. }
  445. else if ("level".equalsIgnoreCase(a.getNodeName()))
  446. {
  447. int lvl = Integer.decode(getValue(a.getNodeValue(), template));
  448. cond = joinAnd(cond, new ConditionPlayerLevel(lvl));
  449. }
  450. else if ("levelRange".equalsIgnoreCase(a.getNodeName()))
  451. {
  452. String[] range = getValue(a.getNodeValue(), template).split(";");
  453. if (range.length == 2)
  454. {
  455. int[] lvlRange = new int[2];
  456. lvlRange[0] = Integer.decode(getValue(a.getNodeValue(), template).split(";")[0]);
  457. lvlRange[1] = Integer.decode(getValue(a.getNodeValue(), template).split(";")[1]);
  458. cond = joinAnd(cond, new ConditionPlayerLevelRange(lvlRange));
  459. }
  460. }
  461. else if ("resting".equalsIgnoreCase(a.getNodeName()))
  462. {
  463. boolean val = Boolean.parseBoolean(a.getNodeValue());
  464. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.RESTING, val));
  465. }
  466. else if ("flying".equalsIgnoreCase(a.getNodeName()))
  467. {
  468. boolean val = Boolean.parseBoolean(a.getNodeValue());
  469. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.FLYING, val));
  470. }
  471. else if ("moving".equalsIgnoreCase(a.getNodeName()))
  472. {
  473. boolean val = Boolean.parseBoolean(a.getNodeValue());
  474. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.MOVING, val));
  475. }
  476. else if ("running".equalsIgnoreCase(a.getNodeName()))
  477. {
  478. boolean val = Boolean.parseBoolean(a.getNodeValue());
  479. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.RUNNING, val));
  480. }
  481. else if ("standing".equalsIgnoreCase(a.getNodeName()))
  482. {
  483. boolean val = Boolean.parseBoolean(a.getNodeValue());
  484. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.STANDING, val));
  485. }
  486. else if ("behind".equalsIgnoreCase(a.getNodeName()))
  487. {
  488. boolean val = Boolean.parseBoolean(a.getNodeValue());
  489. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.BEHIND, val));
  490. }
  491. else if ("front".equalsIgnoreCase(a.getNodeName()))
  492. {
  493. boolean val = Boolean.parseBoolean(a.getNodeValue());
  494. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.FRONT, val));
  495. }
  496. else if ("chaotic".equalsIgnoreCase(a.getNodeName()))
  497. {
  498. boolean val = Boolean.parseBoolean(a.getNodeValue());
  499. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.CHAOTIC, val));
  500. }
  501. else if ("olympiad".equalsIgnoreCase(a.getNodeName()))
  502. {
  503. boolean val = Boolean.parseBoolean(a.getNodeValue());
  504. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.OLYMPIAD, val));
  505. }
  506. else if ("ishero".equalsIgnoreCase(a.getNodeName()))
  507. {
  508. boolean val = Boolean.parseBoolean(a.getNodeValue());
  509. cond = joinAnd(cond, new ConditionPlayerIsHero(val));
  510. }
  511. else if ("transformationId".equalsIgnoreCase(a.getNodeName()))
  512. {
  513. int id = Integer.parseInt(a.getNodeValue());
  514. cond = joinAnd(cond, new ConditionPlayerTransformationId(id));
  515. }
  516. else if ("hp".equalsIgnoreCase(a.getNodeName()))
  517. {
  518. int hp = Integer.decode(getValue(a.getNodeValue(), null));
  519. cond = joinAnd(cond, new ConditionPlayerHp(hp));
  520. }
  521. else if ("mp".equalsIgnoreCase(a.getNodeName()))
  522. {
  523. int hp = Integer.decode(getValue(a.getNodeValue(), null));
  524. cond = joinAnd(cond, new ConditionPlayerMp(hp));
  525. }
  526. else if ("cp".equalsIgnoreCase(a.getNodeName()))
  527. {
  528. int cp = Integer.decode(getValue(a.getNodeValue(), null));
  529. cond = joinAnd(cond, new ConditionPlayerCp(cp));
  530. }
  531. else if ("grade".equalsIgnoreCase(a.getNodeName()))
  532. {
  533. int expIndex = Integer.decode(getValue(a.getNodeValue(), template));
  534. cond = joinAnd(cond, new ConditionPlayerGrade(expIndex));
  535. }
  536. else if ("pkCount".equalsIgnoreCase(a.getNodeName()))
  537. {
  538. int expIndex = Integer.decode(getValue(a.getNodeValue(), template));
  539. cond = joinAnd(cond, new ConditionPlayerPkCount(expIndex));
  540. }
  541. else if ("siegezone".equalsIgnoreCase(a.getNodeName()))
  542. {
  543. int value = Integer.decode(getValue(a.getNodeValue(), null));
  544. cond = joinAnd(cond, new ConditionSiegeZone(value, true));
  545. }
  546. else if ("siegeside".equalsIgnoreCase(a.getNodeName()))
  547. {
  548. int value = Integer.decode(getValue(a.getNodeValue(), null));
  549. cond = joinAnd(cond, new ConditionPlayerSiegeSide(value));
  550. }
  551. else if ("battle_force".equalsIgnoreCase(a.getNodeName()))
  552. {
  553. forces[0] = Byte.decode(getValue(a.getNodeValue(), null));
  554. }
  555. else if ("spell_force".equalsIgnoreCase(a.getNodeName()))
  556. {
  557. forces[1] = Byte.decode(getValue(a.getNodeValue(), null));
  558. }
  559. else if ("charges".equalsIgnoreCase(a.getNodeName()))
  560. {
  561. int value = Integer.decode(getValue(a.getNodeValue(), template));
  562. cond = joinAnd(cond, new ConditionPlayerCharges(value));
  563. }
  564. else if ("souls".equalsIgnoreCase(a.getNodeName()))
  565. {
  566. int value = Integer.decode(getValue(a.getNodeValue(), template));
  567. cond = joinAnd(cond, new ConditionPlayerSouls(value));
  568. }
  569. else if ("weight".equalsIgnoreCase(a.getNodeName()))
  570. {
  571. int weight = Integer.decode(getValue(a.getNodeValue(), null));
  572. cond = joinAnd(cond, new ConditionPlayerWeight(weight));
  573. }
  574. else if ("invSize".equalsIgnoreCase(a.getNodeName()))
  575. {
  576. int size = Integer.decode(getValue(a.getNodeValue(), null));
  577. cond = joinAnd(cond, new ConditionPlayerInvSize(size));
  578. }
  579. else if ("isClanLeader".equalsIgnoreCase(a.getNodeName()))
  580. {
  581. boolean val = Boolean.parseBoolean(a.getNodeValue());
  582. cond = joinAnd(cond, new ConditionPlayerIsClanLeader(val));
  583. }
  584. else if ("onTvTEvent".equalsIgnoreCase(a.getNodeName()))
  585. {
  586. boolean val = Boolean.parseBoolean(a.getNodeValue());
  587. cond = joinAnd(cond, new ConditionPlayerTvTEvent(val));
  588. }
  589. else if ("pledgeClass".equalsIgnoreCase(a.getNodeName()))
  590. {
  591. int pledgeClass = Integer.decode(getValue(a.getNodeValue(), null));
  592. cond = joinAnd(cond, new ConditionPlayerPledgeClass(pledgeClass));
  593. }
  594. else if ("clanHall".equalsIgnoreCase(a.getNodeName()))
  595. {
  596. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  597. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  598. while (st.hasMoreTokens())
  599. {
  600. String item = st.nextToken().trim();
  601. array.add(Integer.decode(getValue(item, null)));
  602. }
  603. cond = joinAnd(cond, new ConditionPlayerHasClanHall(array));
  604. }
  605. else if ("fort".equalsIgnoreCase(a.getNodeName()))
  606. {
  607. int fort = Integer.decode(getValue(a.getNodeValue(), null));
  608. cond = joinAnd(cond, new ConditionPlayerHasFort(fort));
  609. }
  610. else if ("castle".equalsIgnoreCase(a.getNodeName()))
  611. {
  612. int castle = Integer.decode(getValue(a.getNodeValue(), null));
  613. cond = joinAnd(cond, new ConditionPlayerHasCastle(castle));
  614. }
  615. else if ("sex".equalsIgnoreCase(a.getNodeName()))
  616. {
  617. int sex = Integer.decode(getValue(a.getNodeValue(), null));
  618. cond = joinAnd(cond, new ConditionPlayerSex(sex));
  619. }
  620. else if ("flyMounted".equalsIgnoreCase(a.getNodeName()))
  621. {
  622. boolean val = Boolean.parseBoolean(a.getNodeValue());
  623. cond = joinAnd(cond, new ConditionPlayerFlyMounted(val));
  624. }
  625. else if ("vehicleMounted".equalsIgnoreCase(a.getNodeName()))
  626. {
  627. boolean val = Boolean.parseBoolean(a.getNodeValue());
  628. cond = joinAnd(cond, new ConditionPlayerVehicleMounted(val));
  629. }
  630. else if ("landingZone".equalsIgnoreCase(a.getNodeName()))
  631. {
  632. boolean val = Boolean.parseBoolean(a.getNodeValue());
  633. cond = joinAnd(cond, new ConditionPlayerLandingZone(val));
  634. }
  635. else if ("active_effect_id".equalsIgnoreCase(a.getNodeName()))
  636. {
  637. int effect_id = Integer.decode(getValue(a.getNodeValue(), template));
  638. cond = joinAnd(cond, new ConditionPlayerActiveEffectId(effect_id));
  639. }
  640. else if ("active_effect_id_lvl".equalsIgnoreCase(a.getNodeName()))
  641. {
  642. String val = getValue(a.getNodeValue(), template);
  643. int effect_id = Integer.decode(getValue(val.split(",")[0], template));
  644. int effect_lvl = Integer.decode(getValue(val.split(",")[1], template));
  645. cond = joinAnd(cond, new ConditionPlayerActiveEffectId(effect_id, effect_lvl));
  646. }
  647. else if ("active_skill_id".equalsIgnoreCase(a.getNodeName()))
  648. {
  649. int skill_id = Integer.decode(getValue(a.getNodeValue(), template));
  650. cond = joinAnd(cond, new ConditionPlayerActiveSkillId(skill_id));
  651. }
  652. else if ("active_skill_id_lvl".equalsIgnoreCase(a.getNodeName()))
  653. {
  654. String val = getValue(a.getNodeValue(), template);
  655. int skill_id = Integer.decode(getValue(val.split(",")[0], template));
  656. int skill_lvl = Integer.decode(getValue(val.split(",")[1], template));
  657. cond = joinAnd(cond, new ConditionPlayerActiveSkillId(skill_id, skill_lvl));
  658. }
  659. else if ("class_id_restriction".equalsIgnoreCase(a.getNodeName()))
  660. {
  661. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  662. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  663. while (st.hasMoreTokens())
  664. {
  665. String item = st.nextToken().trim();
  666. array.add(Integer.decode(getValue(item, null)));
  667. }
  668. cond = joinAnd(cond, new ConditionPlayerClassIdRestriction(array));
  669. }
  670. else if ("subclass".equalsIgnoreCase(a.getNodeName()))
  671. {
  672. boolean val = Boolean.parseBoolean(a.getNodeValue());
  673. cond = joinAnd(cond, new ConditionPlayerSubclass(val));
  674. }
  675. else if ("instanceId".equalsIgnoreCase(a.getNodeName()))
  676. {
  677. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  678. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  679. while (st.hasMoreTokens())
  680. {
  681. String item = st.nextToken().trim();
  682. array.add(Integer.decode(getValue(item, null)));
  683. }
  684. cond = joinAnd(cond, new ConditionPlayerInstanceId(array));
  685. }
  686. else if ("agathionId".equalsIgnoreCase(a.getNodeName()))
  687. {
  688. int agathionId = Integer.decode(a.getNodeValue());
  689. cond = joinAnd(cond, new ConditionPlayerAgathionId(agathionId));
  690. }
  691. else if ("cloakStatus".equalsIgnoreCase(a.getNodeName()))
  692. {
  693. int val = Integer.parseInt(a.getNodeValue());
  694. cond = joinAnd(cond, new ConditionPlayerCloakStatus(val));
  695. }
  696. else if ("hasPet".equalsIgnoreCase(a.getNodeName()))
  697. {
  698. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  699. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  700. while (st.hasMoreTokens())
  701. {
  702. String item = st.nextToken().trim();
  703. array.add(Integer.decode(getValue(item, null)));
  704. }
  705. cond = joinAnd(cond, new ConditionPlayerHasPet(array));
  706. }
  707. else if ("servitorNpcId".equalsIgnoreCase(a.getNodeName()))
  708. {
  709. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  710. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  711. while (st.hasMoreTokens())
  712. {
  713. String item = st.nextToken().trim();
  714. array.add(Integer.decode(getValue(item, null)));
  715. }
  716. cond = joinAnd(cond, new ConditionPlayerServitorNpcId(array));
  717. }
  718. else if ("npcIdRadius".equalsIgnoreCase(a.getNodeName()))
  719. {
  720. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  721. int npcId = 0;
  722. int radius = 0;
  723. if (st.countTokens() > 1)
  724. {
  725. npcId = Integer.decode(getValue(st.nextToken().trim(), null));
  726. radius = Integer.decode(getValue(st.nextToken().trim(), null));
  727. }
  728. cond = joinAnd(cond, new ConditionPlayerRangeFromNpc(npcId, radius));
  729. }
  730. else if ("canSweep".equalsIgnoreCase(a.getNodeName()))
  731. {
  732. cond = joinAnd(cond, new ConditionPlayerCanSweep(Boolean.parseBoolean(a.getNodeValue())));
  733. }
  734. else if ("insideZoneId".equalsIgnoreCase(a.getNodeName()))
  735. {
  736. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  737. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  738. while (st.hasMoreTokens())
  739. {
  740. String item = st.nextToken().trim();
  741. array.add(Integer.decode(getValue(item, null)));
  742. }
  743. cond = joinAnd(cond, new ConditionPlayerInsideZoneId(array));
  744. }
  745. }
  746. if ((forces[0] + forces[1]) > 0)
  747. {
  748. cond = joinAnd(cond, new ConditionForceBuff(forces));
  749. }
  750. if (cond == null)
  751. {
  752. _log.severe("Unrecognized <player> condition in " + _file);
  753. }
  754. return cond;
  755. }
  756. protected Condition parseTargetCondition(Node n, Object template)
  757. {
  758. Condition cond = null;
  759. NamedNodeMap attrs = n.getAttributes();
  760. for (int i = 0; i < attrs.getLength(); i++)
  761. {
  762. Node a = attrs.item(i);
  763. if ("aggro".equalsIgnoreCase(a.getNodeName()))
  764. {
  765. boolean val = Boolean.parseBoolean(a.getNodeValue());
  766. cond = joinAnd(cond, new ConditionTargetAggro(val));
  767. }
  768. else if ("siegezone".equalsIgnoreCase(a.getNodeName()))
  769. {
  770. int value = Integer.decode(getValue(a.getNodeValue(), null));
  771. cond = joinAnd(cond, new ConditionSiegeZone(value, false));
  772. }
  773. else if ("level".equalsIgnoreCase(a.getNodeName()))
  774. {
  775. int lvl = Integer.decode(getValue(a.getNodeValue(), template));
  776. cond = joinAnd(cond, new ConditionTargetLevel(lvl));
  777. }
  778. else if ("levelRange".equalsIgnoreCase(a.getNodeName()))
  779. {
  780. String[] range = getValue(a.getNodeValue(), template).split(";");
  781. if (range.length == 2)
  782. {
  783. int[] lvlRange = new int[2];
  784. lvlRange[0] = Integer.decode(getValue(a.getNodeValue(), template).split(";")[0]);
  785. lvlRange[1] = Integer.decode(getValue(a.getNodeValue(), template).split(";")[1]);
  786. cond = joinAnd(cond, new ConditionTargetLevelRange(lvlRange));
  787. }
  788. }
  789. else if ("playable".equalsIgnoreCase(a.getNodeName()))
  790. {
  791. cond = joinAnd(cond, new ConditionTargetPlayable());
  792. }
  793. else if ("class_id_restriction".equalsIgnoreCase(a.getNodeName()))
  794. {
  795. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  796. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  797. while (st.hasMoreTokens())
  798. {
  799. String item = st.nextToken().trim();
  800. array.add(Integer.decode(getValue(item, null)));
  801. }
  802. cond = joinAnd(cond, new ConditionTargetClassIdRestriction(array));
  803. }
  804. else if ("active_effect_id".equalsIgnoreCase(a.getNodeName()))
  805. {
  806. int effect_id = Integer.decode(getValue(a.getNodeValue(), template));
  807. cond = joinAnd(cond, new ConditionTargetActiveEffectId(effect_id));
  808. }
  809. else if ("active_effect_id_lvl".equalsIgnoreCase(a.getNodeName()))
  810. {
  811. String val = getValue(a.getNodeValue(), template);
  812. int effect_id = Integer.decode(getValue(val.split(",")[0], template));
  813. int effect_lvl = Integer.decode(getValue(val.split(",")[1], template));
  814. cond = joinAnd(cond, new ConditionTargetActiveEffectId(effect_id, effect_lvl));
  815. }
  816. else if ("active_skill_id".equalsIgnoreCase(a.getNodeName()))
  817. {
  818. int skill_id = Integer.decode(getValue(a.getNodeValue(), template));
  819. cond = joinAnd(cond, new ConditionTargetActiveSkillId(skill_id));
  820. }
  821. else if ("active_skill_id_lvl".equalsIgnoreCase(a.getNodeName()))
  822. {
  823. String val = getValue(a.getNodeValue(), template);
  824. int skill_id = Integer.decode(getValue(val.split(",")[0], template));
  825. int skill_lvl = Integer.decode(getValue(val.split(",")[1], template));
  826. cond = joinAnd(cond, new ConditionTargetActiveSkillId(skill_id, skill_lvl));
  827. }
  828. else if ("abnormal".equalsIgnoreCase(a.getNodeName()))
  829. {
  830. int abnormalId = Integer.decode(getValue(a.getNodeValue(), template));
  831. cond = joinAnd(cond, new ConditionTargetAbnormal(abnormalId));
  832. }
  833. else if ("mindistance".equalsIgnoreCase(a.getNodeName()))
  834. {
  835. int distance = Integer.decode(getValue(a.getNodeValue(), null));
  836. cond = joinAnd(cond, new ConditionMinDistance(distance * distance));
  837. }
  838. // used for npc race
  839. else if ("race_id".equalsIgnoreCase(a.getNodeName()))
  840. {
  841. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  842. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  843. while (st.hasMoreTokens())
  844. {
  845. String item = st.nextToken().trim();
  846. array.add(Integer.decode(getValue(item, null)));
  847. }
  848. cond = joinAnd(cond, new ConditionTargetRaceId(array));
  849. }
  850. // used for pc race
  851. else if ("races".equalsIgnoreCase(a.getNodeName()))
  852. {
  853. final String[] racesVal = a.getNodeValue().split(",");
  854. final Race[] races = new Race[racesVal.length];
  855. for (int r = 0; r < racesVal.length; r++)
  856. {
  857. if (racesVal[r] != null)
  858. {
  859. races[r] = Race.valueOf(racesVal[r]);
  860. }
  861. }
  862. cond = joinAnd(cond, new ConditionTargetRace(races));
  863. }
  864. else if ("using".equalsIgnoreCase(a.getNodeName()))
  865. {
  866. int mask = 0;
  867. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  868. while (st.hasMoreTokens())
  869. {
  870. String item = st.nextToken().trim();
  871. for (L2WeaponType wt : L2WeaponType.values())
  872. {
  873. if (wt.toString().equals(item))
  874. {
  875. mask |= wt.mask();
  876. break;
  877. }
  878. }
  879. for (L2ArmorType at : L2ArmorType.values())
  880. {
  881. if (at.toString().equals(item))
  882. {
  883. mask |= at.mask();
  884. break;
  885. }
  886. }
  887. }
  888. cond = joinAnd(cond, new ConditionTargetUsesWeaponKind(mask));
  889. }
  890. else if ("npcId".equalsIgnoreCase(a.getNodeName()))
  891. {
  892. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  893. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  894. while (st.hasMoreTokens())
  895. {
  896. String item = st.nextToken().trim();
  897. array.add(Integer.decode(getValue(item, null)));
  898. }
  899. cond = joinAnd(cond, new ConditionTargetNpcId(array));
  900. }
  901. else if ("npcType".equalsIgnoreCase(a.getNodeName()))
  902. {
  903. String values = getValue(a.getNodeValue(), template).trim();
  904. String[] valuesSplit = values.split(",");
  905. InstanceType[] types = new InstanceType[valuesSplit.length];
  906. InstanceType type;
  907. for (int j = 0; j < valuesSplit.length; j++)
  908. {
  909. type = Enum.valueOf(InstanceType.class, valuesSplit[j]);
  910. if (type == null)
  911. {
  912. throw new IllegalArgumentException("Instance type not recognized: " + valuesSplit[j]);
  913. }
  914. types[j] = type;
  915. }
  916. cond = joinAnd(cond, new ConditionTargetNpcType(types));
  917. }
  918. else if ("weight".equalsIgnoreCase(a.getNodeName()))
  919. {
  920. int weight = Integer.decode(getValue(a.getNodeValue(), null));
  921. cond = joinAnd(cond, new ConditionTargetWeight(weight));
  922. }
  923. else if ("invSize".equalsIgnoreCase(a.getNodeName()))
  924. {
  925. int size = Integer.decode(getValue(a.getNodeValue(), null));
  926. cond = joinAnd(cond, new ConditionTargetInvSize(size));
  927. }
  928. }
  929. if (cond == null)
  930. {
  931. _log.severe("Unrecognized <target> condition in " + _file);
  932. }
  933. return cond;
  934. }
  935. protected Condition parseUsingCondition(Node n)
  936. {
  937. Condition cond = null;
  938. NamedNodeMap attrs = n.getAttributes();
  939. for (int i = 0; i < attrs.getLength(); i++)
  940. {
  941. Node a = attrs.item(i);
  942. if ("kind".equalsIgnoreCase(a.getNodeName()))
  943. {
  944. int mask = 0;
  945. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  946. while (st.hasMoreTokens())
  947. {
  948. int old = mask;
  949. String item = st.nextToken().trim();
  950. if (ItemTable._weaponTypes.containsKey(item))
  951. {
  952. mask |= ItemTable._weaponTypes.get(item).mask();
  953. }
  954. if (ItemTable._armorTypes.containsKey(item))
  955. {
  956. mask |= ItemTable._armorTypes.get(item).mask();
  957. }
  958. if (old == mask)
  959. {
  960. _log.info("[parseUsingCondition=\"kind\"] Unknown item type name: " + item);
  961. }
  962. }
  963. cond = joinAnd(cond, new ConditionUsingItemType(mask));
  964. }
  965. else if ("skill".equalsIgnoreCase(a.getNodeName()))
  966. {
  967. int id = Integer.parseInt(a.getNodeValue());
  968. cond = joinAnd(cond, new ConditionUsingSkill(id));
  969. }
  970. else if ("slotitem".equalsIgnoreCase(a.getNodeName()))
  971. {
  972. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ";");
  973. int id = Integer.parseInt(st.nextToken().trim());
  974. int slot = Integer.parseInt(st.nextToken().trim());
  975. int enchant = 0;
  976. if (st.hasMoreTokens())
  977. {
  978. enchant = Integer.parseInt(st.nextToken().trim());
  979. }
  980. cond = joinAnd(cond, new ConditionSlotItemId(slot, id, enchant));
  981. }
  982. else if ("weaponChange".equalsIgnoreCase(a.getNodeName()))
  983. {
  984. boolean val = Boolean.parseBoolean(a.getNodeValue());
  985. cond = joinAnd(cond, new ConditionChangeWeapon(val));
  986. }
  987. }
  988. if (cond == null)
  989. {
  990. _log.severe("Unrecognized <using> condition in " + _file);
  991. }
  992. return cond;
  993. }
  994. protected Condition parseGameCondition(Node n)
  995. {
  996. Condition cond = null;
  997. NamedNodeMap attrs = n.getAttributes();
  998. for (int i = 0; i < attrs.getLength(); i++)
  999. {
  1000. Node a = attrs.item(i);
  1001. if ("skill".equalsIgnoreCase(a.getNodeName()))
  1002. {
  1003. boolean val = Boolean.parseBoolean(a.getNodeValue());
  1004. cond = joinAnd(cond, new ConditionWithSkill(val));
  1005. }
  1006. if ("night".equalsIgnoreCase(a.getNodeName()))
  1007. {
  1008. boolean val = Boolean.parseBoolean(a.getNodeValue());
  1009. cond = joinAnd(cond, new ConditionGameTime(CheckGameTime.NIGHT, val));
  1010. }
  1011. if ("chance".equalsIgnoreCase(a.getNodeName()))
  1012. {
  1013. int val = Integer.decode(getValue(a.getNodeValue(), null));
  1014. cond = joinAnd(cond, new ConditionGameChance(val));
  1015. }
  1016. }
  1017. if (cond == null)
  1018. {
  1019. _log.severe("Unrecognized <game> condition in " + _file);
  1020. }
  1021. return cond;
  1022. }
  1023. protected void parseTable(Node n)
  1024. {
  1025. NamedNodeMap attrs = n.getAttributes();
  1026. String name = attrs.getNamedItem("name").getNodeValue();
  1027. if (name.charAt(0) != '#')
  1028. {
  1029. throw new IllegalArgumentException("Table name must start with #");
  1030. }
  1031. StringTokenizer data = new StringTokenizer(n.getFirstChild().getNodeValue());
  1032. List<String> array = new ArrayList<>(data.countTokens());
  1033. while (data.hasMoreTokens())
  1034. {
  1035. array.add(data.nextToken());
  1036. }
  1037. setTable(name, array.toArray(new String[array.size()]));
  1038. }
  1039. protected void parseBeanSet(Node n, StatsSet set, Integer level)
  1040. {
  1041. String name = n.getAttributes().getNamedItem("name").getNodeValue().trim();
  1042. String value = n.getAttributes().getNamedItem("val").getNodeValue().trim();
  1043. char ch = value.isEmpty() ? ' ' : value.charAt(0);
  1044. if ((ch == '#') || (ch == '-') || Character.isDigit(ch))
  1045. {
  1046. set.set(name, String.valueOf(getValue(value, level)));
  1047. }
  1048. else
  1049. {
  1050. set.set(name, value);
  1051. }
  1052. }
  1053. protected void setExtractableSkillData(StatsSet set, String value)
  1054. {
  1055. set.set("capsuled_items_skill", value);
  1056. }
  1057. protected Lambda getLambda(Node n, Object template)
  1058. {
  1059. Node nval = n.getAttributes().getNamedItem("val");
  1060. if (nval != null)
  1061. {
  1062. String val = nval.getNodeValue();
  1063. if (val.charAt(0) == '#')
  1064. { // table by level
  1065. return new LambdaConst(Double.parseDouble(getTableValue(val)));
  1066. }
  1067. else if (val.charAt(0) == '$')
  1068. {
  1069. if (val.equalsIgnoreCase("$player_level"))
  1070. {
  1071. return new LambdaStats(LambdaStats.StatsType.PLAYER_LEVEL);
  1072. }
  1073. if (val.equalsIgnoreCase("$target_level"))
  1074. {
  1075. return new LambdaStats(LambdaStats.StatsType.TARGET_LEVEL);
  1076. }
  1077. if (val.equalsIgnoreCase("$player_max_hp"))
  1078. {
  1079. return new LambdaStats(LambdaStats.StatsType.PLAYER_MAX_HP);
  1080. }
  1081. if (val.equalsIgnoreCase("$player_max_mp"))
  1082. {
  1083. return new LambdaStats(LambdaStats.StatsType.PLAYER_MAX_MP);
  1084. }
  1085. // try to find value out of item fields
  1086. StatsSet set = getStatsSet();
  1087. String field = set.getString(val.substring(1));
  1088. if (field != null)
  1089. {
  1090. return new LambdaConst(Double.parseDouble(getValue(field, template)));
  1091. }
  1092. // failed
  1093. throw new IllegalArgumentException("Unknown value " + val);
  1094. }
  1095. else
  1096. {
  1097. return new LambdaConst(Double.parseDouble(val));
  1098. }
  1099. }
  1100. LambdaCalc calc = new LambdaCalc();
  1101. n = n.getFirstChild();
  1102. while ((n != null) && (n.getNodeType() != Node.ELEMENT_NODE))
  1103. {
  1104. n = n.getNextSibling();
  1105. }
  1106. if ((n == null) || !"val".equals(n.getNodeName()))
  1107. {
  1108. throw new IllegalArgumentException("Value not specified");
  1109. }
  1110. for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
  1111. {
  1112. if (n.getNodeType() != Node.ELEMENT_NODE)
  1113. {
  1114. continue;
  1115. }
  1116. attachLambdaFunc(n, template, calc);
  1117. }
  1118. return calc;
  1119. }
  1120. protected String getValue(String value, Object template)
  1121. {
  1122. // is it a table?
  1123. if (value.charAt(0) == '#')
  1124. {
  1125. if (template instanceof L2Skill)
  1126. {
  1127. return getTableValue(value);
  1128. }
  1129. else if (template instanceof Integer)
  1130. {
  1131. return getTableValue(value, ((Integer) template).intValue());
  1132. }
  1133. else
  1134. {
  1135. throw new IllegalStateException();
  1136. }
  1137. }
  1138. return value;
  1139. }
  1140. protected Condition joinAnd(Condition cond, Condition c)
  1141. {
  1142. if (cond == null)
  1143. {
  1144. return c;
  1145. }
  1146. if (cond instanceof ConditionLogicAnd)
  1147. {
  1148. ((ConditionLogicAnd) cond).add(c);
  1149. return cond;
  1150. }
  1151. ConditionLogicAnd and = new ConditionLogicAnd();
  1152. and.add(cond);
  1153. and.add(c);
  1154. return and;
  1155. }
  1156. }