2
0

NpcData.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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.datatables;
  20. import java.sql.Connection;
  21. import java.sql.ResultSet;
  22. import java.sql.Statement;
  23. import java.util.ArrayList;
  24. import java.util.Collections;
  25. import java.util.EnumMap;
  26. import java.util.HashMap;
  27. import java.util.HashSet;
  28. import java.util.List;
  29. import java.util.Map;
  30. import java.util.Set;
  31. import java.util.concurrent.ConcurrentHashMap;
  32. import java.util.logging.Level;
  33. import java.util.stream.Collectors;
  34. import org.w3c.dom.NamedNodeMap;
  35. import org.w3c.dom.Node;
  36. import com.l2jserver.Config;
  37. import com.l2jserver.L2DatabaseFactory;
  38. import com.l2jserver.gameserver.engines.DocumentParser;
  39. import com.l2jserver.gameserver.enums.AISkillScope;
  40. import com.l2jserver.gameserver.model.L2MinionData;
  41. import com.l2jserver.gameserver.model.StatsSet;
  42. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  43. import com.l2jserver.gameserver.model.base.ClassId;
  44. import com.l2jserver.gameserver.model.drops.DropListScope;
  45. import com.l2jserver.gameserver.model.drops.GeneralDropItem;
  46. import com.l2jserver.gameserver.model.drops.GroupedGeneralDropItem;
  47. import com.l2jserver.gameserver.model.drops.IDropItem;
  48. import com.l2jserver.gameserver.model.effects.L2EffectType;
  49. import com.l2jserver.gameserver.model.holders.SkillHolder;
  50. import com.l2jserver.gameserver.model.skills.Skill;
  51. import com.l2jserver.gameserver.util.Util;
  52. /**
  53. * NPC data parser.
  54. * @author Nos
  55. */
  56. public class NpcData extends DocumentParser
  57. {
  58. private final Map<Integer, L2NpcTemplate> _npcs = new ConcurrentHashMap<>();
  59. private final Map<String, Integer> _clans = new ConcurrentHashMap<>();
  60. // SQL Queries
  61. private static final String SELECT_MINION_ALL = "SELECT * FROM minions ORDER BY boss_id";
  62. protected NpcData()
  63. {
  64. load();
  65. }
  66. @Override
  67. public synchronized void load()
  68. {
  69. parseDatapackDirectory("data/stats/npcs", false);
  70. _log.info(getClass().getSimpleName() + ": Loaded " + _npcs.size() + " NPCs.");
  71. if (Config.CUSTOM_NPC_DATA)
  72. {
  73. final int npcCount = _npcs.size();
  74. parseDatapackDirectory("data/stats/npcs/custom", true);
  75. _log.info(getClass().getSimpleName() + ": Loaded " + (_npcs.size() - npcCount) + " Custom NPCs.");
  76. }
  77. loadMinions();
  78. loadNpcsSkillLearn();
  79. }
  80. @Override
  81. protected void parseDocument()
  82. {
  83. for (Node node = getCurrentDocument().getFirstChild(); node != null; node = node.getNextSibling())
  84. {
  85. if ("list".equalsIgnoreCase(node.getNodeName()))
  86. {
  87. for (Node list_node = node.getFirstChild(); list_node != null; list_node = list_node.getNextSibling())
  88. {
  89. if ("npc".equalsIgnoreCase(list_node.getNodeName()))
  90. {
  91. NamedNodeMap attrs = list_node.getAttributes();
  92. final StatsSet set = new StatsSet();
  93. final int npcId = parseInteger(attrs, "id");
  94. Map<String, Object> parameters = null;
  95. Map<Integer, Skill> skills = null;
  96. Set<Integer> clans = null;
  97. Set<Integer> enemyClans = null;
  98. Map<DropListScope, List<IDropItem>> dropLists = null;
  99. set.set("id", npcId);
  100. set.set("displayId", parseInteger(attrs, "displayId"));
  101. set.set("level", parseByte(attrs, "level"));
  102. set.set("type", parseString(attrs, "type"));
  103. set.set("name", parseString(attrs, "name"));
  104. set.set("usingServerSideName", parseBoolean(attrs, "usingServerSideName"));
  105. set.set("title", parseString(attrs, "title"));
  106. set.set("usingServerSideTitle", parseBoolean(attrs, "usingServerSideTitle"));
  107. for (Node npc_node = list_node.getFirstChild(); npc_node != null; npc_node = npc_node.getNextSibling())
  108. {
  109. attrs = npc_node.getAttributes();
  110. switch (npc_node.getNodeName().toLowerCase())
  111. {
  112. case "parameters":
  113. {
  114. if (parameters == null)
  115. {
  116. parameters = new HashMap<>();
  117. }
  118. for (Node parameters_node = npc_node.getFirstChild(); parameters_node != null; parameters_node = parameters_node.getNextSibling())
  119. {
  120. attrs = parameters_node.getAttributes();
  121. switch (parameters_node.getNodeName().toLowerCase())
  122. {
  123. case "param":
  124. {
  125. parameters.put(parseString(attrs, "name"), parseString(attrs, "value"));
  126. break;
  127. }
  128. case "skill":
  129. {
  130. parameters.put(parseString(attrs, "name"), new SkillHolder(parseInteger(attrs, "id"), parseInteger(attrs, "level")));
  131. break;
  132. }
  133. case "minions":
  134. {
  135. // TODO: Implement me
  136. break;
  137. }
  138. }
  139. }
  140. break;
  141. }
  142. case "race":
  143. case "sex":
  144. set.set(npc_node.getNodeName(), npc_node.getTextContent().toUpperCase());
  145. break;
  146. case "equipment":
  147. {
  148. set.set("chestId", parseInteger(attrs, "chest"));
  149. set.set("rhandId", parseInteger(attrs, "rhand"));
  150. set.set("lhandId", parseInteger(attrs, "lhand"));
  151. set.set("weaponEnchant", parseInteger(attrs, "weaponEnchant"));
  152. break;
  153. }
  154. case "acquire":
  155. {
  156. set.set("expRate", parseDouble(attrs, "expRate"));
  157. set.set("sp", parseDouble(attrs, "sp"));
  158. set.set("raidPoints", parseDouble(attrs, "raidPoints"));
  159. break;
  160. }
  161. case "stats":
  162. {
  163. set.set("baseSTR", parseInteger(attrs, "str"));
  164. set.set("baseINT", parseInteger(attrs, "int"));
  165. set.set("baseDEX", parseInteger(attrs, "dex"));
  166. set.set("baseWIT", parseInteger(attrs, "wit"));
  167. set.set("baseCON", parseInteger(attrs, "con"));
  168. set.set("baseMEN", parseInteger(attrs, "men"));
  169. for (Node stats_node = npc_node.getFirstChild(); stats_node != null; stats_node = stats_node.getNextSibling())
  170. {
  171. attrs = stats_node.getAttributes();
  172. switch (stats_node.getNodeName().toLowerCase())
  173. {
  174. case "vitals":
  175. {
  176. set.set("baseHpMax", parseDouble(attrs, "hp"));
  177. set.set("baseHpReg", parseDouble(attrs, "hpRegen"));
  178. set.set("baseMpMax", parseDouble(attrs, "mp"));
  179. set.set("baseMpReg", parseDouble(attrs, "mpRegen"));
  180. break;
  181. }
  182. case "attack":
  183. {
  184. set.set("basePAtk", parseDouble(attrs, "physical"));
  185. set.set("baseMAtk", parseDouble(attrs, "magical"));
  186. set.set("baseRndDam", parseInteger(attrs, "random"));
  187. set.set("baseCritRate", parseInteger(attrs, "critical"));
  188. set.set("accuracy", parseDouble(attrs, "accuracy"));// TODO: Implement me
  189. set.set("basePAtkSpd", parseInteger(attrs, "attackSpeed"));
  190. set.set("reuseDelay", parseInteger(attrs, "reuseDelay"));// TODO: Implement me
  191. set.set("baseAtkType", parseString(attrs, "type"));
  192. set.set("baseAtkRange", parseInteger(attrs, "range"));
  193. set.set("distance", parseInteger(attrs, "distance"));// TODO: Implement me
  194. set.set("width", parseInteger(attrs, "width"));// TODO: Implement me
  195. break;
  196. }
  197. case "defence":
  198. {
  199. set.set("basePDef", parseDouble(attrs, "physical"));
  200. set.set("baseMDef", parseDouble(attrs, "magical"));
  201. set.set("evasion", parseInteger(attrs, "evasion"));// TODO: Implement me
  202. set.set("baseShldDef", parseInteger(attrs, "shield"));
  203. set.set("baseShldRate", parseInteger(attrs, "shieldRate"));
  204. break;
  205. }
  206. case "attribute":
  207. {
  208. for (Node attribute_node = stats_node.getFirstChild(); attribute_node != null; attribute_node = attribute_node.getNextSibling())
  209. {
  210. attrs = attribute_node.getAttributes();
  211. switch (attribute_node.getNodeName().toLowerCase())
  212. {
  213. case "attack":
  214. {
  215. String attackAttributeType = parseString(attrs, "type");
  216. switch (attackAttributeType.toUpperCase())
  217. {
  218. case "FIRE":
  219. set.set("baseFire", parseInteger(attrs, "value"));
  220. break;
  221. case "WATER":
  222. set.set("baseWater", parseInteger(attrs, "value"));
  223. break;
  224. case "WIND":
  225. set.set("baseWind", parseInteger(attrs, "value"));
  226. break;
  227. case "EARTH":
  228. set.set("baseEarth", parseInteger(attrs, "value"));
  229. break;
  230. case "DARK":
  231. set.set("baseDark", parseInteger(attrs, "value"));
  232. break;
  233. case "HOLY":
  234. set.set("baseHoly", parseInteger(attrs, "value"));
  235. break;
  236. }
  237. break;
  238. }
  239. case "defence":
  240. {
  241. set.set("baseFireRes", parseInteger(attrs, "fire"));
  242. set.set("baseWaterRes", parseInteger(attrs, "water"));
  243. set.set("baseWindRes", parseInteger(attrs, "wind"));
  244. set.set("baseEarthRes", parseInteger(attrs, "earth"));
  245. set.set("baseHolyRes", parseInteger(attrs, "holy"));
  246. set.set("baseDarkRes", parseInteger(attrs, "dark"));
  247. set.set("baseElementRes", parseInteger(attrs, "default"));
  248. break;
  249. }
  250. }
  251. }
  252. break;
  253. }
  254. case "speed":
  255. {
  256. for (Node speed_node = stats_node.getFirstChild(); speed_node != null; speed_node = speed_node.getNextSibling())
  257. {
  258. attrs = speed_node.getAttributes();
  259. switch (speed_node.getNodeName().toLowerCase())
  260. {
  261. case "walk":
  262. {
  263. set.set("baseWalkSpd", parseFloat(attrs, "ground"));
  264. set.set("baseSwimWalkSpd", parseFloat(attrs, "swim"));
  265. set.set("baseFlyWalkSpd", parseFloat(attrs, "fly"));
  266. break;
  267. }
  268. case "run":
  269. {
  270. set.set("baseRunSpd", parseFloat(attrs, "ground"));
  271. set.set("baseSwimRunSpd", parseFloat(attrs, "swim"));
  272. set.set("baseFlyRunSpd", parseFloat(attrs, "fly"));
  273. break;
  274. }
  275. }
  276. }
  277. break;
  278. }
  279. case "hit_time":
  280. set.set("hit_time", npc_node.getTextContent());// TODO: Implement me default 600 (value in ms)
  281. break;
  282. }
  283. }
  284. break;
  285. }
  286. case "status":
  287. {
  288. set.set("unique", parseBoolean(attrs, "unique"));
  289. set.set("attackable", parseBoolean(attrs, "attackable"));
  290. set.set("targetable", parseBoolean(attrs, "targetable"));
  291. set.set("undying", parseBoolean(attrs, "undying"));
  292. set.set("showName", parseBoolean(attrs, "showName"));
  293. set.set("flying", parseBoolean(attrs, "flying"));
  294. set.set("canMove", parseBoolean(attrs, "canMove"));
  295. set.set("noSleepMode", parseBoolean(attrs, "noSleepMode"));
  296. set.set("passableDoor", parseBoolean(attrs, "passableDoor"));
  297. set.set("hasSummoner", parseBoolean(attrs, "hasSummoner"));
  298. set.set("canBeSown", parseBoolean(attrs, "canBeSown"));
  299. break;
  300. }
  301. case "skill_list":
  302. {
  303. skills = new HashMap<>();
  304. for (Node skill_list_node = npc_node.getFirstChild(); skill_list_node != null; skill_list_node = skill_list_node.getNextSibling())
  305. {
  306. if ("skill".equalsIgnoreCase(skill_list_node.getNodeName()))
  307. {
  308. attrs = skill_list_node.getAttributes();
  309. final int skillId = parseInteger(attrs, "id");
  310. final int skillLevel = parseInteger(attrs, "level");
  311. final Skill skill = SkillData.getInstance().getSkill(skillId, skillLevel);
  312. if (skill != null)
  313. {
  314. skills.put(skill.getId(), skill);
  315. }
  316. else
  317. {
  318. _log.warning("[" + getCurrentFile().getName() + "] skill not found. NPC ID: " + npcId + " Skill ID:" + skillId + " Skill Level: " + skillLevel);
  319. }
  320. }
  321. }
  322. break;
  323. }
  324. case "shots":
  325. {
  326. set.set("soulShot", parseInteger(attrs, "soul"));
  327. set.set("spiritShot", parseInteger(attrs, "spirit"));
  328. set.set("shotShotChance", parseInteger(attrs, "shotChance"));
  329. set.set("spiritShotChance", parseInteger(attrs, "spiritChance"));
  330. break;
  331. }
  332. case "corpse_time":
  333. set.set("corpseTime", npc_node.getTextContent());
  334. break;
  335. case "ex_crt_effect":
  336. set.set("ex_crt_effect", npc_node.getTextContent()); // TODO: Implement me default ? type boolean
  337. break;
  338. case "s_npc_prop_hp_rate":
  339. set.set("s_npc_prop_hp_rate", npc_node.getTextContent()); // TODO: Implement me default 1 type double
  340. break;
  341. case "ai":
  342. {
  343. set.set("aiType", parseString(attrs, "type"));
  344. set.set("aggroRange", parseInteger(attrs, "aggroRange"));
  345. set.set("clanHelpRange", parseInteger(attrs, "clanHelpRange"));
  346. set.set("dodge", parseInteger(attrs, "dodge"));
  347. set.set("isChaos", parseBoolean(attrs, "isChaos"));
  348. set.set("isAggressive", parseBoolean(attrs, "isAggressive"));
  349. for (Node ai_node = npc_node.getFirstChild(); ai_node != null; ai_node = ai_node.getNextSibling())
  350. {
  351. attrs = ai_node.getAttributes();
  352. switch (ai_node.getNodeName().toLowerCase())
  353. {
  354. case "skill":
  355. {
  356. set.set("minSkillChance", parseInteger(attrs, "minChance"));
  357. set.set("maxSkillChance", parseInteger(attrs, "maxChance"));
  358. set.set("primarySkillId", parseInteger(attrs, "primaryId"));
  359. set.set("shortRangeSkillId", parseInteger(attrs, "shortRangeId"));
  360. set.set("shortRangeSkillChance", parseInteger(attrs, "shortRangeChance"));
  361. set.set("longRangeSkillId", parseInteger(attrs, "longRangeId"));
  362. set.set("longRangeSkillChance", parseInteger(attrs, "longRangeChance"));
  363. break;
  364. }
  365. case "clan_list":
  366. {
  367. for (Node clan_list_node = ai_node.getFirstChild(); clan_list_node != null; clan_list_node = clan_list_node.getNextSibling())
  368. {
  369. attrs = clan_list_node.getAttributes();
  370. switch (clan_list_node.getNodeName().toLowerCase())
  371. {
  372. case "clan":
  373. {
  374. if (clans == null)
  375. {
  376. clans = new HashSet<>(1);
  377. }
  378. clans.add(getOrCreateClanId(clan_list_node.getTextContent()));
  379. break;
  380. }
  381. case "enemy_clan":
  382. {
  383. if (enemyClans == null)
  384. {
  385. enemyClans = new HashSet<>(1);
  386. }
  387. enemyClans.add(getOrCreateClanId(clan_list_node.getTextContent()));
  388. break;
  389. }
  390. }
  391. }
  392. break;
  393. }
  394. }
  395. }
  396. break;
  397. }
  398. case "drop_lists":
  399. {
  400. for (Node drop_lists_node = npc_node.getFirstChild(); drop_lists_node != null; drop_lists_node = drop_lists_node.getNextSibling())
  401. {
  402. DropListScope dropListScope = null;
  403. try
  404. {
  405. dropListScope = Enum.valueOf(DropListScope.class, drop_lists_node.getNodeName().toUpperCase());
  406. }
  407. catch (Exception e)
  408. {
  409. }
  410. if (dropListScope != null)
  411. {
  412. if (dropLists == null)
  413. {
  414. dropLists = new EnumMap<>(DropListScope.class);
  415. }
  416. List<IDropItem> dropList = new ArrayList<>();
  417. parseDropList(drop_lists_node, dropListScope, dropList);
  418. dropLists.put(dropListScope, Collections.unmodifiableList(dropList));
  419. }
  420. }
  421. break;
  422. }
  423. case "collision":
  424. {
  425. for (Node collision_node = npc_node.getFirstChild(); collision_node != null; collision_node = collision_node.getNextSibling())
  426. {
  427. attrs = collision_node.getAttributes();
  428. switch (collision_node.getNodeName().toLowerCase())
  429. {
  430. case "radius":
  431. {
  432. set.set("collision_radius", parseDouble(attrs, "normal"));
  433. set.set("collisionRadiusGrown", parseDouble(attrs, "grown"));
  434. break;
  435. }
  436. case "height":
  437. {
  438. set.set("collision_height", parseDouble(attrs, "normal"));
  439. set.set("collisionHeightGrown", parseDouble(attrs, "grown"));
  440. break;
  441. }
  442. }
  443. }
  444. break;
  445. }
  446. }
  447. }
  448. L2NpcTemplate template = _npcs.get(npcId);
  449. if (template == null)
  450. {
  451. template = new L2NpcTemplate(set);
  452. _npcs.put(template.getId(), template);
  453. }
  454. else
  455. {
  456. template.set(set);
  457. }
  458. if (parameters != null)
  459. {
  460. // Using unmodifiable map parameters of template are not meant to be changed at runtime.
  461. template.setParameters(new StatsSet(Collections.unmodifiableMap(parameters)));
  462. }
  463. else
  464. {
  465. template.setParameters(null);
  466. }
  467. if (skills != null)
  468. {
  469. Map<AISkillScope, List<Skill>> aiSkillLists = null;
  470. for (Skill skill : skills.values())
  471. {
  472. if (!skill.isPassive())
  473. {
  474. if (aiSkillLists == null)
  475. {
  476. aiSkillLists = new EnumMap<>(AISkillScope.class);
  477. }
  478. List<AISkillScope> aiSkillScopes = new ArrayList<>();
  479. final AISkillScope shortOrLongRangeScope = skill.getCastRange() <= 150 ? AISkillScope.SHORT_RANGE : AISkillScope.SHORT_RANGE;
  480. if (skill.isSuicideAttack())
  481. {
  482. aiSkillScopes.add(AISkillScope.SUICIDE);
  483. }
  484. else
  485. {
  486. aiSkillScopes.add(AISkillScope.GENERAL);
  487. if (skill.isContinuous())
  488. {
  489. if (!skill.isDebuff())
  490. {
  491. aiSkillScopes.add(AISkillScope.BUFF);
  492. }
  493. else
  494. {
  495. aiSkillScopes.add(AISkillScope.DEBUFF);
  496. aiSkillScopes.add(AISkillScope.COT);
  497. aiSkillScopes.add(shortOrLongRangeScope);
  498. }
  499. }
  500. else
  501. {
  502. if (skill.hasEffectType(L2EffectType.DISPEL, L2EffectType.DISPEL_BY_SLOT))
  503. {
  504. aiSkillScopes.add(AISkillScope.NEGATIVE);
  505. aiSkillScopes.add(shortOrLongRangeScope);
  506. }
  507. else if (skill.hasEffectType(L2EffectType.HEAL))
  508. {
  509. aiSkillScopes.add(AISkillScope.HEAL);
  510. }
  511. else if (skill.hasEffectType(L2EffectType.PHYSICAL_ATTACK, L2EffectType.PHYSICAL_ATTACK_HP_LINK, L2EffectType.MAGICAL_ATTACK, L2EffectType.DEATH_LINK, L2EffectType.HP_DRAIN))
  512. {
  513. aiSkillScopes.add(AISkillScope.ATTACK);
  514. aiSkillScopes.add(AISkillScope.UNIVERSAL);
  515. aiSkillScopes.add(shortOrLongRangeScope);
  516. }
  517. else if (skill.hasEffectType(L2EffectType.SLEEP))
  518. {
  519. aiSkillScopes.add(AISkillScope.IMMOBILIZE);
  520. }
  521. else if (skill.hasEffectType(L2EffectType.STUN, L2EffectType.ROOT))
  522. {
  523. aiSkillScopes.add(AISkillScope.IMMOBILIZE);
  524. aiSkillScopes.add(shortOrLongRangeScope);
  525. }
  526. else if (skill.hasEffectType(L2EffectType.MUTE, L2EffectType.FEAR))
  527. {
  528. aiSkillScopes.add(AISkillScope.COT);
  529. aiSkillScopes.add(shortOrLongRangeScope);
  530. }
  531. else if (skill.hasEffectType(L2EffectType.PARALYZE))
  532. {
  533. aiSkillScopes.add(AISkillScope.IMMOBILIZE);
  534. aiSkillScopes.add(shortOrLongRangeScope);
  535. }
  536. else if (skill.hasEffectType(L2EffectType.DMG_OVER_TIME, L2EffectType.DMG_OVER_TIME_PERCENT))
  537. {
  538. aiSkillScopes.add(shortOrLongRangeScope);
  539. }
  540. else if (skill.hasEffectType(L2EffectType.RESURRECTION))
  541. {
  542. aiSkillScopes.add(AISkillScope.RES);
  543. }
  544. else
  545. {
  546. aiSkillScopes.add(AISkillScope.UNIVERSAL);
  547. }
  548. }
  549. }
  550. for (AISkillScope aiSkillScope : aiSkillScopes)
  551. {
  552. List<Skill> aiSkills = aiSkillLists.get(aiSkillScope);
  553. if (aiSkills == null)
  554. {
  555. aiSkills = new ArrayList<>();
  556. aiSkillLists.put(aiSkillScope, aiSkills);
  557. }
  558. aiSkills.add(skill);
  559. }
  560. }
  561. }
  562. template.setSkills(skills);
  563. template.setAISkillLists(aiSkillLists);
  564. }
  565. else
  566. {
  567. template.setSkills(null);
  568. template.setAISkillLists(null);
  569. }
  570. template.setClans(clans);
  571. template.setEnemyClans(enemyClans);
  572. template.setDropLists(dropLists);
  573. }
  574. }
  575. }
  576. }
  577. }
  578. private void parseDropList(Node drop_list_node, DropListScope dropListScope, List<IDropItem> drops)
  579. {
  580. for (Node drop_node = drop_list_node.getFirstChild(); drop_node != null; drop_node = drop_node.getNextSibling())
  581. {
  582. NamedNodeMap attrs = drop_node.getAttributes();
  583. switch (drop_node.getNodeName().toLowerCase())
  584. {
  585. case "group":
  586. {
  587. GroupedGeneralDropItem dropItem = dropListScope.newGroupedDropItem(parseDouble(attrs, "chance"));
  588. List<IDropItem> groupedDropList = new ArrayList<>(2);
  589. for (Node group_node = drop_node.getFirstChild(); group_node != null; group_node = group_node.getNextSibling())
  590. {
  591. parseDropListItem(group_node, dropListScope, groupedDropList);
  592. }
  593. List<GeneralDropItem> items = new ArrayList<>(groupedDropList.size());
  594. for (IDropItem item : groupedDropList)
  595. {
  596. if (item instanceof GeneralDropItem)
  597. {
  598. items.add((GeneralDropItem) item);
  599. }
  600. else
  601. {
  602. _log.warning("[" + getCurrentFile() + "] grouped general drop item supports only general drop item.");
  603. }
  604. }
  605. dropItem.setItems(items);
  606. drops.add(dropItem);
  607. break;
  608. }
  609. default:
  610. {
  611. parseDropListItem(drop_node, dropListScope, drops);
  612. break;
  613. }
  614. }
  615. }
  616. }
  617. private void parseDropListItem(Node drop_list_item, DropListScope dropListScope, List<IDropItem> drops)
  618. {
  619. NamedNodeMap attrs = drop_list_item.getAttributes();
  620. switch (drop_list_item.getNodeName().toLowerCase())
  621. {
  622. case "item":
  623. {
  624. final IDropItem dropItem = dropListScope.newDropItem(parseInteger(attrs, "id"), parseLong(attrs, "min"), parseLong(attrs, "max"), parseDouble(attrs, "chance"));
  625. if (dropItem != null)
  626. {
  627. drops.add(dropItem);
  628. }
  629. break;
  630. }
  631. }
  632. }
  633. /**
  634. * Gets or creates a clan id if it doesnt exists.
  635. * @param clanName the clan name to get or create its id
  636. * @return the clan id for the given clan name
  637. */
  638. private int getOrCreateClanId(String clanName)
  639. {
  640. Integer id = _clans.get(clanName.toUpperCase());
  641. if (id == null)
  642. {
  643. id = _clans.size();
  644. _clans.put(clanName.toUpperCase(), id);
  645. }
  646. return id;
  647. }
  648. /**
  649. * Gets the clan id
  650. * @param clanName the clan name to get its id
  651. * @return the clan id for the given clan name if it exists, -1 otherwise
  652. */
  653. public int getClanId(String clanName)
  654. {
  655. Integer id = _clans.get(clanName.toUpperCase());
  656. return id != null ? id : -1;
  657. }
  658. /**
  659. * Gets the template.
  660. * @param id the template Id to get.
  661. * @return the template for the given id.
  662. */
  663. public L2NpcTemplate getTemplate(int id)
  664. {
  665. return _npcs.get(id);
  666. }
  667. /**
  668. * Gets the template by name.
  669. * @param name of the template to get.
  670. * @return the template for the given name.
  671. */
  672. public L2NpcTemplate getTemplateByName(String name)
  673. {
  674. for (L2NpcTemplate npcTemplate : _npcs.values())
  675. {
  676. if (npcTemplate.getName().equalsIgnoreCase(name))
  677. {
  678. return npcTemplate;
  679. }
  680. }
  681. return null;
  682. }
  683. /**
  684. * Gets the all of level.
  685. * @param lvls of all the templates to get.
  686. * @return the template list for the given level.
  687. */
  688. public List<L2NpcTemplate> getAllOfLevel(int... lvls)
  689. {
  690. //@formatter:off
  691. return _npcs.values().stream()
  692. .filter(template -> Util.contains(lvls, template.getLevel()))
  693. .collect(Collectors.toList());
  694. //@formatter:on
  695. }
  696. /**
  697. * Gets the all monsters of level.
  698. * @param lvls of all the monster templates to get.
  699. * @return the template list for the given level.
  700. */
  701. public List<L2NpcTemplate> getAllMonstersOfLevel(int... lvls)
  702. {
  703. //@formatter:off
  704. return _npcs.values().stream()
  705. .filter(template -> Util.contains(lvls, template.getLevel()))
  706. .filter(template -> template.isType("L2Monster"))
  707. .collect(Collectors.toList());
  708. //@formatter:on
  709. }
  710. /**
  711. * Gets the all npc starting with.
  712. * @param letters of all the NPC templates which its name start with.
  713. * @return the template list for the given letter.
  714. */
  715. public List<L2NpcTemplate> getAllNpcStartingWith(String... letters)
  716. {
  717. //@formatter:off
  718. return _npcs.values().stream()
  719. .filter(template -> Util.startsWith(letters, template.getName()))
  720. .filter(template -> template.isType("L2Npc"))
  721. .collect(Collectors.toList());
  722. //@formatter:on
  723. }
  724. /**
  725. * Gets the all npc of class type.
  726. * @param classTypes of all the templates to get.
  727. * @return the template list for the given class type.
  728. */
  729. public List<L2NpcTemplate> getAllNpcOfClassType(String... classTypes)
  730. {
  731. //@formatter:off
  732. return _npcs.values().stream()
  733. .filter(template -> Util.contains(classTypes, template.getType(), true))
  734. .collect(Collectors.toList());
  735. //@formatter:on
  736. }
  737. public void loadNpcsSkillLearn()
  738. {
  739. _npcs.values().forEach(template ->
  740. {
  741. final List<ClassId> teachInfo = SkillLearnData.getInstance().getSkillLearnData(template.getId());
  742. if (teachInfo != null)
  743. {
  744. template.addTeachInfo(teachInfo);
  745. }
  746. });
  747. }
  748. public void loadMinions()
  749. {
  750. final String query = SELECT_MINION_ALL;
  751. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  752. Statement statement = con.createStatement())
  753. {
  754. int count = 0;
  755. try (ResultSet rset = statement.executeQuery(query))
  756. {
  757. L2MinionData minionDat = null;
  758. L2NpcTemplate npcDat = null;
  759. int raidId;
  760. while (rset.next())
  761. {
  762. raidId = rset.getInt("boss_id");
  763. npcDat = _npcs.get(raidId);
  764. if (npcDat == null)
  765. {
  766. _log.warning(getClass().getSimpleName() + ": Minion references undefined boss NPC. Boss NpcId: " + raidId);
  767. continue;
  768. }
  769. minionDat = new L2MinionData();
  770. minionDat.setMinionId(rset.getInt("minion_id"));
  771. minionDat.setAmountMin(rset.getInt("amount_min"));
  772. minionDat.setAmountMax(rset.getInt("amount_max"));
  773. npcDat.addMinionData(minionDat);
  774. count++;
  775. }
  776. }
  777. _log.info(getClass().getSimpleName() + ": Loaded " + count + " Minions.");
  778. }
  779. catch (Exception e)
  780. {
  781. _log.log(Level.SEVERE, getClass().getSimpleName() + ": Error loading minion data.", e);
  782. }
  783. }
  784. /**
  785. * Gets the single instance of NpcData.
  786. * @return single instance of NpcData
  787. */
  788. public static NpcData getInstance()
  789. {
  790. return SingletonHolder._instance;
  791. }
  792. private static class SingletonHolder
  793. {
  794. protected static final NpcData _instance = new NpcData();
  795. }
  796. }