PetDataTable.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. parseDatapackFile("data/stats/npc/PetData.xml");
  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. // index ignored for now
  61. L2PetData data = new L2PetData();
  62. for (Node p = d.getFirstChild(); p != null; p = p.getNextSibling())
  63. {
  64. if (p.getNodeName().equals("set"))
  65. {
  66. attrs = p.getAttributes();
  67. String type = attrs.getNamedItem("name").getNodeValue();
  68. if ("food".equals(type))
  69. {
  70. for (String foodId : attrs.getNamedItem("val").getNodeValue().split(";"))
  71. {
  72. data.addFood(Integer.valueOf(foodId));
  73. }
  74. }
  75. else if ("load".equals(type))
  76. {
  77. data.setLoad(parseInt(attrs, "val"));
  78. }
  79. else if ("hungry_limit".equals(type))
  80. {
  81. data.setHungryLimit(parseInt(attrs, "val"));
  82. }
  83. // sync_level and evolve ignored
  84. }
  85. else if (p.getNodeName().equals("skills"))
  86. {
  87. for (Node s = p.getFirstChild(); s != null; s = s.getNextSibling())
  88. {
  89. if (s.getNodeName().equals("skill"))
  90. {
  91. attrs = s.getAttributes();
  92. data.addNewSkill(parseInt(attrs, "skillId"), parseInt(attrs, "skillLvl"), parseInt(attrs, "minLvl"));
  93. }
  94. }
  95. }
  96. else if (p.getNodeName().equals("stats"))
  97. {
  98. for (Node s = p.getFirstChild(); s != null; s = s.getNextSibling())
  99. {
  100. if (s.getNodeName().equals("stat"))
  101. {
  102. final int level = Integer.parseInt(s.getAttributes().getNamedItem("level").getNodeValue());
  103. final StatsSet set = new StatsSet();
  104. for (Node bean = s.getFirstChild(); bean != null; bean = bean.getNextSibling())
  105. {
  106. if (bean.getNodeName().equals("set"))
  107. {
  108. attrs = bean.getAttributes();
  109. set.set(attrs.getNamedItem("name").getNodeValue(), attrs.getNamedItem("val").getNodeValue());
  110. }
  111. }
  112. data.addNewStat(level, new L2PetLevelData(set));
  113. }
  114. }
  115. }
  116. }
  117. _pets.put(npcId, data);
  118. }
  119. }
  120. }
  121. /**
  122. * Gets the pet level data.
  123. * @param petId the pet Id.
  124. * @param petLevel the pet level.
  125. * @return the pet's parameters for the given Id and level.
  126. */
  127. public L2PetLevelData getPetLevelData(int petId, int petLevel)
  128. {
  129. final L2PetData pd = getPetData(petId);
  130. if (pd != null)
  131. {
  132. return pd.getPetLevelData(petLevel);
  133. }
  134. return null;
  135. }
  136. /**
  137. * Gets the pet data.
  138. * @param petId the pet Id.
  139. * @return the pet data
  140. */
  141. public L2PetData getPetData(int petId)
  142. {
  143. if (!_pets.containsKey(petId))
  144. {
  145. _log.info(getClass().getSimpleName() + ": Missing pet data for npcid: " + petId);
  146. }
  147. return _pets.get(petId);
  148. }
  149. /**
  150. * Gets the pet min level.
  151. * @param petId the pet Id.
  152. * @return the pet min level
  153. */
  154. public int getPetMinLevel(int petId)
  155. {
  156. return _pets.get(petId).getMinLevel();
  157. }
  158. /**
  159. * Checks if is wolf.
  160. * @param npcId the NPC Id to verify.
  161. * @return {@code true} if the given Id is from a wolf, {@code false} otherwise.
  162. */
  163. public static boolean isWolf(int npcId)
  164. {
  165. return npcId == 12077;
  166. }
  167. /**
  168. * Checks if is evolved wolf.
  169. * @param npcId the NPC Id to verify.
  170. * @return {@code true} if the given Id is from an evolved wolf, {@code false} otherwise.
  171. */
  172. public static boolean isEvolvedWolf(int npcId)
  173. {
  174. return (npcId == 16030) || (npcId == 16037) || (npcId == 16025) || (npcId == 16041) || (npcId == 16042);
  175. }
  176. /**
  177. * Checks if is sin eater.
  178. * @param npcId the NPC Id to verify.
  179. * @return {@code true} if the given Id is from a Sin Eater, {@code false} otherwise.
  180. */
  181. public static boolean isSinEater(int npcId)
  182. {
  183. return npcId == 12564;
  184. }
  185. /**
  186. * Checks if is hatchling.
  187. * @param npcId the NPC Id to verify.
  188. * @return {@code true} if the given Id is from a hatchling, {@code false} otherwise.
  189. */
  190. public static boolean isHatchling(int npcId)
  191. {
  192. return (npcId > 12310) && (npcId < 12314);
  193. }
  194. /**
  195. * Checks if is strider.
  196. * @param npcId the NPC Id to verify.
  197. * @return {@code true} if the given Id is from a strider, {@code false} otherwise.
  198. */
  199. public static boolean isStrider(int npcId)
  200. {
  201. return ((npcId > 12525) && (npcId < 12529)) || ((npcId > 16037) && (npcId < 16041)) || (npcId == 16068);
  202. }
  203. /**
  204. * Checks if is wyvern.
  205. * @param npcId the NPC Id to verify.
  206. * @return {@code true} if the given Id is from a wyvern, {@code false} otherwise.
  207. */
  208. public static boolean isWyvern(int npcId)
  209. {
  210. return npcId == 12621;
  211. }
  212. /**
  213. * Checks if is baby.
  214. * @param npcId the NPC Id to verify.
  215. * @return {@code true} if the given Id is from a baby pet, {@code false} otherwise.
  216. */
  217. public static boolean isBaby(int npcId)
  218. {
  219. return (npcId > 12779) && (npcId < 12783);
  220. }
  221. /**
  222. * Checks if is improved baby.
  223. * @param npcId the NPC Id to verify.
  224. * @return {@code true} if the given Id is from an improved baby pet, {@code false} otherwise.
  225. */
  226. public static boolean isImprovedBaby(int npcId)
  227. {
  228. return (npcId > 16033) && (npcId < 16037);
  229. }
  230. /**
  231. * Gets the pet items by npc.
  232. * @param npcId the NPC Id to get its summoning item.
  233. * @return an array containing the list of summoning items for the given NPC Id.
  234. */
  235. public static int[] getPetItemsByNpc(int npcId)
  236. {
  237. switch (npcId)
  238. {
  239. case 12077:// Wolf
  240. return new int[]
  241. {
  242. 2375
  243. };
  244. case 16025:// Great Wolf
  245. return new int[]
  246. {
  247. 9882
  248. };
  249. case 16030:// Black Wolf
  250. return new int[]
  251. {
  252. 10163
  253. };
  254. case 16037:// White Great Wolf
  255. return new int[]
  256. {
  257. 10307
  258. };
  259. case 16041:// Fenrir
  260. return new int[]
  261. {
  262. 10426
  263. };
  264. case 16042:// White Fenrir
  265. return new int[]
  266. {
  267. 10611
  268. };
  269. case 12564:// Sin Eater
  270. return new int[]
  271. {
  272. 4425
  273. };
  274. case 12311:// hatchling of wind
  275. case 12312:// hatchling of star
  276. case 12313:// hatchling of twilight
  277. return new int[]
  278. {
  279. 3500,
  280. 3501,
  281. 3502
  282. };
  283. case 12526:// wind strider
  284. case 12527:// Star strider
  285. case 12528:// Twilight strider
  286. case 16038: // red strider of wind
  287. case 16039: // red strider of star
  288. case 16040: // red strider of dusk
  289. case 16068: // Guardian Strider
  290. return new int[]
  291. {
  292. 4422,
  293. 4423,
  294. 4424,
  295. 10308,
  296. 10309,
  297. 10310,
  298. 14819
  299. };
  300. case 12621:// Wyvern
  301. return new int[]
  302. {
  303. 8663
  304. };
  305. case 12780:// Baby Buffalo
  306. case 12782:// Baby Cougar
  307. case 12781:// Baby Kookaburra
  308. return new int[]
  309. {
  310. 6648,
  311. 6649,
  312. 6650
  313. };
  314. case 16034:// Improved Baby Buffalo
  315. case 16036:// Improved Baby Cougar
  316. case 16035:// Improved Baby Kookaburra
  317. return new int[]
  318. {
  319. 10311,
  320. 10312,
  321. 10313
  322. };
  323. // unknown item id.. should never happen
  324. default:
  325. return new int[]
  326. {
  327. 0
  328. };
  329. }
  330. }
  331. /**
  332. * Checks if is mountable.
  333. * @param npcId the NPC Id to verify.
  334. * @return {@code true} if the given Id is from a mountable pet, {@code false} otherwise.
  335. */
  336. public static boolean isMountable(int npcId)
  337. {
  338. return (npcId == 12526 // wind strider
  339. ) || (npcId == 12527 // star strider
  340. ) || (npcId == 12528 // twilight strider
  341. ) || (npcId == 12621 // wyvern
  342. ) || (npcId == 16037 // Great Snow Wolf
  343. ) || (npcId == 16041 // Fenrir Wolf
  344. ) || (npcId == 16042 // White Fenrir Wolf
  345. ) || (npcId == 16038 // Red Wind Strider
  346. ) || (npcId == 16039 // Red Star Strider
  347. ) || (npcId == 16040 // Red Twilight Strider
  348. ) || (npcId == 16068); // Guardian Strider
  349. }
  350. /**
  351. * Gets the single instance of PetDataTable.
  352. * @return this class unique instance.
  353. */
  354. public static PetDataTable getInstance()
  355. {
  356. return SingletonHolder._instance;
  357. }
  358. private static class SingletonHolder
  359. {
  360. protected static final PetDataTable _instance = new PetDataTable();
  361. }
  362. }