L2PetDataTable.java 11 KB

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