L2PetDataTable.java 10 KB

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