DocumentBase.java 41 KB

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