NpcData.java 25 KB

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