Advertisement
Guest User

javas

a guest
May 26th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.73 KB | None | 0 0
  1. AlchemyDataTemplate.java
  2. -----------------------------------------------------------------------------------------------------------------------
  3.  
  4. package lineage2.gameserver.templates.item;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. public final class AlchemyDataTemplate
  10. {
  11. private final int _skillId;
  12. private final int _skillLevel;
  13. private final int _successRate;
  14. private final List<AlchemyItem> _ingridients = new ArrayList();
  15. private final List<AlchemyItem> _onSuccessProducts = new ArrayList();
  16. private final List<AlchemyItem> _onFailProducts = new ArrayList();
  17.  
  18. public AlchemyDataTemplate(int skillId, int skillLevel, int successRate)
  19. {
  20. _skillId = skillId;
  21. _skillLevel = skillLevel;
  22. _successRate = successRate;
  23. }
  24.  
  25. public int getSkillId()
  26. {
  27. return _skillId;
  28. }
  29.  
  30. public int getSkillLevel()
  31. {
  32. return _skillLevel;
  33. }
  34.  
  35. public int getSuccessRate()
  36. {
  37. return _successRate;
  38. }
  39.  
  40. public void addIngridient(AlchemyItem ingridient)
  41. {
  42. _ingridients.add(ingridient);
  43. }
  44.  
  45. public AlchemyItem[] getIngridients()
  46. {
  47. return (AlchemyItem[])_ingridients.toArray(new AlchemyItem[_ingridients.size()]);
  48. }
  49.  
  50. public void addOnSuccessProduct(AlchemyItem product)
  51. {
  52. _onSuccessProducts.add(product);
  53. }
  54.  
  55. public AlchemyItem[] getOnSuccessProducts()
  56. {
  57. return (AlchemyItem[])_onSuccessProducts.toArray(new AlchemyItem[_onSuccessProducts.size()]);
  58. }
  59.  
  60. public void addOnFailProduct(AlchemyItem product)
  61. {
  62. _onFailProducts.add(product);
  63. }
  64.  
  65. public AlchemyItem[] getOnFailProducts()
  66. {
  67. return (AlchemyItem[])_onFailProducts.toArray(new AlchemyItem[_onFailProducts.size()]);
  68. }
  69.  
  70. public static class AlchemyItem
  71. {
  72. private final int _id;
  73. private final int _count;
  74.  
  75. public AlchemyItem(int id, int count)
  76. {
  77. _id = id;
  78. _count = count;
  79. }
  80.  
  81. public int getId()
  82. {
  83. return _id;
  84. }
  85.  
  86. public long getCount()
  87. {
  88. return _count;
  89. }
  90. }
  91. }
  92.  
  93. -----------------------------------------------------------------------------------------------------------------------
  94. RequestAlchemyConversion .java
  95.  
  96.  
  97.  
  98. package lineage2.gameserver.network.l2.c2s;
  99.  
  100. import gnu.trove.iterator.TIntLongIterator;
  101. import gnu.trove.map.TIntLongMap;
  102. import gnu.trove.map.hash.TIntLongHashMap;
  103. import lineage2.commons.util.Rnd;
  104. import lineage2.gameserver.data.xml.holder.AlchemyDataHolder;
  105. import lineage2.gameserver.tables.SkillTable;
  106. import lineage2.gameserver.model.Player;
  107. import lineage2.gameserver.model.Skill;
  108. import lineage2.gameserver.model.items.Inventory;
  109. import lineage2.gameserver.model.items.ItemInstance;
  110. import lineage2.gameserver.network.GameClient;
  111. import lineage2.gameserver.network.clientpackets.L2GameClientPacket;
  112. import lineage2.gameserver.network.serverpackets.components.SystemMsg;
  113. import lineage2.gameserver.network.serverpackets.ExAlchemyConversion;
  114. import lineage2.gameserver.network.serverpackets.SystemMessage;
  115. import lineage2.gameserver.templates.item.AlchemyDataTemplate;
  116. import lineage2.gameserver.templates.item.AlchemyDataTemplate.AlchemyItem;
  117. import lineage2.gameserver.utils.ItemFunctions;
  118. import org.slf4j.Logger;
  119. import org.slf4j.LoggerFactory;
  120.  
  121. public class RequestAlchemyConversion extends L2GameClientPacket
  122. {
  123. private static final Logger _log = LoggerFactory.getLogger(RequestAlchemyConversion.class);
  124. private int _count;
  125. private int _skillId;
  126. private int _skillLevel;
  127.  
  128. protected void readImpl()
  129. {
  130. _count = readD();
  131.  
  132. readH();
  133.  
  134. _skillId = readD();
  135. _skillLevel = readD();
  136. }
  137.  
  138. protected void runImpl()
  139. {
  140. Player activeChar = ((GameClient)getClient()).getActiveChar();
  141. if (activeChar == null)
  142. {
  143. return;
  144. }
  145. if (_count <= 0)
  146. {
  147. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  148. return;
  149. }
  150.  
  151. if (activeChar.isActionsDisabled())
  152. {
  153. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  154. return;
  155. }
  156.  
  157. if (activeChar.isInCombat())
  158. {
  159. activeChar.sendPacket(SystemMsg.YOU_CANNOT_USE_ALCHEMY_DURING_BATTLE);
  160. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  161. return;
  162. }
  163.  
  164. if ((activeChar.isInStoreMode()) || (activeChar.isInTrade()))
  165. {
  166. activeChar.sendPacket(SystemMsg.YOU_CANNOT_USE_ALCHEMY_WHILE_TRADING_OR_USING_A_PRIVATE_STORE_OR_SHOP);
  167. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  168. return;
  169. }
  170.  
  171. if (activeChar.isDead())
  172. {
  173. activeChar.sendPacket(SystemMsg.YOU_CANNOT_USE_ALCHEMY_WHILE_DEAD);
  174. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  175. return;
  176. }
  177.  
  178. if (activeChar.isMovementDisabled())
  179. {
  180. activeChar.sendPacket(SystemMsg.YOU_CANNOT_USE_ALCHEMY_WHILE_IMMOBILE);
  181. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  182. return;
  183. }
  184.  
  185. Skill skill = SkillTable.getInstance().getSkill(_skillId, _skillLevel);
  186. if (skill == null)
  187. {
  188. _log.warn(getClass().getSimpleName() + ": Error while alchemy: Cannot find alchemy skill[" + _skillId + "-" + _skillLevel + "]!");
  189.  
  190. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  191. return;
  192. }
  193.  
  194. AlchemyDataTemplate data = AlchemyDataHolder.getInstance().getData(skill);
  195. if (data == null)
  196. {
  197. _log.warn(getClass().getSimpleName() + ": Error while alchemy: Cannot find alchemy data[" + _skillId + "-" + _skillLevel + "]!");
  198.  
  199. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  200. return;
  201. }
  202. AlchemyDataTemplate.AlchemyItem[] ingridients = data.getIngridients();
  203. AlchemyDataTemplate.AlchemyItem[] onSuccessProducts = data.getOnSuccessProducts();
  204. AlchemyDataTemplate.AlchemyItem[] onFailProducts = data.getOnFailProducts();
  205.  
  206. TIntLongMap deletedItems = new TIntLongHashMap();
  207. TIntLongMap addedItems = new TIntLongHashMap();
  208.  
  209. int convensionCount = _count;
  210.  
  211. Inventory inventory = activeChar.getInventory();
  212.  
  213. inventory.writeLock();
  214. AlchemyDataTemplate.AlchemyItem ingridient;
  215. long count;
  216. try
  217. {
  218. for (AlchemyDataTemplate.AlchemyItem ingridient : ingridients)
  219. {
  220. ItemInstance item = inventory.getItemByItemId(ingridient.getId());
  221. if ((item == null) || (item.getCount() < ingridient.getCount()))
  222. {
  223. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  224. return;
  225. }
  226. convensionCount = Math.min(convensionCount, (int)Math.floor(item.getCount() / ingridient.getCount()));
  227. }
  228.  
  229. for (AlchemyDataTemplate.AlchemyItem ingridient: ingridients)
  230. {
  231. count = ingridient.getCount() * convensionCount;
  232. if (inventory.destroyItemByItemId(ingridient.getId(), count))
  233. {
  234. long deleted = deletedItems.get(ingridient.getId());
  235. deletedItems.put(ingridient.getId(), deleted + count);
  236. }
  237. }
  238. }
  239. finally
  240. {
  241. inventory.writeUnlock();
  242. }
  243.  
  244. int successCount = 0;
  245. int failCount = 0;
  246.  
  247. for (int i = 0; i < convensionCount; i++)
  248. {
  249. if (Rnd.chance(data.getSuccessRate()))
  250. successCount++;
  251. else
  252. failCount++;
  253. }
  254. AlchemyDataTemplate.AlchemyItem[] arrayOfAlchemyItem2;
  255. if (successCount > 0)
  256. {
  257. arrayOfAlchemyItem2 = onSuccessProducts; ingridient = arrayOfAlchemyItem2.length; for (count = 0; count < ingridient; count++)
  258. {
  259. AlchemyDataTemplate.AlchemyItem product = arrayOfAlchemyItem2[count];
  260.  
  261. long count = product.getCount() * successCount;
  262. long deleted = deletedItems.get(product.getId());
  263. if (deleted > 0L)
  264. {
  265. deletedItems.put(product.getId(), Math.max(0L, deleted - count));
  266.  
  267. long added = count - deleted;
  268. if (added > 0L)
  269. addedItems.put(product.getId(), addedItems.get(product.getId()) + added);
  270. }
  271. else
  272. {
  273. addedItems.put(product.getId(), addedItems.get(product.getId()) + count);
  274. }
  275. }
  276. }
  277. if (failCount > 0)
  278. {
  279. arrayOfAlchemyItem2 = onFailProducts; ingridient = arrayOfAlchemyItem2.length; for (count = 0; count < ingridient; count++)
  280. {
  281. AlchemyDataTemplate.AlchemyItem product = arrayOfAlchemyItem2[count];
  282.  
  283. long count = product.getCount() * failCount;
  284. long deleted = deletedItems.get(product.getId());
  285. if (deleted > 0L)
  286. {
  287. deletedItems.put(product.getId(), Math.max(0L, deleted - count));
  288.  
  289. long added = count - deleted;
  290. if (added > 0L)
  291. addedItems.put(product.getId(), addedItems.get(product.getId()) + added);
  292. }
  293. else
  294. {
  295. addedItems.put(product.getId(), addedItems.get(product.getId()) + count);
  296. }
  297. }
  298. }
  299. for (TIntLongIterator iterator = deletedItems.iterator(); iterator.hasNext(); )
  300. {
  301. iterator.advance();
  302.  
  303. long count = iterator.value();
  304. if (count > 0L)
  305. {
  306. activeChar.sendPacket(SystemMessagePacket.removeItems(iterator.key(), count));
  307. }
  308. }
  309. for (TIntLongIterator iterator = addedItems.iterator(); iterator.hasNext(); )
  310. {
  311. iterator.advance();
  312.  
  313. long count = iterator.value();
  314. if (count > 0L)
  315. {
  316. ItemFunctions.addItem(activeChar, iterator.key(), count, true);
  317. }
  318. }
  319. if ((successCount == 0) && (failCount == 0))
  320. activeChar.sendPacket(ExAlchemyConversion.FAIL);
  321. else
  322. activeChar.sendPacket(new ExAlchemyConversion(successCount, failCount));
  323. }
  324. }
  325.  
  326.  
  327. -----------------------------------------------------------------------------------------------------------------------
  328. ExAlchemySkillList .java
  329.  
  330.  
  331.  
  332.  
  333. package lineage2.gameserver.network.serverpackets;
  334.  
  335. import java.util.ArrayList;
  336. import java.util.List;
  337. import lineage2.gameserver.model.Player;
  338. import lineage2.gameserver.model.Skill;
  339.  
  340. public class ExAlchemySkillList extends L2GameServerPacket
  341. {
  342. private final List<Skill> _skills;
  343.  
  344. public ExAlchemySkillList(Player player)
  345. {
  346. _skills = new ArrayList(player.getAllAlchemySkills());
  347. }
  348.  
  349. protected void writeImpl()
  350. {
  351. writeD(this._skills.size());
  352. for (Skill skill : _skills)
  353. {
  354. writeD(skill.getId());
  355. writeD(skill.getLevel());
  356. writeQ(0x00); //Âñåãëà 0
  357. int visible = 0x01;
  358. if(skill.getId() == 17943)
  359. {
  360. visible = 0x00;
  361. }
  362. writeC(visible);
  363. }
  364. }
  365. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement