DocumentBase.java 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  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.ConditionPlayerCanSummon;
  59. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCanSummonSiegeGolem;
  60. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCanSweep;
  61. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCanTakeCastle;
  62. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCanTakeFort;
  63. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCanTransform;
  64. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCanUntransform;
  65. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCharges;
  66. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCheckAbnormal;
  67. import com.l2jserver.gameserver.model.conditions.ConditionPlayerClassIdRestriction;
  68. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCloakStatus;
  69. import com.l2jserver.gameserver.model.conditions.ConditionPlayerCp;
  70. import com.l2jserver.gameserver.model.conditions.ConditionPlayerFlyMounted;
  71. import com.l2jserver.gameserver.model.conditions.ConditionPlayerGrade;
  72. import com.l2jserver.gameserver.model.conditions.ConditionPlayerHasCastle;
  73. import com.l2jserver.gameserver.model.conditions.ConditionPlayerHasClanHall;
  74. import com.l2jserver.gameserver.model.conditions.ConditionPlayerHasFort;
  75. import com.l2jserver.gameserver.model.conditions.ConditionPlayerHasPet;
  76. import com.l2jserver.gameserver.model.conditions.ConditionPlayerHp;
  77. import com.l2jserver.gameserver.model.conditions.ConditionPlayerInsideZoneId;
  78. import com.l2jserver.gameserver.model.conditions.ConditionPlayerInstanceId;
  79. import com.l2jserver.gameserver.model.conditions.ConditionPlayerInvSize;
  80. import com.l2jserver.gameserver.model.conditions.ConditionPlayerIsClanLeader;
  81. import com.l2jserver.gameserver.model.conditions.ConditionPlayerIsHero;
  82. import com.l2jserver.gameserver.model.conditions.ConditionPlayerLandingZone;
  83. import com.l2jserver.gameserver.model.conditions.ConditionPlayerLevel;
  84. import com.l2jserver.gameserver.model.conditions.ConditionPlayerLevelRange;
  85. import com.l2jserver.gameserver.model.conditions.ConditionPlayerMp;
  86. import com.l2jserver.gameserver.model.conditions.ConditionPlayerPkCount;
  87. import com.l2jserver.gameserver.model.conditions.ConditionPlayerPledgeClass;
  88. import com.l2jserver.gameserver.model.conditions.ConditionPlayerRace;
  89. import com.l2jserver.gameserver.model.conditions.ConditionPlayerRangeFromNpc;
  90. import com.l2jserver.gameserver.model.conditions.ConditionPlayerServitorNpcId;
  91. import com.l2jserver.gameserver.model.conditions.ConditionPlayerSex;
  92. import com.l2jserver.gameserver.model.conditions.ConditionPlayerSiegeSide;
  93. import com.l2jserver.gameserver.model.conditions.ConditionPlayerSouls;
  94. import com.l2jserver.gameserver.model.conditions.ConditionPlayerState;
  95. import com.l2jserver.gameserver.model.conditions.ConditionPlayerSubclass;
  96. import com.l2jserver.gameserver.model.conditions.ConditionPlayerTransformationId;
  97. import com.l2jserver.gameserver.model.conditions.ConditionPlayerTvTEvent;
  98. import com.l2jserver.gameserver.model.conditions.ConditionPlayerVehicleMounted;
  99. import com.l2jserver.gameserver.model.conditions.ConditionPlayerWeight;
  100. import com.l2jserver.gameserver.model.conditions.ConditionSiegeZone;
  101. import com.l2jserver.gameserver.model.conditions.ConditionSlotItemId;
  102. import com.l2jserver.gameserver.model.conditions.ConditionTargetAbnormal;
  103. import com.l2jserver.gameserver.model.conditions.ConditionTargetActiveEffectId;
  104. import com.l2jserver.gameserver.model.conditions.ConditionTargetActiveSkillId;
  105. import com.l2jserver.gameserver.model.conditions.ConditionTargetAggro;
  106. import com.l2jserver.gameserver.model.conditions.ConditionTargetClassIdRestriction;
  107. import com.l2jserver.gameserver.model.conditions.ConditionTargetInvSize;
  108. import com.l2jserver.gameserver.model.conditions.ConditionTargetLevel;
  109. import com.l2jserver.gameserver.model.conditions.ConditionTargetLevelRange;
  110. import com.l2jserver.gameserver.model.conditions.ConditionTargetMyPartyExceptMe;
  111. import com.l2jserver.gameserver.model.conditions.ConditionTargetNpcId;
  112. import com.l2jserver.gameserver.model.conditions.ConditionTargetNpcType;
  113. import com.l2jserver.gameserver.model.conditions.ConditionTargetPlayable;
  114. import com.l2jserver.gameserver.model.conditions.ConditionTargetRace;
  115. import com.l2jserver.gameserver.model.conditions.ConditionTargetUsesWeaponKind;
  116. import com.l2jserver.gameserver.model.conditions.ConditionTargetWeight;
  117. import com.l2jserver.gameserver.model.conditions.ConditionUsingItemType;
  118. import com.l2jserver.gameserver.model.conditions.ConditionUsingSkill;
  119. import com.l2jserver.gameserver.model.conditions.ConditionUsingSlotType;
  120. import com.l2jserver.gameserver.model.conditions.ConditionWithSkill;
  121. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  122. import com.l2jserver.gameserver.model.interfaces.IIdentifiable;
  123. import com.l2jserver.gameserver.model.items.L2Item;
  124. import com.l2jserver.gameserver.model.items.type.ArmorType;
  125. import com.l2jserver.gameserver.model.items.type.WeaponType;
  126. import com.l2jserver.gameserver.model.skills.AbnormalType;
  127. import com.l2jserver.gameserver.model.skills.EffectScope;
  128. import com.l2jserver.gameserver.model.skills.Skill;
  129. import com.l2jserver.gameserver.model.skills.funcs.FuncTemplate;
  130. import com.l2jserver.gameserver.model.skills.funcs.Lambda;
  131. import com.l2jserver.gameserver.model.skills.funcs.LambdaCalc;
  132. import com.l2jserver.gameserver.model.skills.funcs.LambdaConst;
  133. import com.l2jserver.gameserver.model.skills.funcs.LambdaStats;
  134. import com.l2jserver.gameserver.model.stats.Env;
  135. import com.l2jserver.gameserver.model.stats.Stats;
  136. /**
  137. * @author mkizub
  138. */
  139. public abstract class DocumentBase
  140. {
  141. protected final Logger _log = Logger.getLogger(getClass().getName());
  142. private final File _file;
  143. protected Map<String, String[]> _tables;
  144. protected DocumentBase(File pFile)
  145. {
  146. _file = pFile;
  147. _tables = new FastMap<>();
  148. }
  149. public Document parse()
  150. {
  151. Document doc = null;
  152. try
  153. {
  154. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  155. factory.setValidating(false);
  156. factory.setIgnoringComments(true);
  157. doc = factory.newDocumentBuilder().parse(_file);
  158. parseDocument(doc);
  159. }
  160. catch (Exception e)
  161. {
  162. _log.log(Level.SEVERE, "Error loading file " + _file, e);
  163. }
  164. return doc;
  165. }
  166. protected abstract void parseDocument(Document doc);
  167. protected abstract StatsSet getStatsSet();
  168. protected abstract String getTableValue(String name);
  169. protected abstract String getTableValue(String name, int idx);
  170. protected void resetTable()
  171. {
  172. _tables = new FastMap<>();
  173. }
  174. protected void setTable(String name, String[] table)
  175. {
  176. _tables.put(name, table);
  177. }
  178. protected void parseTemplate(Node n, Object template)
  179. {
  180. parseTemplate(n, template, null);
  181. }
  182. protected void parseTemplate(Node n, Object template, EffectScope effectScope)
  183. {
  184. Condition condition = null;
  185. n = n.getFirstChild();
  186. if (n == null)
  187. {
  188. return;
  189. }
  190. if ("cond".equalsIgnoreCase(n.getNodeName()))
  191. {
  192. condition = parseCondition(n.getFirstChild(), template);
  193. Node msg = n.getAttributes().getNamedItem("msg");
  194. Node msgId = n.getAttributes().getNamedItem("msgId");
  195. if ((condition != null) && (msg != null))
  196. {
  197. condition.setMessage(msg.getNodeValue());
  198. }
  199. else if ((condition != null) && (msgId != null))
  200. {
  201. condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
  202. Node addName = n.getAttributes().getNamedItem("addName");
  203. if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
  204. {
  205. condition.addName();
  206. }
  207. }
  208. n = n.getNextSibling();
  209. }
  210. for (; n != null; n = n.getNextSibling())
  211. {
  212. switch (n.getNodeName().toLowerCase())
  213. {
  214. case "add":
  215. {
  216. attachFunc(n, template, "Add", condition);
  217. break;
  218. }
  219. case "sub":
  220. {
  221. attachFunc(n, template, "Sub", condition);
  222. break;
  223. }
  224. case "mul":
  225. {
  226. attachFunc(n, template, "Mul", condition);
  227. break;
  228. }
  229. case "basemul":
  230. {
  231. attachFunc(n, template, "BaseMul", condition);
  232. break;
  233. }
  234. case "div":
  235. {
  236. attachFunc(n, template, "Div", condition);
  237. break;
  238. }
  239. case "set":
  240. {
  241. attachFunc(n, template, "Set", condition);
  242. break;
  243. }
  244. case "share":
  245. {
  246. attachFunc(n, template, "Share", condition);
  247. break;
  248. }
  249. case "enchant":
  250. {
  251. attachFunc(n, template, "Enchant", condition);
  252. break;
  253. }
  254. case "enchanthp":
  255. {
  256. attachFunc(n, template, "EnchantHp", condition);
  257. break;
  258. }
  259. case "effect":
  260. {
  261. if (template instanceof AbstractEffect)
  262. {
  263. throw new RuntimeException("Nested effects");
  264. }
  265. attachEffect(n, template, condition, effectScope);
  266. break;
  267. }
  268. }
  269. }
  270. }
  271. protected void attachFunc(Node n, Object template, String name, Condition attachCond)
  272. {
  273. Stats stat = Stats.valueOfXml(n.getAttributes().getNamedItem("stat").getNodeValue());
  274. String order = n.getAttributes().getNamedItem("order").getNodeValue();
  275. Lambda lambda = getLambda(n, template);
  276. int ord = Integer.decode(getValue(order, template));
  277. Condition applayCond = parseCondition(n.getFirstChild(), template);
  278. FuncTemplate ft = new FuncTemplate(attachCond, applayCond, name, stat, ord, lambda);
  279. if (template instanceof L2Item)
  280. {
  281. ((L2Item) template).attach(ft);
  282. }
  283. else if (template instanceof Skill)
  284. {
  285. ((Skill) template).attach(ft);
  286. }
  287. else if (template instanceof AbstractEffect)
  288. {
  289. ((AbstractEffect) template).attach(ft);
  290. }
  291. }
  292. protected void attachLambdaFunc(Node n, Object template, LambdaCalc calc)
  293. {
  294. String name = n.getNodeName();
  295. final StringBuilder sb = new StringBuilder(name);
  296. sb.setCharAt(0, Character.toUpperCase(name.charAt(0)));
  297. name = sb.toString();
  298. Lambda lambda = getLambda(n, template);
  299. FuncTemplate ft = new FuncTemplate(null, null, name, null, calc.funcs.length, lambda);
  300. calc.addFunc(ft.getFunc(new Env(), calc));
  301. }
  302. protected void attachEffect(Node n, Object template, Condition attachCond)
  303. {
  304. attachEffect(n, template, attachCond, null);
  305. }
  306. protected void attachEffect(Node n, Object template, Condition attachCond, EffectScope effectScope)
  307. {
  308. final NamedNodeMap attrs = n.getAttributes();
  309. final StatsSet set = new StatsSet();
  310. for (int i = 0; i < attrs.getLength(); i++)
  311. {
  312. Node att = attrs.item(i);
  313. set.set(att.getNodeName(), getValue(att.getNodeValue(), template));
  314. }
  315. final StatsSet parameters = parseParameters(n.getFirstChild(), template);
  316. final Condition applayCond = parseCondition(n.getFirstChild(), template);
  317. if (template instanceof IIdentifiable)
  318. {
  319. set.set("id", ((IIdentifiable) template).getId());
  320. }
  321. final AbstractEffect effect = AbstractEffect.createEffect(attachCond, applayCond, set, parameters);
  322. parseTemplate(n, effect);
  323. if (template instanceof L2Item)
  324. {
  325. ((L2Item) template).attach(effect);
  326. }
  327. else if (template instanceof Skill)
  328. {
  329. final Skill skill = (Skill) template;
  330. if (effectScope != null)
  331. {
  332. skill.addEffect(effectScope, effect);
  333. }
  334. else if (skill.isPassive())
  335. {
  336. skill.addEffect(EffectScope.PASSIVE, effect);
  337. }
  338. else
  339. {
  340. skill.addEffect(EffectScope.GENERAL, effect);
  341. }
  342. }
  343. }
  344. /**
  345. * Parse effect's parameters.
  346. * @param n the node to start the parsing
  347. * @param template the effect template
  348. * @return the list of parameters if any, {@code null} otherwise
  349. */
  350. private StatsSet parseParameters(Node n, Object template)
  351. {
  352. StatsSet parameters = null;
  353. while ((n != null))
  354. {
  355. // Parse all parameters.
  356. if ((n.getNodeType() == Node.ELEMENT_NODE) && "param".equals(n.getNodeName()))
  357. {
  358. if (parameters == null)
  359. {
  360. parameters = new StatsSet();
  361. }
  362. NamedNodeMap params = n.getAttributes();
  363. for (int i = 0; i < params.getLength(); i++)
  364. {
  365. Node att = params.item(i);
  366. parameters.set(att.getNodeName(), getValue(att.getNodeValue(), template));
  367. }
  368. }
  369. n = n.getNextSibling();
  370. }
  371. return parameters == null ? StatsSet.EMPTY_STATSET : parameters;
  372. }
  373. protected Condition parseCondition(Node n, Object template)
  374. {
  375. while ((n != null) && (n.getNodeType() != Node.ELEMENT_NODE))
  376. {
  377. n = n.getNextSibling();
  378. }
  379. Condition condition = null;
  380. if (n != null)
  381. {
  382. switch (n.getNodeName().toLowerCase())
  383. {
  384. case "and":
  385. {
  386. condition = parseLogicAnd(n, template);
  387. break;
  388. }
  389. case "or":
  390. {
  391. condition = parseLogicOr(n, template);
  392. break;
  393. }
  394. case "not":
  395. {
  396. condition = parseLogicNot(n, template);
  397. break;
  398. }
  399. case "player":
  400. {
  401. condition = parsePlayerCondition(n, template);
  402. break;
  403. }
  404. case "target":
  405. {
  406. condition = parseTargetCondition(n, template);
  407. break;
  408. }
  409. case "using":
  410. {
  411. condition = parseUsingCondition(n);
  412. break;
  413. }
  414. case "game":
  415. {
  416. condition = parseGameCondition(n);
  417. break;
  418. }
  419. }
  420. }
  421. return condition;
  422. }
  423. protected Condition parseLogicAnd(Node n, Object template)
  424. {
  425. ConditionLogicAnd cond = new ConditionLogicAnd();
  426. for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
  427. {
  428. if (n.getNodeType() == Node.ELEMENT_NODE)
  429. {
  430. cond.add(parseCondition(n, template));
  431. }
  432. }
  433. if ((cond.conditions == null) || (cond.conditions.length == 0))
  434. {
  435. _log.severe("Empty <and> condition in " + _file);
  436. }
  437. return cond;
  438. }
  439. protected Condition parseLogicOr(Node n, Object template)
  440. {
  441. ConditionLogicOr cond = new ConditionLogicOr();
  442. for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
  443. {
  444. if (n.getNodeType() == Node.ELEMENT_NODE)
  445. {
  446. cond.add(parseCondition(n, template));
  447. }
  448. }
  449. if ((cond.conditions == null) || (cond.conditions.length == 0))
  450. {
  451. _log.severe("Empty <or> condition in " + _file);
  452. }
  453. return cond;
  454. }
  455. protected Condition parseLogicNot(Node n, Object template)
  456. {
  457. for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
  458. {
  459. if (n.getNodeType() == Node.ELEMENT_NODE)
  460. {
  461. return new ConditionLogicNot(parseCondition(n, template));
  462. }
  463. }
  464. _log.severe("Empty <not> condition in " + _file);
  465. return null;
  466. }
  467. protected Condition parsePlayerCondition(Node n, Object template)
  468. {
  469. Condition cond = null;
  470. NamedNodeMap attrs = n.getAttributes();
  471. for (int i = 0; i < attrs.getLength(); i++)
  472. {
  473. Node a = attrs.item(i);
  474. switch (a.getNodeName().toLowerCase())
  475. {
  476. case "races":
  477. {
  478. final String[] racesVal = a.getNodeValue().split(",");
  479. final Race[] races = new Race[racesVal.length];
  480. for (int r = 0; r < racesVal.length; r++)
  481. {
  482. if (racesVal[r] != null)
  483. {
  484. races[r] = Race.valueOf(racesVal[r]);
  485. }
  486. }
  487. cond = joinAnd(cond, new ConditionPlayerRace(races));
  488. break;
  489. }
  490. case "level":
  491. {
  492. int lvl = Integer.decode(getValue(a.getNodeValue(), template));
  493. cond = joinAnd(cond, new ConditionPlayerLevel(lvl));
  494. break;
  495. }
  496. case "levelrange":
  497. {
  498. String[] range = getValue(a.getNodeValue(), template).split(";");
  499. if (range.length == 2)
  500. {
  501. int[] lvlRange = new int[2];
  502. lvlRange[0] = Integer.decode(getValue(a.getNodeValue(), template).split(";")[0]);
  503. lvlRange[1] = Integer.decode(getValue(a.getNodeValue(), template).split(";")[1]);
  504. cond = joinAnd(cond, new ConditionPlayerLevelRange(lvlRange));
  505. }
  506. break;
  507. }
  508. case "resting":
  509. {
  510. boolean val = Boolean.parseBoolean(a.getNodeValue());
  511. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.RESTING, val));
  512. break;
  513. }
  514. case "flying":
  515. {
  516. boolean val = Boolean.parseBoolean(a.getNodeValue());
  517. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.FLYING, val));
  518. break;
  519. }
  520. case "moving":
  521. {
  522. boolean val = Boolean.parseBoolean(a.getNodeValue());
  523. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.MOVING, val));
  524. break;
  525. }
  526. case "running":
  527. {
  528. boolean val = Boolean.parseBoolean(a.getNodeValue());
  529. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.RUNNING, val));
  530. break;
  531. }
  532. case "standing":
  533. {
  534. boolean val = Boolean.parseBoolean(a.getNodeValue());
  535. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.STANDING, val));
  536. break;
  537. }
  538. case "behind":
  539. {
  540. boolean val = Boolean.parseBoolean(a.getNodeValue());
  541. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.BEHIND, val));
  542. break;
  543. }
  544. case "front":
  545. {
  546. boolean val = Boolean.parseBoolean(a.getNodeValue());
  547. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.FRONT, val));
  548. break;
  549. }
  550. case "chaotic":
  551. {
  552. boolean val = Boolean.parseBoolean(a.getNodeValue());
  553. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.CHAOTIC, val));
  554. break;
  555. }
  556. case "olympiad":
  557. {
  558. boolean val = Boolean.parseBoolean(a.getNodeValue());
  559. cond = joinAnd(cond, new ConditionPlayerState(PlayerState.OLYMPIAD, val));
  560. break;
  561. }
  562. case "ishero":
  563. {
  564. boolean val = Boolean.parseBoolean(a.getNodeValue());
  565. cond = joinAnd(cond, new ConditionPlayerIsHero(val));
  566. break;
  567. }
  568. case "transformationid":
  569. {
  570. int id = Integer.parseInt(a.getNodeValue());
  571. cond = joinAnd(cond, new ConditionPlayerTransformationId(id));
  572. break;
  573. }
  574. case "hp":
  575. {
  576. int hp = Integer.decode(getValue(a.getNodeValue(), null));
  577. cond = joinAnd(cond, new ConditionPlayerHp(hp));
  578. break;
  579. }
  580. case "mp":
  581. {
  582. int hp = Integer.decode(getValue(a.getNodeValue(), null));
  583. cond = joinAnd(cond, new ConditionPlayerMp(hp));
  584. break;
  585. }
  586. case "cp":
  587. {
  588. int cp = Integer.decode(getValue(a.getNodeValue(), null));
  589. cond = joinAnd(cond, new ConditionPlayerCp(cp));
  590. break;
  591. }
  592. case "grade":
  593. {
  594. int expIndex = Integer.decode(getValue(a.getNodeValue(), template));
  595. cond = joinAnd(cond, new ConditionPlayerGrade(expIndex));
  596. break;
  597. }
  598. case "pkcount":
  599. {
  600. int expIndex = Integer.decode(getValue(a.getNodeValue(), template));
  601. cond = joinAnd(cond, new ConditionPlayerPkCount(expIndex));
  602. break;
  603. }
  604. case "siegezone":
  605. {
  606. int value = Integer.decode(getValue(a.getNodeValue(), null));
  607. cond = joinAnd(cond, new ConditionSiegeZone(value, true));
  608. break;
  609. }
  610. case "siegeside":
  611. {
  612. int value = Integer.decode(getValue(a.getNodeValue(), null));
  613. cond = joinAnd(cond, new ConditionPlayerSiegeSide(value));
  614. break;
  615. }
  616. case "charges":
  617. {
  618. int value = Integer.decode(getValue(a.getNodeValue(), template));
  619. cond = joinAnd(cond, new ConditionPlayerCharges(value));
  620. break;
  621. }
  622. case "souls":
  623. {
  624. int value = Integer.decode(getValue(a.getNodeValue(), template));
  625. cond = joinAnd(cond, new ConditionPlayerSouls(value));
  626. break;
  627. }
  628. case "weight":
  629. {
  630. int weight = Integer.decode(getValue(a.getNodeValue(), null));
  631. cond = joinAnd(cond, new ConditionPlayerWeight(weight));
  632. break;
  633. }
  634. case "invsize":
  635. {
  636. int size = Integer.decode(getValue(a.getNodeValue(), null));
  637. cond = joinAnd(cond, new ConditionPlayerInvSize(size));
  638. break;
  639. }
  640. case "isclanleader":
  641. {
  642. boolean val = Boolean.parseBoolean(a.getNodeValue());
  643. cond = joinAnd(cond, new ConditionPlayerIsClanLeader(val));
  644. break;
  645. }
  646. case "ontvtevent":
  647. {
  648. boolean val = Boolean.parseBoolean(a.getNodeValue());
  649. cond = joinAnd(cond, new ConditionPlayerTvTEvent(val));
  650. break;
  651. }
  652. case "pledgeclass":
  653. {
  654. int pledgeClass = Integer.decode(getValue(a.getNodeValue(), null));
  655. cond = joinAnd(cond, new ConditionPlayerPledgeClass(pledgeClass));
  656. break;
  657. }
  658. case "clanhall":
  659. {
  660. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  661. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  662. while (st.hasMoreTokens())
  663. {
  664. String item = st.nextToken().trim();
  665. array.add(Integer.decode(getValue(item, null)));
  666. }
  667. cond = joinAnd(cond, new ConditionPlayerHasClanHall(array));
  668. break;
  669. }
  670. case "fort":
  671. {
  672. int fort = Integer.decode(getValue(a.getNodeValue(), null));
  673. cond = joinAnd(cond, new ConditionPlayerHasFort(fort));
  674. break;
  675. }
  676. case "castle":
  677. {
  678. int castle = Integer.decode(getValue(a.getNodeValue(), null));
  679. cond = joinAnd(cond, new ConditionPlayerHasCastle(castle));
  680. break;
  681. }
  682. case "sex":
  683. {
  684. int sex = Integer.decode(getValue(a.getNodeValue(), null));
  685. cond = joinAnd(cond, new ConditionPlayerSex(sex));
  686. break;
  687. }
  688. case "flymounted":
  689. {
  690. boolean val = Boolean.parseBoolean(a.getNodeValue());
  691. cond = joinAnd(cond, new ConditionPlayerFlyMounted(val));
  692. break;
  693. }
  694. case "vehiclemounted":
  695. {
  696. boolean val = Boolean.parseBoolean(a.getNodeValue());
  697. cond = joinAnd(cond, new ConditionPlayerVehicleMounted(val));
  698. break;
  699. }
  700. case "landingzone":
  701. {
  702. boolean val = Boolean.parseBoolean(a.getNodeValue());
  703. cond = joinAnd(cond, new ConditionPlayerLandingZone(val));
  704. break;
  705. }
  706. case "active_effect_id":
  707. {
  708. int effect_id = Integer.decode(getValue(a.getNodeValue(), template));
  709. cond = joinAnd(cond, new ConditionPlayerActiveEffectId(effect_id));
  710. break;
  711. }
  712. case "active_effect_id_lvl":
  713. {
  714. String val = getValue(a.getNodeValue(), template);
  715. int effect_id = Integer.decode(getValue(val.split(",")[0], template));
  716. int effect_lvl = Integer.decode(getValue(val.split(",")[1], template));
  717. cond = joinAnd(cond, new ConditionPlayerActiveEffectId(effect_id, effect_lvl));
  718. break;
  719. }
  720. case "active_skill_id":
  721. {
  722. int skill_id = Integer.decode(getValue(a.getNodeValue(), template));
  723. cond = joinAnd(cond, new ConditionPlayerActiveSkillId(skill_id));
  724. break;
  725. }
  726. case "active_skill_id_lvl":
  727. {
  728. String val = getValue(a.getNodeValue(), template);
  729. int skill_id = Integer.decode(getValue(val.split(",")[0], template));
  730. int skill_lvl = Integer.decode(getValue(val.split(",")[1], template));
  731. cond = joinAnd(cond, new ConditionPlayerActiveSkillId(skill_id, skill_lvl));
  732. break;
  733. }
  734. case "class_id_restriction":
  735. {
  736. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  737. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  738. while (st.hasMoreTokens())
  739. {
  740. String item = st.nextToken().trim();
  741. array.add(Integer.decode(getValue(item, null)));
  742. }
  743. cond = joinAnd(cond, new ConditionPlayerClassIdRestriction(array));
  744. break;
  745. }
  746. case "subclass":
  747. {
  748. boolean val = Boolean.parseBoolean(a.getNodeValue());
  749. cond = joinAnd(cond, new ConditionPlayerSubclass(val));
  750. break;
  751. }
  752. case "instanceid":
  753. {
  754. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  755. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  756. while (st.hasMoreTokens())
  757. {
  758. String item = st.nextToken().trim();
  759. array.add(Integer.decode(getValue(item, null)));
  760. }
  761. cond = joinAnd(cond, new ConditionPlayerInstanceId(array));
  762. break;
  763. }
  764. case "agathionid":
  765. {
  766. int agathionId = Integer.decode(a.getNodeValue());
  767. cond = joinAnd(cond, new ConditionPlayerAgathionId(agathionId));
  768. break;
  769. }
  770. case "cloakstatus":
  771. {
  772. boolean val = Boolean.parseBoolean(a.getNodeValue());
  773. cond = joinAnd(cond, new ConditionPlayerCloakStatus(val));
  774. break;
  775. }
  776. case "haspet":
  777. {
  778. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  779. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  780. while (st.hasMoreTokens())
  781. {
  782. String item = st.nextToken().trim();
  783. array.add(Integer.decode(getValue(item, null)));
  784. }
  785. cond = joinAnd(cond, new ConditionPlayerHasPet(array));
  786. break;
  787. }
  788. case "servitornpcid":
  789. {
  790. StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  791. ArrayList<Integer> array = new ArrayList<>(st.countTokens());
  792. while (st.hasMoreTokens())
  793. {
  794. String item = st.nextToken().trim();
  795. array.add(Integer.decode(getValue(item, null)));
  796. }
  797. cond = joinAnd(cond, new ConditionPlayerServitorNpcId(array));
  798. break;
  799. }
  800. case "npcidradius":
  801. {
  802. final StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
  803. if (st.countTokens() == 3)
  804. {
  805. final String[] ids = st.nextToken().split(";");
  806. final int[] npcIds = new int[ids.length];
  807. for (int index = 0; index < ids.length; index++)
  808. {
  809. npcIds[index] = Integer.parseInt(getValue(ids[index], template));
  810. }
  811. final int radius = Integer.parseInt(st.nextToken());
  812. final boolean val = Boolean.parseBoolean(st.nextToken());
  813. cond = joinAnd(cond, new ConditionPlayerRangeFromNpc(npcIds, radius, val));
  814. }
  815. break;
  816. }
  817. case "callpc":
  818. {
  819. cond = joinAnd(cond, new ConditionPlayerCallPc(Boolean.parseBoolean(a.getNodeValue())));
  820. break;
  821. }
  822. case "cancreatebase":
  823. {
  824. cond = joinAnd(cond, new ConditionPlayerCanCreateBase(Boolean.parseBoolean(a.getNodeValue())));
  825. break;
  826. }
  827. case "cancreateoutpost":
  828. {
  829. cond = joinAnd(cond, new ConditionPlayerCanCreateOutpost(Boolean.parseBoolean(a.getNodeValue())));
  830. break;
  831. }
  832. case "canescape":
  833. {
  834. cond = joinAnd(cond, new ConditionPlayerCanEscape(Boolean.parseBoolean(a.getNodeValue())));
  835. break;
  836. }
  837. case "canrefuelairship":
  838. {
  839. cond = joinAnd(cond, new ConditionPlayerCanRefuelAirship(Integer.parseInt(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 Lambda getLambda(Node n, Object template)
  1261. {
  1262. Node nval = n.getAttributes().getNamedItem("val");
  1263. if (nval != null)
  1264. {
  1265. String val = nval.getNodeValue();
  1266. if (val.charAt(0) == '#')
  1267. { // table by level
  1268. return new LambdaConst(Double.parseDouble(getTableValue(val)));
  1269. }
  1270. else if (val.charAt(0) == '$')
  1271. {
  1272. if (val.equalsIgnoreCase("$player_level"))
  1273. {
  1274. return new LambdaStats(LambdaStats.StatsType.PLAYER_LEVEL);
  1275. }
  1276. if (val.equalsIgnoreCase("$target_level"))
  1277. {
  1278. return new LambdaStats(LambdaStats.StatsType.TARGET_LEVEL);
  1279. }
  1280. if (val.equalsIgnoreCase("$player_max_hp"))
  1281. {
  1282. return new LambdaStats(LambdaStats.StatsType.PLAYER_MAX_HP);
  1283. }
  1284. if (val.equalsIgnoreCase("$player_max_mp"))
  1285. {
  1286. return new LambdaStats(LambdaStats.StatsType.PLAYER_MAX_MP);
  1287. }
  1288. // try to find value out of item fields
  1289. StatsSet set = getStatsSet();
  1290. String field = set.getString(val.substring(1));
  1291. if (field != null)
  1292. {
  1293. return new LambdaConst(Double.parseDouble(getValue(field, template)));
  1294. }
  1295. // failed
  1296. throw new IllegalArgumentException("Unknown value " + val);
  1297. }
  1298. else
  1299. {
  1300. return new LambdaConst(Double.parseDouble(val));
  1301. }
  1302. }
  1303. LambdaCalc calc = new LambdaCalc();
  1304. n = n.getFirstChild();
  1305. while ((n != null) && (n.getNodeType() != Node.ELEMENT_NODE))
  1306. {
  1307. n = n.getNextSibling();
  1308. }
  1309. if ((n == null) || !"val".equals(n.getNodeName()))
  1310. {
  1311. throw new IllegalArgumentException("Value not specified");
  1312. }
  1313. for (n = n.getFirstChild(); n != null; n = n.getNextSibling())
  1314. {
  1315. if (n.getNodeType() != Node.ELEMENT_NODE)
  1316. {
  1317. continue;
  1318. }
  1319. attachLambdaFunc(n, template, calc);
  1320. }
  1321. return calc;
  1322. }
  1323. protected String getValue(String value, Object template)
  1324. {
  1325. // is it a table?
  1326. if (value.charAt(0) == '#')
  1327. {
  1328. if (template instanceof Skill)
  1329. {
  1330. return getTableValue(value);
  1331. }
  1332. else if (template instanceof Integer)
  1333. {
  1334. return getTableValue(value, ((Integer) template).intValue());
  1335. }
  1336. else
  1337. {
  1338. throw new IllegalStateException();
  1339. }
  1340. }
  1341. return value;
  1342. }
  1343. protected Condition joinAnd(Condition cond, Condition c)
  1344. {
  1345. if (cond == null)
  1346. {
  1347. return c;
  1348. }
  1349. if (cond instanceof ConditionLogicAnd)
  1350. {
  1351. ((ConditionLogicAnd) cond).add(c);
  1352. return cond;
  1353. }
  1354. ConditionLogicAnd and = new ConditionLogicAnd();
  1355. and.add(cond);
  1356. and.add(c);
  1357. return and;
  1358. }
  1359. }