2
0

PetDataTable.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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 wolf.
  180. * @param npcId the NPC Id to verify.
  181. * @return {@code true} if the given Id is from a wolf, {@code false} otherwise.
  182. */
  183. public static boolean isWolf(int npcId)
  184. {
  185. return npcId == 12077;
  186. }
  187. /**
  188. * Checks if is evolved wolf.
  189. * @param npcId the NPC Id to verify.
  190. * @return {@code true} if the given Id is from an evolved wolf, {@code false} otherwise.
  191. */
  192. public static boolean isEvolvedWolf(int npcId)
  193. {
  194. return (npcId == 16030) || (npcId == 16037) || (npcId == 16025) || (npcId == 16041) || (npcId == 16042);
  195. }
  196. /**
  197. * Checks if is sin eater.
  198. * @param npcId the NPC Id to verify.
  199. * @return {@code true} if the given Id is from a Sin Eater, {@code false} otherwise.
  200. */
  201. public static boolean isSinEater(int npcId)
  202. {
  203. return npcId == 12564;
  204. }
  205. /**
  206. * Checks if is hatchling.
  207. * @param npcId the NPC Id to verify.
  208. * @return {@code true} if the given Id is from a hatchling, {@code false} otherwise.
  209. */
  210. public static boolean isHatchling(int npcId)
  211. {
  212. return (npcId > 12310) && (npcId < 12314);
  213. }
  214. /**
  215. * Checks if is strider.
  216. * @param npcId the NPC Id to verify.
  217. * @return {@code true} if the given Id is from a strider, {@code false} otherwise.
  218. */
  219. public static boolean isStrider(int npcId)
  220. {
  221. return ((npcId > 12525) && (npcId < 12529)) || ((npcId > 16037) && (npcId < 16041)) || (npcId == 16068);
  222. }
  223. /**
  224. * Checks if is wyvern.
  225. * @param npcId the NPC Id to verify.
  226. * @return {@code true} if the given Id is from a wyvern, {@code false} otherwise.
  227. */
  228. public static boolean isWyvern(int npcId)
  229. {
  230. return npcId == 12621;
  231. }
  232. /**
  233. * Checks if is baby.
  234. * @param npcId the NPC Id to verify.
  235. * @return {@code true} if the given Id is from a baby pet, {@code false} otherwise.
  236. */
  237. public static boolean isBaby(int npcId)
  238. {
  239. return (npcId > 12779) && (npcId < 12783);
  240. }
  241. /**
  242. * Checks if is improved baby.
  243. * @param npcId the NPC Id to verify.
  244. * @return {@code true} if the given Id is from an improved baby pet, {@code false} otherwise.
  245. */
  246. public static boolean isImprovedBaby(int npcId)
  247. {
  248. return (npcId > 16033) && (npcId < 16037);
  249. }
  250. /**
  251. * Gets the pet items by npc.
  252. * @param npcId the NPC Id to get its summoning item.
  253. * @return an array containing the list of summoning items for the given NPC Id.
  254. */
  255. public static int[] getPetItemsByNpc(int npcId)
  256. {
  257. switch (npcId)
  258. {
  259. case 12077:// Wolf
  260. return new int[]
  261. {
  262. 2375
  263. };
  264. case 16025:// Great Wolf
  265. return new int[]
  266. {
  267. 9882
  268. };
  269. case 16030:// Black Wolf
  270. return new int[]
  271. {
  272. 10163
  273. };
  274. case 16037:// White Great Wolf
  275. return new int[]
  276. {
  277. 10307
  278. };
  279. case 16041:// Fenrir
  280. return new int[]
  281. {
  282. 10426
  283. };
  284. case 16042:// White Fenrir
  285. return new int[]
  286. {
  287. 10611
  288. };
  289. case 12564:// Sin Eater
  290. return new int[]
  291. {
  292. 4425
  293. };
  294. case 12311:// hatchling of wind
  295. case 12312:// hatchling of star
  296. case 12313:// hatchling of twilight
  297. return new int[]
  298. {
  299. 3500,
  300. 3501,
  301. 3502
  302. };
  303. case 12526:// wind strider
  304. case 12527:// Star strider
  305. case 12528:// Twilight strider
  306. case 16038: // red strider of wind
  307. case 16039: // red strider of star
  308. case 16040: // red strider of dusk
  309. case 16068: // Guardian Strider
  310. return new int[]
  311. {
  312. 4422,
  313. 4423,
  314. 4424,
  315. 10308,
  316. 10309,
  317. 10310,
  318. 14819
  319. };
  320. case 12621:// Wyvern
  321. return new int[]
  322. {
  323. 8663
  324. };
  325. case 12780:// Baby Buffalo
  326. case 12782:// Baby Cougar
  327. case 12781:// Baby Kookaburra
  328. return new int[]
  329. {
  330. 6648,
  331. 6649,
  332. 6650
  333. };
  334. case 16034:// Improved Baby Buffalo
  335. case 16036:// Improved Baby Cougar
  336. case 16035:// Improved Baby Kookaburra
  337. return new int[]
  338. {
  339. 10311,
  340. 10312,
  341. 10313
  342. };
  343. // unknown item id.. should never happen
  344. default:
  345. return new int[]
  346. {
  347. 0
  348. };
  349. }
  350. }
  351. /**
  352. * Checks if is mountable.
  353. * @param npcId the NPC Id to verify.
  354. * @return {@code true} if the given Id is from a mountable pet, {@code false} otherwise.
  355. */
  356. public static boolean isMountable(int npcId)
  357. {
  358. return (npcId == 12526 // wind strider
  359. ) || (npcId == 12527 // star strider
  360. ) || (npcId == 12528 // twilight strider
  361. ) || (npcId == 12621 // wyvern
  362. ) || (npcId == 16037 // Great Snow Wolf
  363. ) || (npcId == 16041 // Fenrir Wolf
  364. ) || (npcId == 16042 // White Fenrir Wolf
  365. ) || (npcId == 16038 // Red Wind Strider
  366. ) || (npcId == 16039 // Red Star Strider
  367. ) || (npcId == 16040 // Red Twilight Strider
  368. ) || (npcId == 16068); // Guardian Strider
  369. }
  370. /**
  371. * Gets the single instance of PetDataTable.
  372. * @return this class unique instance.
  373. */
  374. public static PetDataTable getInstance()
  375. {
  376. return SingletonHolder._instance;
  377. }
  378. private static class SingletonHolder
  379. {
  380. protected static final PetDataTable _instance = new PetDataTable();
  381. }
  382. }