AbstractRefinePacket.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.clientpackets;
  20. import java.util.Arrays;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.enums.ItemLocation;
  25. import com.l2jserver.gameserver.enums.PrivateStoreType;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.items.L2Armor;
  28. import com.l2jserver.gameserver.model.items.L2Item;
  29. import com.l2jserver.gameserver.model.items.L2Weapon;
  30. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  31. import com.l2jserver.gameserver.model.items.type.CrystalType;
  32. import com.l2jserver.gameserver.network.SystemMessageId;
  33. public abstract class AbstractRefinePacket extends L2GameClientPacket
  34. {
  35. public static final int GRADE_NONE = 0;
  36. public static final int GRADE_MID = 1;
  37. public static final int GRADE_HIGH = 2;
  38. public static final int GRADE_TOP = 3;
  39. public static final int GRADE_ACC = 4; // Accessory LS
  40. protected static final int GEMSTONE_D = 2130;
  41. protected static final int GEMSTONE_C = 2131;
  42. protected static final int GEMSTONE_B = 2132;
  43. private static final Map<Integer, LifeStone> _lifeStones = new HashMap<>();
  44. protected static final class LifeStone
  45. {
  46. // lifestone level to player level table
  47. private static final int[] LEVELS =
  48. {
  49. 46,
  50. 49,
  51. 52,
  52. 55,
  53. 58,
  54. 61,
  55. 64,
  56. 67,
  57. 70,
  58. 76,
  59. 80,
  60. 82,
  61. 84,
  62. 85
  63. };
  64. private final int _grade;
  65. private final int _level;
  66. public LifeStone(int grade, int level)
  67. {
  68. _grade = grade;
  69. _level = level;
  70. }
  71. public final int getLevel()
  72. {
  73. return _level;
  74. }
  75. public final int getGrade()
  76. {
  77. return _grade;
  78. }
  79. public final int getPlayerLevel()
  80. {
  81. return LEVELS[_level];
  82. }
  83. }
  84. static
  85. {
  86. // itemId, (LS grade, LS level)
  87. _lifeStones.put(8723, new LifeStone(GRADE_NONE, 0));
  88. _lifeStones.put(8724, new LifeStone(GRADE_NONE, 1));
  89. _lifeStones.put(8725, new LifeStone(GRADE_NONE, 2));
  90. _lifeStones.put(8726, new LifeStone(GRADE_NONE, 3));
  91. _lifeStones.put(8727, new LifeStone(GRADE_NONE, 4));
  92. _lifeStones.put(8728, new LifeStone(GRADE_NONE, 5));
  93. _lifeStones.put(8729, new LifeStone(GRADE_NONE, 6));
  94. _lifeStones.put(8730, new LifeStone(GRADE_NONE, 7));
  95. _lifeStones.put(8731, new LifeStone(GRADE_NONE, 8));
  96. _lifeStones.put(8732, new LifeStone(GRADE_NONE, 9));
  97. _lifeStones.put(8733, new LifeStone(GRADE_MID, 0));
  98. _lifeStones.put(8734, new LifeStone(GRADE_MID, 1));
  99. _lifeStones.put(8735, new LifeStone(GRADE_MID, 2));
  100. _lifeStones.put(8736, new LifeStone(GRADE_MID, 3));
  101. _lifeStones.put(8737, new LifeStone(GRADE_MID, 4));
  102. _lifeStones.put(8738, new LifeStone(GRADE_MID, 5));
  103. _lifeStones.put(8739, new LifeStone(GRADE_MID, 6));
  104. _lifeStones.put(8740, new LifeStone(GRADE_MID, 7));
  105. _lifeStones.put(8741, new LifeStone(GRADE_MID, 8));
  106. _lifeStones.put(8742, new LifeStone(GRADE_MID, 9));
  107. _lifeStones.put(8743, new LifeStone(GRADE_HIGH, 0));
  108. _lifeStones.put(8744, new LifeStone(GRADE_HIGH, 1));
  109. _lifeStones.put(8745, new LifeStone(GRADE_HIGH, 2));
  110. _lifeStones.put(8746, new LifeStone(GRADE_HIGH, 3));
  111. _lifeStones.put(8747, new LifeStone(GRADE_HIGH, 4));
  112. _lifeStones.put(8748, new LifeStone(GRADE_HIGH, 5));
  113. _lifeStones.put(8749, new LifeStone(GRADE_HIGH, 6));
  114. _lifeStones.put(8750, new LifeStone(GRADE_HIGH, 7));
  115. _lifeStones.put(8751, new LifeStone(GRADE_HIGH, 8));
  116. _lifeStones.put(8752, new LifeStone(GRADE_HIGH, 9));
  117. _lifeStones.put(8753, new LifeStone(GRADE_TOP, 0));
  118. _lifeStones.put(8754, new LifeStone(GRADE_TOP, 1));
  119. _lifeStones.put(8755, new LifeStone(GRADE_TOP, 2));
  120. _lifeStones.put(8756, new LifeStone(GRADE_TOP, 3));
  121. _lifeStones.put(8757, new LifeStone(GRADE_TOP, 4));
  122. _lifeStones.put(8758, new LifeStone(GRADE_TOP, 5));
  123. _lifeStones.put(8759, new LifeStone(GRADE_TOP, 6));
  124. _lifeStones.put(8760, new LifeStone(GRADE_TOP, 7));
  125. _lifeStones.put(8761, new LifeStone(GRADE_TOP, 8));
  126. _lifeStones.put(8762, new LifeStone(GRADE_TOP, 9));
  127. _lifeStones.put(9573, new LifeStone(GRADE_NONE, 10));
  128. _lifeStones.put(9574, new LifeStone(GRADE_MID, 10));
  129. _lifeStones.put(9575, new LifeStone(GRADE_HIGH, 10));
  130. _lifeStones.put(9576, new LifeStone(GRADE_TOP, 10));
  131. _lifeStones.put(10483, new LifeStone(GRADE_NONE, 11));
  132. _lifeStones.put(10484, new LifeStone(GRADE_MID, 11));
  133. _lifeStones.put(10485, new LifeStone(GRADE_HIGH, 11));
  134. _lifeStones.put(10486, new LifeStone(GRADE_TOP, 11));
  135. _lifeStones.put(12754, new LifeStone(GRADE_ACC, 0));
  136. _lifeStones.put(12755, new LifeStone(GRADE_ACC, 1));
  137. _lifeStones.put(12756, new LifeStone(GRADE_ACC, 2));
  138. _lifeStones.put(12757, new LifeStone(GRADE_ACC, 3));
  139. _lifeStones.put(12758, new LifeStone(GRADE_ACC, 4));
  140. _lifeStones.put(12759, new LifeStone(GRADE_ACC, 5));
  141. _lifeStones.put(12760, new LifeStone(GRADE_ACC, 6));
  142. _lifeStones.put(12761, new LifeStone(GRADE_ACC, 7));
  143. _lifeStones.put(12762, new LifeStone(GRADE_ACC, 8));
  144. _lifeStones.put(12763, new LifeStone(GRADE_ACC, 9));
  145. _lifeStones.put(12821, new LifeStone(GRADE_ACC, 10));
  146. _lifeStones.put(12822, new LifeStone(GRADE_ACC, 11));
  147. _lifeStones.put(12840, new LifeStone(GRADE_ACC, 0));
  148. _lifeStones.put(12841, new LifeStone(GRADE_ACC, 1));
  149. _lifeStones.put(12842, new LifeStone(GRADE_ACC, 2));
  150. _lifeStones.put(12843, new LifeStone(GRADE_ACC, 3));
  151. _lifeStones.put(12844, new LifeStone(GRADE_ACC, 4));
  152. _lifeStones.put(12845, new LifeStone(GRADE_ACC, 5));
  153. _lifeStones.put(12846, new LifeStone(GRADE_ACC, 6));
  154. _lifeStones.put(12847, new LifeStone(GRADE_ACC, 7));
  155. _lifeStones.put(12848, new LifeStone(GRADE_ACC, 8));
  156. _lifeStones.put(12849, new LifeStone(GRADE_ACC, 9));
  157. _lifeStones.put(12850, new LifeStone(GRADE_ACC, 10));
  158. _lifeStones.put(12851, new LifeStone(GRADE_ACC, 11));
  159. _lifeStones.put(14008, new LifeStone(GRADE_ACC, 12));
  160. _lifeStones.put(14166, new LifeStone(GRADE_NONE, 12));
  161. _lifeStones.put(14167, new LifeStone(GRADE_MID, 12));
  162. _lifeStones.put(14168, new LifeStone(GRADE_HIGH, 12));
  163. _lifeStones.put(14169, new LifeStone(GRADE_TOP, 12));
  164. _lifeStones.put(16160, new LifeStone(GRADE_NONE, 13));
  165. _lifeStones.put(16161, new LifeStone(GRADE_MID, 13));
  166. _lifeStones.put(16162, new LifeStone(GRADE_HIGH, 13));
  167. _lifeStones.put(16163, new LifeStone(GRADE_TOP, 13));
  168. _lifeStones.put(16177, new LifeStone(GRADE_ACC, 13));
  169. _lifeStones.put(16164, new LifeStone(GRADE_NONE, 13));
  170. _lifeStones.put(16165, new LifeStone(GRADE_MID, 13));
  171. _lifeStones.put(16166, new LifeStone(GRADE_HIGH, 13));
  172. _lifeStones.put(16167, new LifeStone(GRADE_TOP, 13));
  173. _lifeStones.put(16178, new LifeStone(GRADE_ACC, 13));
  174. }
  175. protected static final LifeStone getLifeStone(int itemId)
  176. {
  177. return _lifeStones.get(itemId);
  178. }
  179. /**
  180. * Checks player, source item, lifestone and gemstone validity for augmentation process
  181. * @param player
  182. * @param item
  183. * @param refinerItem
  184. * @param gemStones
  185. * @return
  186. */
  187. protected static final boolean isValid(L2PcInstance player, L2ItemInstance item, L2ItemInstance refinerItem, L2ItemInstance gemStones)
  188. {
  189. if (!isValid(player, item, refinerItem))
  190. {
  191. return false;
  192. }
  193. // GemStones must belong to owner
  194. if (gemStones.getOwnerId() != player.getObjectId())
  195. {
  196. return false;
  197. }
  198. // .. and located in inventory
  199. if (gemStones.getItemLocation() != ItemLocation.INVENTORY)
  200. {
  201. return false;
  202. }
  203. final CrystalType grade = item.getItem().getItemGrade();
  204. final LifeStone ls = _lifeStones.get(refinerItem.getId());
  205. // Check for item id
  206. if (getGemStoneId(grade) != gemStones.getId())
  207. {
  208. return false;
  209. }
  210. // Count must be greater or equal of required number
  211. if (getGemStoneCount(grade, ls.getGrade()) > gemStones.getCount())
  212. {
  213. return false;
  214. }
  215. return true;
  216. }
  217. /**
  218. * Checks player, source item and lifestone validity for augmentation process
  219. * @param player
  220. * @param item
  221. * @param refinerItem
  222. * @return
  223. */
  224. protected static final boolean isValid(L2PcInstance player, L2ItemInstance item, L2ItemInstance refinerItem)
  225. {
  226. if (!isValid(player, item))
  227. {
  228. return false;
  229. }
  230. // Item must belong to owner
  231. if (refinerItem.getOwnerId() != player.getObjectId())
  232. {
  233. return false;
  234. }
  235. // Lifestone must be located in inventory
  236. if (refinerItem.getItemLocation() != ItemLocation.INVENTORY)
  237. {
  238. return false;
  239. }
  240. final LifeStone ls = _lifeStones.get(refinerItem.getId());
  241. if (ls == null)
  242. {
  243. return false;
  244. }
  245. // weapons can't be augmented with accessory ls
  246. if ((item.getItem() instanceof L2Weapon) && (ls.getGrade() == GRADE_ACC))
  247. {
  248. return false;
  249. }
  250. // and accessory can't be augmented with weapon ls
  251. if ((item.getItem() instanceof L2Armor) && (ls.getGrade() != GRADE_ACC))
  252. {
  253. return false;
  254. }
  255. // check for level of the lifestone
  256. if (player.getLevel() < ls.getPlayerLevel())
  257. {
  258. return false;
  259. }
  260. return true;
  261. }
  262. /**
  263. * Check both player and source item conditions for augmentation process
  264. * @param player
  265. * @param item
  266. * @return
  267. */
  268. protected static final boolean isValid(L2PcInstance player, L2ItemInstance item)
  269. {
  270. if (!isValid(player))
  271. {
  272. return false;
  273. }
  274. // Item must belong to owner
  275. if (item.getOwnerId() != player.getObjectId())
  276. {
  277. return false;
  278. }
  279. if (item.isAugmented())
  280. {
  281. return false;
  282. }
  283. if (item.isHeroItem())
  284. {
  285. return false;
  286. }
  287. if (item.isShadowItem())
  288. {
  289. return false;
  290. }
  291. if (item.isCommonItem())
  292. {
  293. return false;
  294. }
  295. if (item.isEtcItem())
  296. {
  297. return false;
  298. }
  299. if (item.isTimeLimitedItem())
  300. {
  301. return false;
  302. }
  303. if (item.isPvp() && !Config.ALT_ALLOW_AUGMENT_PVP_ITEMS)
  304. {
  305. return false;
  306. }
  307. if (item.getItem().getCrystalType().isLesser(CrystalType.C))
  308. {
  309. return false;
  310. }
  311. // Source item can be equipped or in inventory
  312. switch (item.getItemLocation())
  313. {
  314. case INVENTORY:
  315. case PAPERDOLL:
  316. break;
  317. default:
  318. return false;
  319. }
  320. if (item.getItem() instanceof L2Weapon)
  321. {
  322. switch (((L2Weapon) item.getItem()).getItemType())
  323. {
  324. case NONE:
  325. case FISHINGROD:
  326. return false;
  327. default:
  328. break;
  329. }
  330. }
  331. else if (item.getItem() instanceof L2Armor)
  332. {
  333. // only accessories can be augmented
  334. switch (item.getItem().getBodyPart())
  335. {
  336. case L2Item.SLOT_LR_FINGER:
  337. case L2Item.SLOT_LR_EAR:
  338. case L2Item.SLOT_NECK:
  339. break;
  340. default:
  341. return false;
  342. }
  343. }
  344. else
  345. {
  346. return false; // neither weapon nor armor ?
  347. }
  348. // blacklist check
  349. if (Arrays.binarySearch(Config.AUGMENTATION_BLACKLIST, item.getId()) >= 0)
  350. {
  351. return false;
  352. }
  353. return true;
  354. }
  355. /**
  356. * Check if player's conditions valid for augmentation process
  357. * @param player
  358. * @return
  359. */
  360. protected static final boolean isValid(L2PcInstance player)
  361. {
  362. if (player.getPrivateStoreType() != PrivateStoreType.NONE)
  363. {
  364. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_A_PRIVATE_STORE_OR_PRIVATE_WORKSHOP_IS_IN_OPERATION);
  365. return false;
  366. }
  367. if (player.getActiveTradeList() != null)
  368. {
  369. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_TRADING);
  370. return false;
  371. }
  372. if (player.isDead())
  373. {
  374. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_DEAD);
  375. return false;
  376. }
  377. if (player.isParalyzed())
  378. {
  379. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_PARALYZED);
  380. return false;
  381. }
  382. if (player.isFishing())
  383. {
  384. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_FISHING);
  385. return false;
  386. }
  387. if (player.isSitting())
  388. {
  389. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_SITTING_DOWN);
  390. return false;
  391. }
  392. if (player.isCursedWeaponEquipped())
  393. {
  394. return false;
  395. }
  396. if (player.isEnchanting() || player.isProcessingTransaction())
  397. {
  398. return false;
  399. }
  400. return true;
  401. }
  402. /**
  403. * @param itemGrade
  404. * @return GemStone itemId based on item grade
  405. */
  406. protected static final int getGemStoneId(CrystalType itemGrade)
  407. {
  408. switch (itemGrade)
  409. {
  410. case C:
  411. case B:
  412. return GEMSTONE_D;
  413. case A:
  414. case S:
  415. return GEMSTONE_C;
  416. case S80:
  417. case S84:
  418. return GEMSTONE_B;
  419. default:
  420. return 0;
  421. }
  422. }
  423. /**
  424. * Different for weapon and accessory augmentation.
  425. * @param itemGrade
  426. * @param lifeStoneGrade
  427. * @return GemStone count based on item grade and life stone grade
  428. */
  429. protected static final int getGemStoneCount(CrystalType itemGrade, int lifeStoneGrade)
  430. {
  431. switch (lifeStoneGrade)
  432. {
  433. case GRADE_ACC:
  434. switch (itemGrade)
  435. {
  436. case C:
  437. return 200;
  438. case B:
  439. return 300;
  440. case A:
  441. return 200;
  442. case S:
  443. return 250;
  444. case S80:
  445. return 360;
  446. case S84:
  447. return 480;
  448. default:
  449. return 0;
  450. }
  451. default:
  452. switch (itemGrade)
  453. {
  454. case C:
  455. return 20;
  456. case B:
  457. return 30;
  458. case A:
  459. return 20;
  460. case S:
  461. return 25;
  462. case S80:
  463. case S84:
  464. return 36;
  465. default:
  466. return 0;
  467. }
  468. }
  469. }
  470. }