NpcData.java 25 KB

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