warc222

[SHARE] Augment shop

Sep 17th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.22 KB | None | 0 0
  1. package com.l2jfrozen.gameserver.model.actor.instance;
  2.  
  3.  
  4. import com.l2jfrozen.gameserver.ai.CtrlIntention;
  5. import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  6. import com.l2jfrozen.gameserver.model.Inventory;
  7. import java.sql.Connection;
  8. import java.sql.PreparedStatement;
  9. import java.sql.ResultSet;
  10.  
  11. import com.l2jfrozen.util.database.L2DatabaseFactory;
  12.  
  13. import java.util.HashMap;
  14. import java.util.Map;
  15. import java.util.logging.Level;
  16.  
  17. import javolution.text.TextBuilder;
  18.  
  19. import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
  20. import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
  21. import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
  22. import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
  23. import com.l2jfrozen.gameserver.network.serverpackets.StatusUpdate;
  24. import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
  25. import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
  26.  
  27.  
  28. /**
  29. *
  30. * @author Token
  31. *
  32. */
  33. public class L2AugmenterInstance extends L2FolkInstance
  34. {
  35. private final static int ITEM_ID = 57;
  36. private final static int ITEM_COUNT = 1000000;
  37.  
  38.  
  39.  
  40. public L2AugmenterInstance(int objectId, L2NpcTemplate template)
  41. {
  42. super(objectId, template);
  43.  
  44. }
  45.  
  46. @Override
  47. public void onBypassFeedback(L2PcInstance player, String command)
  48. {
  49.  
  50.  
  51. if (player == null || player.getLastFolkNPC() == null || player.getLastFolkNPC().getObjectId() != this.getObjectId())
  52. {
  53. return;
  54. }
  55. else if (command.startsWith("active"))
  56. {
  57. showActiveWindow(player, 0);
  58. }
  59. else if (command.startsWith("passive"))
  60. {
  61. showPassiveWindow(player, 0);
  62. }
  63. else if (command.startsWith("back"))
  64. {
  65. showChatWindow(player, 0);
  66. }
  67. else if (command.startsWith("focus"))
  68. {
  69. addAugment(player, 14863, 3141, 10);
  70. }
  71. else if (command.startsWith("might"))
  72. {
  73. addAugment(player, 14960, 3132, 10);
  74. }
  75. else if (command.startsWith("healEmpower"))
  76. {
  77. addAugment(player, 15125, 3138, 10);
  78. }
  79. else if (command.startsWith("magicBarrier"))
  80. {
  81. addAugment(player, 15214, 3245, 10);
  82. }
  83. else if (command.startsWith("empower"))
  84. {
  85. addAugment(player, 15389, 3246, 10);
  86. }
  87. else if (command.startsWith("wildMagic"))
  88. {
  89. addAugment(player, 15446, 3250, 10);
  90. }
  91. }
  92.  
  93.  
  94. @Override
  95. public void onAction(L2PcInstance player)
  96. {
  97.  
  98. if (!this.canTarget(player))
  99. return;
  100.  
  101. player.setLastFolkNPC(this);
  102.  
  103. if(player.getTarget() != this)
  104. {
  105. player.setTarget(this);
  106. getAI();
  107. MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
  108. player.sendPacket(my);
  109.  
  110. StatusUpdate su = new StatusUpdate(getObjectId());
  111. su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
  112. su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
  113. player.sendPacket(su);
  114. player.sendPacket(new ValidateLocation(this));
  115. }
  116. else
  117. {
  118. if(!isAutoAttackable(player))
  119. showChatWindow(player, 0);
  120. else if(!player.isAlikeDead())
  121. player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
  122.  
  123. player.sendPacket(new ValidateLocation(this));
  124. player.sendPacket(ActionFailed.STATIC_PACKET);
  125. }
  126. }
  127.  
  128. @Override
  129. public void showChatWindow(L2PcInstance player, int val)
  130. {
  131. TextBuilder tb = new TextBuilder();
  132. tb.append("<html><title>Augmenter</title><body><center><br>");
  133. tb.append("<font color=LEVEL>Welcome "+ player.getName()+" </font><br>");
  134. tb.append("<button value=\"Active\" action=\"bypass -h npc_%objectId%_active\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  135. tb.append("<button value=\"Passive\" action=\"bypass -h npc_%objectId%_passive\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  136.  
  137.  
  138.  
  139. tb.append("<br><br><br><span color=LEVEL>By Token</span>");
  140.  
  141. NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  142. msg.setHtml(tb.toString());
  143. msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  144.  
  145. player.sendPacket(msg);
  146. }
  147.  
  148.  
  149. public void showActiveWindow(L2PcInstance player, int val)
  150. {
  151. TextBuilder tb = new TextBuilder();
  152. tb.append("<html><title>Augmenter</title><body><center><br>");
  153.  
  154.  
  155. tb.append("<button value=\"Focus\" action=\"bypass -h npc_%objectId%_focus\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  156. tb.append("<button value=\"Heal Emp\" action=\"bypass -h npc_%objectId%_healEmpower\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  157. tb.append("<button value=\"Might\" action=\"bypass -h npc_%objectId%_might\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  158. tb.append("<br/><button value=\"Back\" action=\"bypass -h npc_%objectId%_back\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  159.  
  160. NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  161. msg.setHtml(tb.toString());
  162. msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  163.  
  164. player.sendPacket(msg);
  165. }
  166. public void showPassiveWindow(L2PcInstance player, int val)
  167. {
  168. TextBuilder tb = new TextBuilder();
  169. tb.append("<html><title>Augmenter</title><body><center><br>");
  170.  
  171.  
  172. tb.append("<button value=\"Magic barrier\" action=\"bypass -h npc_%objectId%_magicBarrier\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  173. tb.append("<button value=\"Empower\" action=\"bypass -h npc_%objectId%_empower\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  174. tb.append("<button value=\"Wild magic\" action=\"bypass -h npc_%objectId%_wildMagic\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  175. tb.append("<br/><button value=\"Back\" action=\"bypass -h npc_%objectId%_back\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\">");
  176.  
  177. NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  178. msg.setHtml(tb.toString());
  179. msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  180.  
  181. player.sendPacket(msg);
  182. }
  183.  
  184.  
  185.  
  186. private static void addAugment(L2PcInstance player, int attribute, int skill, int level)
  187. {
  188. L2ItemInstance item = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  189. if (item == null)
  190. {
  191. player.sendMessage("You have to equip a weapon.");
  192. return;
  193. }
  194. if (player.getInventory().getInventoryItemCount(ITEM_ID, -1) < ITEM_COUNT)
  195. {
  196.  
  197. player.sendMessage("You dont have enough item.");
  198. return;
  199. }
  200. if (item.isAugmented())
  201. {
  202. player.sendMessage("Remove augment first.");
  203. return;
  204. }
  205.  
  206. Connection con = null;
  207. try
  208. {
  209. player.destroyItemByItemId("Consume", ITEM_ID, ITEM_COUNT, player, true);
  210. con = L2DatabaseFactory.getInstance().getConnection();
  211. PreparedStatement statement = con.prepareStatement("REPLACE INTO augmentations VALUES(?,?,?,?)");
  212. statement.setInt(1, item.getObjectId());
  213.  
  214. statement.setInt(2, attribute*65536+1);
  215. statement.setInt(3, skill);
  216. statement.setInt(4, level);
  217.  
  218.  
  219. statement.executeUpdate();
  220. player.sendMessage("Succesfully augmented. You have to relog now.");
  221. statement.close();
  222.  
  223. }
  224. catch (Exception e)
  225. {
  226. _log.log(Level.SEVERE, "Could not augment item: "+item.getObjectId()+" ", e);
  227. }
  228. finally
  229. {
  230. L2DatabaseFactory.close(con);
  231. }
  232. }
  233.  
  234.  
  235. }
  236.  
  237.  
  238.  
  239.  
  240.  
  241. INSERT INTO `custom_npc` VALUES ('70016',22124,'Augmenter',1,'Augment shop',1,'NPC.a_guard_MHuman','11.00','27.00','80','male','L2Augmenter',5,'5','5','5.00','5.00','5','5','5','5','5','5','5','5','5','5',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0,'0','LAST_HIT')
Advertisement
Add Comment
Please, Sign In to add comment