Guest User

Fastaugment By AbsolutePower v3

a guest
Sep 5th, 2016
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.75 KB | None | 0 0
  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.l2jhellas.gameserver.model.actor.instance;
  16.  
  17. import java.util.StringTokenizer;
  18.  
  19. import com.l2jhellas.gameserver.ai.CtrlIntention;
  20. import com.l2jhellas.gameserver.datatables.xml.AugmentationData;
  21. import com.l2jhellas.gameserver.model.L2Augmentation;
  22. import com.l2jhellas.gameserver.model.L2ItemInstance;
  23. import com.l2jhellas.gameserver.network.SystemMessageId;
  24. import com.l2jhellas.gameserver.network.serverpackets.ActionFailed;
  25. import com.l2jhellas.gameserver.network.serverpackets.ExShowScreenMessage;
  26. import com.l2jhellas.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS;
  27. import com.l2jhellas.gameserver.network.serverpackets.ExVariationCancelResult;
  28. import com.l2jhellas.gameserver.network.serverpackets.ExVariationResult;
  29. import com.l2jhellas.gameserver.network.serverpackets.InventoryUpdate;
  30. import com.l2jhellas.gameserver.network.serverpackets.MyTargetSelected;
  31. import com.l2jhellas.gameserver.network.serverpackets.NpcHtmlMessage;
  32. import com.l2jhellas.gameserver.network.serverpackets.SkillList;
  33. import com.l2jhellas.gameserver.network.serverpackets.SocialAction;
  34. import com.l2jhellas.gameserver.network.serverpackets.StatusUpdate;
  35. import com.l2jhellas.gameserver.network.serverpackets.SystemMessage;
  36. import com.l2jhellas.gameserver.network.serverpackets.ValidateLocation;
  37. import com.l2jhellas.gameserver.templates.L2Item;
  38. import com.l2jhellas.gameserver.templates.L2NpcTemplate;
  39. import com.l2jhellas.gameserver.templates.L2Weapon;
  40. import com.l2jhellas.util.Rnd;
  41.  
  42.  
  43. /**
  44. * Author AbsolutePower
  45. */
  46. public final class L2FastAugByAbsoInstance extends L2NpcInstance
  47. {
  48.  
  49. public L2FastAugByAbsoInstance(int objectId, L2NpcTemplate template)
  50. {
  51. super(objectId, template);
  52. }
  53.  
  54. @Override
  55. public void onBypassFeedback(L2PcInstance player, String command)
  56. {
  57. if(player==null)
  58. return;
  59.  
  60. final StringTokenizer st = new StringTokenizer(command, " ");
  61. final String currentcommand = st.nextToken();
  62.  
  63. final String letsSliptIt = currentcommand;
  64. final String[] nowTheId = letsSliptIt.split("-");
  65.  
  66. final String OurSplititCommand = nowTheId[0];
  67. final String FinallyWeHaveObjectId = nowTheId[1];
  68.  
  69. switch (OurSplititCommand)
  70. {
  71. case "showremlist":
  72. showListWindowForRemove(player);
  73. player.sendPacket(new ActionFailed());
  74. break;
  75. case "showauglist":
  76. showListWindow(player);
  77. player.sendPacket(new ActionFailed());
  78. break;
  79. case "tryremove":
  80.  
  81. final L2ItemInstance itemToRem = player.getInventory().getItemByObjectId(Integer.parseInt(FinallyWeHaveObjectId));
  82.  
  83. if(itemToRem == null )
  84. {
  85. player.sendPacket(new ActionFailed());
  86. return;
  87. }
  88.  
  89. if (itemToRem.isEquipped())
  90. {
  91. player.disarmWeapons();
  92. player.broadcastUserInfo();
  93. }
  94.  
  95. itemToRem.removeAugmentation();
  96.  
  97. player.sendPacket(new ExVariationCancelResult(1));
  98.  
  99. InventoryUpdate iu = new InventoryUpdate();
  100. iu.addModifiedItem(itemToRem);
  101. player.sendPacket(iu);
  102.  
  103. player.sendPacket(new SkillList());
  104.  
  105. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AUGMENTATION_HAS_BEEN_SUCCESSFULLY_REMOVED_FROM_YOUR_S1);
  106. sm.addItemName(itemToRem);
  107. player.sendPacket(sm);
  108. showListWindowForRemove(player);
  109. player.sendPacket(new ActionFailed());
  110. break;
  111.  
  112. case "tryaug":
  113. if (player.getInventory().getInventoryItemCount(57, 0) < 200000)
  114. {
  115. player.sendMessage("You do not have enough adena!");
  116. player.sendPacket(new ActionFailed());
  117. return;
  118. }
  119.  
  120. final L2ItemInstance itemToAug = player.getInventory().getItemByObjectId(Integer.parseInt(FinallyWeHaveObjectId));
  121.  
  122.  
  123. if(itemToAug == null )
  124. {
  125. player.sendPacket(new ActionFailed());
  126. return;
  127. }
  128.  
  129. if (itemToAug.isEquipped())
  130. {
  131. player.disarmWeapons();
  132. player.broadcastUserInfo();
  133. }
  134.  
  135. final L2Augmentation aug = AugmentationData.getInstance().generateRandomAugmentation(itemToAug,2,2);
  136. itemToAug.setAugmentation(aug);
  137.  
  138. final int stat12 = 0x0000FFFF & aug.getAugmentationId();
  139. final int stat34 = aug.getAugmentationId() >> 16;
  140. player.sendPacket(new ExVariationResult(stat12, stat34, 1));
  141.  
  142. InventoryUpdate iua = new InventoryUpdate();
  143. iua.addModifiedItem(itemToAug);
  144. player.sendPacket(iua);
  145.  
  146. StatusUpdate su = new StatusUpdate(player.getObjectId());
  147. su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
  148. player.sendPacket(su);
  149.  
  150. showListWindow(player);
  151.  
  152. player.getInventory().reduceAdena("FastAugh", 200000, player, null);
  153.  
  154. player.sendPacket(SystemMessageId.THE_ITEM_WAS_SUCCESSFULLY_AUGMENTED);
  155.  
  156. if(itemToAug.getAugmentation().getSkill()!=null)
  157. {
  158. player.sendPacket(new ExShowScreenMessage("You have " + itemToAug.getAugmentation().getSkill().getName(), 5000, SMPOS.TOP_CENTER, true));
  159. player.sendPacket(new SkillList());
  160. }
  161.  
  162. player.sendPacket(new ActionFailed());
  163. break;
  164. default: // Send a Server->Client packet ActionFailed to the L2PcInstance
  165. player.sendPacket(new ActionFailed());
  166. return;
  167. }
  168.  
  169. super.onBypassFeedback(player, command);
  170.  
  171. player.sendPacket(new ActionFailed());
  172. }
  173.  
  174. public void showListWindow(L2PcInstance player)
  175. {
  176. NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  177. StringBuilder tb = new StringBuilder("");
  178. String Rem = "RemoveAug";
  179. L2ItemInstance[] invitems = player.getInventory().getItems();
  180.  
  181. tb.append("<html><head><title>By AbsolutePower</title></head><body>");
  182. tb.append("<center>");
  183. tb.append("<table width=\"250\" cellpadding=\"5\" bgcolor=\"000000\">");
  184. tb.append("<tr>");
  185. tb.append("<td width=\"45\" valign=\"top\" align=\"center\"><img src=\"L2ui_ch3.menubutton4\" width=\"38\" height=\"38\"></td>");
  186. tb.append("<td valign=\"top\"><font color=\"FF6600\">AugmentHelper</font>");
  187. tb.append("<br1><font color=\"00FF00ju\">" + player.getName() + "</font>, use this menu for fast augment :)<br1></td>");
  188. tb.append("</tr>");
  189. tb.append("</table>");
  190. tb.append("</center>");
  191. tb.append("<center>");
  192. tb.append("<br>");
  193.  
  194. for (L2ItemInstance item : invitems)
  195. {
  196. if(item==null)
  197. continue;
  198.  
  199. boolean canBeShow = isValid(player, item);
  200.  
  201. if(canBeShow)
  202. {
  203. tb.append("<button value=\""+item.getItemName()+"\" action=\"bypass -h npc_" + getObjectId() + "_tryaug-"+item.getObjectId()+"\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\"><br>");
  204. }
  205. }
  206.  
  207. tb.append("<br>");
  208. tb.append("<button value=\""+Rem+"\" action=\"bypass -h npc_" + getObjectId() + "_showremlist-1"+"\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\"><br>");
  209. tb.append("</center>");
  210. tb.append("</body></html>");
  211.  
  212. nhm.setHtml(tb.toString());
  213. player.sendPacket(nhm);
  214. }
  215.  
  216. public void showListWindowForRemove(L2PcInstance player)
  217. {
  218. NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  219. StringBuilder tb = new StringBuilder("");
  220. String Rem = "GobackToAugList";
  221. L2ItemInstance[] invitems = player.getInventory().getItems();
  222.  
  223. tb.append("<html><head><title>By AbsolutePower</title></head><body>");
  224. tb.append("<center>");
  225. tb.append("<table width=\"250\" cellpadding=\"5\" bgcolor=\"000000\">");
  226. tb.append("<tr>");
  227. tb.append("<td width=\"45\" valign=\"top\" align=\"center\"><img src=\"L2ui_ch3.menubutton4\" width=\"38\" height=\"38\"></td>");
  228. tb.append("<td valign=\"top\"><font color=\"FF6600\">AugmentHelper</font>");
  229. tb.append("<br1><font color=\"00FF00ju\">" + player.getName() + "</font>, use this menu for fast augment :)<br1></td>");
  230. tb.append("</tr>");
  231. tb.append("</table>");
  232. tb.append("</center>");
  233. tb.append("<center>");
  234. tb.append("<br>");
  235.  
  236. for (L2ItemInstance item : invitems)
  237. {
  238. if(item==null)
  239. continue;
  240.  
  241. boolean canBeShow = item.isAugmented();
  242.  
  243. if(canBeShow)
  244. {
  245. tb.append("<button value=\""+item.getItemName()+"\" action=\"bypass -h npc_" + getObjectId() + "_tryremove-"+item.getObjectId()+"\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\"><br>");
  246. }
  247. }
  248.  
  249. tb.append("<br>");
  250. tb.append("<button value=\""+Rem+"\" action=\"bypass -h npc_" + getObjectId() + "_showauglist-1"+"\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\"><br>");
  251. tb.append("</center>");
  252. tb.append("</body></html>");
  253.  
  254. nhm.setHtml(tb.toString());
  255. player.sendPacket(nhm);
  256. }
  257.  
  258. protected static final boolean isValid(L2PcInstance player, L2ItemInstance item)
  259. {
  260. if (!isValid(player))
  261. return false;
  262.  
  263. if (item.getOwnerId() != player.getObjectId())
  264. return false;
  265. if (item.isAugmented())
  266. return false;
  267. if (item.isHeroItem())
  268. return false;
  269. if (item.isShadowItem())
  270. return false;
  271. if (item.getItem().getCrystalType() < L2Item.CRYSTAL_C)
  272. return false;
  273. if(item.isQuestItem())
  274. return false;
  275.  
  276. switch (item.getLocation())
  277. {
  278. case INVENTORY:
  279. case PAPERDOLL:
  280. break;
  281. default:
  282. return false;
  283. }
  284.  
  285. if (item.getItem() instanceof L2Weapon)
  286. {
  287. switch (((L2Weapon) item.getItem()).getItemType())
  288. {
  289. case NONE:
  290. case ROD:
  291. return false;
  292. default:
  293. break;
  294. }
  295. }
  296. else
  297. return false;
  298.  
  299. return true;
  300. }
  301.  
  302. protected static final boolean isValid(L2PcInstance player)
  303. {
  304. if (player.isInStoreMode())
  305. {
  306. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_A_PRIVATE_STORE_OR_PRIVATE_WORKSHOP_IS_IN_OPERATION);
  307. return false;
  308. }
  309. if (player.getActiveTradeList() != null)
  310. {
  311. player.sendPacket(SystemMessageId.AUGMENTED_ITEM_CANNOT_BE_DISCARDED);
  312. return false;
  313. }
  314. if (player.isDead())
  315. {
  316. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_DEAD);
  317. return false;
  318. }
  319. if (player.isParalyzed())
  320. {
  321. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_PARALYZED);
  322. return false;
  323. }
  324. if (player.isFishing())
  325. {
  326. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_FISHING);
  327. return false;
  328. }
  329. if (player.isSitting())
  330. {
  331. player.sendPacket(SystemMessageId.YOU_CANNOT_AUGMENT_ITEMS_WHILE_SITTING_DOWN);
  332. return false;
  333. }
  334. if (player.isCursedWeaponEquiped())
  335. return false;
  336. if (player.isProcessingTransaction())
  337. return false;
  338.  
  339. return true;
  340. }
  341.  
  342. @Override
  343. public void onAction(L2PcInstance player)
  344. {
  345. if (this != player.getTarget())
  346. {
  347. player.setTarget(this);
  348. player.sendPacket(new MyTargetSelected(getObjectId(), player.getLevel() - getLevel()));
  349. player.sendPacket(new ValidateLocation(this));
  350. }
  351. else if (isInsideRadius(player, INTERACTION_DISTANCE, false, false))
  352. {
  353. SocialAction sa = new SocialAction(this.getObjectId(), Rnd.get(8));
  354. broadcastPacket(sa);
  355. player.setLastFolkNPC(this);
  356. showListWindow(player);
  357. player.sendPacket(ActionFailed.STATIC_PACKET);
  358. }
  359. else {
  360. player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  361. player.sendPacket(ActionFailed.STATIC_PACKET);
  362. }
  363. }
  364. }
Advertisement
Add Comment
Please, Sign In to add comment