Advertisement
LIONN

Npc AIO Shop v1

Mar 27th, 2012
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.61 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2jFrozen_GameServer
  3. Index: head-src/com/l2jfrozen/Config.java
  4. ===================================================================
  5. --- head-src/com/l2jfrozen/Config.java  (revision 986)
  6. +++ head-src/com/l2jfrozen/Config.java  (working copy)
  7. @@ -570,6 +570,9 @@
  8.     public static int AIO_TCOLOR;
  9.     public static boolean ALLOW_AIO_USE_GK;
  10.     public static boolean ALLOW_AIO_USE_CM;
  11. +   public static int AIO_ITEM_ID;
  12. +   public static int AIO_ITEM_CNT;
  13. +
  14.     public static boolean ANNOUNCE_CASTLE_LORDS;
  15.    
  16.     /** Configuration to allow custom items to be given on character creation */
  17. @@ -674,6 +677,8 @@
  18.             AIO_TCOLOR = Integer.decode("0x" + otherSettings.getProperty("AioTitleColor", "88AA88"));
  19.             ALLOW_AIO_USE_GK = Boolean.parseBoolean(otherSettings.getProperty("AllowAioUseGk", "False"));
  20.             ALLOW_AIO_USE_CM = Boolean.parseBoolean(otherSettings.getProperty("AllowAioUseClassMaster", "False"));
  21. +           AIO_ITEM_ID = Integer.parseInt(otherSettings.getProperty("AioItemId", "3470"));
  22. +           AIO_ITEM_CNT = Integer.parseInt(otherSettings.getProperty("AioItemCount", "50"));
  23.             ANNOUNCE_CASTLE_LORDS = Boolean.parseBoolean(otherSettings.getProperty("AnnounceCastleLords", "False"));
  24.             if(ENABLE_AIO_SYSTEM) //create map if system is enabled
  25.             {
  26. Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2AioSellerInstance.java
  27. ===================================================================
  28. --- head-src/com/l2jfrozen/gameserver/model/actor/instance/L2AioSellerInstance.java (revision 0)
  29. +++ head-src/com/l2jfrozen/gameserver/model/actor/instance/L2AioSellerInstance.java (working copy)
  30. @@ -0,0 +1,273 @@
  31. +/* This program is free software; you can redistribute it and/or modify
  32. + * it under the terms of the GNU General Public License as published by
  33. + * the Free Software Foundation; either version 2, or (at your option)
  34. + * any later version.
  35. + *
  36. + * This program is distributed in the hope that it will be useful,
  37. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  39. + * GNU General Public License for more details.
  40. + *
  41. + * You should have received a copy of the GNU General Public License
  42. + * along with this program; if not, write to the Free Software
  43. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  44. + * 02111-1307, USA.
  45. + *
  46. + * http://www.gnu.org/copyleft/gpl.html
  47. + */
  48. +package com.l2jfrozen.gameserver.model.actor.instance;
  49. +
  50. +import java.sql.Connection;
  51. +import java.sql.PreparedStatement;
  52. +import java.util.logging.Level;
  53. +
  54. +import javolution.text.TextBuilder;
  55. +
  56. +import com.l2jfrozen.Config;
  57. +import com.l2jfrozen.gameserver.ai.CtrlIntention;
  58. +import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
  59. +import com.l2jfrozen.gameserver.network.serverpackets.EtcStatusUpdate;
  60. +import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
  61. +import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
  62. +import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
  63. +import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
  64. +import com.l2jfrozen.util.CloseUtil;
  65. +import com.l2jfrozen.util.database.L2DatabaseFactory;
  66. +
  67. +/**
  68. + * @author RedHoT
  69. + */
  70. +public class L2AioSellerInstance extends L2FolkInstance
  71. +{
  72. +   public L2AioSellerInstance(int objectId, L2NpcTemplate template)
  73. +   {
  74. +       super(objectId, template);
  75. +   }
  76. +  
  77. +   @Override
  78. +   public void onAction(L2PcInstance player)
  79. +   {
  80. +       if (!canTarget(player))
  81. +           return;
  82. +      
  83. +       player.setLastFolkNPC(this);
  84. +      
  85. +       // Check if the L2PcInstance already target the L2NpcInstance
  86. +       if (this != player.getTarget())
  87. +       {
  88. +           // Set the target of the L2PcInstance player
  89. +           player.setTarget(this);
  90. +          
  91. +           // Send a Server->Client packet MyTargetSelected to the L2PcInstance player
  92. +           MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
  93. +           player.sendPacket(my);
  94. +           my = null;
  95. +          
  96. +           // Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client
  97. +           player.sendPacket(new ValidateLocation(this));
  98. +       }
  99. +       else
  100. +       {
  101. +           // Calculate the distance between the L2PcInstance and the L2NpcInstance
  102. +           if (!canInteract(player))
  103. +           {
  104. +               // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
  105. +               player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  106. +           }
  107. +           else
  108. +           {
  109. +               showHtmlWindow(player);
  110. +           }
  111. +       }
  112. +       // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  113. +       player.sendPacket(ActionFailed.STATIC_PACKET);
  114. +   }
  115. +  
  116. +   @Override
  117. +   public void onBypassFeedback(L2PcInstance player, String command)
  118. +   {
  119. +       int itemId = Config.AIO_ITEM_ID;
  120. +       int itemCount = Config.AIO_ITEM_CNT;
  121. +      
  122. +       L2ItemInstance itemInstance = player.getInventory().getItemByItemId(itemId);
  123. +      
  124. +       if (command.startsWith("add_aio_1"))
  125. +       {
  126. +           if (itemInstance == null || !itemInstance.isStackable() && player.getInventory().getInventoryItemCount(itemId, -1) < itemCount)
  127. +           {
  128. +               player.sendMessage("You do not have enough items!");
  129. +               return;
  130. +           }
  131. +           if (itemInstance.isStackable())
  132. +           {
  133. +               if (!player.destroyItemByItemId("Aio Seller", itemId, itemCount, player.getTarget(), true))
  134. +               {
  135. +                   player.sendMessage("You do not have enough items!");
  136. +                   return;
  137. +               }
  138. +           }
  139. +           else
  140. +               for (int i = 0; i < itemCount; i++)
  141. +                   player.destroyItemByItemId("Aio Seller", itemId, 1, player.getTarget(), true);
  142. +          
  143. +           doAio(player, 30);
  144. +       }
  145. +       else if (command.startsWith("add_aio_2"))
  146. +       {
  147. +           if (itemInstance == null || !itemInstance.isStackable() && player.getInventory().getInventoryItemCount(itemId, -1) < (itemCount * 1.67))
  148. +           {
  149. +               player.sendMessage("You do not have enough items!");
  150. +               return;
  151. +           }
  152. +           if (itemInstance.isStackable())
  153. +           {
  154. +               if (!player.destroyItemByItemId("Aio Seller", itemId, (int) (itemCount * 1.67), player.getTarget(), true))
  155. +               {
  156. +                   player.sendMessage("You do not have enough items!");
  157. +                   return;
  158. +               }
  159. +           }
  160. +           else
  161. +               for (int i = 0; i < (itemCount * 1.67); i++)
  162. +                   player.destroyItemByItemId("Aio Seller", itemId, 1, player.getTarget(), true);
  163. +          
  164. +           doAio(player, 60);
  165. +       }
  166. +       else if (command.startsWith("add_aio_3"))
  167. +       {
  168. +           if (itemInstance == null || !itemInstance.isStackable() && player.getInventory().getInventoryItemCount(itemId, -1) < (itemCount * 2.5))
  169. +           {
  170. +               player.sendMessage("You do not have enough items!");
  171. +               return;
  172. +           }
  173. +           if (itemInstance.isStackable())
  174. +           {
  175. +               if (!player.destroyItemByItemId("Aio Seller", itemId, (int) (itemCount * 2.5), player.getTarget(), true))
  176. +               {
  177. +                   player.sendMessage("You do not have enough items!");
  178. +                   return;
  179. +               }
  180. +           }
  181. +           else
  182. +               for (int i = 0; i < (itemCount * 2.5); i++)
  183. +                   player.destroyItemByItemId("Aio Seller", itemId, 1, player.getTarget(), true);
  184. +          
  185. +           doAio(player, 90);
  186. +       }
  187. +       else if (command.startsWith("remove_aio"))
  188. +       {
  189. +           removeAio(player);
  190. +       }
  191. +       showHtmlWindow(player);
  192. +   }
  193. +  
  194. +   private void showHtmlWindow(L2PcInstance activeChar)
  195. +   {
  196. +       NpcHtmlMessage nhm = new NpcHtmlMessage(5);
  197. +       TextBuilder replyMSG = new TextBuilder("");
  198. +      
  199. +       replyMSG.append("<html><title>Aio Seller NPC</title><body><center>");
  200. +       replyMSG.append("<img src=L2UI_CH3.herotower_deco width=256 height=32><br>");
  201. +       replyMSG.append("<font color=LEVEL>NPC Aio Seller</font><br>");
  202. +       replyMSG.append("<img src=L2UI.SquareGray width=300 height=1><br>");
  203. +       replyMSG.append("<center><button value=\"1 month\" action=\"bypass -h npc_" + getObjectId() + "_add_aio_1\" width=205 height=20 back=\"sek.cbui81\" fore=\"sek.cbui79\"></center>");
  204. +       replyMSG.append("<center><button value=\"2 months\" action=\"bypass -h npc_" + getObjectId() + "_add_aio_2\" width=205 height=20 back=\"sek.cbui81\" fore=\"sek.cbui79\"></center>");
  205. +       replyMSG.append("<center><button value=\"3 months\" action=\"bypass -h npc_" + getObjectId() + "_add_aio_3\" width=205 height=20 back=\"sek.cbui81\" fore=\"sek.cbui79\"></center><br>");
  206. +       replyMSG.append("<img src=L2UI_CH3.herotower_deco width=256 height=32><br>");
  207. +       replyMSG.append("<center><button value=\"Remove\" action=\"bypass -h npc_" + getObjectId() + "_remove_aio\" width=205 height=20 back=\"sek.cbui81\" fore=\"sek.cbui79\"></center><br>");
  208. +       replyMSG.append("<img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br>");
  209. +       replyMSG.append("<img src=l2ui.bbs_lineage2 height=16 width=80>");
  210. +       replyMSG.append("<font color=808080>" + Config.ALT_Server_Name + "</font>");
  211. +       replyMSG.append("</center></body></html>");
  212. +      
  213. +       nhm.setHtml(replyMSG.toString());
  214. +       activeChar.sendPacket(nhm);
  215. +      
  216. +       activeChar.sendPacket(new ActionFailed());
  217. +   }
  218. +  
  219. +   public void doAio(L2PcInstance player, int days)
  220. +   {
  221. +       if (player == null)
  222. +           return;
  223. +      
  224. +       player.setAio(true);
  225. +       player.setEndTime("aio", days);
  226. +       player.getStat().addExp(player.getStat().getExpForLevel(81));
  227. +      
  228. +       Connection connection = null;
  229. +       try
  230. +       {
  231. +           connection = L2DatabaseFactory.getInstance().getConnection(false);
  232. +          
  233. +           PreparedStatement statement = connection.prepareStatement("UPDATE characters SET aio=1, aio_end=? WHERE obj_id=?");
  234. +           statement.setLong(1, player.getAioEndTime());
  235. +           statement.setInt(2, player.getObjectId());
  236. +           statement.execute();
  237. +           statement.close();
  238. +           connection.close();
  239. +          
  240. +           if (Config.ALLOW_AIO_NCOLOR && player.isAio())
  241. +               player.getAppearance().setNameColor(Config.AIO_NCOLOR);
  242. +          
  243. +           if (Config.ALLOW_AIO_TCOLOR && player.isAio())
  244. +               player.getAppearance().setTitleColor(Config.AIO_TCOLOR);
  245. +          
  246. +           player.rewardAioSkills();
  247. +           player.broadcastUserInfo();
  248. +           player.sendPacket(new EtcStatusUpdate(player));
  249. +           player.sendSkillList();
  250. +           player.sendMessage("You are now an Aio, Congratulations!");
  251. +           player.broadcastUserInfo();
  252. +       }
  253. +       catch (Exception e)
  254. +       {
  255. +           if (Config.ENABLE_ALL_EXCEPTIONS)
  256. +               e.printStackTrace();
  257. +          
  258. +           _log.log(Level.WARNING, "could not set Aio stats to char:", e);
  259. +       }
  260. +       finally
  261. +       {
  262. +           CloseUtil.close(connection);
  263. +       }
  264. +   }
  265. +  
  266. +   public void removeAio(L2PcInstance player)
  267. +   {
  268. +       player.setAio(false);
  269. +       player.setAioEndTime(0);
  270. +      
  271. +       Connection connection = null;
  272. +       try
  273. +       {
  274. +           connection = L2DatabaseFactory.getInstance().getConnection(false);
  275. +          
  276. +           PreparedStatement statement = connection.prepareStatement("UPDATE characters SET Aio=0, Aio_end=0 WHERE obj_id=?");
  277. +           statement.setInt(1, player.getObjectId());
  278. +           statement.execute();
  279. +           statement.close();
  280. +           connection.close();
  281. +          
  282. +           player.lostAioSkills();
  283. +           player.getAppearance().setNameColor(0xFFFFFF);
  284. +           player.getAppearance().setTitleColor(0xFFFF77);
  285. +           player.broadcastUserInfo();
  286. +           player.sendPacket(new EtcStatusUpdate(player));
  287. +           player.sendSkillList();
  288. +           player.sendMessage("Now You are not an Aio..");
  289. +           player.broadcastUserInfo();
  290. +       }
  291. +       catch (Exception e)
  292. +       {
  293. +           if (Config.ENABLE_ALL_EXCEPTIONS)
  294. +               e.printStackTrace();
  295. +          
  296. +           _log.log(Level.WARNING, "could not remove Aio stats of char:", e);
  297. +       }
  298. +       finally
  299. +       {
  300. +           CloseUtil.close(connection);
  301. +       }
  302. +   }
  303. +}
  304. \ No newline at end of file
  305. Index: config/head/other.properties
  306. ===================================================================
  307. --- config/head/other.properties    (revision 986)
  308. +++ config/head/other.properties    (working copy)
  309. @@ -229,6 +229,9 @@
  310.  # Aio Buffers can speak to Class Master?
  311.  AllowAioUseClassMaster = False
  312.  
  313. +AioItemId = 3470
  314. +AioItemCount = 30
  315. +
  316.  # Announce castle lords on enter game. default = false
  317.  AnnounceCastleLords = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement