AdminEditNpc.java 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  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 net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.sql.SQLException;
  19. import java.util.List;
  20. import java.util.StringTokenizer;
  21. import java.util.logging.Logger;
  22. import javolution.text.TextBuilder;
  23. import javolution.util.FastList;
  24. import net.sf.l2j.L2DatabaseFactory;
  25. import net.sf.l2j.gameserver.TradeController;
  26. import net.sf.l2j.gameserver.cache.HtmCache;
  27. import net.sf.l2j.gameserver.datatables.ItemTable;
  28. import net.sf.l2j.gameserver.datatables.NpcTable;
  29. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  30. import net.sf.l2j.gameserver.model.L2DropCategory;
  31. import net.sf.l2j.gameserver.model.L2DropData;
  32. import net.sf.l2j.gameserver.model.L2Object;
  33. import net.sf.l2j.gameserver.model.L2TradeList;
  34. import net.sf.l2j.gameserver.model.L2TradeList.L2TradeItem;
  35. import net.sf.l2j.gameserver.model.actor.instance.L2BoxInstance;
  36. import net.sf.l2j.gameserver.model.actor.instance.L2MerchantInstance;
  37. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  38. import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
  39. import net.sf.l2j.gameserver.templates.L2Item;
  40. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  41. import net.sf.l2j.gameserver.templates.StatsSet;
  42. /**
  43. * @author terry
  44. *
  45. * Window - Preferences - Java - Code Style - Code Templates
  46. */
  47. public class AdminEditNpc implements IAdminCommandHandler {
  48. private static Logger _log = Logger.getLogger(AdminEditChar.class.getName());
  49. private final static int PAGE_LIMIT = 7;
  50. private static final String[] ADMIN_COMMANDS = {
  51. "admin_edit_npc",
  52. "admin_save_npc",
  53. "admin_show_droplist",
  54. "admin_edit_drop",
  55. "admin_add_drop",
  56. "admin_del_drop",
  57. "admin_showShop",
  58. "admin_showShopList",
  59. "admin_addShopItem",
  60. "admin_delShopItem",
  61. "admin_box_access",
  62. "admin_editShopItem",
  63. "admin_close_window"
  64. };
  65. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  66. {//TODO: Tokenize and protect arguments parsing. Externalize HTML.
  67. if (command.startsWith("admin_showShop "))
  68. {
  69. String[] args = command.split(" ");
  70. if (args.length > 1)
  71. showShop(activeChar, Integer.parseInt(command.split(" ")[1]));
  72. }
  73. else if(command.startsWith("admin_showShopList "))
  74. {
  75. String[] args = command.split(" ");
  76. if (args.length > 2)
  77. showShopList(activeChar, Integer.parseInt(command.split(" ")[1]), Integer.parseInt(command.split(" ")[2]));
  78. }
  79. else if(command.startsWith("admin_edit_npc "))
  80. {
  81. try
  82. {
  83. String[] commandSplit = command.split(" ");
  84. int npcId = Integer.valueOf(commandSplit[1]);
  85. L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId);
  86. Show_Npc_Property(activeChar, npc);
  87. }
  88. catch (Exception e)
  89. {
  90. activeChar.sendMessage("Wrong usage: //edit_npc <npcId>");
  91. }
  92. }
  93. else if(command.startsWith("admin_show_droplist "))
  94. {
  95. int npcId = 0;
  96. try
  97. {
  98. npcId = Integer.parseInt(command.substring(20).trim());
  99. }
  100. catch(Exception e){}
  101. if(npcId > 0)
  102. showNpcDropList(activeChar, npcId);
  103. else
  104. activeChar.sendMessage("Usage: //show_droplist <npc_id>");
  105. }
  106. else if(command.startsWith("admin_addShopItem "))
  107. {
  108. String[] args = command.split(" ");
  109. if (args.length > 1)
  110. addShopItem(activeChar, args);
  111. }
  112. else if(command.startsWith("admin_delShopItem "))
  113. {
  114. String[] args = command.split(" ");
  115. if (args.length > 2)
  116. delShopItem(activeChar, args);
  117. }
  118. else if(command.startsWith("admin_editShopItem "))
  119. {
  120. String[] args = command.split(" ");
  121. if (args.length > 2)
  122. editShopItem(activeChar, args);
  123. }
  124. else if(command.startsWith("admin_save_npc "))
  125. {
  126. try
  127. {
  128. save_npc_property(activeChar, command);
  129. }
  130. catch (StringIndexOutOfBoundsException e)
  131. {}
  132. }
  133. else if(command.startsWith("admin_edit_drop "))
  134. {
  135. int npcId = -1, itemId = 0, category = -1000;
  136. try
  137. {
  138. StringTokenizer st = new StringTokenizer(command.substring(16).trim());
  139. if (st.countTokens() == 3)
  140. {
  141. try
  142. {
  143. npcId = Integer.parseInt(st.nextToken());
  144. itemId = Integer.parseInt(st.nextToken());
  145. category = Integer.parseInt(st.nextToken());
  146. showEditDropData(activeChar, npcId, itemId, category);
  147. }
  148. catch(Exception e)
  149. {}
  150. }
  151. else if (st.countTokens() == 6)
  152. {
  153. try
  154. {
  155. npcId = Integer.parseInt(st.nextToken());
  156. itemId = Integer.parseInt(st.nextToken());
  157. category = Integer.parseInt(st.nextToken());
  158. int min = Integer.parseInt(st.nextToken());
  159. int max = Integer.parseInt(st.nextToken());
  160. int chance = Integer.parseInt(st.nextToken());
  161. updateDropData(activeChar, npcId, itemId, min, max, category, chance);
  162. }
  163. catch(Exception e)
  164. {
  165. _log.fine("admin_edit_drop parements error: " + command);
  166. }
  167. }
  168. else
  169. activeChar.sendMessage("Usage: //edit_drop <npc_id> <item_id> <category> [<min> <max> <chance>]");
  170. }
  171. catch (StringIndexOutOfBoundsException e)
  172. {
  173. activeChar.sendMessage("Usage: //edit_drop <npc_id> <item_id> <category> [<min> <max> <chance>]");
  174. }
  175. }
  176. else if (command.startsWith("admin_add_drop "))
  177. {
  178. int npcId = -1;
  179. try
  180. {
  181. StringTokenizer st = new StringTokenizer(command.substring(15).trim());
  182. if(st.countTokens() == 1)
  183. {
  184. try
  185. {
  186. String[] input = command.substring(15).split(" ");
  187. if (input.length < 1)
  188. return true;
  189. npcId = Integer.parseInt(input[0]);
  190. }
  191. catch(Exception e){}
  192. if(npcId > 0)
  193. {
  194. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  195. showAddDropData(activeChar, npcData);
  196. }
  197. }
  198. else if(st.countTokens() == 6)
  199. {
  200. try
  201. {
  202. npcId = Integer.parseInt(st.nextToken());
  203. int itemId = Integer.parseInt(st.nextToken());
  204. int category = Integer.parseInt(st.nextToken());
  205. int min = Integer.parseInt(st.nextToken());
  206. int max = Integer.parseInt(st.nextToken());
  207. int chance = Integer.parseInt(st.nextToken());
  208. addDropData(activeChar, npcId, itemId, min, max, category, chance);
  209. }
  210. catch(Exception e)
  211. {
  212. _log.fine("admin_add_drop parements error: " + command);
  213. }
  214. }
  215. else
  216. activeChar.sendMessage("Usage: //add_drop <npc_id> [<item_id> <category> <min> <max> <chance>]");
  217. }
  218. catch (StringIndexOutOfBoundsException e)
  219. {
  220. activeChar.sendMessage("Usage: //add_drop <npc_id> [<item_id> <category> <min> <max> <chance>]");
  221. }
  222. }
  223. else if(command.startsWith("admin_del_drop "))
  224. {
  225. int npcId = -1, itemId = -1, category = -1000;
  226. try
  227. {
  228. String[] input = command.substring(15).split(" ");
  229. if (input.length >= 3)
  230. {
  231. npcId = Integer.parseInt(input[0]);
  232. itemId = Integer.parseInt(input[1]);
  233. category = Integer.parseInt(input[2]);
  234. }
  235. }
  236. catch(Exception e){}
  237. if(npcId > 0)
  238. deleteDropData(activeChar, npcId, itemId, category);
  239. else
  240. activeChar.sendMessage("Usage: //del_drop <npc_id> <item_id> <category>");
  241. }
  242. else if(command.startsWith("admin_box_access"))
  243. {
  244. L2Object target = activeChar.getTarget();
  245. String[] players = command.split(" ");
  246. if (target instanceof L2BoxInstance)
  247. {
  248. L2BoxInstance box = (L2BoxInstance) target;
  249. if (players.length > 1)
  250. {
  251. boolean access = true;
  252. for (int i = 1; i < players.length; i++)
  253. {
  254. if (players[i].equals("no"))
  255. {
  256. access = false;
  257. continue;
  258. }
  259. box.grantAccess(players[i],access);
  260. }
  261. }
  262. else
  263. {
  264. try
  265. {
  266. String msg = "Access:";
  267. for (Object p : box.getAccess())
  268. msg += " "+(String)p;
  269. activeChar.sendMessage(msg);
  270. }
  271. catch (Exception e)
  272. {
  273. _log.info("box_access: "+e);
  274. }
  275. }
  276. }
  277. }
  278. return true;
  279. }
  280. private void editShopItem(L2PcInstance activeChar, String[] args)
  281. {
  282. int tradeListID = Integer.parseInt(args[1]);
  283. int itemID = Integer.parseInt(args[2]);
  284. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  285. L2Item item = ItemTable.getInstance().getTemplate(itemID);
  286. if (tradeList.getPriceForItemId(itemID) < 0)
  287. {
  288. return;
  289. }
  290. if (args.length > 3)
  291. {
  292. int price = Integer.parseInt(args[3]);
  293. int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);
  294. tradeList.replaceItem(itemID, Integer.parseInt(args[3]));
  295. updateTradeList(itemID, price, tradeListID, order);
  296. activeChar.sendMessage("Updated price for "+item.getName()+" in Trade List "+tradeListID);
  297. showShopList(activeChar, tradeListID, 1);
  298. return;
  299. }
  300. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  301. TextBuilder replyMSG = new TextBuilder();
  302. replyMSG.append("<html><title>Merchant Shop Item Edit</title>");
  303. replyMSG.append("<body>");
  304. replyMSG.append("<br>Edit an entry in merchantList.");
  305. replyMSG.append("<br>Editing Item: "+item.getName());
  306. replyMSG.append("<table>");
  307. replyMSG.append("<tr><td width=100>Property</td><td width=100>Edit Field</td><td width=100>Old Value</td></tr>");
  308. replyMSG.append("<tr><td><br></td><td></td></tr>");
  309. replyMSG.append("<tr><td>Price</td><td><edit var=\"price\" width=80></td><td>"+tradeList.getPriceForItemId(itemID)+"</td></tr>");
  310. replyMSG.append("</table>");
  311. replyMSG.append("<center><br><br><br>");
  312. replyMSG.append("<button value=\"Save\" action=\"bypass -h admin_editShopItem " + tradeListID + " " + itemID + " $price\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  313. replyMSG.append("<br><button value=\"Back\" action=\"bypass -h admin_showShopList " + tradeListID +" 1\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  314. replyMSG.append("</center>");
  315. replyMSG.append("</body></html>");
  316. adminReply.setHtml(replyMSG.toString());
  317. activeChar.sendPacket(adminReply);
  318. }
  319. private void delShopItem(L2PcInstance activeChar, String[] args)
  320. {
  321. int tradeListID = Integer.parseInt(args[1]);
  322. int itemID = Integer.parseInt(args[2]);
  323. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  324. if (tradeList.getPriceForItemId(itemID) < 0)
  325. return;
  326. if (args.length > 3)
  327. {
  328. int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);
  329. tradeList.removeItem(itemID);
  330. deleteTradeList(tradeListID, order);
  331. activeChar.sendMessage("Deleted "+ItemTable.getInstance().getTemplate(itemID).getName()+" from Trade List "+tradeListID);
  332. showShopList(activeChar, tradeListID, 1);
  333. return;
  334. }
  335. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  336. TextBuilder replyMSG = new TextBuilder();
  337. replyMSG.append("<html><title>Merchant Shop Item Delete</title>");
  338. replyMSG.append("<body>");
  339. replyMSG.append("<br>Delete entry in merchantList.");
  340. replyMSG.append("<br>Item to Delete: "+ItemTable.getInstance().getTemplate(itemID).getName());
  341. replyMSG.append("<table>");
  342. replyMSG.append("<tr><td width=100>Property</td><td width=100>Value</td></tr>");
  343. replyMSG.append("<tr><td><br></td><td></td></tr>");
  344. replyMSG.append("<tr><td>Price</td><td>"+tradeList.getPriceForItemId(itemID)+"</td></tr>");
  345. replyMSG.append("</table>");
  346. replyMSG.append("<center><br><br><br>");
  347. replyMSG.append("<button value=\"Confirm\" action=\"bypass -h admin_delShopItem " + tradeListID + " " + itemID + " 1\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  348. replyMSG.append("<br><button value=\"Back\" action=\"bypass -h admin_showShopList " + tradeListID +" 1\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  349. replyMSG.append("</center>");
  350. replyMSG.append("</body></html>");
  351. adminReply.setHtml(replyMSG.toString());
  352. activeChar.sendPacket(adminReply);
  353. }
  354. private void addShopItem(L2PcInstance activeChar, String[] args)
  355. {
  356. int tradeListID = Integer.parseInt(args[1]);
  357. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  358. if (tradeList == null)
  359. {
  360. activeChar.sendMessage("TradeList not found!");
  361. return;
  362. }
  363. if (args.length > 3)
  364. {
  365. int order = tradeList.getItems().size() + 1; // last item order + 1
  366. int itemID = Integer.parseInt(args[2]);
  367. int price = Integer.parseInt(args[3]);
  368. L2TradeItem newItem = new L2TradeItem(itemID);
  369. newItem.setPrice(price);
  370. newItem.setMaxCount(-1);
  371. tradeList.addItem(newItem);
  372. storeTradeList(itemID, price, tradeListID, order);
  373. activeChar.sendMessage("Added "+ItemTable.getInstance().getTemplate(itemID).getName()+" to Trade List "+tradeList.getListId());
  374. showShopList(activeChar, tradeListID, 1);
  375. return;
  376. }
  377. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  378. TextBuilder replyMSG = new TextBuilder();
  379. replyMSG.append("<html><title>Merchant Shop Item Add</title>");
  380. replyMSG.append("<body>");
  381. replyMSG.append("<br>Add a new entry in merchantList.");
  382. replyMSG.append("<table>");
  383. replyMSG.append("<tr><td width=100>Property</td><td>Edit Field</td></tr>");
  384. replyMSG.append("<tr><td><br></td><td></td></tr>");
  385. replyMSG.append("<tr><td>ItemID</td><td><edit var=\"itemID\" width=80></td></tr>");
  386. replyMSG.append("<tr><td>Price</td><td><edit var=\"price\" width=80></td></tr>");
  387. replyMSG.append("</table>");
  388. replyMSG.append("<center><br><br><br>");
  389. replyMSG.append("<button value=\"Save\" action=\"bypass -h admin_addShopItem " + tradeListID + " $itemID $price\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  390. replyMSG.append("<br><button value=\"Back\" action=\"bypass -h admin_showShopList " + tradeListID +" 1\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  391. replyMSG.append("</center>");
  392. replyMSG.append("</body></html>");
  393. adminReply.setHtml(replyMSG.toString());
  394. activeChar.sendPacket(adminReply);
  395. }
  396. private void showShopList(L2PcInstance activeChar, int tradeListID, int page)
  397. {
  398. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  399. if (page > tradeList.getItems().size() / PAGE_LIMIT + 1 || page < 1)
  400. return;
  401. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  402. TextBuilder html = itemListHtml(tradeList, page);
  403. adminReply.setHtml(html.toString());
  404. activeChar.sendPacket(adminReply);
  405. }
  406. private TextBuilder itemListHtml(L2TradeList tradeList, int page)
  407. {
  408. TextBuilder replyMSG = new TextBuilder();
  409. replyMSG.append("<html><title>Merchant Shop List Page: "+page+"</title>");
  410. replyMSG.append("<body>");
  411. replyMSG.append("<br>Edit, add or delete entries in a merchantList.");
  412. replyMSG.append("<table>");
  413. replyMSG.append("<tr><td width=150>Item Name</td><td width=60>Price</td><td width=40>Delete</td></tr>");
  414. int start = ((page-1) * PAGE_LIMIT);
  415. int end = Math.min(((page-1) * PAGE_LIMIT) + (PAGE_LIMIT-1), tradeList.getItems().size() - 1);
  416. for (L2TradeItem item : tradeList.getItems(start, end+1))
  417. {
  418. replyMSG.append("<tr><td><a action=\"bypass -h admin_editShopItem "+tradeList.getListId()+" "+item.getItemId()+"\">"+ItemTable.getInstance().getTemplate(item.getItemId()).getName()+"</a></td>");
  419. replyMSG.append("<td>"+item.getPrice()+"</td>");
  420. replyMSG.append("<td><button value=\"Del\" action=\"bypass -h admin_delShopItem "+tradeList.getListId()+" "+item.getItemId()+"\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  421. replyMSG.append("</tr>");
  422. }//*/
  423. replyMSG.append("<tr>");
  424. int min = 1;
  425. int max = tradeList.getItems().size() / PAGE_LIMIT + 1;
  426. if (page > 1)
  427. {
  428. replyMSG.append("<td><button value=\"Page"+(page - 1)+"\" action=\"bypass -h admin_showShopList "+tradeList.getListId()+" "+(page - 1)+"\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  429. }
  430. if (page < max)
  431. {
  432. if (page <= min)
  433. replyMSG.append("<td></td>");
  434. replyMSG.append("<td><button value=\"Page"+(page + 1)+"\" action=\"bypass -h admin_showShopList "+tradeList.getListId()+" "+(page + 1)+"\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
  435. }
  436. replyMSG.append("</tr><tr><td>.</td></tr>");
  437. replyMSG.append("</table>");
  438. replyMSG.append("<center>");
  439. replyMSG.append("<button value=\"Add\" action=\"bypass -h admin_addShopItem "+tradeList.getListId()+"\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  440. replyMSG.append("<button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  441. replyMSG.append("</center></body></html>");
  442. return replyMSG;
  443. }
  444. private void showShop(L2PcInstance activeChar, int merchantID)
  445. {
  446. List<L2TradeList> tradeLists = getTradeLists(merchantID);
  447. if(tradeLists == null)
  448. {
  449. activeChar.sendMessage("Unknown npc template Id: " + merchantID);
  450. return ;
  451. }
  452. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  453. TextBuilder replyMSG = new TextBuilder("<html><title>Merchant Shop Lists</title>");
  454. replyMSG.append("<body>");
  455. if (activeChar.getTarget() instanceof L2MerchantInstance)
  456. {
  457. String mpcName = ((L2MerchantInstance) activeChar.getTarget()).getMpc().getName();
  458. replyMSG.append("<br>NPC: "+activeChar.getTarget().getName());
  459. replyMSG.append("<br>Price Config: "+mpcName);
  460. }
  461. replyMSG.append("<br>Select a list to view");
  462. replyMSG.append("<table>");
  463. replyMSG.append("<tr><td>Mecrchant List ID</td></tr>");
  464. for (L2TradeList tradeList : tradeLists)
  465. {
  466. if (tradeList != null)
  467. replyMSG.append("<tr><td><a action=\"bypass -h admin_showShopList "+tradeList.getListId()+" 1\">Trade List "+tradeList.getListId()+"</a></td></tr>");
  468. }
  469. replyMSG.append("</table>");
  470. replyMSG.append("<center>");
  471. replyMSG.append("<button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  472. replyMSG.append("</center></body></html>");
  473. adminReply.setHtml(replyMSG.toString());
  474. activeChar.sendPacket(adminReply);
  475. }
  476. private void storeTradeList(int itemID, int price, int tradeListID, int order)
  477. {
  478. java.sql.Connection con = null;
  479. try
  480. {
  481. con = L2DatabaseFactory.getInstance().getConnection();
  482. PreparedStatement stmt = con.prepareStatement("INSERT INTO merchant_buylists (`item_id`,`price`,`shop_id`,`order`) values ("+itemID+","+price+","+tradeListID+","+order+")");
  483. stmt.execute();
  484. stmt.close();
  485. }
  486. catch (SQLException esql)
  487. {
  488. esql.printStackTrace();
  489. }
  490. finally
  491. {
  492. try
  493. {
  494. con.close();
  495. }
  496. catch (SQLException e)
  497. {
  498. e.printStackTrace();
  499. }
  500. }
  501. }
  502. private void updateTradeList(int itemID, int price, int tradeListID, int order)
  503. {
  504. java.sql.Connection con = null;
  505. try
  506. {
  507. con = L2DatabaseFactory.getInstance().getConnection();
  508. PreparedStatement stmt = con.prepareStatement("UPDATE merchant_buylists SET `price`='"+price+"' WHERE `shop_id`='"+tradeListID+"' AND `order`='"+order+"'");
  509. stmt.execute();
  510. stmt.close();
  511. }catch (SQLException esql)
  512. {
  513. esql.printStackTrace();
  514. }
  515. finally
  516. {
  517. try
  518. {
  519. con.close();
  520. }
  521. catch (SQLException e)
  522. {
  523. e.printStackTrace();
  524. }
  525. }
  526. }
  527. private void deleteTradeList(int tradeListID, int order)
  528. {
  529. java.sql.Connection con = null;
  530. try
  531. {
  532. con = L2DatabaseFactory.getInstance().getConnection();
  533. PreparedStatement stmt = con.prepareStatement("DELETE FROM merchant_buylists WHERE `shop_id`='"+tradeListID+"' AND `order`='"+order+"'");
  534. stmt.execute();
  535. stmt.close();
  536. }
  537. catch (SQLException esql)
  538. {
  539. esql.printStackTrace();
  540. }
  541. finally
  542. {
  543. try
  544. {
  545. con.close();
  546. }
  547. catch (SQLException e)
  548. {
  549. e.printStackTrace();
  550. }
  551. }
  552. }
  553. private int findOrderTradeList(int itemID, int price, int tradeListID)
  554. {
  555. java.sql.Connection con = null;
  556. int order = 0;
  557. try
  558. {
  559. con = L2DatabaseFactory.getInstance().getConnection();
  560. PreparedStatement stmt = con.prepareStatement("SELECT * FROM merchant_buylists WHERE `shop_id`='"+tradeListID+"' AND `item_id` ='"+itemID+"' AND `price` = '"+price+"'");
  561. ResultSet rs = stmt.executeQuery();
  562. rs.first();
  563. order = rs.getInt("order");
  564. stmt.close();
  565. rs.close();
  566. }
  567. catch (SQLException esql)
  568. {
  569. esql.printStackTrace();
  570. }
  571. finally
  572. {
  573. try
  574. {
  575. con.close();
  576. }
  577. catch (SQLException e)
  578. {
  579. e.printStackTrace();
  580. }
  581. }
  582. return order;
  583. }
  584. private List<L2TradeList> getTradeLists(int merchantID)
  585. {
  586. String target = "npc_%objectId%_Buy";
  587. String content = HtmCache.getInstance().getHtm("data/html/merchant/"+merchantID+".htm");
  588. if (content == null)
  589. {
  590. content = HtmCache.getInstance().getHtm("data/html/merchant/30001.htm");
  591. if (content == null)
  592. return null;
  593. }
  594. List<L2TradeList> tradeLists = new FastList<L2TradeList>();
  595. String[] lines = content.split("\n");
  596. int pos = 0;
  597. for (String line : lines)
  598. {
  599. pos = line.indexOf(target);
  600. if (pos >= 0)
  601. {
  602. int tradeListID = Integer.decode((line.substring(pos+target.length()+1)).split("\"")[0]);
  603. tradeLists.add(TradeController.getInstance().getBuyList(tradeListID));
  604. }
  605. }
  606. return tradeLists;
  607. }
  608. public String[] getAdminCommandList() {
  609. return ADMIN_COMMANDS;
  610. }
  611. private void Show_Npc_Property(L2PcInstance activeChar, L2NpcTemplate npc)
  612. {
  613. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  614. String content = HtmCache.getInstance().getHtm("data/html/admin/editnpc.htm");
  615. if (content != null)
  616. {
  617. adminReply.setHtml(content);
  618. adminReply.replace("%npcId%", String.valueOf(npc.npcId));
  619. adminReply.replace("%templateId%", String.valueOf(npc.idTemplate));
  620. adminReply.replace("%name%", npc.name);
  621. adminReply.replace("%serverSideName%", npc.serverSideName == true ? "1" : "0");
  622. adminReply.replace("%title%", npc.title);
  623. adminReply.replace("%serverSideTitle%", npc.serverSideTitle == true ? "1" : "0");
  624. adminReply.replace("%collisionRadius%", String.valueOf(npc.collisionRadius));
  625. adminReply.replace("%collisionHeight%", String.valueOf(npc.collisionHeight));
  626. adminReply.replace("%level%", String.valueOf(npc.level));
  627. adminReply.replace("%sex%", String.valueOf(npc.sex));
  628. adminReply.replace("%type%", String.valueOf(npc.type));
  629. adminReply.replace("%attackRange%", String.valueOf(npc.baseAtkRange));
  630. adminReply.replace("%hp%", String.valueOf(npc.baseHpMax));
  631. adminReply.replace("%mp%", String.valueOf(npc.baseMpMax));
  632. adminReply.replace("%hpRegen%", String.valueOf(npc.baseHpReg));
  633. adminReply.replace("%mpRegen%", String.valueOf(npc.baseMpReg));
  634. adminReply.replace("%str%", String.valueOf(npc.baseSTR));
  635. adminReply.replace("%con%", String.valueOf(npc.baseCON));
  636. adminReply.replace("%dex%", String.valueOf(npc.baseDEX));
  637. adminReply.replace("%int%", String.valueOf(npc.baseINT));
  638. adminReply.replace("%wit%", String.valueOf(npc.baseWIT));
  639. adminReply.replace("%men%", String.valueOf(npc.baseMEN));
  640. adminReply.replace("%exp%", String.valueOf(npc.rewardExp));
  641. adminReply.replace("%sp%", String.valueOf(npc.rewardSp));
  642. adminReply.replace("%pAtk%", String.valueOf(npc.basePAtk));
  643. adminReply.replace("%pDef%", String.valueOf(npc.basePDef));
  644. adminReply.replace("%mAtk%", String.valueOf(npc.baseMAtk));
  645. adminReply.replace("%mDef%", String.valueOf(npc.baseMDef));
  646. adminReply.replace("%pAtkSpd%", String.valueOf(npc.basePAtkSpd));
  647. adminReply.replace("%aggro%", String.valueOf(npc.aggroRange));
  648. adminReply.replace("%mAtkSpd%", String.valueOf(npc.baseMAtkSpd));
  649. adminReply.replace("%rHand%", String.valueOf(npc.rhand));
  650. adminReply.replace("%lHand%", String.valueOf(npc.lhand));
  651. adminReply.replace("%armor%", String.valueOf(npc.armor));
  652. adminReply.replace("%walkSpd%", String.valueOf(npc.baseWalkSpd));
  653. adminReply.replace("%runSpd%", String.valueOf(npc.baseRunSpd));
  654. adminReply.replace("%factionId%", npc.factionId == null ? "" : npc.factionId);
  655. adminReply.replace("%factionRange%", String.valueOf(npc.factionRange));
  656. adminReply.replace("%isUndead%", npc.isUndead ? "1" : "0");
  657. adminReply.replace("%absorbLevel%", String.valueOf(npc.absorbLevel));
  658. }
  659. else
  660. adminReply.setHtml("<html><head><body>File not found: data/html/admin/editnpc.htm</body></html>");
  661. activeChar.sendPacket(adminReply);
  662. }
  663. private void save_npc_property(L2PcInstance activeChar, String command)
  664. {
  665. String[] commandSplit = command.split(" ");
  666. if (commandSplit.length < 4)
  667. return;
  668. StatsSet newNpcData = new StatsSet();
  669. try
  670. {
  671. newNpcData.set("npcId", commandSplit[1]);
  672. String statToSet = commandSplit[2];
  673. String value = commandSplit[3];
  674. if (commandSplit.length > 4)
  675. {
  676. for (int i=0;i<commandSplit.length-3;i++)
  677. value += " " + commandSplit[i+4];
  678. }
  679. if (statToSet.equals("templateId"))
  680. newNpcData.set("idTemplate", Integer.valueOf(value));
  681. else if (statToSet.equals("name"))
  682. newNpcData.set("name", value);
  683. else if (statToSet.equals("serverSideName"))
  684. newNpcData.set("serverSideName", Integer.valueOf(value));
  685. else if (statToSet.equals("title"))
  686. newNpcData.set("title", value);
  687. else if (statToSet.equals("serverSideTitle"))
  688. newNpcData.set("serverSideTitle", Integer.valueOf(value) == 1 ? 1 : 0);
  689. else if (statToSet.equals("collisionRadius"))
  690. newNpcData.set("collision_radius", Integer.valueOf(value));
  691. else if (statToSet.equals("collisionHeight"))
  692. newNpcData.set("collision_height", Integer.valueOf(value));
  693. else if (statToSet.equals("level"))
  694. newNpcData.set("level", Integer.valueOf(value));
  695. else if (statToSet.equals("sex"))
  696. {
  697. int intValue = Integer.valueOf(value);
  698. newNpcData.set("sex", intValue == 0 ? "male" : intValue == 1 ? "female" : "etc");
  699. }
  700. else if (statToSet.equals("type"))
  701. {
  702. Class.forName("net.sf.l2j.gameserver.model.actor.instance." + value + "Instance");
  703. newNpcData.set("type", value);
  704. }
  705. else if (statToSet.equals("attackRange"))
  706. newNpcData.set("attackrange", Integer.valueOf(value));
  707. else if (statToSet.equals("hp"))
  708. newNpcData.set("hp", Integer.valueOf(value));
  709. else if (statToSet.equals("mp"))
  710. newNpcData.set("mp", Integer.valueOf(value));
  711. else if (statToSet.equals("hpRegen"))
  712. newNpcData.set("hpreg", Integer.valueOf(value));
  713. else if (statToSet.equals("mpRegen"))
  714. newNpcData.set("mpreg", Integer.valueOf(value));
  715. else if (statToSet.equals("str"))
  716. newNpcData.set("str", Integer.valueOf(value));
  717. else if (statToSet.equals("con"))
  718. newNpcData.set("con", Integer.valueOf(value));
  719. else if (statToSet.equals("dex"))
  720. newNpcData.set("dex", Integer.valueOf(value));
  721. else if (statToSet.equals("int"))
  722. newNpcData.set("int", Integer.valueOf(value));
  723. else if (statToSet.equals("wit"))
  724. newNpcData.set("wit", Integer.valueOf(value));
  725. else if (statToSet.equals("men"))
  726. newNpcData.set("men", Integer.valueOf(value));
  727. else if (statToSet.equals("exp"))
  728. newNpcData.set("exp", Integer.valueOf(value));
  729. else if (statToSet.equals("sp"))
  730. newNpcData.set("sp", Integer.valueOf(value));
  731. else if (statToSet.equals("pAtk"))
  732. newNpcData.set("patk", Integer.valueOf(value));
  733. else if (statToSet.equals("pDef"))
  734. newNpcData.set("pdef", Integer.valueOf(value));
  735. else if (statToSet.equals("mAtk"))
  736. newNpcData.set("matk", Integer.valueOf(value));
  737. else if (statToSet.equals("mDef"))
  738. newNpcData.set("mdef", Integer.valueOf(value));
  739. else if (statToSet.equals("pAtkSpd"))
  740. newNpcData.set("atkspd", Integer.valueOf(value));
  741. else if (statToSet.equals("aggro"))
  742. newNpcData.set("aggro", Integer.valueOf(value));
  743. else if (statToSet.equals("mAtkSpd"))
  744. newNpcData.set("matkspd", Integer.valueOf(value));
  745. else if (statToSet.equals("rHand"))
  746. newNpcData.set("rhand", Integer.valueOf(value));
  747. else if (statToSet.equals("lHand"))
  748. newNpcData.set("lhand", Integer.valueOf(value));
  749. else if (statToSet.equals("armor"))
  750. newNpcData.set("armor", Integer.valueOf(value));
  751. else if (statToSet.equals("runSpd"))
  752. newNpcData.set("runspd", Integer.valueOf(value));
  753. else if (statToSet.equals("factionId"))
  754. newNpcData.set("faction_id", value);
  755. else if (statToSet.equals("factionRange"))
  756. newNpcData.set("faction_range", Integer.valueOf(value));
  757. else if (statToSet.equals("isUndead"))
  758. newNpcData.set("isUndead", Integer.valueOf(value) == 1 ? 1 : 0);
  759. else if (statToSet.equals("absorbLevel"))
  760. {
  761. int intVal = Integer.valueOf(value);
  762. newNpcData.set("absorb_level", intVal < 0 ? 0 : intVal > 12 ? 0 : intVal);
  763. }
  764. }
  765. catch (Exception e)
  766. {
  767. _log.warning("Error saving new npc value: " + e);
  768. }
  769. NpcTable.getInstance().saveNpc(newNpcData);
  770. int npcId = newNpcData.getInteger("npcId");
  771. NpcTable.getInstance().reloadNpc(npcId);
  772. Show_Npc_Property(activeChar, NpcTable.getInstance().getTemplate(npcId));
  773. }
  774. private void showNpcDropList(L2PcInstance activeChar, int npcId)
  775. {
  776. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  777. if(npcData == null)
  778. {
  779. activeChar.sendMessage("unknown npc template id" + npcId);
  780. return ;
  781. }
  782. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  783. TextBuilder replyMSG = new TextBuilder("<html><title>NPC: "+ npcData.name + "("+npcData.npcId+") 's drop manage</title>");
  784. replyMSG.append("<body>");
  785. replyMSG.append("<br>Notes: click[drop_id]to show the detail of drop data,click[del] to delete the drop data!");
  786. replyMSG.append("<table>");
  787. replyMSG.append("<tr><td>npc_id itemId category</td><td>item[id]</td><td>type</td><td>del</td></tr>");
  788. if (npcData.getDropData()!=null)
  789. for(L2DropCategory cat:npcData.getDropData())
  790. for(L2DropData drop : cat.getAllDrops())
  791. {
  792. replyMSG.append("<tr><td><a action=\"bypass -h admin_edit_drop " + npcData.npcId + " " + drop.getItemId()+ " " + cat.getCategoryType() + "\">"
  793. + npcData.npcId + " " + drop.getItemId() + " " + cat.getCategoryType() + "</a></td>" +
  794. "<td>" + ItemTable.getInstance().getTemplate(drop.getItemId()).getName() + "[" + drop.getItemId() + "]" + "</td><td>" + (drop.isQuestDrop()?"Q":(cat.isSweep()?"S":"D")) + "</td><td>" +
  795. "<a action=\"bypass -h admin_del_drop " + npcData.npcId + " " + drop.getItemId() +" "+ cat.getCategoryType() +"\">del</a></td></tr>");
  796. }
  797. replyMSG.append("</table>");
  798. replyMSG.append("<center>");
  799. replyMSG.append("<button value=\"Add DropData\" action=\"bypass -h admin_add_drop "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  800. replyMSG.append("<button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  801. replyMSG.append("</center></body></html>");
  802. adminReply.setHtml(replyMSG.toString());
  803. activeChar.sendPacket(adminReply);
  804. }
  805. private void showEditDropData(L2PcInstance activeChar, int npcId, int itemId, int category)
  806. {
  807. java.sql.Connection con = null;
  808. try
  809. {
  810. con = L2DatabaseFactory.getInstance().getConnection();
  811. PreparedStatement statement = con.prepareStatement("SELECT mobId, itemId, min, max, category, chance FROM droplist WHERE mobId=" + npcId + " AND itemId=" + itemId+ " AND category=" + category);
  812. ResultSet dropData = statement.executeQuery();
  813. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  814. TextBuilder replyMSG = new TextBuilder("<html><title>the detail of dropdata: (" + npcId + " " + itemId + " " + category + ")</title>");
  815. replyMSG.append("<body>");
  816. if(dropData.next()){
  817. replyMSG.append("<table>");
  818. replyMSG.append("<tr><td>Appertain of NPC</td><td>"+ NpcTable.getInstance().getTemplate(dropData.getInt("mobId")).name + "</td></tr>");
  819. replyMSG.append("<tr><td>ItemName</td><td>"+ ItemTable.getInstance().getTemplate(dropData.getInt("itemId")).getName() + "(" + dropData.getInt("itemId") + ")</td></tr>");
  820. replyMSG.append("<tr><td>Category</td><td>"+ ((category==-1)?"sweep":Integer.toString(category)) + "</td></tr>");
  821. replyMSG.append("<tr><td>MIN(" + dropData.getInt("min") + ")</td><td><edit var=\"min\" width=80></td></tr>");
  822. replyMSG.append("<tr><td>MAX(" + dropData.getInt("max") + ")</td><td><edit var=\"max\" width=80></td></tr>");
  823. replyMSG.append("<tr><td>CHANCE("+ dropData.getInt("chance") + ")</td><td><edit var=\"chance\" width=80></td></tr>");
  824. replyMSG.append("</table>");
  825. replyMSG.append("<center>");
  826. replyMSG.append("<button value=\"Save Modify\" action=\"bypass -h admin_edit_drop " + npcId + " " + itemId + " " + category +" $min $max $chance\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  827. replyMSG.append("<br><button value=\"DropList\" action=\"bypass -h admin_show_droplist " + dropData.getInt("mobId") +"\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  828. replyMSG.append("</center>");
  829. }
  830. dropData.close();
  831. statement.close();
  832. replyMSG.append("</body></html>");
  833. adminReply.setHtml(replyMSG.toString());
  834. activeChar.sendPacket(adminReply);
  835. }
  836. catch(Exception e){}
  837. finally
  838. {
  839. try { con.close(); } catch (Exception e) {}
  840. }
  841. }
  842. private void showAddDropData(L2PcInstance activeChar, L2NpcTemplate npcData)
  843. {
  844. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  845. TextBuilder replyMSG = new TextBuilder("<html><title>Add dropdata to " + npcData.name + "(" + npcData.npcId + ")</title>");
  846. replyMSG.append("<body>");
  847. replyMSG.append("<table>");
  848. replyMSG.append("<tr><td>Item-Id</td><td><edit var=\"itemId\" width=80></td></tr>");
  849. replyMSG.append("<tr><td>MIN</td><td><edit var=\"min\" width=80></td></tr>");
  850. replyMSG.append("<tr><td>MAX</td><td><edit var=\"max\" width=80></td></tr>");
  851. replyMSG.append("<tr><td>CATEGORY(sweep=-1)</td><td><edit var=\"category\" width=80></td></tr>");
  852. replyMSG.append("<tr><td>CHANCE(0-1000000)</td><td><edit var=\"chance\" width=80></td></tr>");
  853. replyMSG.append("</table>");
  854. replyMSG.append("<center>");
  855. replyMSG.append("<button value=\"SAVE\" action=\"bypass -h admin_add_drop " + npcData.npcId + " $itemId $category $min $max $chance\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  856. replyMSG.append("<br><button value=\"DropList\" action=\"bypass -h admin_show_droplist " + npcData.npcId +"\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  857. replyMSG.append("</center>");
  858. replyMSG.append("</body></html>");
  859. adminReply.setHtml(replyMSG.toString());
  860. activeChar.sendPacket(adminReply);
  861. }
  862. private void updateDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  863. {
  864. java.sql.Connection con = null;
  865. try
  866. {
  867. con = L2DatabaseFactory.getInstance().getConnection();
  868. PreparedStatement statement = con.prepareStatement("UPDATE droplist SET min=?, max=?, chance=? WHERE mobId=? AND itemId=? AND category=?");
  869. statement.setInt(1, min);
  870. statement.setInt(2, max);
  871. statement.setInt(3, chance);
  872. statement.setInt(4, npcId);
  873. statement.setInt(5, itemId);
  874. statement.setInt(6, category);
  875. statement.execute();
  876. statement.close();
  877. PreparedStatement statement2 = con.prepareStatement("SELECT mobId FROM droplist WHERE mobId=? AND itemId=? AND category=?");
  878. statement2.setInt(1, npcId);
  879. statement2.setInt(2, itemId);
  880. statement2.setInt(3, category);
  881. ResultSet npcIdRs = statement2.executeQuery();
  882. if(npcIdRs.next()) npcId = npcIdRs.getInt("mobId");
  883. npcIdRs.close();
  884. statement2.close();
  885. if(npcId > 0)
  886. {
  887. reLoadNpcDropList(npcId);
  888. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  889. TextBuilder replyMSG = new TextBuilder("<html><title>Drop data modify complete!</title>");
  890. replyMSG.append("<body>");
  891. replyMSG.append("<center><button value=\"DropList\" action=\"bypass -h admin_show_droplist "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  892. replyMSG.append("</body></html>");
  893. adminReply.setHtml(replyMSG.toString());
  894. activeChar.sendPacket(adminReply);
  895. }
  896. else
  897. activeChar.sendMessage("unknown error!");
  898. }
  899. catch(Exception e){ e.printStackTrace(); }
  900. finally
  901. {
  902. try { con.close(); } catch (Exception e) {}
  903. }
  904. }
  905. private void addDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  906. {
  907. java.sql.Connection con = null;
  908. try
  909. {
  910. con = L2DatabaseFactory.getInstance().getConnection();
  911. PreparedStatement statement = con.prepareStatement("INSERT INTO droplist(mobId, itemId, min, max, category, chance) values(?,?,?,?,?,?)");
  912. statement.setInt(1, npcId);
  913. statement.setInt(2, itemId);
  914. statement.setInt(3, min);
  915. statement.setInt(4, max);
  916. statement.setInt(5, category);
  917. statement.setInt(6, chance);
  918. statement.execute();
  919. statement.close();
  920. reLoadNpcDropList(npcId);
  921. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  922. TextBuilder replyMSG = new TextBuilder("<html><title>Add drop data complete!</title>");
  923. replyMSG.append("<body>");
  924. replyMSG.append("<center><button value=\"Continue add\" action=\"bypass -h admin_add_drop "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  925. replyMSG.append("<br><br><button value=\"DropList\" action=\"bypass -h admin_show_droplist "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  926. replyMSG.append("</center></body></html>");
  927. adminReply.setHtml(replyMSG.toString());
  928. activeChar.sendPacket(adminReply);
  929. }
  930. catch(Exception e){}
  931. finally
  932. {
  933. try { con.close(); } catch (Exception e) {}
  934. }
  935. }
  936. private void deleteDropData(L2PcInstance activeChar, int npcId, int itemId, int category)
  937. {
  938. java.sql.Connection con = null;
  939. try
  940. {
  941. con = L2DatabaseFactory.getInstance().getConnection();
  942. if(npcId > 0)
  943. {
  944. PreparedStatement statement2 = con.prepareStatement("DELETE FROM droplist WHERE mobId=? AND itemId=? AND category=?");
  945. statement2.setInt(1, npcId);
  946. statement2.setInt(2, itemId);
  947. statement2.setInt(3, category);
  948. statement2.execute();
  949. statement2.close();
  950. reLoadNpcDropList(npcId);
  951. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  952. TextBuilder replyMSG = new TextBuilder("<html><title>Delete drop data(" + npcId+", "+ itemId+", "+ category + ")complete</title>");
  953. replyMSG.append("<body>");
  954. replyMSG.append("<center><button value=\"DropList\" action=\"bypass -h admin_show_droplist "+ npcId + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  955. replyMSG.append("</body></html>");
  956. adminReply.setHtml(replyMSG.toString());
  957. activeChar.sendPacket(adminReply);
  958. }
  959. }
  960. catch(Exception e){}
  961. finally
  962. {
  963. try { con.close(); } catch (Exception e) {}
  964. }
  965. }
  966. private void reLoadNpcDropList(int npcId)
  967. {
  968. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  969. if (npcData == null)
  970. return;
  971. // reset the drop lists
  972. npcData.clearAllDropData();
  973. // get the drops
  974. java.sql.Connection con = null;
  975. try
  976. {
  977. con = L2DatabaseFactory.getInstance().getConnection();
  978. L2DropData dropData = null;
  979. npcData.clearAllDropData();
  980. PreparedStatement statement = con.prepareStatement("SELECT " + L2DatabaseFactory.getInstance().safetyString(new String[] {"mobId", "itemId", "min", "max", "category", "chance"}) + " FROM droplist WHERE mobId=?");
  981. statement.setInt(1, npcId);
  982. ResultSet dropDataList = statement.executeQuery();
  983. while(dropDataList.next())
  984. {
  985. dropData = new L2DropData();
  986. dropData.setItemId(dropDataList.getInt("itemId"));
  987. dropData.setMinDrop(dropDataList.getInt("min"));
  988. dropData.setMaxDrop(dropDataList.getInt("max"));
  989. dropData.setChance(dropDataList.getInt("chance"));
  990. int category = dropDataList.getInt("category");
  991. npcData.addDropData(dropData, category);
  992. }
  993. dropDataList.close();
  994. statement.close();
  995. }
  996. catch(Exception e){}
  997. finally
  998. {
  999. try { con.close(); } catch (Exception e) {}
  1000. }
  1001. }
  1002. }