PetDataTable.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /*
  2. * Copyright (C) 2004-2013 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.util.HashMap;
  21. import java.util.Map;
  22. import org.w3c.dom.NamedNodeMap;
  23. import org.w3c.dom.Node;
  24. import com.l2jserver.gameserver.engines.DocumentParser;
  25. import com.l2jserver.gameserver.model.L2PetData;
  26. import com.l2jserver.gameserver.model.L2PetLevelData;
  27. import com.l2jserver.gameserver.model.StatsSet;
  28. /**
  29. * This class parse and hold all pet parameters.<br>
  30. * TODO: Unhardcode where is possible boolean methods and load and use all pet parameters.
  31. * @author Zoey76 (rework)
  32. */
  33. public final class PetDataTable extends DocumentParser
  34. {
  35. private static final Map<Integer, L2PetData> _pets = new HashMap<>();
  36. /**
  37. * Instantiates a new pet data table.
  38. */
  39. protected PetDataTable()
  40. {
  41. load();
  42. }
  43. @Override
  44. public void load()
  45. {
  46. _pets.clear();
  47. parseDirectory("data/stats/pets/");
  48. _log.info(getClass().getSimpleName() + ": Loaded " + _pets.size() + " Pets.");
  49. }
  50. @Override
  51. protected void parseDocument()
  52. {
  53. NamedNodeMap attrs;
  54. Node n = getCurrentDocument().getFirstChild();
  55. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  56. {
  57. if (d.getNodeName().equals("pet"))
  58. {
  59. int npcId = parseInt(d.getAttributes(), "id");
  60. int itemId = parseInt(d.getAttributes(), "itemId");
  61. // index ignored for now
  62. L2PetData data = new L2PetData(npcId, itemId);
  63. for (Node p = d.getFirstChild(); p != null; p = p.getNextSibling())
  64. {
  65. if (p.getNodeName().equals("set"))
  66. {
  67. attrs = p.getAttributes();
  68. String type = attrs.getNamedItem("name").getNodeValue();
  69. if ("food".equals(type))
  70. {
  71. for (String foodId : attrs.getNamedItem("val").getNodeValue().split(";"))
  72. {
  73. data.addFood(Integer.valueOf(foodId));
  74. }
  75. }
  76. else if ("load".equals(type))
  77. {
  78. data.setLoad(parseInt(attrs, "val"));
  79. }
  80. else if ("hungry_limit".equals(type))
  81. {
  82. data.setHungryLimit(parseInt(attrs, "val"));
  83. }
  84. else if ("sync_level".equals(type))
  85. {
  86. data.setSyncLevel(parseInt(attrs, "val") == 1);
  87. }
  88. // evolve ignored
  89. }
  90. else if (p.getNodeName().equals("skills"))
  91. {
  92. for (Node s = p.getFirstChild(); s != null; s = s.getNextSibling())
  93. {
  94. if (s.getNodeName().equals("skill"))
  95. {
  96. attrs = s.getAttributes();
  97. data.addNewSkill(parseInt(attrs, "skillId"), parseInt(attrs, "skillLvl"), parseInt(attrs, "minLvl"));
  98. }
  99. }
  100. }
  101. else if (p.getNodeName().equals("stats"))
  102. {
  103. for (Node s = p.getFirstChild(); s != null; s = s.getNextSibling())
  104. {
  105. if (s.getNodeName().equals("stat"))
  106. {
  107. final int level = Integer.parseInt(s.getAttributes().getNamedItem("level").getNodeValue());
  108. final StatsSet set = new StatsSet();
  109. for (Node bean = s.getFirstChild(); bean != null; bean = bean.getNextSibling())
  110. {
  111. if (bean.getNodeName().equals("set"))
  112. {
  113. attrs = bean.getAttributes();
  114. set.set(attrs.getNamedItem("name").getNodeValue(), attrs.getNamedItem("val").getNodeValue());
  115. }
  116. }
  117. data.addNewStat(level, new L2PetLevelData(set));
  118. }
  119. }
  120. }
  121. }
  122. _pets.put(npcId, data);
  123. }
  124. }
  125. }
  126. /**
  127. * @param itemId
  128. * @return
  129. */
  130. public L2PetData getPetDataByItemId(int itemId)
  131. {
  132. for (L2PetData data : _pets.values())
  133. {
  134. if (data.getItemId() == itemId)
  135. {
  136. return data;
  137. }
  138. }
  139. return null;
  140. }
  141. /**
  142. * Gets the pet level data.
  143. * @param petId the pet Id.
  144. * @param petLevel the pet level.
  145. * @return the pet's parameters for the given Id and level.
  146. */
  147. public L2PetLevelData getPetLevelData(int petId, int petLevel)
  148. {
  149. final L2PetData pd = getPetData(petId);
  150. if (pd != null)
  151. {
  152. return pd.getPetLevelData(petLevel);
  153. }
  154. return null;
  155. }
  156. /**
  157. * Gets the pet data.
  158. * @param petId the pet Id.
  159. * @return the pet data
  160. */
  161. public L2PetData getPetData(int petId)
  162. {
  163. if (!_pets.containsKey(petId))
  164. {
  165. _log.info(getClass().getSimpleName() + ": Missing pet data for npcid: " + petId);
  166. }
  167. return _pets.get(petId);
  168. }
  169. /**
  170. * Gets the pet min level.
  171. * @param petId the pet Id.
  172. * @return the pet min level
  173. */
  174. public int getPetMinLevel(int petId)
  175. {
  176. return _pets.get(petId).getMinLevel();
  177. }
  178. /**
  179. * Checks if is strider.
  180. * @param npcId the NPC Id to verify.
  181. * @return {@code true} if the given Id is from a strider, {@code false} otherwise.
  182. */
  183. public static boolean isStrider(int npcId)
  184. {
  185. return ((npcId >= 12526) && (npcId <= 12528)) || ((npcId >= 16038) && (npcId <= 16040)) || (npcId == 16068);
  186. }
  187. /**
  188. * Checks if is grow up wolf group.
  189. * @param npcId the NPC Id to verify.
  190. * @return {@code true} if the given Id is from a grow up wolf group, {@code false} otherwise.
  191. */
  192. public static boolean isGrowUpWolfGroup(int npcId)
  193. {
  194. return (npcId == 16025) || (npcId == 16030) || (npcId == 16037) || (npcId == 16041) || (npcId == 16042);
  195. }
  196. /**
  197. * Checks if is hatchling group.
  198. * @param npcId the NPC Id to verify.
  199. * @return {@code true} if the given Id is from a hatchling group, {@code false} otherwise.
  200. */
  201. public static boolean isHatchlingGroup(int npcId)
  202. {
  203. return (npcId >= 12311) && (npcId <= 12313);
  204. }
  205. /**
  206. * Checks if is all wolf group.
  207. * @param npcId the NPC Id to verify.
  208. * @return {@code true} if the given Id is from all wolf group, {@code false} otherwise.
  209. */
  210. public static boolean isAllWolfGroup(int npcId)
  211. {
  212. return (npcId == 12077) || (npcId == 16025) || (npcId == 16030) || (npcId == 16037) || (npcId == 16041) || (npcId == 16042);
  213. }
  214. /**
  215. * Checks if is baby pet group.
  216. * @param npcId the NPC Id to verify.
  217. * @return {@code true} if the given Id is from a baby pet group, {@code false} otherwise.
  218. */
  219. public static boolean isBabyPetGroup(int npcId)
  220. {
  221. return (npcId >= 12780) && (npcId <= 12782);
  222. }
  223. /**
  224. * Checks if is upgrade baby pet group.
  225. * @param npcId the NPC Id to verify.
  226. * @return {@code true} if the given Id is from an upgrade baby pet group, {@code false} otherwise.
  227. */
  228. public static boolean isUpgradeBabyPetGroup(int npcId)
  229. {
  230. return (npcId >= 16034) && (npcId <= 16036);
  231. }
  232. /**
  233. * Checks if is item equip pet group.
  234. * @param npcId the NPC Id to verify.
  235. * @return {@code true} if the given Id is from an item equip pet group, {@code false} otherwise.
  236. */
  237. public static boolean isItemEquipPetGroup(int npcId)
  238. {
  239. return (npcId == 12077) || ((npcId >= 12311) && (npcId <= 12313)) || ((npcId >= 12526) && (npcId <= 12528)) || ((npcId >= 12780) && (npcId <= 12782)) || (npcId == 16025) || (npcId == 16030) || ((npcId >= 16034) && (npcId <= 16036)) || (npcId == 16037) || ((npcId >= 16038) && (npcId <= 16042)) || (npcId == 16068) || (npcId == 16067) || (npcId == 16071) || (npcId == 16072) || (npcId == 1561);
  240. }
  241. /**
  242. * Gets the pet items by npc.
  243. * @param npcId the NPC Id to get its summoning item.
  244. * @return an array containing the list of summoning items for the given NPC Id.
  245. */
  246. public static int[] getPetItemsByNpc(int npcId)
  247. {
  248. switch (npcId)
  249. {
  250. case 12077:// Wolf
  251. return new int[]
  252. {
  253. 2375
  254. };
  255. case 16025:// Great Wolf
  256. return new int[]
  257. {
  258. 9882
  259. };
  260. case 16030:// Black Wolf
  261. return new int[]
  262. {
  263. 10163
  264. };
  265. case 16037:// White Great Wolf
  266. return new int[]
  267. {
  268. 10307
  269. };
  270. case 16041:// Fenrir
  271. return new int[]
  272. {
  273. 10426
  274. };
  275. case 16042:// White Fenrir
  276. return new int[]
  277. {
  278. 10611
  279. };
  280. case 12564:// Sin Eater
  281. return new int[]
  282. {
  283. 4425
  284. };
  285. case 12311:// hatchling of wind
  286. case 12312:// hatchling of star
  287. case 12313:// hatchling of twilight
  288. return new int[]
  289. {
  290. 3500,
  291. 3501,
  292. 3502
  293. };
  294. case 12526:// wind strider
  295. case 12527:// Star strider
  296. case 12528:// Twilight strider
  297. case 16038: // red strider of wind
  298. case 16039: // red strider of star
  299. case 16040: // red strider of dusk
  300. case 16068: // Guardian Strider
  301. return new int[]
  302. {
  303. 4422,
  304. 4423,
  305. 4424,
  306. 10308,
  307. 10309,
  308. 10310,
  309. 14819
  310. };
  311. case 12621:// Wyvern
  312. return new int[]
  313. {
  314. 8663
  315. };
  316. case 12780:// Baby Buffalo
  317. case 12782:// Baby Cougar
  318. case 12781:// Baby Kookaburra
  319. return new int[]
  320. {
  321. 6648,
  322. 6649,
  323. 6650
  324. };
  325. case 16034:// Improved Baby Buffalo
  326. case 16036:// Improved Baby Cougar
  327. case 16035:// Improved Baby Kookaburra
  328. return new int[]
  329. {
  330. 10311,
  331. 10312,
  332. 10313
  333. };
  334. // unknown item id.. should never happen
  335. default:
  336. return new int[]
  337. {
  338. 0
  339. };
  340. }
  341. }
  342. /**
  343. * Checks if is mountable.
  344. * @param npcId the NPC Id to verify.
  345. * @return {@code true} if the given Id is from a mountable pet, {@code false} otherwise.
  346. */
  347. public static boolean isMountable(int npcId)
  348. {
  349. return (npcId == 12526 // wind strider
  350. ) || (npcId == 12527 // star strider
  351. ) || (npcId == 12528 // twilight strider
  352. ) || (npcId == 12621 // wyvern
  353. ) || (npcId == 16037 // Great Snow Wolf
  354. ) || (npcId == 16041 // Fenrir Wolf
  355. ) || (npcId == 16042 // White Fenrir Wolf
  356. ) || (npcId == 16038 // Red Wind Strider
  357. ) || (npcId == 16039 // Red Star Strider
  358. ) || (npcId == 16040 // Red Twilight Strider
  359. ) || (npcId == 16068); // Guardian Strider
  360. }
  361. /**
  362. * Gets the single instance of PetDataTable.
  363. * @return this class unique instance.
  364. */
  365. public static PetDataTable getInstance()
  366. {
  367. return SingletonHolder._instance;
  368. }
  369. private static class SingletonHolder
  370. {
  371. protected static final PetDataTable _instance = new PetDataTable();
  372. }
  373. }