2
0

PetDataTable.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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.map.hash.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.model.item.L2Item;
  29. import com.l2jserver.gameserver.model.item.type.L2EtcItemType;
  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. return;
  61. }
  62. Node n = doc.getFirstChild();
  63. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  64. {
  65. if (d.getNodeName().equals("pet"))
  66. {
  67. int npcId = Integer.parseInt(d.getAttributes().getNamedItem("id").getNodeValue());
  68. //index ignored for now
  69. L2PetData data = new L2PetData();
  70. for (Node p = d.getFirstChild(); p != null; p = p.getNextSibling())
  71. {
  72. if (p.getNodeName().equals("set"))
  73. {
  74. NamedNodeMap attrs = p.getAttributes();
  75. String type = attrs.getNamedItem("name").getNodeValue();
  76. if ("food".equals(type))
  77. {
  78. String[] values = attrs.getNamedItem("val").getNodeValue().split(";");
  79. int[] food = new int[values.length];
  80. for (int i = 0; i < values.length; i++)
  81. {
  82. food[i] = Integer.parseInt(values[i]);
  83. }
  84. data.set_food(food);
  85. }
  86. else if ("load".equals(type))
  87. {
  88. data.set_load(Integer.parseInt(attrs.getNamedItem("val").getNodeValue()));
  89. }
  90. else if ("hungry_limit".equals(type))
  91. {
  92. data.set_hungry_limit(Integer.parseInt(attrs.getNamedItem("val").getNodeValue()));
  93. }
  94. //sync_level and evolve ignored
  95. }
  96. else if (p.getNodeName().equals("skills"))
  97. {
  98. for (Node s = p.getFirstChild(); s != null; s = s.getNextSibling())
  99. {
  100. if (s.getNodeName().equals("skill"))
  101. {
  102. NamedNodeMap attrs = s.getAttributes();
  103. int skillId = Integer.parseInt(attrs.getNamedItem("skillId").getNodeValue());
  104. int skillLvl = Integer.parseInt(attrs.getNamedItem("skillLvl").getNodeValue());
  105. int minLvl = Integer.parseInt(attrs.getNamedItem("minLvl").getNodeValue());
  106. data.addNewSkill(skillId, skillLvl, minLvl);
  107. }
  108. }
  109. }
  110. else if (p.getNodeName().equals("stats"))
  111. {
  112. for (Node s = p.getFirstChild(); s != null; s = s.getNextSibling())
  113. {
  114. if (s.getNodeName().equals("stat"))
  115. {
  116. int level = Integer.parseInt(s.getAttributes().getNamedItem("level").getNodeValue());
  117. L2PetLevelData stat = new L2PetLevelData();
  118. for (Node bean = s.getFirstChild(); bean != null; bean = bean.getNextSibling())
  119. {
  120. if (bean.getNodeName().equals("set"))
  121. {
  122. NamedNodeMap attrs = bean.getAttributes();
  123. String type = attrs.getNamedItem("name").getNodeValue();
  124. String value = attrs.getNamedItem("val").getNodeValue();
  125. if ("max_meal".equals(type))
  126. {
  127. stat.setPetMaxFeed(Integer.parseInt(value));
  128. }
  129. else if ("exp".equals(type))
  130. {
  131. stat.setPetMaxExp(Long.parseLong(value));
  132. }
  133. else if ("get_exp_type".equals(type))
  134. {
  135. stat.setOwnerExpTaken(Integer.parseInt(value));
  136. }
  137. else if ("consume_meal_in_battle".equals(type))
  138. {
  139. stat.setPetFeedBattle(Integer.parseInt(value));
  140. }
  141. else if ("consume_meal_in_normal".equals(type))
  142. {
  143. stat.setPetFeedNormal(Integer.parseInt(value));
  144. }
  145. else if ("org_pattack".equals(type))
  146. {
  147. stat.setPetPAtk(Float.parseFloat(value));
  148. }
  149. else if ("org_pdefend".equals(type))
  150. {
  151. stat.setPetPDef(Float.parseFloat(value));
  152. }
  153. else if ("org_mattack".equals(type))
  154. {
  155. stat.setPetMAtk(Float.parseFloat(value));
  156. }
  157. else if ("org_mdefend".equals(type))
  158. {
  159. stat.setPetMDef(Float.parseFloat(value));
  160. }
  161. else if ("org_hp".equals(type))
  162. {
  163. stat.setPetMaxHP(Float.parseFloat(value));
  164. }
  165. else if ("org_mp".equals(type))
  166. {
  167. stat.setPetMaxMP(Float.parseFloat(value));
  168. }
  169. else if ("org_hp_regen".equals(type))
  170. {
  171. stat.setPetRegenHP(Float.parseFloat(value));
  172. }
  173. else if ("org_mp_regen".equals(type))
  174. {
  175. stat.setPetRegenMP(Float.parseFloat(value));
  176. }
  177. else if ("soulshot_count".equals(type))
  178. {
  179. stat.setPetSoulShot((short) Integer.parseInt(value));
  180. }
  181. else if ("spiritshot_count".equals(type))
  182. {
  183. stat.setPetSpiritShot((short) Integer.parseInt(value));
  184. }
  185. }
  186. }
  187. data.addNewStat(stat, level);
  188. }
  189. }
  190. }
  191. }
  192. _petTable.put(npcId, data);
  193. }
  194. }
  195. }
  196. else
  197. _log.warning("Not found PetData.xml");
  198. _log.info(getClass().getSimpleName()+": Loaded " + _petTable.size() + " Pets.");
  199. }
  200. public L2PetLevelData getPetLevelData(int petID, int petLevel)
  201. {
  202. return _petTable.get(petID).getPetLevelData(petLevel);
  203. }
  204. public L2PetData getPetData(int petID)
  205. {
  206. if (!_petTable.contains(petID))
  207. _log.info("Missing pet data for npcid: "+petID);
  208. return _petTable.get(petID);
  209. }
  210. public int getPetMinLevel(int petID)
  211. {
  212. return _petTable.get(petID).getMinLevel();
  213. }
  214. /*
  215. * Pets stuffs
  216. */
  217. public static boolean isWolf(int npcId)
  218. {
  219. return npcId == 12077;
  220. }
  221. public static boolean isEvolvedWolf(int npcId)
  222. {
  223. return npcId == 16030 || npcId == 16037 || npcId == 16025 || npcId == 16041 || npcId == 16042;
  224. }
  225. public static boolean isSinEater(int npcId)
  226. {
  227. return npcId == 12564;
  228. }
  229. public static boolean isHatchling(int npcId)
  230. {
  231. return npcId > 12310 && npcId < 12314;
  232. }
  233. public static boolean isStrider(int npcId)
  234. {
  235. return (npcId > 12525 && npcId < 12529) || (npcId > 16037 && npcId < 16041) || npcId == 16068;
  236. }
  237. public static boolean isWyvern(int npcId)
  238. {
  239. return npcId == 12621;
  240. }
  241. public static boolean isBaby(int npcId)
  242. {
  243. return npcId > 12779 && npcId < 12783;
  244. }
  245. public static boolean isImprovedBaby(int npcId)
  246. {
  247. return npcId > 16033 && npcId < 16037;
  248. }
  249. public static boolean isPetFood(int itemId)
  250. {
  251. switch (itemId)
  252. {
  253. case 2515:
  254. case 4038:
  255. case 5168:
  256. case 5169:
  257. case 6316:
  258. case 7582:
  259. case 9668:
  260. case 10425:
  261. return true;
  262. default:
  263. return false;
  264. }
  265. }
  266. /**
  267. * @param npcId
  268. * @return
  269. * @see L2PetData#getFood()
  270. */
  271. @Deprecated
  272. public static int[] getFoodItemId(int npcId)
  273. {
  274. switch (npcId)
  275. {
  276. case 12077:// Wolf
  277. case 12564://Sin Eater
  278. return new int[] { 2515 };
  279. case 16030:// Great Wolf
  280. case 16025:// Black Wolf
  281. case 16037:// White Great Wolf
  282. case 16041:// Fenrir
  283. case 16042:// White Fenrir
  284. return new int[] { 9668 };
  285. case 12311:// hatchling of wind
  286. case 12312:// hatchling of star
  287. case 12313:// hatchling of twilight
  288. return new int[] { 4038 };
  289. case 12526:// wind strider
  290. case 12527:// Star strider
  291. case 12528:// Twilight strider
  292. case 16038:// red wind strider
  293. case 16039:// red Star strider
  294. case 16040:// red Twilight strider
  295. case 16068:// Guardian Strider
  296. return new int[] { 5168, 5169 };
  297. case 12621: // wyvern
  298. return new int[] { 6316 };
  299. case 12780:// Baby Buffalo
  300. case 12782:// Baby Cougar
  301. case 12781:// Baby Kookaburra
  302. return new int[] { 7582 };
  303. case 16034:// Improved Baby Buffalo
  304. case 16036:// Improved Baby Cougar
  305. case 16035:// Improved Baby Kookaburra
  306. return new int[] { 10425 };
  307. default:
  308. return new int[] { 0 };
  309. }
  310. }
  311. public static boolean isPetItem(int itemId)
  312. {
  313. L2Item item = ItemTable.getInstance().getTemplate(itemId);
  314. if (item != null && item.getItemType() == L2EtcItemType.PET_COLLAR)
  315. return true;
  316. return false;
  317. /*switch (itemId)
  318. {
  319. case 2375: // Wolf
  320. case 3500: // hatchling of wind
  321. case 3501: // hatchling of star
  322. case 3502: // hatchling of twilight
  323. case 4422: // strider of wind
  324. case 4423: // strider of star
  325. case 4424: // strider of dusk
  326. case 4425: // Sin Eater
  327. case 6648: // baby buffalo
  328. case 6649: // baby cougar
  329. case 6650: // baby kookaburra
  330. case 8663: // Wyvern
  331. case 9882: // Great Wolf
  332. case 10163: // Black Wolf
  333. case 10307: // Great Snow Wolf
  334. case 10308: // red strider of wind
  335. case 10309: // red strider of star
  336. case 10310: // red strider of dusk
  337. case 10311: // improved buffalo
  338. case 10312: // improved cougar
  339. case 10313: // improved kookaburra
  340. case 10426: // Fenrir
  341. case 10611: // White Fenrir
  342. case 14819: // Guardian Strider
  343. return true;
  344. default:
  345. return false;
  346. }*/
  347. }
  348. public static int[] getPetItemsByNpc(int npcId)
  349. {
  350. switch (npcId)
  351. {
  352. case 12077:// Wolf
  353. return new int[] { 2375 };
  354. case 16025:// Great Wolf
  355. return new int[] { 9882 };
  356. case 16030:// Black Wolf
  357. return new int[] { 10163 };
  358. case 16037:// White Great Wolf
  359. return new int[] { 10307 };
  360. case 16041:// Fenrir
  361. return new int[] { 10426 };
  362. case 16042:// White Fenrir
  363. return new int[] { 10611 };
  364. case 12564://Sin Eater
  365. return new int[] { 4425 };
  366. case 12311:// hatchling of wind
  367. case 12312:// hatchling of star
  368. case 12313:// hatchling of twilight
  369. return new int[] { 3500, 3501, 3502 };
  370. case 12526:// wind strider
  371. case 12527:// Star strider
  372. case 12528:// Twilight strider
  373. case 16038: // red strider of wind
  374. case 16039: // red strider of star
  375. case 16040: // red strider of dusk
  376. case 16068: // Guardian Strider
  377. return new int[] { 4422, 4423, 4424, 10308, 10309, 10310 , 14819};
  378. case 12621:// Wyvern
  379. return new int[] { 8663 };
  380. case 12780:// Baby Buffalo
  381. case 12782:// Baby Cougar
  382. case 12781:// Baby Kookaburra
  383. return new int[] { 6648, 6649, 6650 };
  384. case 16034:// Improved Baby Buffalo
  385. case 16036:// Improved Baby Cougar
  386. case 16035:// Improved Baby Kookaburra
  387. return new int[] { 10311, 10312, 10313 };
  388. // unknown item id.. should never happen
  389. default:
  390. return new int[] { 0 };
  391. }
  392. }
  393. public static boolean isMountable(int npcId)
  394. {
  395. return npcId == 12526 // wind strider
  396. || npcId == 12527 // star strider
  397. || npcId == 12528 // twilight strider
  398. || npcId == 12621 // wyvern
  399. || npcId == 16037 // Great Snow Wolf
  400. || npcId == 16041 // Fenrir Wolf
  401. || npcId == 16042 // White Fenrir Wolf
  402. || npcId == 16038 // Red Wind Strider
  403. || npcId == 16039 // Red Star Strider
  404. || npcId == 16040 // Red Twilight Strider
  405. || npcId == 16068; // Guardian Strider
  406. }
  407. @SuppressWarnings("synthetic-access")
  408. private static class SingletonHolder
  409. {
  410. protected static final PetDataTable _instance = new PetDataTable();
  411. }
  412. public static void main(String... s)
  413. {
  414. getInstance();
  415. }
  416. }