L2PetDataTable.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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 net.sf.l2j.gameserver.model;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.util.Map;
  20. import java.util.logging.Logger;
  21. import javolution.util.FastMap;
  22. import net.sf.l2j.L2DatabaseFactory;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  24. public class L2PetDataTable
  25. {
  26. private static Logger _log = Logger.getLogger(L2PetInstance.class.getName());
  27. private static L2PetDataTable _instance;
  28. //private static final int[] PET_LIST = { 12077, 12312, 12313, 12311, 12527, 12528, 12526 };
  29. private static Map<Integer, Map<Integer, L2PetData>> _petTable;
  30. public static L2PetDataTable getInstance()
  31. {
  32. if (_instance == null)
  33. _instance = new L2PetDataTable();
  34. return _instance;
  35. }
  36. private L2PetDataTable()
  37. {
  38. _petTable = new FastMap<Integer, Map<Integer, L2PetData>>();
  39. }
  40. public void loadPetsData()
  41. {
  42. Connection con = null;
  43. try
  44. {
  45. con = L2DatabaseFactory.getInstance().getConnection();
  46. PreparedStatement statement = con.prepareStatement("SELECT typeID, level, expMax, hpMax, mpMax, patk, pdef, matk, mdef, acc, evasion, crit, speed, atk_speed, cast_speed, feedMax, feedbattle, feednormal, loadMax, hpregen, mpregen, owner_exp_taken FROM pets_stats");
  47. ResultSet rset = statement.executeQuery();
  48. int petId, petLevel;
  49. while (rset.next())
  50. {
  51. petId = rset.getInt("typeID");
  52. petLevel = rset.getInt("level");
  53. //build the petdata for this level
  54. L2PetData petData = new L2PetData();
  55. petData.setPetID(petId);
  56. petData.setPetLevel(petLevel);
  57. petData.setPetMaxExp(rset.getLong("expMax"));
  58. petData.setPetMaxHP(rset.getInt("hpMax"));
  59. petData.setPetMaxMP(rset.getInt("mpMax"));
  60. petData.setPetPAtk(rset.getInt("patk"));
  61. petData.setPetPDef(rset.getInt("pdef"));
  62. petData.setPetMAtk(rset.getInt("matk"));
  63. petData.setPetMDef(rset.getInt("mdef"));
  64. petData.setPetAccuracy(rset.getInt("acc"));
  65. petData.setPetEvasion(rset.getInt("evasion"));
  66. petData.setPetCritical(rset.getInt("crit"));
  67. petData.setPetSpeed(rset.getInt("speed"));
  68. petData.setPetAtkSpeed(rset.getInt("atk_speed"));
  69. petData.setPetCastSpeed(rset.getInt("cast_speed"));
  70. petData.setPetMaxFeed(rset.getInt("feedMax"));
  71. petData.setPetFeedNormal(rset.getInt("feednormal"));
  72. petData.setPetFeedBattle(rset.getInt("feedbattle"));
  73. petData.setPetMaxLoad(rset.getInt("loadMax"));
  74. petData.setPetRegenHP(rset.getInt("hpregen"));
  75. petData.setPetRegenMP(rset.getInt("mpregen"));
  76. petData.setPetRegenMP(rset.getInt("mpregen"));
  77. petData.setOwnerExpTaken(rset.getFloat("owner_exp_taken"));
  78. // if its the first data for this petid, we initialize its level FastMap
  79. if (!_petTable.containsKey(petId))
  80. _petTable.put(petId, new FastMap<Integer, L2PetData>());
  81. _petTable.get(petId).put(petLevel, petData);
  82. }
  83. rset.close();
  84. statement.close();
  85. }
  86. catch (Exception e)
  87. {
  88. _log.warning("Could not load pets stats: " + e);
  89. }
  90. finally
  91. {
  92. try
  93. {
  94. con.close();
  95. }
  96. catch (Exception e)
  97. {
  98. }
  99. }
  100. }
  101. public void addPetData(L2PetData petData)
  102. {
  103. Map<Integer, L2PetData> h = _petTable.get(petData.getPetID());
  104. if (h == null)
  105. {
  106. Map<Integer, L2PetData> statTable = new FastMap<Integer, L2PetData>();
  107. statTable.put(petData.getPetLevel(), petData);
  108. _petTable.put(petData.getPetID(), statTable);
  109. return;
  110. }
  111. h.put(petData.getPetLevel(), petData);
  112. }
  113. public void addPetData(L2PetData[] petLevelsList)
  114. {
  115. for (L2PetData petData : petLevelsList)
  116. addPetData(petData);
  117. }
  118. public L2PetData getPetData(int petID, int petLevel)
  119. {
  120. //_log.info("Getting id "+petID+" level "+ petLevel);
  121. return _petTable.get(petID).get(petLevel);
  122. }
  123. /**
  124. * Pets stuffs
  125. */
  126. public static boolean isWolf(int npcId)
  127. {
  128. return npcId == 12077;
  129. }
  130. public static boolean isEvolvedWolf(int npcId)
  131. {
  132. return npcId == 16030 || npcId == 16037 || npcId == 16025 || npcId == 16041 || npcId == 16042;
  133. }
  134. public static boolean isSinEater(int npcId)
  135. {
  136. return npcId == 12564;
  137. }
  138. public static boolean isHatchling(int npcId)
  139. {
  140. return npcId > 12310 && npcId < 12314;
  141. }
  142. public static boolean isStrider(int npcId)
  143. {
  144. return (npcId > 12525 && npcId < 12529) || (npcId > 16037 && npcId < 16041);
  145. }
  146. public static boolean isWyvern(int npcId)
  147. {
  148. return npcId == 12621;
  149. }
  150. public static boolean isBaby(int npcId)
  151. {
  152. return npcId > 12779 && npcId < 12783;
  153. }
  154. public static boolean isImprovedBaby(int npcId)
  155. {
  156. return npcId > 16033 && npcId < 16037;
  157. }
  158. public static boolean isPetFood(int itemId)
  159. {
  160. switch (itemId)
  161. {
  162. case 2515:
  163. case 4038:
  164. case 5168:
  165. case 5169:
  166. case 6316:
  167. case 7582:
  168. case 9668:
  169. case 10425:
  170. {
  171. return true;
  172. }
  173. default:
  174. {
  175. return false;
  176. }
  177. }
  178. }
  179. public static boolean isWolfFood(int itemId)
  180. {
  181. return itemId == 2515;
  182. }
  183. public static boolean isEvolvedWolfFood(int itemId)
  184. {
  185. return itemId == 9668;
  186. }
  187. public static boolean isSinEaterFood(int itemId)
  188. {
  189. return itemId == 2515;
  190. }
  191. public static boolean isHatchlingFood(int itemId)
  192. {
  193. return itemId == 4038;
  194. }
  195. public static boolean isStriderFood(int itemId)
  196. {
  197. return itemId == 5168 || itemId == 5169;
  198. }
  199. public static boolean isWyvernFood(int itemId)
  200. {
  201. return itemId == 6316;
  202. }
  203. public static boolean isBabyFood(int itemId)
  204. {
  205. return itemId == 7582;
  206. }
  207. public static boolean isImprovedBabyFood(int itemId)
  208. {
  209. return itemId == 10425;
  210. }
  211. public static int[] getFoodItemId(int npcId)
  212. {
  213. switch (npcId)
  214. {
  215. case 12077:// Wolf
  216. case 12564://Sin Eater
  217. return new int[]{2515};
  218. case 16030:// Great Wolf
  219. case 16025:// Black Wolf
  220. case 16037:// White Great Wolf
  221. case 16041:// Fenrir
  222. case 16042:// White Fenrir
  223. return new int[]{9668};
  224. case 12311:// hatchling of wind
  225. case 12312:// hatchling of star
  226. case 12313:// hatchling of twilight
  227. return new int[]{4038};
  228. case 12526:// wind strider
  229. case 12527:// Star strider
  230. case 12528:// Twilight strider
  231. case 16038:// red wind strider
  232. case 16039:// red Star strider
  233. case 16040:// red Twilight strider
  234. return new int[]{5168,5169};
  235. case 12621: // wyvern
  236. return new int[]{6316};
  237. case 12780:// Baby Buffalo
  238. case 12782:// Baby Cougar
  239. case 12781:// Baby Kookaburra
  240. return new int[]{7582};
  241. case 16034:// Improved Baby Buffalo
  242. case 16036:// Improved Baby Cougar
  243. case 16035:// Improved Baby Kookaburra
  244. return new int[]{10425};
  245. default:
  246. return new int[]{0};
  247. }
  248. }
  249. public static boolean isPetItem(int itemId)
  250. {
  251. switch (itemId)
  252. {
  253. case 2375: // Wolf
  254. case 3500: // hatchling of wind
  255. case 3501: // hatchling of star
  256. case 3502: // hatchling of twilight
  257. case 4422: // strider of wind
  258. case 4423: // strider of star
  259. case 4424: // strider of dusk
  260. case 4425: // Sin Eater
  261. case 6648: // baby buffalo
  262. case 6649: // baby cougar
  263. case 6650: // baby kookaburra
  264. case 8663: // Wyvern
  265. case 9882: // Great Wolf
  266. case 10163: // Black Wolf
  267. case 10307: // Great Snow Wolf
  268. case 10308: // red strider of wind
  269. case 10309: // red strider of star
  270. case 10310: // red strider of dusk
  271. case 10311: // improved buffalo
  272. case 10312: // improved cougar
  273. case 10313: // improved kookaburra
  274. case 10426: // Fenrir
  275. case 10611: // White Fenrir
  276. {
  277. return true;
  278. }
  279. default:
  280. {
  281. return false;
  282. }
  283. }
  284. }
  285. public static int[] getPetItemsByNpc(int npcId)
  286. {
  287. switch (npcId)
  288. {
  289. case 12077:// Wolf
  290. return new int[]
  291. {
  292. 2375
  293. };
  294. case 16025:// Great Wolf
  295. return new int[]
  296. {
  297. 9882
  298. };
  299. case 16030:// Black Wolf
  300. return new int[]
  301. {
  302. 10163
  303. };
  304. case 16037:// White Great Wolf
  305. return new int[]
  306. {
  307. 10307
  308. };
  309. case 16041:// Fenrir
  310. return new int[]
  311. {
  312. 10426
  313. };
  314. case 16042:// White Fenrir
  315. return new int[]
  316. {
  317. 10611
  318. };
  319. case 12564://Sin Eater
  320. return new int[]
  321. {
  322. 4425
  323. };
  324. case 12311:// hatchling of wind
  325. case 12312:// hatchling of star
  326. case 12313:// hatchling of twilight
  327. return new int[]
  328. {
  329. 3500, 3501, 3502
  330. };
  331. case 12526:// wind strider
  332. case 12527:// Star strider
  333. case 12528:// Twilight strider
  334. case 16038: // red strider of wind
  335. case 16039: // red strider of star
  336. case 16040: // red strider of dusk
  337. return new int[]
  338. {
  339. 4422, 4423, 4424, 10308, 10309, 10310
  340. };
  341. case 12621:// Wyvern
  342. return new int[]
  343. {
  344. 8663
  345. };
  346. case 12780:// Baby Buffalo
  347. case 12782:// Baby Cougar
  348. case 12781:// Baby Kookaburra
  349. return new int[]
  350. {
  351. 6648, 6649, 6650
  352. };
  353. case 16034:// Improved Baby Buffalo
  354. case 16036:// Improved Baby Cougar
  355. case 16035:// Improved Baby Kookaburra
  356. return new int[]
  357. {
  358. 10311, 10312, 10313
  359. };
  360. // unknown item id.. should never happen
  361. default:
  362. return new int[]
  363. {
  364. 0
  365. };
  366. }
  367. }
  368. public static boolean isMountable(int npcId)
  369. {
  370. return npcId == 12526 // wind strider
  371. || npcId == 12527 // star strider
  372. || npcId == 12528 // twilight strider
  373. || npcId == 12621 // wyvern
  374. || npcId == 16037 // Great Snow Wolf
  375. || npcId == 16041 // Fenrir Wolf
  376. || npcId == 16042 // White Fenrir Wolf
  377. || npcId == 16038 // Red Wind Strider
  378. || npcId == 16039 // Red Star Strider
  379. || npcId == 16040 // Red Twilight Strider
  380. || npcId == 16040; // horse
  381. }
  382. }