2
0

PetDataTable.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. if (attrs.getNamedItem("name").getNodeValue().equals("speed_on_ride"))
  115. {
  116. set.set("walkSpeedOnRide", attrs.getNamedItem("walk").getNodeValue());
  117. set.set("runSpeedOnRide", attrs.getNamedItem("run").getNodeValue());
  118. set.set("slowSwimSpeedOnRide", attrs.getNamedItem("slowSwim").getNodeValue());
  119. set.set("fastSwimSpeedOnRide", attrs.getNamedItem("fastSwim").getNodeValue());
  120. if (attrs.getNamedItem("slowFly") != null)
  121. {
  122. set.set("slowFlySpeedOnRide", attrs.getNamedItem("slowFly").getNodeValue());
  123. }
  124. if (attrs.getNamedItem("fastFly") != null)
  125. {
  126. set.set("fastFlySpeedOnRide", attrs.getNamedItem("fastFly").getNodeValue());
  127. }
  128. }
  129. else
  130. {
  131. set.set(attrs.getNamedItem("name").getNodeValue(), attrs.getNamedItem("val").getNodeValue());
  132. }
  133. }
  134. }
  135. data.addNewStat(level, new L2PetLevelData(set));
  136. }
  137. }
  138. }
  139. }
  140. _pets.put(npcId, data);
  141. }
  142. }
  143. }
  144. /**
  145. * @param itemId
  146. * @return
  147. */
  148. public L2PetData getPetDataByItemId(int itemId)
  149. {
  150. for (L2PetData data : _pets.values())
  151. {
  152. if (data.getItemId() == itemId)
  153. {
  154. return data;
  155. }
  156. }
  157. return null;
  158. }
  159. /**
  160. * Gets the pet level data.
  161. * @param petId the pet Id.
  162. * @param petLevel the pet level.
  163. * @return the pet's parameters for the given Id and level.
  164. */
  165. public L2PetLevelData getPetLevelData(int petId, int petLevel)
  166. {
  167. final L2PetData pd = getPetData(petId);
  168. if (pd != null)
  169. {
  170. return pd.getPetLevelData(petLevel);
  171. }
  172. return null;
  173. }
  174. /**
  175. * Gets the pet data.
  176. * @param petId the pet Id.
  177. * @return the pet data
  178. */
  179. public L2PetData getPetData(int petId)
  180. {
  181. if (!_pets.containsKey(petId))
  182. {
  183. _log.info(getClass().getSimpleName() + ": Missing pet data for npcid: " + petId);
  184. }
  185. return _pets.get(petId);
  186. }
  187. /**
  188. * Gets the pet min level.
  189. * @param petId the pet Id.
  190. * @return the pet min level
  191. */
  192. public int getPetMinLevel(int petId)
  193. {
  194. return _pets.get(petId).getMinLevel();
  195. }
  196. /**
  197. * Checks if is strider.
  198. * @param npcId the NPC Id to verify.
  199. * @return {@code true} if the given Id is from a strider, {@code false} otherwise.
  200. */
  201. public static boolean isStrider(int npcId)
  202. {
  203. return ((npcId >= 12526) && (npcId <= 12528)) || ((npcId >= 16038) && (npcId <= 16040)) || (npcId == 16068);
  204. }
  205. /**
  206. * Checks if is grow up wolf group.
  207. * @param npcId the NPC Id to verify.
  208. * @return {@code true} if the given Id is from a grow up wolf group, {@code false} otherwise.
  209. */
  210. public static boolean isGrowUpWolfGroup(int npcId)
  211. {
  212. return (npcId == 16025) || (npcId == 16030) || (npcId == 16037) || (npcId == 16041) || (npcId == 16042);
  213. }
  214. /**
  215. * Checks if is hatchling group.
  216. * @param npcId the NPC Id to verify.
  217. * @return {@code true} if the given Id is from a hatchling group, {@code false} otherwise.
  218. */
  219. public static boolean isHatchlingGroup(int npcId)
  220. {
  221. return (npcId >= 12311) && (npcId <= 12313);
  222. }
  223. /**
  224. * Checks if is all wolf group.
  225. * @param npcId the NPC Id to verify.
  226. * @return {@code true} if the given Id is from all wolf group, {@code false} otherwise.
  227. */
  228. public static boolean isAllWolfGroup(int npcId)
  229. {
  230. return (npcId == 12077) || (npcId == 16025) || (npcId == 16030) || (npcId == 16037) || (npcId == 16041) || (npcId == 16042);
  231. }
  232. /**
  233. * Checks if is baby pet group.
  234. * @param npcId the NPC Id to verify.
  235. * @return {@code true} if the given Id is from a baby pet group, {@code false} otherwise.
  236. */
  237. public static boolean isBabyPetGroup(int npcId)
  238. {
  239. return (npcId >= 12780) && (npcId <= 12782);
  240. }
  241. /**
  242. * Checks if is upgrade baby pet group.
  243. * @param npcId the NPC Id to verify.
  244. * @return {@code true} if the given Id is from an upgrade baby pet group, {@code false} otherwise.
  245. */
  246. public static boolean isUpgradeBabyPetGroup(int npcId)
  247. {
  248. return (npcId >= 16034) && (npcId <= 16036);
  249. }
  250. /**
  251. * Checks if is item equip pet group.
  252. * @param npcId the NPC Id to verify.
  253. * @return {@code true} if the given Id is from an item equip pet group, {@code false} otherwise.
  254. */
  255. public static boolean isItemEquipPetGroup(int npcId)
  256. {
  257. 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);
  258. }
  259. /**
  260. * Gets the pet items by npc.
  261. * @param npcId the NPC Id to get its summoning item.
  262. * @return an array containing the list of summoning items for the given NPC Id.
  263. */
  264. public static int[] getPetItemsByNpc(int npcId)
  265. {
  266. switch (npcId)
  267. {
  268. case 12077:// Wolf
  269. return new int[]
  270. {
  271. 2375
  272. };
  273. case 16025:// Great Wolf
  274. return new int[]
  275. {
  276. 9882
  277. };
  278. case 16030:// Black Wolf
  279. return new int[]
  280. {
  281. 10163
  282. };
  283. case 16037:// White Great Wolf
  284. return new int[]
  285. {
  286. 10307
  287. };
  288. case 16041:// Fenrir
  289. return new int[]
  290. {
  291. 10426
  292. };
  293. case 16042:// White Fenrir
  294. return new int[]
  295. {
  296. 10611
  297. };
  298. case 12564:// Sin Eater
  299. return new int[]
  300. {
  301. 4425
  302. };
  303. case 12311:// hatchling of wind
  304. case 12312:// hatchling of star
  305. case 12313:// hatchling of twilight
  306. return new int[]
  307. {
  308. 3500,
  309. 3501,
  310. 3502
  311. };
  312. case 12526:// wind strider
  313. case 12527:// Star strider
  314. case 12528:// Twilight strider
  315. case 16038: // red strider of wind
  316. case 16039: // red strider of star
  317. case 16040: // red strider of dusk
  318. case 16068: // Guardian Strider
  319. return new int[]
  320. {
  321. 4422,
  322. 4423,
  323. 4424,
  324. 10308,
  325. 10309,
  326. 10310,
  327. 14819
  328. };
  329. case 12621:// Wyvern
  330. return new int[]
  331. {
  332. 8663
  333. };
  334. case 12780:// Baby Buffalo
  335. case 12782:// Baby Cougar
  336. case 12781:// Baby Kookaburra
  337. return new int[]
  338. {
  339. 6648,
  340. 6649,
  341. 6650
  342. };
  343. case 16034:// Improved Baby Buffalo
  344. case 16036:// Improved Baby Cougar
  345. case 16035:// Improved Baby Kookaburra
  346. return new int[]
  347. {
  348. 10311,
  349. 10312,
  350. 10313
  351. };
  352. // unknown item id.. should never happen
  353. default:
  354. return new int[]
  355. {
  356. 0
  357. };
  358. }
  359. }
  360. /**
  361. * Checks if is mountable.
  362. * @param npcId the NPC Id to verify.
  363. * @return {@code true} if the given Id is from a mountable pet, {@code false} otherwise.
  364. */
  365. public static boolean isMountable(int npcId)
  366. {
  367. return (npcId == 12526 // wind strider
  368. ) || (npcId == 12527 // star strider
  369. ) || (npcId == 12528 // twilight strider
  370. ) || (npcId == 12621 // wyvern
  371. ) || (npcId == 16037 // Great Snow Wolf
  372. ) || (npcId == 16041 // Fenrir Wolf
  373. ) || (npcId == 16042 // White Fenrir Wolf
  374. ) || (npcId == 16038 // Red Wind Strider
  375. ) || (npcId == 16039 // Red Star Strider
  376. ) || (npcId == 16040 // Red Twilight Strider
  377. ) || (npcId == 16068); // Guardian Strider
  378. }
  379. /**
  380. * Gets the single instance of PetDataTable.
  381. * @return this class unique instance.
  382. */
  383. public static PetDataTable getInstance()
  384. {
  385. return SingletonHolder._instance;
  386. }
  387. private static class SingletonHolder
  388. {
  389. protected static final PetDataTable _instance = new PetDataTable();
  390. }
  391. }