AbstractRefinePacket.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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.network.clientpackets;
  16. import java.util.Arrays;
  17. import java.util.Map;
  18. import javolution.util.FastMap;
  19. import com.l2jserver.Config;
  20. import com.l2jserver.gameserver.model.L2ItemInstance;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. import com.l2jserver.gameserver.templates.item.L2Armor;
  25. import com.l2jserver.gameserver.templates.item.L2Item;
  26. import com.l2jserver.gameserver.templates.item.L2Weapon;
  27. public abstract class AbstractRefinePacket extends L2GameClientPacket
  28. {
  29. public static final int GRADE_NONE = 0;
  30. public static final int GRADE_MID = 1;
  31. public static final int GRADE_HIGH = 2;
  32. public static final int GRADE_TOP = 3;
  33. public static final int GRADE_ACC = 4; // Accessory LS
  34. protected static final int GEMSTONE_D = 2130;
  35. protected static final int GEMSTONE_C = 2131;
  36. protected static final int GEMSTONE_B = 2132;
  37. private static final Map<Integer, LifeStone> _lifeStones = new FastMap<Integer, LifeStone>();
  38. protected static final class LifeStone
  39. {
  40. // lifestone level to player level table
  41. private static final int[] LEVELS = {46, 49, 52, 55, 58, 61, 64, 67, 70, 76, 80, 82, 84};
  42. private final int _grade;
  43. private final int _level;
  44. public LifeStone(int grade, int level)
  45. {
  46. _grade = grade;
  47. _level = level;
  48. }
  49. public final int getLevel()
  50. {
  51. return _level;
  52. }
  53. public final int getGrade()
  54. {
  55. return _grade;
  56. }
  57. public final int getPlayerLevel()
  58. {
  59. return LEVELS[_level];
  60. }
  61. }
  62. static
  63. {
  64. // itemId, (LS grade, LS level)
  65. _lifeStones.put(8723, new LifeStone(GRADE_NONE, 0));
  66. _lifeStones.put(8724, new LifeStone(GRADE_NONE, 1));
  67. _lifeStones.put(8725, new LifeStone(GRADE_NONE, 2));
  68. _lifeStones.put(8726, new LifeStone(GRADE_NONE, 3));
  69. _lifeStones.put(8727, new LifeStone(GRADE_NONE, 4));
  70. _lifeStones.put(8728, new LifeStone(GRADE_NONE, 5));
  71. _lifeStones.put(8729, new LifeStone(GRADE_NONE, 6));
  72. _lifeStones.put(8730, new LifeStone(GRADE_NONE, 7));
  73. _lifeStones.put(8731, new LifeStone(GRADE_NONE, 8));
  74. _lifeStones.put(8732, new LifeStone(GRADE_NONE, 9));
  75. _lifeStones.put(8733, new LifeStone(GRADE_MID, 0));
  76. _lifeStones.put(8734, new LifeStone(GRADE_MID, 1));
  77. _lifeStones.put(8735, new LifeStone(GRADE_MID, 2));
  78. _lifeStones.put(8736, new LifeStone(GRADE_MID, 3));
  79. _lifeStones.put(8737, new LifeStone(GRADE_MID, 4));
  80. _lifeStones.put(8738, new LifeStone(GRADE_MID, 5));
  81. _lifeStones.put(8739, new LifeStone(GRADE_MID, 6));
  82. _lifeStones.put(8740, new LifeStone(GRADE_MID, 7));
  83. _lifeStones.put(8741, new LifeStone(GRADE_MID, 8));
  84. _lifeStones.put(8742, new LifeStone(GRADE_MID, 9));
  85. _lifeStones.put(8743, new LifeStone(GRADE_HIGH, 0));
  86. _lifeStones.put(8744, new LifeStone(GRADE_HIGH, 1));
  87. _lifeStones.put(8745, new LifeStone(GRADE_HIGH, 2));
  88. _lifeStones.put(8746, new LifeStone(GRADE_HIGH, 3));
  89. _lifeStones.put(8747, new LifeStone(GRADE_HIGH, 4));
  90. _lifeStones.put(8748, new LifeStone(GRADE_HIGH, 5));
  91. _lifeStones.put(8749, new LifeStone(GRADE_HIGH, 6));
  92. _lifeStones.put(8750, new LifeStone(GRADE_HIGH, 7));
  93. _lifeStones.put(8751, new LifeStone(GRADE_HIGH, 8));
  94. _lifeStones.put(8752, new LifeStone(GRADE_HIGH, 9));
  95. _lifeStones.put(8753, new LifeStone(GRADE_TOP, 0));
  96. _lifeStones.put(8754, new LifeStone(GRADE_TOP, 1));
  97. _lifeStones.put(8755, new LifeStone(GRADE_TOP, 2));
  98. _lifeStones.put(8756, new LifeStone(GRADE_TOP, 3));
  99. _lifeStones.put(8757, new LifeStone(GRADE_TOP, 4));
  100. _lifeStones.put(8758, new LifeStone(GRADE_TOP, 5));
  101. _lifeStones.put(8759, new LifeStone(GRADE_TOP, 6));
  102. _lifeStones.put(8760, new LifeStone(GRADE_TOP, 7));
  103. _lifeStones.put(8761, new LifeStone(GRADE_TOP, 8));
  104. _lifeStones.put(8762, new LifeStone(GRADE_TOP, 9));
  105. _lifeStones.put(9573, new LifeStone(GRADE_NONE, 10));
  106. _lifeStones.put(9574, new LifeStone(GRADE_MID, 10));
  107. _lifeStones.put(9575, new LifeStone(GRADE_HIGH, 10));
  108. _lifeStones.put(9576, new LifeStone(GRADE_TOP, 10));
  109. _lifeStones.put(10483, new LifeStone(GRADE_NONE, 11));
  110. _lifeStones.put(10484, new LifeStone(GRADE_MID, 11));
  111. _lifeStones.put(10485, new LifeStone(GRADE_HIGH, 11));
  112. _lifeStones.put(10486, new LifeStone(GRADE_TOP, 11));
  113. _lifeStones.put(12754, new LifeStone(GRADE_ACC, 0));
  114. _lifeStones.put(12755, new LifeStone(GRADE_ACC, 1));
  115. _lifeStones.put(12756, new LifeStone(GRADE_ACC, 2));
  116. _lifeStones.put(12757, new LifeStone(GRADE_ACC, 3));
  117. _lifeStones.put(12758, new LifeStone(GRADE_ACC, 4));
  118. _lifeStones.put(12759, new LifeStone(GRADE_ACC, 5));
  119. _lifeStones.put(12760, new LifeStone(GRADE_ACC, 6));
  120. _lifeStones.put(12761, new LifeStone(GRADE_ACC, 7));
  121. _lifeStones.put(12762, new LifeStone(GRADE_ACC, 8));
  122. _lifeStones.put(12763, new LifeStone(GRADE_ACC, 9));
  123. _lifeStones.put(12821, new LifeStone(GRADE_ACC, 10));
  124. _lifeStones.put(12822, new LifeStone(GRADE_ACC, 11));
  125. _lifeStones.put(12840, new LifeStone(GRADE_ACC, 0));
  126. _lifeStones.put(12841, new LifeStone(GRADE_ACC, 1));
  127. _lifeStones.put(12842, new LifeStone(GRADE_ACC, 2));
  128. _lifeStones.put(12843, new LifeStone(GRADE_ACC, 3));
  129. _lifeStones.put(12844, new LifeStone(GRADE_ACC, 4));
  130. _lifeStones.put(12845, new LifeStone(GRADE_ACC, 5));
  131. _lifeStones.put(12846, new LifeStone(GRADE_ACC, 6));
  132. _lifeStones.put(12847, new LifeStone(GRADE_ACC, 7));
  133. _lifeStones.put(12848, new LifeStone(GRADE_ACC, 8));
  134. _lifeStones.put(12849, new LifeStone(GRADE_ACC, 9));
  135. _lifeStones.put(12850, new LifeStone(GRADE_ACC, 10));
  136. _lifeStones.put(12851, new LifeStone(GRADE_ACC, 11));
  137. _lifeStones.put(14008, new LifeStone(GRADE_ACC, 12));
  138. _lifeStones.put(14166, new LifeStone(GRADE_NONE, 12));
  139. _lifeStones.put(14167, new LifeStone(GRADE_MID, 12));
  140. _lifeStones.put(14168, new LifeStone(GRADE_HIGH, 12));
  141. _lifeStones.put(14169, new LifeStone(GRADE_TOP, 12));
  142. }
  143. protected static final LifeStone getLifeStone(int itemId)
  144. {
  145. return _lifeStones.get(itemId);
  146. }
  147. /*
  148. * Checks player, source item, lifestone and gemstone validity for augmentation process
  149. */
  150. protected static final boolean isValid(L2PcInstance player, L2ItemInstance item, L2ItemInstance refinerItem, L2ItemInstance gemStones)
  151. {
  152. if (!isValid(player, item, refinerItem))
  153. return false;
  154. // GemStones must belong to owner
  155. if (gemStones.getOwnerId() != player.getObjectId())
  156. return false;
  157. // .. and located in inventory
  158. if (gemStones.getLocation() != L2ItemInstance.ItemLocation.INVENTORY)
  159. return false;
  160. final int grade = item.getItem().getItemGrade();
  161. final LifeStone ls = getLifeStone(refinerItem.getItemId());
  162. // Check for item id
  163. if (getGemStoneId(grade) != gemStones.getItemId())
  164. return false;
  165. // Count must be greater or equal of required number
  166. if (getGemStoneCount(grade, ls.getGrade()) > gemStones.getCount())
  167. return false;
  168. return true;
  169. }
  170. /*
  171. * Checks player, source item and lifestone validity for augmentation process
  172. */
  173. protected static final boolean isValid(L2PcInstance player, L2ItemInstance item, L2ItemInstance refinerItem)
  174. {
  175. if (!isValid(player, item))
  176. return false;
  177. // Item must belong to owner
  178. if (refinerItem.getOwnerId() != player.getObjectId())
  179. return false;
  180. // Lifestone must be located in inventory
  181. if (refinerItem.getLocation() != L2ItemInstance.ItemLocation.INVENTORY)
  182. return false;
  183. final LifeStone ls = getLifeStone(refinerItem.getItemId());
  184. if (ls == null)
  185. return false;
  186. // weapons can't be augmented with accessory ls
  187. if (item.getItem() instanceof L2Weapon && ls.getGrade() == GRADE_ACC)
  188. return false;
  189. // and accessory can't be augmented with weapon ls
  190. if (item.getItem() instanceof L2Armor && ls.getGrade() != GRADE_ACC)
  191. return false;
  192. // check for level of the lifestone
  193. if (player.getLevel() < ls.getPlayerLevel())
  194. return false;
  195. return true;
  196. }
  197. /*
  198. * Check both player and source item conditions for augmentation process
  199. */
  200. protected static final boolean isValid(L2PcInstance player, L2ItemInstance item)
  201. {
  202. if (!isValid(player))
  203. return false;
  204. // Item must belong to owner
  205. if (item.getOwnerId() != player.getObjectId())
  206. return false;
  207. if (item.isAugmented())
  208. return false;
  209. if (item.isHeroItem())
  210. return false;
  211. if (item.isShadowItem())
  212. return false;
  213. if (item.isCommonItem())
  214. return false;
  215. if (item.isEtcItem())
  216. return false;
  217. if (item.isTimeLimitedItem())
  218. return false;
  219. if (item.isPvp())
  220. return false;
  221. if (item.getItem().getCrystalType() < L2Item.CRYSTAL_C)
  222. return false;
  223. // Source item can be equipped or in inventory
  224. switch (item.getLocation())
  225. {
  226. case INVENTORY:
  227. case PAPERDOLL:
  228. break;
  229. default:
  230. return false;
  231. }
  232. if (item.getItem() instanceof L2Weapon)
  233. {
  234. switch (((L2Weapon)item.getItem()).getItemType())
  235. {
  236. case NONE:
  237. case FISHINGROD:
  238. return false;
  239. default:
  240. break;
  241. }
  242. }
  243. else if (item.getItem() instanceof L2Armor)
  244. {
  245. // only accessories can be augmented
  246. switch (item.getItem().getBodyPart())
  247. {
  248. case L2Item.SLOT_LR_FINGER:
  249. case L2Item.SLOT_LR_EAR:
  250. case L2Item.SLOT_NECK:
  251. break;
  252. default:
  253. return false;
  254. }
  255. }
  256. else
  257. return false; // neither weapon nor armor ?
  258. // blacklist check
  259. if (Arrays.binarySearch(Config.AUGMENTATION_BLACKLIST, item.getItemId()) >= 0)
  260. return false;
  261. return true;
  262. }
  263. /*
  264. * Check if player's conditions valid for augmentation process
  265. */
  266. protected static final boolean isValid(L2PcInstance player)
  267. {
  268. if (player.getPrivateStoreType() != L2PcInstance.STORE_PRIVATE_NONE)
  269. {
  270. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_A_PRIVATE_STORE_OR_PRIVATE_WORKSHOP_IS_IN_OPERATION));
  271. return false;
  272. }
  273. if (player.getActiveTradeList() != null)
  274. {
  275. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_TRADING));
  276. return false;
  277. }
  278. if (player.isDead())
  279. {
  280. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_DEAD));
  281. return false;
  282. }
  283. if (player.isParalyzed())
  284. {
  285. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_PARALYZED));
  286. return false;
  287. }
  288. if (player.isFishing())
  289. {
  290. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_FISHING));
  291. return false;
  292. }
  293. if (player.isSitting())
  294. {
  295. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_SITTING_DOWN));
  296. return false;
  297. }
  298. if (player.isCursedWeaponEquipped())
  299. return false;
  300. if (player.isEnchanting() || player.isProcessingTransaction())
  301. return false;
  302. return true;
  303. }
  304. /*
  305. * Returns GemStone itemId based on item grade
  306. */
  307. protected static final int getGemStoneId(int itemGrade)
  308. {
  309. switch (itemGrade)
  310. {
  311. case L2Item.CRYSTAL_C:
  312. case L2Item.CRYSTAL_B:
  313. return GEMSTONE_D;
  314. case L2Item.CRYSTAL_A:
  315. case L2Item.CRYSTAL_S:
  316. return GEMSTONE_C;
  317. case L2Item.CRYSTAL_S80:
  318. case L2Item.CRYSTAL_S84:
  319. return GEMSTONE_B;
  320. default:
  321. return 0;
  322. }
  323. }
  324. /*
  325. * Returns GemStone count based on item grade and lifestone grade
  326. * (different for weapon and accessory augmentation)
  327. */
  328. protected static final int getGemStoneCount(int itemGrade, int lifeStoneGrade)
  329. {
  330. switch (lifeStoneGrade)
  331. {
  332. case GRADE_ACC:
  333. switch (itemGrade)
  334. {
  335. case L2Item.CRYSTAL_C:
  336. return 200;
  337. case L2Item.CRYSTAL_B:
  338. return 300;
  339. case L2Item.CRYSTAL_A:
  340. return 200;
  341. case L2Item.CRYSTAL_S:
  342. return 250;
  343. case L2Item.CRYSTAL_S80:
  344. return 360;
  345. case L2Item.CRYSTAL_S84:
  346. return 480;
  347. default:
  348. return 0;
  349. }
  350. default:
  351. switch (itemGrade)
  352. {
  353. case L2Item.CRYSTAL_C:
  354. return 20;
  355. case L2Item.CRYSTAL_B:
  356. return 30;
  357. case L2Item.CRYSTAL_A:
  358. return 20;
  359. case L2Item.CRYSTAL_S:
  360. return 25;
  361. case L2Item.CRYSTAL_S80:
  362. case L2Item.CRYSTAL_S84:
  363. return 36;
  364. default:
  365. return 0;
  366. }
  367. }
  368. }
  369. }