NpcData.java 29 KB

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