PetDataTable.java 10 KB

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