NpcData.java 29 KB

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