DocumentBase.java 40 KB

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