2
0

PetDataTable.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.datatables;
  16. import gnu.trove.TIntObjectHashMap;
  17. import java.io.File;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import javax.xml.parsers.DocumentBuilderFactory;
  21. import org.w3c.dom.Document;
  22. import org.w3c.dom.NamedNodeMap;
  23. import org.w3c.dom.Node;
  24. import com.l2jserver.Config;
  25. import com.l2jserver.gameserver.model.L2PetData;
  26. import com.l2jserver.gameserver.model.L2PetLevelData;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  28. import com.l2jserver.gameserver.templates.item.L2EtcItemType;
  29. import com.l2jserver.gameserver.templates.item.L2Item;
  30. public class PetDataTable
  31. {
  32. private static Logger _log = Logger.getLogger(L2PetInstance.class.getName());
  33. private static TIntObjectHashMap<L2PetData> _petTable;
  34. public static PetDataTable getInstance()
  35. {
  36. return SingletonHolder._instance;
  37. }
  38. private PetDataTable()
  39. {
  40. _petTable = new TIntObjectHashMap<L2PetData>();
  41. load();
  42. }
  43. public void load()
  44. {
  45. _petTable.clear();
  46. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  47. factory.setValidating(false);
  48. factory.setIgnoringComments(true);
  49. File file = new File(Config.DATAPACK_ROOT, "data/stats/npc/PetData.xml");
  50. Document doc = null;
  51. if (file.exists())
  52. {
  53. try
  54. {
  55. doc = factory.newDocumentBuilder().parse(file);
  56. }
  57. catch (Exception e)
  58. {
  59. _log.log(Level.WARNING, "Could not parse PetData.xml file: " + e.getMessage(), e);
  60. }
  61. Node n = doc.getFirstChild();
  62. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  63. {
  64. if (d.getNodeName().equals("pet"))
  65. {
  66. int npcId = Integer.parseInt(d.getAttributes().getNamedItem("id").getNodeValue());
  67. //index ignored for now
  68. L2PetData data = new L2PetData();
  69. for (Node p = d.getFirstChild(); p != null; p = p.getNextSibling())
  70. {
  71. if (p.getNodeName().equals("set"))
  72. {
  73. NamedNodeMap attrs = p.getAttributes();
  74. String type = attrs.getNamedItem("name").getNodeValue();
  75. if ("food".equals(type))
  76. {
  77. String[] values = attrs.getNamedItem("val").getNodeValue().split(";");
  78. int[] food = new int[values.length];
  79. for (int i = 0; i < values.length; i++)
  80. {
  81. food[i] = Integer.parseInt(values[i]);
  82. }
  83. data.set_food(food);
  84. }
  85. else if ("load".equals(type))
  86. {
  87. data.set_load(Integer.parseInt(attrs.getNamedItem("val").getNodeValue()));
  88. }
  89. else if ("hungry_limit".equals(type))
  90. {
  91. data.set_hungry_limit(Integer.parseInt(attrs.getNamedItem("val").getNodeValue()));
  92. }
  93. //sync_level and evolve ignored
  94. }
  95. else if (p.getNodeName().equals("skills"))
  96. {
  97. for (Node s = p.getFirstChild(); s != null; s = s.getNextSibling())
  98. {
  99. if (s.getNodeName().equals("skill"))
  100. {
  101. NamedNodeMap attrs = s.getAttributes();
  102. int skillId = Integer.parseInt(attrs.getNamedItem("skillId").getNodeValue());
  103. int skillLvl = Integer.parseInt(attrs.getNamedItem("skillLvl").getNodeValue());
  104. int minLvl = Integer.parseInt(attrs.getNamedItem("minLvl").getNodeValue());
  105. data.addNewSkill(skillId, skillLvl, minLvl);
  106. }
  107. }
  108. }
  109. else if (p.getNodeName().equals("stats"))
  110. {
  111. for (Node s = p.getFirstChild(); s != null; s = s.getNextSibling())
  112. {
  113. if (s.getNodeName().equals("stat"))
  114. {
  115. int level = Integer.parseInt(s.getAttributes().getNamedItem("level").getNodeValue());
  116. L2PetLevelData stat = new L2PetLevelData();
  117. for (Node bean = s.getFirstChild(); bean != null; bean = bean.getNextSibling())
  118. {
  119. if (bean.getNodeName().equals("set"))
  120. {
  121. NamedNodeMap attrs = bean.getAttributes();
  122. String type = attrs.getNamedItem("name").getNodeValue();
  123. String value = attrs.getNamedItem("val").getNodeValue();
  124. if ("exp".equals(type))
  125. {
  126. stat.setPetMaxExp(Long.parseLong(value));
  127. }
  128. else if ("get_exp_type".equals(type))
  129. {
  130. stat.setOwnerExpTaken(Integer.parseInt(value));
  131. }
  132. else if ("consume_meal_in_battle".equals(type))
  133. {
  134. stat.setPetFeedBattle(Integer.parseInt(value));
  135. }
  136. else if ("consume_meal_in_normal".equals(type))
  137. {
  138. stat.setPetFeedNormal(Integer.parseInt(value));
  139. }
  140. else if ("max_meal".equals(type))
  141. {
  142. stat.setPetMaxFeed(Integer.parseInt(value));
  143. }
  144. else if ("soulshot_count".equals(type))
  145. {
  146. stat.setPetSoulShot((short) Integer.parseInt(value));
  147. }
  148. else if ("spiritshot_count".equals(type))
  149. {
  150. stat.setPetSpiritShot((short) Integer.parseInt(value));
  151. }
  152. else if ("hp".equals(type))
  153. {
  154. stat.setPetMaxHP(Integer.parseInt(value));
  155. }
  156. else if ("mp".equals(type))
  157. {
  158. stat.setPetMaxMP(Integer.parseInt(value));
  159. }
  160. else if ("pdef".equals(type))
  161. {
  162. stat.setPetPDef(Integer.parseInt(value));
  163. }
  164. else if ("mdef".equals(type))
  165. {
  166. stat.setPetMDef(Integer.parseInt(value));
  167. }
  168. else if ("patk".equals(type))
  169. {
  170. stat.setPetPAtk(Integer.parseInt(value));
  171. }
  172. else if ("matk".equals(type))
  173. {
  174. stat.setPetMAtk(Integer.parseInt(value));
  175. }
  176. else if ("hpreg".equals(type))
  177. {
  178. stat.setPetRegenHP(Integer.parseInt(value));
  179. }
  180. else if ("mpreg".equals(type))
  181. {
  182. stat.setPetRegenMP(Integer.parseInt(value));
  183. }
  184. }
  185. }
  186. data.addNewStat(stat, level);
  187. }
  188. }
  189. }
  190. }
  191. _petTable.put(npcId, data);
  192. }
  193. }
  194. }
  195. else
  196. _log.warning("Not found PetData.xml");
  197. _log.info(getClass().getSimpleName()+": Loaded " + _petTable.size() + " Pets.");
  198. }
  199. public L2PetLevelData getPetLevelData(int petID, int petLevel)
  200. {
  201. return _petTable.get(petID).getPetLevelData(petLevel);
  202. }
  203. public L2PetData getPetData(int petID)
  204. {
  205. if (!_petTable.contains(petID))
  206. _log.info("Missing pet data for npcid: "+petID);
  207. return _petTable.get(petID);
  208. }
  209. public int getPetMinLevel(int petID)
  210. {
  211. return _petTable.get(petID).getMinLevel();
  212. }
  213. /*
  214. * Pets stuffs
  215. */
  216. public static boolean isWolf(int npcId)
  217. {
  218. return npcId == 12077;
  219. }
  220. public static boolean isEvolvedWolf(int npcId)
  221. {
  222. return npcId == 16030 || npcId == 16037 || npcId == 16025 || npcId == 16041 || npcId == 16042;
  223. }
  224. public static boolean isSinEater(int npcId)
  225. {
  226. return npcId == 12564;
  227. }
  228. public static boolean isHatchling(int npcId)
  229. {
  230. return npcId > 12310 && npcId < 12314;
  231. }
  232. public static boolean isStrider(int npcId)
  233. {
  234. return (npcId > 12525 && npcId < 12529) || (npcId > 16037 && npcId < 16041) || npcId == 16068;
  235. }
  236. public static boolean isWyvern(int npcId)
  237. {
  238. return npcId == 12621;
  239. }
  240. public static boolean isBaby(int npcId)
  241. {
  242. return npcId > 12779 && npcId < 12783;
  243. }
  244. public static boolean isImprovedBaby(int npcId)
  245. {
  246. return npcId > 16033 && npcId < 16037;
  247. }
  248. public static boolean isPetFood(int itemId)
  249. {
  250. switch (itemId)
  251. {
  252. case 2515:
  253. case 4038:
  254. case 5168:
  255. case 5169:
  256. case 6316:
  257. case 7582:
  258. case 9668:
  259. case 10425:
  260. return true;
  261. default:
  262. return false;
  263. }
  264. }
  265. /**
  266. * @see L2PetData#getFood()
  267. *
  268. */
  269. @Deprecated
  270. public static int[] getFoodItemId(int npcId)
  271. {
  272. switch (npcId)
  273. {
  274. case 12077:// Wolf
  275. case 12564://Sin Eater
  276. return new int[] { 2515 };
  277. case 16030:// Great Wolf
  278. case 16025:// Black Wolf
  279. case 16037:// White Great Wolf
  280. case 16041:// Fenrir
  281. case 16042:// White Fenrir
  282. return new int[] { 9668 };
  283. case 12311:// hatchling of wind
  284. case 12312:// hatchling of star
  285. case 12313:// hatchling of twilight
  286. return new int[] { 4038 };
  287. case 12526:// wind strider
  288. case 12527:// Star strider
  289. case 12528:// Twilight strider
  290. case 16038:// red wind strider
  291. case 16039:// red Star strider
  292. case 16040:// red Twilight strider
  293. case 16068:// Guardian Strider
  294. return new int[] { 5168, 5169 };
  295. case 12621: // wyvern
  296. return new int[] { 6316 };
  297. case 12780:// Baby Buffalo
  298. case 12782:// Baby Cougar
  299. case 12781:// Baby Kookaburra
  300. return new int[] { 7582 };
  301. case 16034:// Improved Baby Buffalo
  302. case 16036:// Improved Baby Cougar
  303. case 16035:// Improved Baby Kookaburra
  304. return new int[] { 10425 };
  305. default:
  306. return new int[] { 0 };
  307. }
  308. }
  309. public static boolean isPetItem(int itemId)
  310. {
  311. L2Item item = ItemTable.getInstance().getTemplate(itemId);
  312. if (item != null && item.getItemType() == L2EtcItemType.PET_COLLAR)
  313. return true;
  314. return false;
  315. /*switch (itemId)
  316. {
  317. case 2375: // Wolf
  318. case 3500: // hatchling of wind
  319. case 3501: // hatchling of star
  320. case 3502: // hatchling of twilight
  321. case 4422: // strider of wind
  322. case 4423: // strider of star
  323. case 4424: // strider of dusk
  324. case 4425: // Sin Eater
  325. case 6648: // baby buffalo
  326. case 6649: // baby cougar
  327. case 6650: // baby kookaburra
  328. case 8663: // Wyvern
  329. case 9882: // Great Wolf
  330. case 10163: // Black Wolf
  331. case 10307: // Great Snow Wolf
  332. case 10308: // red strider of wind
  333. case 10309: // red strider of star
  334. case 10310: // red strider of dusk
  335. case 10311: // improved buffalo
  336. case 10312: // improved cougar
  337. case 10313: // improved kookaburra
  338. case 10426: // Fenrir
  339. case 10611: // White Fenrir
  340. case 14819: // Guardian Strider
  341. return true;
  342. default:
  343. return false;
  344. }*/
  345. }
  346. public static int[] getPetItemsByNpc(int npcId)
  347. {
  348. switch (npcId)
  349. {
  350. case 12077:// Wolf
  351. return new int[] { 2375 };
  352. case 16025:// Great Wolf
  353. return new int[] { 9882 };
  354. case 16030:// Black Wolf
  355. return new int[] { 10163 };
  356. case 16037:// White Great Wolf
  357. return new int[] { 10307 };
  358. case 16041:// Fenrir
  359. return new int[] { 10426 };
  360. case 16042:// White Fenrir
  361. return new int[] { 10611 };
  362. case 12564://Sin Eater
  363. return new int[] { 4425 };
  364. case 12311:// hatchling of wind
  365. case 12312:// hatchling of star
  366. case 12313:// hatchling of twilight
  367. return new int[] { 3500, 3501, 3502 };
  368. case 12526:// wind strider
  369. case 12527:// Star strider
  370. case 12528:// Twilight strider
  371. case 16038: // red strider of wind
  372. case 16039: // red strider of star
  373. case 16040: // red strider of dusk
  374. case 16068: // Guardian Strider
  375. return new int[] { 4422, 4423, 4424, 10308, 10309, 10310 , 14819};
  376. case 12621:// Wyvern
  377. return new int[] { 8663 };
  378. case 12780:// Baby Buffalo
  379. case 12782:// Baby Cougar
  380. case 12781:// Baby Kookaburra
  381. return new int[] { 6648, 6649, 6650 };
  382. case 16034:// Improved Baby Buffalo
  383. case 16036:// Improved Baby Cougar
  384. case 16035:// Improved Baby Kookaburra
  385. return new int[] { 10311, 10312, 10313 };
  386. // unknown item id.. should never happen
  387. default:
  388. return new int[] { 0 };
  389. }
  390. }
  391. public static boolean isMountable(int npcId)
  392. {
  393. return npcId == 12526 // wind strider
  394. || npcId == 12527 // star strider
  395. || npcId == 12528 // twilight strider
  396. || npcId == 12621 // wyvern
  397. || npcId == 16037 // Great Snow Wolf
  398. || npcId == 16041 // Fenrir Wolf
  399. || npcId == 16042 // White Fenrir Wolf
  400. || npcId == 16038 // Red Wind Strider
  401. || npcId == 16039 // Red Star Strider
  402. || npcId == 16040 // Red Twilight Strider
  403. || npcId == 16068; // Guardian Strider
  404. }
  405. @SuppressWarnings("synthetic-access")
  406. private static class SingletonHolder
  407. {
  408. protected static final PetDataTable _instance = new PetDataTable();
  409. }
  410. public static void main(String... s)
  411. {
  412. getInstance();
  413. }
  414. }