NpcData.java 30 KB

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