DocumentBase.java 41 KB

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