AdminEditNpc.java 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.sql.ResultSet;
  23. import java.util.HashMap;
  24. import java.util.Iterator;
  25. import java.util.List;
  26. import java.util.Map;
  27. import java.util.StringTokenizer;
  28. import java.util.logging.Level;
  29. import java.util.logging.Logger;
  30. import com.l2jserver.Config;
  31. import com.l2jserver.L2DatabaseFactory;
  32. import com.l2jserver.gameserver.TradeController;
  33. import com.l2jserver.gameserver.cache.HtmCache;
  34. import com.l2jserver.gameserver.datatables.ItemTable;
  35. import com.l2jserver.gameserver.datatables.MerchantPriceConfigTable.MerchantPriceConfig;
  36. import com.l2jserver.gameserver.datatables.NpcTable;
  37. import com.l2jserver.gameserver.datatables.SkillTable;
  38. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  39. import com.l2jserver.gameserver.model.L2DropCategory;
  40. import com.l2jserver.gameserver.model.L2DropData;
  41. import com.l2jserver.gameserver.model.L2Object;
  42. import com.l2jserver.gameserver.model.L2TradeList;
  43. import com.l2jserver.gameserver.model.L2TradeList.L2TradeItem;
  44. import com.l2jserver.gameserver.model.StatsSet;
  45. import com.l2jserver.gameserver.model.actor.L2Npc;
  46. import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
  47. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  48. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  49. import com.l2jserver.gameserver.model.items.L2Item;
  50. import com.l2jserver.gameserver.model.skills.L2Skill;
  51. import com.l2jserver.gameserver.model.skills.L2SkillType;
  52. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  53. import com.l2jserver.util.StringUtil;
  54. /**
  55. * @author terry con.close() change by Zoey76 24/02/2011
  56. */
  57. public class AdminEditNpc implements IAdminCommandHandler
  58. {
  59. private static Logger _log = Logger.getLogger(AdminEditNpc.class.getName());
  60. private final static int PAGE_LIMIT = 20;
  61. private static final String[] ADMIN_COMMANDS =
  62. {
  63. "admin_edit_npc",
  64. "admin_save_npc",
  65. "admin_show_droplist",
  66. "admin_edit_drop",
  67. "admin_add_drop",
  68. "admin_del_drop",
  69. "admin_showShop",
  70. "admin_showShopList",
  71. "admin_addShopItem",
  72. "admin_delShopItem",
  73. "admin_editShopItem",
  74. "admin_close_window",
  75. "admin_show_skilllist_npc",
  76. "admin_add_skill_npc",
  77. "admin_edit_skill_npc",
  78. "admin_del_skill_npc",
  79. "admin_log_npc_spawn"
  80. };
  81. @Override
  82. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  83. {
  84. // TODO: Tokenize and protect arguments parsing. Externalize HTML.
  85. if (command.startsWith("admin_showShop "))
  86. {
  87. String[] args = command.split(" ");
  88. if (args.length > 1)
  89. {
  90. showShop(activeChar, Integer.parseInt(command.split(" ")[1]));
  91. }
  92. }
  93. else if (command.startsWith("admin_log_npc_spawn"))
  94. {
  95. L2Object target = activeChar.getTarget();
  96. if (target instanceof L2Npc)
  97. {
  98. L2Npc npc = (L2Npc) target;
  99. _log.info("('',1," + npc.getNpcId() + "," + npc.getX() + "," + npc.getY() + "," + npc.getZ() + ",0,0," + npc.getHeading() + ",60,0,0),");
  100. }
  101. }
  102. else if (command.startsWith("admin_showShopList "))
  103. {
  104. String[] args = command.split(" ");
  105. if (args.length > 2)
  106. {
  107. showShopList(activeChar, Integer.parseInt(command.split(" ")[1]), Integer.parseInt(command.split(" ")[2]));
  108. }
  109. }
  110. else if (command.startsWith("admin_edit_npc "))
  111. {
  112. try
  113. {
  114. String[] commandSplit = command.split(" ");
  115. int npcId = Integer.parseInt(commandSplit[1]);
  116. L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId);
  117. showNpcProperty(activeChar, npc);
  118. }
  119. catch (Exception e)
  120. {
  121. activeChar.sendMessage("Wrong usage: //edit_npc <npcId>");
  122. }
  123. }
  124. else if (command.startsWith("admin_show_droplist "))
  125. {
  126. StringTokenizer st = new StringTokenizer(command, " ");
  127. st.nextToken();
  128. try
  129. {
  130. int npcId = Integer.parseInt(st.nextToken());
  131. int page = 1;
  132. if (st.hasMoreTokens())
  133. {
  134. page = Integer.parseInt(st.nextToken());
  135. }
  136. showNpcDropList(activeChar, npcId, page);
  137. }
  138. catch (Exception e)
  139. {
  140. activeChar.sendMessage("Usage: //show_droplist <npc_id> [<page>]");
  141. }
  142. }
  143. else if (command.startsWith("admin_addShopItem "))
  144. {
  145. String[] args = command.split(" ");
  146. if (args.length > 1)
  147. {
  148. addShopItem(activeChar, args);
  149. }
  150. }
  151. else if (command.startsWith("admin_delShopItem "))
  152. {
  153. String[] args = command.split(" ");
  154. if (args.length > 2)
  155. {
  156. delShopItem(activeChar, args);
  157. }
  158. }
  159. else if (command.startsWith("admin_editShopItem "))
  160. {
  161. String[] args = command.split(" ");
  162. if (args.length > 2)
  163. {
  164. editShopItem(activeChar, args);
  165. }
  166. }
  167. else if (command.startsWith("admin_save_npc "))
  168. {
  169. try
  170. {
  171. saveNpcProperty(activeChar, command);
  172. }
  173. catch (StringIndexOutOfBoundsException e)
  174. {
  175. }
  176. }
  177. else if (command.startsWith("admin_edit_drop "))
  178. {
  179. int npcId = -1, itemId = 0, category = -1000;
  180. try
  181. {
  182. StringTokenizer st = new StringTokenizer(command.substring(16).trim());
  183. if (st.countTokens() == 3)
  184. {
  185. try
  186. {
  187. npcId = Integer.parseInt(st.nextToken());
  188. itemId = Integer.parseInt(st.nextToken());
  189. category = Integer.parseInt(st.nextToken());
  190. showEditDropData(activeChar, npcId, itemId, category);
  191. }
  192. catch (Exception e)
  193. {
  194. _log.log(Level.WARNING, "", e);
  195. }
  196. }
  197. else if (st.countTokens() == 6)
  198. {
  199. try
  200. {
  201. npcId = Integer.parseInt(st.nextToken());
  202. itemId = Integer.parseInt(st.nextToken());
  203. category = Integer.parseInt(st.nextToken());
  204. int min = Integer.parseInt(st.nextToken());
  205. int max = Integer.parseInt(st.nextToken());
  206. int chance = Integer.parseInt(st.nextToken());
  207. updateDropData(activeChar, npcId, itemId, min, max, category, chance);
  208. }
  209. catch (Exception e)
  210. {
  211. _log.fine("admin_edit_drop parameters error: " + command);
  212. }
  213. }
  214. else
  215. {
  216. activeChar.sendMessage("Usage: //edit_drop <npc_id> <item_id> <category> [<min> <max> <chance>]");
  217. }
  218. }
  219. catch (StringIndexOutOfBoundsException e)
  220. {
  221. activeChar.sendMessage("Usage: //edit_drop <npc_id> <item_id> <category> [<min> <max> <chance>]");
  222. }
  223. }
  224. else if (command.startsWith("admin_add_drop "))
  225. {
  226. int npcId = -1;
  227. try
  228. {
  229. StringTokenizer st = new StringTokenizer(command.substring(15).trim());
  230. if (st.countTokens() == 1)
  231. {
  232. try
  233. {
  234. String[] input = command.substring(15).split(" ");
  235. if (input.length < 1)
  236. {
  237. return true;
  238. }
  239. npcId = Integer.parseInt(input[0]);
  240. }
  241. catch (Exception e)
  242. {
  243. }
  244. if (npcId > 0)
  245. {
  246. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  247. showAddDropData(activeChar, npcData);
  248. }
  249. }
  250. else if (st.countTokens() == 6)
  251. {
  252. try
  253. {
  254. npcId = Integer.parseInt(st.nextToken());
  255. int itemId = Integer.parseInt(st.nextToken());
  256. int category = Integer.parseInt(st.nextToken());
  257. int min = Integer.parseInt(st.nextToken());
  258. int max = Integer.parseInt(st.nextToken());
  259. int chance = Integer.parseInt(st.nextToken());
  260. addDropData(activeChar, npcId, itemId, min, max, category, chance);
  261. }
  262. catch (Exception e)
  263. {
  264. _log.fine("admin_add_drop parameters error: " + command);
  265. }
  266. }
  267. else
  268. {
  269. activeChar.sendMessage("Usage: //add_drop <npc_id> [<item_id> <category> <min> <max> <chance>]");
  270. }
  271. }
  272. catch (StringIndexOutOfBoundsException e)
  273. {
  274. activeChar.sendMessage("Usage: //add_drop <npc_id> [<item_id> <category> <min> <max> <chance>]");
  275. }
  276. }
  277. else if (command.startsWith("admin_del_drop "))
  278. {
  279. StringTokenizer st = new StringTokenizer(command, " ");
  280. st.nextToken();
  281. try
  282. {
  283. int npcId = Integer.parseInt(st.nextToken());
  284. int itemId = Integer.parseInt(st.nextToken());
  285. int category = Integer.parseInt(st.nextToken());
  286. boolean confirmed = false;
  287. if (st.hasMoreTokens())
  288. {
  289. confirmed = true;
  290. }
  291. deleteDropData(activeChar, npcId, itemId, category, confirmed);
  292. }
  293. catch (Exception e)
  294. {
  295. activeChar.sendMessage("Usage: //del_drop <npc_id> <item_id> <category>");
  296. }
  297. }
  298. else if (command.startsWith("admin_show_skilllist_npc "))
  299. {
  300. StringTokenizer st = new StringTokenizer(command, " ");
  301. st.nextToken();
  302. try
  303. {
  304. int npcId = Integer.parseInt(st.nextToken());
  305. int page = 0;
  306. if (st.hasMoreTokens())
  307. {
  308. page = Integer.parseInt(st.nextToken());
  309. }
  310. showNpcSkillList(activeChar, npcId, page);
  311. }
  312. catch (Exception e)
  313. {
  314. activeChar.sendMessage("Usage: //show_skilllist_npc <npc_id> <page>");
  315. }
  316. }
  317. else if (command.startsWith("admin_edit_skill_npc "))
  318. {
  319. try
  320. {
  321. StringTokenizer st = new StringTokenizer(command, " ");
  322. st.nextToken();
  323. int npcId = Integer.parseInt(st.nextToken());
  324. int skillId = Integer.parseInt(st.nextToken());
  325. if (!st.hasMoreTokens())
  326. {
  327. showNpcSkillEdit(activeChar, npcId, skillId);
  328. }
  329. else
  330. {
  331. int level = Integer.parseInt(st.nextToken());
  332. updateNpcSkillData(activeChar, npcId, skillId, level);
  333. }
  334. }
  335. catch (Exception e)
  336. {
  337. activeChar.sendMessage("Usage: //edit_skill_npc <npc_id> <item_id> [<level>]");
  338. }
  339. }
  340. else if (command.startsWith("admin_add_skill_npc "))
  341. {
  342. try
  343. {
  344. StringTokenizer st = new StringTokenizer(command, " ");
  345. st.nextToken();
  346. int npcId = Integer.parseInt(st.nextToken());
  347. if (!st.hasMoreTokens())
  348. {
  349. showNpcSkillAdd(activeChar, npcId);
  350. }
  351. else
  352. {
  353. int skillId = Integer.parseInt(st.nextToken());
  354. int level = Integer.parseInt(st.nextToken());
  355. addNpcSkillData(activeChar, npcId, skillId, level);
  356. }
  357. }
  358. catch (Exception e)
  359. {
  360. activeChar.sendMessage("Usage: //add_skill_npc <npc_id> [<skill_id> <level>]");
  361. }
  362. }
  363. else if (command.startsWith("admin_del_skill_npc "))
  364. {
  365. try
  366. {
  367. StringTokenizer st = new StringTokenizer(command, " ");
  368. st.nextToken();
  369. int npcId = Integer.parseInt(st.nextToken());
  370. int skillId = Integer.parseInt(st.nextToken());
  371. deleteNpcSkillData(activeChar, npcId, skillId);
  372. }
  373. catch (Exception e)
  374. {
  375. activeChar.sendMessage("Usage: //del_skill_npc <npc_id> <skill_id>");
  376. }
  377. }
  378. return true;
  379. }
  380. private void editShopItem(L2PcInstance activeChar, String[] args)
  381. {
  382. int tradeListID = Integer.parseInt(args[1]);
  383. int itemID = Integer.parseInt(args[2]);
  384. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  385. L2Item item = ItemTable.getInstance().getTemplate(itemID);
  386. if (tradeList.getPriceForItemId(itemID) < 0)
  387. {
  388. return;
  389. }
  390. if (args.length > 3)
  391. {
  392. long price = Long.parseLong(args[3]);
  393. int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);
  394. tradeList.replaceItem(itemID, Long.parseLong(args[3]));
  395. updateTradeList(itemID, price, tradeListID, order);
  396. activeChar.sendMessage("Updated price for " + item.getName() + " in Trade List " + tradeListID);
  397. showShopList(activeChar, tradeListID, 1);
  398. return;
  399. }
  400. final String replyMSG = StringUtil.concat("<html><title>Merchant Shop Item Edit</title><body><center><font color=\"LEVEL\">", NpcTable.getInstance().getTemplate(Integer.parseInt(tradeList.getNpcId())).getName(), " (", tradeList.getNpcId(), ") -> ", Integer.toString(tradeListID), "</font></center><table width=\"100%\"><tr><td>Item</td><td>", item.getName(), " (", Integer.toString(item.getItemId()), ")", "</td></tr><tr><td>Price (", String.valueOf(tradeList.getPriceForItemId(itemID)), ")</td><td><edit var=\"price\" width=80></td></tr></table><center><br><button value=\"Save\" action=\"bypass -h admin_editShopItem ", String.valueOf(tradeListID), " ", String.valueOf(itemID), " $price\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Shop List\" action=\"bypass -h admin_showShopList ", String.valueOf(tradeListID), " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  401. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  402. adminReply.setHtml(replyMSG);
  403. activeChar.sendPacket(adminReply);
  404. }
  405. private void delShopItem(L2PcInstance activeChar, String[] args)
  406. {
  407. int tradeListID = Integer.parseInt(args[1]);
  408. int itemID = Integer.parseInt(args[2]);
  409. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  410. if (tradeList.getPriceForItemId(itemID) < 0)
  411. {
  412. return;
  413. }
  414. if (args.length > 3)
  415. {
  416. int order = findOrderTradeList(itemID, tradeList.getPriceForItemId(itemID), tradeListID);
  417. tradeList.removeItem(itemID);
  418. deleteTradeList(tradeListID, order);
  419. activeChar.sendMessage("Deleted " + ItemTable.getInstance().getTemplate(itemID).getName() + " from Trade List " + tradeListID);
  420. showShopList(activeChar, tradeListID, 1);
  421. return;
  422. }
  423. final String replyMSG = StringUtil.concat("<html><title>Merchant Shop Item Delete</title><body><br>Delete entry in trade list ", String.valueOf(tradeListID), "<table width=\"100%\"><tr><td>Item</td><td>", ItemTable.getInstance().getTemplate(itemID).getName(), " (", Integer.toString(itemID), ")</td></tr><tr><td>Price</td><td>", String.valueOf(tradeList.getPriceForItemId(itemID)), "</td></tr></table><center><br><button value=\"Delete\" action=\"bypass -h admin_delShopItem ", String.valueOf(tradeListID), " ", String.valueOf(itemID), " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Shop List\" action=\"bypass -h admin_showShopList ", String.valueOf(tradeListID), " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  424. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  425. adminReply.setHtml(replyMSG);
  426. activeChar.sendPacket(adminReply);
  427. }
  428. private void addShopItem(L2PcInstance activeChar, String[] args)
  429. {
  430. int tradeListID = Integer.parseInt(args[1]);
  431. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  432. if (tradeList == null)
  433. {
  434. activeChar.sendMessage("TradeList not found!");
  435. return;
  436. }
  437. if (args.length > 3)
  438. {
  439. int order = tradeList.getItems().size() + 1; // last item order + 1
  440. int itemID = Integer.parseInt(args[2]);
  441. long price = Long.parseLong(args[3]);
  442. L2TradeItem newItem = new L2TradeItem(tradeListID, itemID);
  443. newItem.setPrice(price);
  444. newItem.setMaxCount(-1);
  445. tradeList.addItem(newItem);
  446. boolean stored = storeTradeList(itemID, price, tradeListID, order);
  447. if (stored)
  448. {
  449. activeChar.sendMessage("Added " + ItemTable.getInstance().getTemplate(itemID).getName() + " to Trade List " + tradeList.getListId());
  450. }
  451. else
  452. {
  453. activeChar.sendMessage("Could not add " + ItemTable.getInstance().getTemplate(itemID).getName() + " to Trade List " + tradeList.getListId() + "!");
  454. }
  455. showShopList(activeChar, tradeListID, 1);
  456. return;
  457. }
  458. final String replyMSG = StringUtil.concat("<html><title>Merchant Shop Item Add</title><body><br>Add a new entry in merchantList.<table width=\"100%\"><tr><td>ItemID</td><td><edit var=\"itemID\" width=80></td></tr><tr><td>Price</td><td><edit var=\"price\" width=80></td></tr></table><center><br><button value=\"Add\" action=\"bypass -h admin_addShopItem ", String.valueOf(tradeListID), " $itemID $price\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Shop List\" action=\"bypass -h admin_showShopList ", String.valueOf(tradeListID), " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  459. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  460. adminReply.setHtml(replyMSG);
  461. activeChar.sendPacket(adminReply);
  462. }
  463. private void showShopList(L2PcInstance activeChar, int tradeListID, int page)
  464. {
  465. L2TradeList tradeList = TradeController.getInstance().getBuyList(tradeListID);
  466. if ((page > ((tradeList.getItems().size() / PAGE_LIMIT) + 1)) || (page < 1))
  467. {
  468. return;
  469. }
  470. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  471. adminReply.setHtml(itemListHtml(tradeList, page));
  472. activeChar.sendPacket(adminReply);
  473. }
  474. private String itemListHtml(L2TradeList tradeList, int page)
  475. {
  476. final StringBuilder replyMSG = new StringBuilder();
  477. int max = tradeList.getItems().size() / PAGE_LIMIT;
  478. if (tradeList.getItems().size() > (PAGE_LIMIT * max))
  479. {
  480. max++;
  481. }
  482. StringUtil.append(replyMSG, "<html><title>Merchant Shop List Page: ", String.valueOf(page), " of ", Integer.toString(max), "</title><body><br><center><font color=\"LEVEL\">", NpcTable.getInstance().getTemplate(Integer.parseInt(tradeList.getNpcId())).getName(), " (", tradeList.getNpcId(), ") Shop ID: ", Integer.toString(tradeList.getListId()), "</font></center><table width=300 bgcolor=666666><tr>");
  483. for (int x = 0; x < max; x++)
  484. {
  485. int pagenr = x + 1;
  486. if (page == pagenr)
  487. {
  488. replyMSG.append("<td>Page ");
  489. replyMSG.append(pagenr);
  490. replyMSG.append("</td>");
  491. }
  492. else
  493. {
  494. replyMSG.append("<td><a action=\"bypass -h admin_showShopList ");
  495. replyMSG.append(tradeList.getListId());
  496. replyMSG.append(" ");
  497. replyMSG.append(x + 1);
  498. replyMSG.append("\"> Page ");
  499. replyMSG.append(pagenr);
  500. replyMSG.append(" </a></td>");
  501. }
  502. }
  503. replyMSG.append("</tr></table><table width=\"100%\"><tr><td width=150>Item</td><td width=60>Price</td><td width=40>Delete</td></tr>");
  504. int start = ((page - 1) * PAGE_LIMIT);
  505. int end = Math.min(((page - 1) * PAGE_LIMIT) + PAGE_LIMIT, tradeList.getItems().size());
  506. for (L2TradeItem item : tradeList.getItems(start, end))
  507. {
  508. StringUtil.append(replyMSG, "<tr><td><a action=\"bypass -h admin_editShopItem ", String.valueOf(tradeList.getListId()), " ", String.valueOf(item.getItemId()), "\">", ItemTable.getInstance().getTemplate(item.getItemId()).getName(), "</a></td><td>", String.valueOf(item.getPrice()), "</td><td><a action=\"bypass -h admin_delShopItem ", String.valueOf(tradeList.getListId()), " ", String.valueOf(item.getItemId()), "\">Delete</a></td></tr>");
  509. }
  510. StringUtil.append(replyMSG, "<tr><td><br><br></td><td> </td><td> </td></tr><tr>");
  511. StringUtil.append(replyMSG, "</tr></table><center><br><button value=\"Add Shop Item\" action=\"bypass -h admin_addShopItem ", String.valueOf(tradeList.getListId()), "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  512. return replyMSG.toString();
  513. }
  514. private void showShop(L2PcInstance activeChar, int merchantID)
  515. {
  516. List<L2TradeList> tradeLists = TradeController.getInstance().getBuyListByNpcId(merchantID);
  517. if (tradeLists == null)
  518. {
  519. activeChar.sendMessage("Unknown npc template Id: " + merchantID);
  520. return;
  521. }
  522. final StringBuilder replyMSG = new StringBuilder();
  523. StringUtil.append(replyMSG, "<html><title>Merchant Shop Lists</title><body>");
  524. if (activeChar.getTarget() instanceof L2MerchantInstance)
  525. {
  526. MerchantPriceConfig mpc = ((L2MerchantInstance) activeChar.getTarget()).getMpc();
  527. StringUtil.append(replyMSG, "<br>NPC: ", activeChar.getTarget().getName(), " (", Integer.toString(merchantID), ") <br>Price Config: ", mpc.getName(), ", ", Integer.toString(mpc.getBaseTax()), "% / ", Integer.toString(mpc.getTotalTax()), "%");
  528. }
  529. StringUtil.append(replyMSG, "<table width=\"100%\">");
  530. for (L2TradeList tradeList : tradeLists)
  531. {
  532. if (tradeList != null)
  533. {
  534. StringUtil.append(replyMSG, "<tr><td><a action=\"bypass -h admin_showShopList ", String.valueOf(tradeList.getListId()), " 1\">Merchant List ID ", String.valueOf(tradeList.getListId()), "</a></td></tr>");
  535. }
  536. }
  537. StringUtil.append(replyMSG, "</table><center><br><button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  538. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  539. adminReply.setHtml(replyMSG.toString());
  540. activeChar.sendPacket(adminReply);
  541. }
  542. private boolean storeTradeList(int itemID, long price, int tradeListID, int order)
  543. {
  544. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  545. {
  546. String table = "merchant_buylists";
  547. if (Config.CUSTOM_MERCHANT_TABLES)
  548. {
  549. table = "custom_merchant_buylists";
  550. }
  551. PreparedStatement stmt = con.prepareStatement("INSERT INTO `" + table + "`(`item_id`,`price`,`shop_id`,`order`) VALUES (?,?,?,?)");
  552. stmt.setInt(1, itemID);
  553. stmt.setLong(2, price);
  554. stmt.setInt(3, tradeListID);
  555. stmt.setInt(4, order);
  556. stmt.execute();
  557. stmt.close();
  558. }
  559. catch (Exception e)
  560. {
  561. _log.warning("Could not store trade list (" + itemID + ", " + price + ", " + tradeListID + ", " + order + "): " + e);
  562. return false;
  563. }
  564. return true;
  565. }
  566. private void updateTradeList(int itemID, long price, int tradeListID, int order)
  567. {
  568. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  569. {
  570. int updated = 0;
  571. if (Config.CUSTOM_MERCHANT_TABLES)
  572. {
  573. PreparedStatement stmt = con.prepareStatement("UPDATE `custom_merchant_buylists` SET `price` = ? WHERE `shop_id` = ? AND `order` = ?");
  574. stmt.setLong(1, price);
  575. stmt.setInt(2, tradeListID);
  576. stmt.setInt(3, order);
  577. updated = stmt.executeUpdate();
  578. stmt.close();
  579. }
  580. if (updated == 0)
  581. {
  582. PreparedStatement stmt = con.prepareStatement("UPDATE `merchant_buylists` SET `price` = ? WHERE `shop_id` = ? AND `order` = ?");
  583. stmt.setLong(1, price);
  584. stmt.setInt(2, tradeListID);
  585. stmt.setInt(3, order);
  586. updated = stmt.executeUpdate();
  587. stmt.close();
  588. }
  589. }
  590. catch (Exception e)
  591. {
  592. _log.warning("Could not update trade list (" + itemID + ", " + price + ", " + tradeListID + ", " + order + "): " + e);
  593. }
  594. }
  595. private void deleteTradeList(int tradeListID, int order)
  596. {
  597. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  598. {
  599. int updated = 0;
  600. if (Config.CUSTOM_MERCHANT_TABLES)
  601. {
  602. PreparedStatement stmt = con.prepareStatement("DELETE FROM `custom_merchant_buylists` WHERE `shop_id` = ? AND `order` = ?");
  603. stmt.setInt(1, tradeListID);
  604. stmt.setInt(2, order);
  605. updated = stmt.executeUpdate();
  606. stmt.close();
  607. }
  608. if (updated == 0)
  609. {
  610. PreparedStatement stmt = con.prepareStatement("DELETE FROM `merchant_buylists` WHERE `shop_id` = ? AND `order` = ?");
  611. stmt.setInt(1, tradeListID);
  612. stmt.setInt(2, order);
  613. updated = stmt.executeUpdate();
  614. stmt.close();
  615. }
  616. }
  617. catch (Exception e)
  618. {
  619. _log.warning("Could not delete trade list (" + tradeListID + ", " + order + "): " + e);
  620. }
  621. }
  622. private int findOrderTradeList(int itemID, long price, int tradeListID)
  623. {
  624. int order = -1;
  625. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  626. {
  627. PreparedStatement stmt = con.prepareStatement("SELECT `order` FROM `merchant_buylists` WHERE `shop_id` = ? AND `item_id` = ? AND `price` = ?");
  628. stmt.setInt(1, tradeListID);
  629. stmt.setInt(2, itemID);
  630. stmt.setLong(3, price);
  631. ResultSet rs = stmt.executeQuery();
  632. if (rs.first())
  633. {
  634. order = rs.getInt("order");
  635. }
  636. stmt.close();
  637. rs.close();
  638. }
  639. catch (Exception e)
  640. {
  641. _log.warning("Could not get order for (" + itemID + ", " + price + ", " + tradeListID + "): " + e);
  642. }
  643. return order;
  644. }
  645. @Override
  646. public String[] getAdminCommandList()
  647. {
  648. return ADMIN_COMMANDS;
  649. }
  650. private void showNpcProperty(L2PcInstance activeChar, L2NpcTemplate npc)
  651. {
  652. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  653. String content = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/editnpc.htm");
  654. if (content != null)
  655. {
  656. adminReply.setHtml(content);
  657. adminReply.replace("%npcId%", String.valueOf(npc.getNpcId()));
  658. adminReply.replace("%templateId%", String.valueOf(npc.getIdTemplate()));
  659. adminReply.replace("%name%", npc.getName());
  660. adminReply.replace("%serverSideName%", npc.isServerSideName() == true ? "1" : "0");
  661. adminReply.replace("%title%", npc.getTitle());
  662. adminReply.replace("%serverSideTitle%", npc.isServerSideTitle() == true ? "1" : "0");
  663. adminReply.replace("%collisionRadius%", String.valueOf(npc.getfCollisionRadius()));
  664. adminReply.replace("%collisionHeight%", String.valueOf(npc.getfCollisionHeight()));
  665. adminReply.replace("%level%", String.valueOf(npc.getLevel()));
  666. adminReply.replace("%sex%", String.valueOf(npc.getSex()));
  667. adminReply.replace("%type%", String.valueOf(npc.getType()));
  668. adminReply.replace("%attackRange%", String.valueOf(npc.getBaseAtkRange()));
  669. adminReply.replace("%hp%", String.valueOf(npc.getBaseHpMax()));
  670. adminReply.replace("%mp%", String.valueOf(npc.getBaseMpMax()));
  671. adminReply.replace("%hpRegen%", String.valueOf(npc.getBaseHpReg()));
  672. adminReply.replace("%mpRegen%", String.valueOf(npc.getBaseMpReg()));
  673. adminReply.replace("%str%", String.valueOf(npc.getBaseSTR()));
  674. adminReply.replace("%con%", String.valueOf(npc.getBaseCON()));
  675. adminReply.replace("%dex%", String.valueOf(npc.getBaseDEX()));
  676. adminReply.replace("%int%", String.valueOf(npc.getBaseINT()));
  677. adminReply.replace("%wit%", String.valueOf(npc.getBaseWIT()));
  678. adminReply.replace("%men%", String.valueOf(npc.getBaseMEN()));
  679. adminReply.replace("%exp%", String.valueOf(npc.getRewardExp()));
  680. adminReply.replace("%sp%", String.valueOf(npc.getRewardSp()));
  681. adminReply.replace("%pAtk%", String.valueOf(npc.getBasePAtk()));
  682. adminReply.replace("%pDef%", String.valueOf(npc.getBasePDef()));
  683. adminReply.replace("%mAtk%", String.valueOf(npc.getBaseMAtk()));
  684. adminReply.replace("%mDef%", String.valueOf(npc.getBaseMDef()));
  685. adminReply.replace("%pAtkSpd%", String.valueOf(npc.getBasePAtkSpd()));
  686. adminReply.replace("%aggro%", String.valueOf(npc.getAIDataStatic().getAggroRange()));
  687. adminReply.replace("%mAtkSpd%", String.valueOf(npc.getBaseMAtkSpd()));
  688. adminReply.replace("%rHand%", String.valueOf(npc.getRightHand()));
  689. adminReply.replace("%lHand%", String.valueOf(npc.getLeftHand()));
  690. adminReply.replace("%enchant%", String.valueOf(npc.getEnchantEffect()));
  691. adminReply.replace("%walkSpd%", String.valueOf(npc.getBaseWalkSpd()));
  692. adminReply.replace("%runSpd%", String.valueOf(npc.getBaseRunSpd()));
  693. adminReply.replace("%factionId%", npc.getAIDataStatic().getClan() == null ? "" : npc.getAIDataStatic().getClan());
  694. adminReply.replace("%factionRange%", String.valueOf(npc.getAIDataStatic().getClanRange()));
  695. }
  696. else
  697. {
  698. adminReply.setHtml("<html><head><body>File not found: data/html/admin/editnpc.htm</body></html>");
  699. }
  700. activeChar.sendPacket(adminReply);
  701. }
  702. private void saveNpcProperty(L2PcInstance activeChar, String command)
  703. {
  704. String[] commandSplit = command.split(" ");
  705. if (commandSplit.length < 4)
  706. {
  707. return;
  708. }
  709. StatsSet newNpcData = new StatsSet();
  710. try
  711. {
  712. newNpcData.set("npcId", commandSplit[1]);
  713. String statToSet = commandSplit[2];
  714. String value = commandSplit[3];
  715. if (commandSplit.length > 4)
  716. {
  717. for (int i = 0; i < (commandSplit.length - 3); i++)
  718. {
  719. value += " " + commandSplit[i + 4];
  720. }
  721. }
  722. if (statToSet.equals("templateId"))
  723. {
  724. newNpcData.set("idTemplate", Integer.parseInt(value));
  725. }
  726. else if (statToSet.equals("name"))
  727. {
  728. newNpcData.set("name", value);
  729. }
  730. else if (statToSet.equals("serverSideName"))
  731. {
  732. newNpcData.set("serverSideName", Integer.parseInt(value));
  733. }
  734. else if (statToSet.equals("title"))
  735. {
  736. newNpcData.set("title", value);
  737. }
  738. else if (statToSet.equals("serverSideTitle"))
  739. {
  740. newNpcData.set("serverSideTitle", Integer.parseInt(value) == 1 ? 1 : 0);
  741. }
  742. else if (statToSet.equals("collisionRadius"))
  743. {
  744. newNpcData.set("collision_radius", Integer.parseInt(value));
  745. }
  746. else if (statToSet.equals("collisionHeight"))
  747. {
  748. newNpcData.set("collision_height", Integer.parseInt(value));
  749. }
  750. else if (statToSet.equals("level"))
  751. {
  752. newNpcData.set("level", Integer.parseInt(value));
  753. }
  754. else if (statToSet.equals("sex"))
  755. {
  756. int intValue = Integer.parseInt(value);
  757. newNpcData.set("sex", intValue == 0 ? "male" : intValue == 1 ? "female" : "etc");
  758. }
  759. else if (statToSet.equals("type"))
  760. {
  761. Class.forName("com.l2jserver.gameserver.model.actor.instance." + value + "Instance");
  762. newNpcData.set("type", value);
  763. }
  764. else if (statToSet.equals("attackRange"))
  765. {
  766. newNpcData.set("attackrange", Integer.parseInt(value));
  767. }
  768. else if (statToSet.equals("hp"))
  769. {
  770. newNpcData.set("hp", Integer.parseInt(value));
  771. }
  772. else if (statToSet.equals("mp"))
  773. {
  774. newNpcData.set("mp", Integer.parseInt(value));
  775. }
  776. else if (statToSet.equals("hpRegen"))
  777. {
  778. newNpcData.set("hpreg", Integer.parseInt(value));
  779. }
  780. else if (statToSet.equals("mpRegen"))
  781. {
  782. newNpcData.set("mpreg", Integer.parseInt(value));
  783. }
  784. else if (statToSet.equals("str"))
  785. {
  786. newNpcData.set("str", Integer.parseInt(value));
  787. }
  788. else if (statToSet.equals("con"))
  789. {
  790. newNpcData.set("con", Integer.parseInt(value));
  791. }
  792. else if (statToSet.equals("dex"))
  793. {
  794. newNpcData.set("dex", Integer.parseInt(value));
  795. }
  796. else if (statToSet.equals("int"))
  797. {
  798. newNpcData.set("int", Integer.parseInt(value));
  799. }
  800. else if (statToSet.equals("wit"))
  801. {
  802. newNpcData.set("wit", Integer.parseInt(value));
  803. }
  804. else if (statToSet.equals("men"))
  805. {
  806. newNpcData.set("men", Integer.parseInt(value));
  807. }
  808. else if (statToSet.equals("exp"))
  809. {
  810. newNpcData.set("exp", Integer.parseInt(value));
  811. }
  812. else if (statToSet.equals("sp"))
  813. {
  814. newNpcData.set("sp", Integer.parseInt(value));
  815. }
  816. else if (statToSet.equals("pAtk"))
  817. {
  818. newNpcData.set("patk", Integer.parseInt(value));
  819. }
  820. else if (statToSet.equals("pDef"))
  821. {
  822. newNpcData.set("pdef", Integer.parseInt(value));
  823. }
  824. else if (statToSet.equals("mAtk"))
  825. {
  826. newNpcData.set("matk", Integer.parseInt(value));
  827. }
  828. else if (statToSet.equals("mDef"))
  829. {
  830. newNpcData.set("mdef", Integer.parseInt(value));
  831. }
  832. else if (statToSet.equals("pAtkSpd"))
  833. {
  834. newNpcData.set("atkspd", Integer.parseInt(value));
  835. }
  836. else if (statToSet.equals("aggro"))
  837. {
  838. newNpcData.set("aggro", Integer.parseInt(value));
  839. }
  840. else if (statToSet.equals("mAtkSpd"))
  841. {
  842. newNpcData.set("matkspd", Integer.parseInt(value));
  843. }
  844. else if (statToSet.equals("rHand"))
  845. {
  846. newNpcData.set("rhand", Integer.parseInt(value));
  847. }
  848. else if (statToSet.equals("lHand"))
  849. {
  850. newNpcData.set("lhand", Integer.parseInt(value));
  851. }
  852. else if (statToSet.equals("armor"))
  853. {
  854. newNpcData.set("armor", Integer.parseInt(value));
  855. }
  856. else if (statToSet.equals("enchant"))
  857. {
  858. newNpcData.set("enchant", Integer.parseInt(value));
  859. }
  860. else if (statToSet.equals("runSpd"))
  861. {
  862. newNpcData.set("runspd", Integer.parseInt(value));
  863. }
  864. else if (statToSet.equals("isUndead"))
  865. {
  866. newNpcData.set("isUndead", Integer.parseInt(value) == 1 ? 1 : 0);
  867. }
  868. else if (statToSet.equals("absorbLevel"))
  869. {
  870. int intVal = Integer.parseInt(value);
  871. newNpcData.set("absorb_level", intVal < 0 ? 0 : intVal > 16 ? 0 : intVal);
  872. }
  873. }
  874. catch (Exception e)
  875. {
  876. activeChar.sendMessage("Could not save npc property!");
  877. _log.warning("Error saving new npc value (" + command + "): " + e);
  878. }
  879. NpcTable.getInstance().saveNpc(newNpcData);
  880. int npcId = newNpcData.getInteger("npcId");
  881. NpcTable.getInstance().reloadNpc(npcId);
  882. showNpcProperty(activeChar, NpcTable.getInstance().getTemplate(npcId));
  883. }
  884. private void showNpcDropList(L2PcInstance activeChar, int npcId, int page)
  885. {
  886. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  887. if (npcData == null)
  888. {
  889. activeChar.sendMessage("Unknown npc template id " + npcId);
  890. return;
  891. }
  892. final StringBuilder replyMSG = new StringBuilder(2900);
  893. replyMSG.append("<html><title>Show droplist page ");
  894. replyMSG.append(page);
  895. replyMSG.append("</title><body><br1><center><font color=\"LEVEL\">");
  896. replyMSG.append(npcData.getName());
  897. replyMSG.append(" (");
  898. replyMSG.append(npcId);
  899. replyMSG.append(")</font></center><br1><table width=\"100%\" border=0><tr><td width=35>cat.</td><td width=210>item</td><td width=30>type</td><td width=25>del</td></tr>");
  900. int myPage = 1;
  901. int i = 0;
  902. int shown = 0;
  903. boolean hasMore = false;
  904. if (npcData.getDropData() != null)
  905. {
  906. for (L2DropCategory cat : npcData.getDropData())
  907. {
  908. if (shown == PAGE_LIMIT)
  909. {
  910. hasMore = true;
  911. break;
  912. }
  913. for (L2DropData drop : cat.getAllDrops())
  914. {
  915. if (myPage != page)
  916. {
  917. i++;
  918. if (i == PAGE_LIMIT)
  919. {
  920. myPage++;
  921. i = 0;
  922. }
  923. continue;
  924. }
  925. if (shown == PAGE_LIMIT)
  926. {
  927. hasMore = true;
  928. break;
  929. }
  930. replyMSG.append("<tr><td>");
  931. replyMSG.append(cat.getCategoryType());
  932. replyMSG.append("</td><td><a action=\"bypass -h admin_edit_drop ");
  933. replyMSG.append(npcId);
  934. replyMSG.append(" ");
  935. replyMSG.append(drop.getItemId());
  936. replyMSG.append(" ");
  937. replyMSG.append(cat.getCategoryType());
  938. replyMSG.append("\">");
  939. replyMSG.append(ItemTable.getInstance().getTemplate(drop.getItemId()).getName());
  940. replyMSG.append(" (");
  941. replyMSG.append(drop.getItemId());
  942. replyMSG.append(")</a></td><td>");
  943. replyMSG.append((drop.isQuestDrop() ? "Q" : (cat.isSweep() ? "S" : "D")));
  944. replyMSG.append("</td><td><a action=\"bypass -h admin_del_drop ");
  945. replyMSG.append(npcId);
  946. replyMSG.append(" ");
  947. replyMSG.append(drop.getItemId());
  948. replyMSG.append(" ");
  949. replyMSG.append(cat.getCategoryType());
  950. replyMSG.append("\">del</a></td></tr>");
  951. shown++;
  952. }
  953. }
  954. }
  955. replyMSG.append("</table><table width=300 bgcolor=666666 border=0><tr>");
  956. if (page > 1)
  957. {
  958. replyMSG.append("<td width=120><a action=\"bypass -h admin_show_droplist ");
  959. replyMSG.append(npcId);
  960. replyMSG.append(" ");
  961. replyMSG.append(page - 1);
  962. replyMSG.append("\">Prev Page</a></td>");
  963. if (!hasMore)
  964. {
  965. replyMSG.append("<td width=100>Page ");
  966. replyMSG.append(page);
  967. replyMSG.append("</td><td width=70></td></tr>");
  968. }
  969. }
  970. if (hasMore)
  971. {
  972. if (page <= 1)
  973. {
  974. replyMSG.append("<td width=120></td>");
  975. }
  976. replyMSG.append("<td width=100>Page ");
  977. replyMSG.append(page);
  978. replyMSG.append("</td><td width=70><a action=\"bypass -h admin_show_droplist ");
  979. replyMSG.append(npcId);
  980. replyMSG.append(" ");
  981. replyMSG.append(page + 1);
  982. replyMSG.append("\">Next Page</a></td></tr>");
  983. }
  984. replyMSG.append("</table><center><br><button value=\"Add Drop Data\" action=\"bypass -h admin_add_drop ");
  985. replyMSG.append(npcId);
  986. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  987. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  988. adminReply.setHtml(replyMSG.toString());
  989. activeChar.sendPacket(adminReply);
  990. }
  991. private void showEditDropData(L2PcInstance activeChar, int npcId, int itemId, int category)
  992. {
  993. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  994. if (npcData == null)
  995. {
  996. activeChar.sendMessage("Unknown npc template id " + npcId);
  997. return;
  998. }
  999. L2Item itemData = ItemTable.getInstance().getTemplate(itemId);
  1000. if (itemData == null)
  1001. {
  1002. activeChar.sendMessage("Unknown item template id " + itemId);
  1003. return;
  1004. }
  1005. final StringBuilder replyMSG = new StringBuilder();
  1006. replyMSG.append("<html><title>Edit drop data</title><body>");
  1007. List<L2DropData> dropDatas = null;
  1008. if (npcData.getDropData() != null)
  1009. {
  1010. for (L2DropCategory dropCat : npcData.getDropData())
  1011. {
  1012. if (dropCat.getCategoryType() == category)
  1013. {
  1014. dropDatas = dropCat.getAllDrops();
  1015. break;
  1016. }
  1017. }
  1018. }
  1019. L2DropData dropData = null;
  1020. if (dropDatas != null)
  1021. {
  1022. for (L2DropData drop : dropDatas)
  1023. {
  1024. if (drop.getItemId() == itemId)
  1025. {
  1026. dropData = drop;
  1027. break;
  1028. }
  1029. }
  1030. }
  1031. if (dropData != null)
  1032. {
  1033. replyMSG.append("<table width=\"100%\"><tr><td>Npc</td><td>");
  1034. replyMSG.append(npcData.getName());
  1035. replyMSG.append(" (");
  1036. replyMSG.append(npcId);
  1037. replyMSG.append(")</td></tr><tr><td>Item</td><td>");
  1038. replyMSG.append(itemData.getName());
  1039. replyMSG.append(" (");
  1040. replyMSG.append(itemId);
  1041. replyMSG.append(")</td></tr><tr><td>Category</td><td>");
  1042. replyMSG.append(((category == -1) ? "-1 (sweep)" : Integer.toString(category)));
  1043. replyMSG.append("</td></tr>");
  1044. replyMSG.append("<tr><td>Min count (");
  1045. replyMSG.append(dropData.getMinDrop());
  1046. replyMSG.append(")</td><td><edit var=\"min\" width=80></td></tr><tr><td>Max count (");
  1047. replyMSG.append(dropData.getMaxDrop());
  1048. replyMSG.append(")</td><td><edit var=\"max\" width=80></td></tr><tr><td>Chance (");
  1049. replyMSG.append(dropData.getChance());
  1050. replyMSG.append(")</td><td><edit var=\"chance\" width=80></td></tr></table><br>");
  1051. replyMSG.append("<center><br><button value=\"Save\" action=\"bypass -h admin_edit_drop ");
  1052. replyMSG.append(npcId);
  1053. replyMSG.append(" ");
  1054. replyMSG.append(itemId);
  1055. replyMSG.append(" ");
  1056. replyMSG.append(category);
  1057. replyMSG.append(" $min $max $chance\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  1058. }
  1059. else
  1060. {
  1061. replyMSG.append("No drop data detail found.<center><br>");
  1062. }
  1063. replyMSG.append("<button value=\"Back to Droplist\" action=\"bypass -h admin_show_droplist ");
  1064. replyMSG.append(npcId);
  1065. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  1066. replyMSG.append("</body></html>");
  1067. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1068. adminReply.setHtml(replyMSG.toString());
  1069. activeChar.sendPacket(adminReply);
  1070. }
  1071. private void showAddDropData(L2PcInstance activeChar, L2NpcTemplate npcData)
  1072. {
  1073. final String replyMSG = StringUtil.concat("<html><title>Add drop data</title><body><table width=\"100%\"><tr><td>Npc</td><td>", npcData.getName(), " (", Integer.toString(npcData.getNpcId()), ")", "</td></tr><tr><td>Item Id</td><td><edit var=\"itemId\" width=80></td></tr><tr><td>Min count</td><td><edit var=\"min\" width=80></td></tr><tr><td>Max count</td><td><edit var=\"max\" width=80></td></tr><tr><td>Category (sweep=-1)</td><td><edit var=\"category\" width=80></td></tr><tr><td>Chance (0-1000000)</td><td><edit var=\"chance\" width=80></td></tr></table><center><br><button value=\"Add\" action=\"bypass -h admin_add_drop ", Integer.toString(npcData.getNpcId()), " $itemId $category $min $max $chance\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Droplist\" action=\"bypass -h admin_show_droplist ", Integer.toString(npcData.getNpcId()), "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1074. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1075. adminReply.setHtml(replyMSG);
  1076. activeChar.sendPacket(adminReply);
  1077. }
  1078. private void updateDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  1079. {
  1080. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1081. {
  1082. int updated = 0;
  1083. if (Config.CUSTOM_DROPLIST_TABLE)
  1084. {
  1085. PreparedStatement statement = con.prepareStatement("UPDATE `custom_droplist` SET `min`=?, `max`=?, `chance`=? WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1086. statement.setInt(1, min);
  1087. statement.setInt(2, max);
  1088. statement.setInt(3, chance);
  1089. statement.setInt(4, npcId);
  1090. statement.setInt(5, itemId);
  1091. statement.setInt(6, category);
  1092. updated = statement.executeUpdate();
  1093. statement.close();
  1094. }
  1095. if (updated == 0)
  1096. {
  1097. PreparedStatement statement = con.prepareStatement("UPDATE `droplist` SET `min`=?, `max`=?, `chance`=? WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1098. statement.setInt(1, min);
  1099. statement.setInt(2, max);
  1100. statement.setInt(3, chance);
  1101. statement.setInt(4, npcId);
  1102. statement.setInt(5, itemId);
  1103. statement.setInt(6, category);
  1104. updated = statement.executeUpdate();
  1105. statement.close();
  1106. }
  1107. reloadNpcDropList(npcId);
  1108. showNpcDropList(activeChar, npcId, 1);
  1109. activeChar.sendMessage("Updated drop data for npc id " + npcId + " and item id " + itemId + " in category " + category + ".");
  1110. }
  1111. catch (Exception e)
  1112. {
  1113. activeChar.sendMessage("Could not update drop data!");
  1114. _log.warning("Error while updating drop data (" + npcId + ", " + itemId + ", " + min + ", " + max + ", " + category + ", " + chance + "): " + e);
  1115. }
  1116. }
  1117. private void addDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
  1118. {
  1119. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1120. {
  1121. String table = "droplist";
  1122. if (Config.CUSTOM_DROPLIST_TABLE)
  1123. {
  1124. table = "custom_droplist";
  1125. }
  1126. PreparedStatement statement = con.prepareStatement("INSERT INTO `" + table + "`(`mobId`, `itemId`, `min`, `max`, `category`, `chance`) VALUES(?,?,?,?,?,?)");
  1127. statement.setInt(1, npcId);
  1128. statement.setInt(2, itemId);
  1129. statement.setInt(3, min);
  1130. statement.setInt(4, max);
  1131. statement.setInt(5, category);
  1132. statement.setInt(6, chance);
  1133. statement.execute();
  1134. statement.close();
  1135. reloadNpcDropList(npcId);
  1136. showNpcDropList(activeChar, npcId, 1);
  1137. activeChar.sendMessage("Added drop data for npc id " + npcId + " with item id " + itemId + " in category " + category + ".");
  1138. }
  1139. catch (Exception e)
  1140. {
  1141. activeChar.sendMessage("Could not add drop data!");
  1142. _log.warning("Error while adding drop data (" + npcId + ", " + itemId + ", " + min + ", " + max + ", " + category + ", " + chance + "): " + e);
  1143. }
  1144. }
  1145. private void deleteDropData(L2PcInstance activeChar, int npcId, int itemId, int category, boolean confirmed)
  1146. {
  1147. if (!confirmed)
  1148. {
  1149. final String replyMSG = StringUtil.concat("<html><title>Drop Data Delete</title><body><br>Delete drop data.", "<table width=\"100%\"><tr><td>NPC</td><td>", NpcTable.getInstance().getTemplate(npcId).getName(), " (", Integer.toString(npcId), ")</td></tr><tr><td>Item ID</td><td>", Integer.toString(itemId), "</td></tr><tr><td>Category</td><td>", Integer.toString(category), "</td></tr></table><center><br><button value=\"Delete\" action=\"bypass -h admin_del_drop ", Integer.toString(npcId), " ", Integer.toString(itemId), " ", Integer.toString(category), " 1\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back to Droplist\" action=\"bypass -h admin_show_droplist ", Integer.toString(npcId), "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1150. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1151. adminReply.setHtml(replyMSG);
  1152. activeChar.sendPacket(adminReply);
  1153. return;
  1154. }
  1155. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1156. {
  1157. int updated = 0;
  1158. if (Config.CUSTOM_DROPLIST_TABLE)
  1159. {
  1160. PreparedStatement statement = con.prepareStatement("DELETE FROM `custom_droplist` WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1161. statement.setInt(1, npcId);
  1162. statement.setInt(2, itemId);
  1163. statement.setInt(3, category);
  1164. updated = statement.executeUpdate();
  1165. statement.close();
  1166. }
  1167. if (updated == 0)
  1168. {
  1169. PreparedStatement statement = con.prepareStatement("DELETE FROM `droplist` WHERE `mobId`=? AND `itemId`=? AND `category`=?");
  1170. statement.setInt(1, npcId);
  1171. statement.setInt(2, itemId);
  1172. statement.setInt(3, category);
  1173. updated = statement.executeUpdate();
  1174. statement.close();
  1175. }
  1176. reloadNpcDropList(npcId);
  1177. showNpcDropList(activeChar, npcId, 1);
  1178. activeChar.sendMessage("Deleted drop data for npc id " + npcId + " and item id " + itemId + " in category " + category + ".");
  1179. }
  1180. catch (Exception e)
  1181. {
  1182. activeChar.sendMessage("Could not delete drop data!");
  1183. _log.warning("Error while deleting drop data (" + npcId + ", " + itemId + ", " + category + "): " + e);
  1184. }
  1185. }
  1186. private void reloadNpcDropList(int npcId)
  1187. {
  1188. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1189. if (npcData == null)
  1190. {
  1191. return;
  1192. }
  1193. // reset the drop lists
  1194. npcData.clearAllDropData();
  1195. // get the drops
  1196. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1197. {
  1198. L2DropData dropData = null;
  1199. PreparedStatement statement = con.prepareStatement("SELECT `mobId`, `itemId`, `min`, `max`, `category`, `chance` FROM `droplist` WHERE `mobId`=?");
  1200. statement.setInt(1, npcId);
  1201. ResultSet dropDataList = statement.executeQuery();
  1202. while (dropDataList.next())
  1203. {
  1204. dropData = new L2DropData();
  1205. dropData.setItemId(dropDataList.getInt("itemId"));
  1206. dropData.setMinDrop(dropDataList.getInt("min"));
  1207. dropData.setMaxDrop(dropDataList.getInt("max"));
  1208. dropData.setChance(dropDataList.getInt("chance"));
  1209. int category = dropDataList.getInt("category");
  1210. npcData.addDropData(dropData, category);
  1211. }
  1212. dropDataList.close();
  1213. statement.close();
  1214. if (Config.CUSTOM_DROPLIST_TABLE)
  1215. {
  1216. PreparedStatement statement2 = con.prepareStatement("SELECT `mobId`, `itemId`, `min`, `max`, `category`, `chance` FROM `custom_droplist` WHERE `mobId`=?");
  1217. statement2.setInt(1, npcId);
  1218. ResultSet dropDataList2 = statement2.executeQuery();
  1219. while (dropDataList2.next())
  1220. {
  1221. dropData = new L2DropData();
  1222. dropData.setItemId(dropDataList2.getInt("itemId"));
  1223. dropData.setMinDrop(dropDataList2.getInt("min"));
  1224. dropData.setMaxDrop(dropDataList2.getInt("max"));
  1225. dropData.setChance(dropDataList2.getInt("chance"));
  1226. int category = dropDataList2.getInt("category");
  1227. npcData.addDropData(dropData, category);
  1228. }
  1229. dropDataList2.close();
  1230. statement2.close();
  1231. }
  1232. }
  1233. catch (Exception e)
  1234. {
  1235. _log.warning("Error while reloading npc droplist (" + npcId + "): " + e);
  1236. }
  1237. }
  1238. private void showNpcSkillList(L2PcInstance activeChar, int npcId, int page)
  1239. {
  1240. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1241. if (npcData == null)
  1242. {
  1243. activeChar.sendMessage("Template id unknown: " + npcId);
  1244. return;
  1245. }
  1246. Map<Integer, L2Skill> skills = new HashMap<>(npcData.getSkills());
  1247. int _skillsize = skills.size();
  1248. int MaxSkillsPerPage = PAGE_LIMIT;
  1249. int MaxPages = _skillsize / MaxSkillsPerPage;
  1250. if (_skillsize > (MaxSkillsPerPage * MaxPages))
  1251. {
  1252. MaxPages++;
  1253. }
  1254. if (page > MaxPages)
  1255. {
  1256. page = MaxPages;
  1257. }
  1258. int SkillsStart = MaxSkillsPerPage * page;
  1259. int SkillsEnd = _skillsize;
  1260. if ((SkillsEnd - SkillsStart) > MaxSkillsPerPage)
  1261. {
  1262. SkillsEnd = SkillsStart + MaxSkillsPerPage;
  1263. }
  1264. StringBuffer replyMSG = new StringBuffer("<html><title>Show NPC Skill List</title><body><center><font color=\"LEVEL\">");
  1265. replyMSG.append(npcData.getName());
  1266. replyMSG.append(" (");
  1267. replyMSG.append(npcData.getNpcId());
  1268. replyMSG.append("): ");
  1269. replyMSG.append(_skillsize);
  1270. replyMSG.append(" skills</font></center><table width=300 bgcolor=666666><tr>");
  1271. for (int x = 0; x < MaxPages; x++)
  1272. {
  1273. int pagenr = x + 1;
  1274. if (page == x)
  1275. {
  1276. replyMSG.append("<td>Page ");
  1277. replyMSG.append(pagenr);
  1278. replyMSG.append("</td>");
  1279. }
  1280. else
  1281. {
  1282. replyMSG.append("<td><a action=\"bypass -h admin_show_skilllist_npc ");
  1283. replyMSG.append(npcData.getNpcId());
  1284. replyMSG.append(" ");
  1285. replyMSG.append(x);
  1286. replyMSG.append("\"> Page ");
  1287. replyMSG.append(pagenr);
  1288. replyMSG.append(" </a></td>");
  1289. }
  1290. }
  1291. replyMSG.append("</tr></table><table width=\"100%\" border=0><tr><td>Skill name [skill id-skill lvl]</td><td>Delete</td></tr>");
  1292. Iterator<L2Skill> skillite = skills.values().iterator();
  1293. for (int i = 0; i < SkillsStart; i++)
  1294. {
  1295. if (skillite.hasNext())
  1296. {
  1297. skillite.next();
  1298. }
  1299. }
  1300. int cnt = SkillsStart;
  1301. L2Skill sk;
  1302. while (skillite.hasNext())
  1303. {
  1304. cnt++;
  1305. if (cnt > SkillsEnd)
  1306. {
  1307. break;
  1308. }
  1309. sk = skillite.next();
  1310. replyMSG.append("<tr><td width=240><a action=\"bypass -h admin_edit_skill_npc ");
  1311. replyMSG.append(npcData.getNpcId());
  1312. replyMSG.append(" ");
  1313. replyMSG.append(sk.getId());
  1314. replyMSG.append("\">");
  1315. if (sk.getSkillType() == L2SkillType.NOTDONE)
  1316. {
  1317. replyMSG.append("<font color=\"777777\">" + sk.getName() + "</font>");
  1318. }
  1319. else
  1320. {
  1321. replyMSG.append(sk.getName());
  1322. }
  1323. replyMSG.append(" [");
  1324. replyMSG.append(sk.getId());
  1325. replyMSG.append("-");
  1326. replyMSG.append(sk.getLevel());
  1327. replyMSG.append("]</a></td><td width=60><a action=\"bypass -h admin_del_skill_npc ");
  1328. replyMSG.append(npcData.getNpcId());
  1329. replyMSG.append(" ");
  1330. replyMSG.append(sk.getId());
  1331. replyMSG.append("\">Delete</a></td></tr>");
  1332. }
  1333. replyMSG.append("</table><br><center><button value=\"Add Skill\" action=\"bypass -h admin_add_skill_npc ");
  1334. replyMSG.append(npcId);
  1335. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Close\" action=\"bypass -h admin_close_window\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1336. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1337. adminReply.setHtml(replyMSG.toString());
  1338. activeChar.sendPacket(adminReply);
  1339. }
  1340. private void showNpcSkillEdit(L2PcInstance activeChar, int npcId, int skillId)
  1341. {
  1342. try
  1343. {
  1344. StringBuffer replyMSG = new StringBuffer("<html><title>NPC Skill Edit</title><body>");
  1345. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1346. if (npcData == null)
  1347. {
  1348. activeChar.sendMessage("Template id unknown: " + npcId);
  1349. return;
  1350. }
  1351. if (npcData.getSkills() == null)
  1352. {
  1353. return;
  1354. }
  1355. L2Skill npcSkill = npcData.getSkills().get(skillId);
  1356. if (npcSkill != null)
  1357. {
  1358. replyMSG.append("<table width=\"100%\"><tr><td>NPC: </td><td>");
  1359. replyMSG.append(NpcTable.getInstance().getTemplate(npcId).getName());
  1360. replyMSG.append(" (");
  1361. replyMSG.append(npcId);
  1362. replyMSG.append(")</td></tr><tr><td>Skill: </td><td>");
  1363. replyMSG.append(npcSkill.getName());
  1364. replyMSG.append(" (");
  1365. replyMSG.append(skillId);
  1366. replyMSG.append(")</td></tr><tr><td>Skill Lvl: (");
  1367. replyMSG.append(npcSkill.getLevel());
  1368. replyMSG.append(") </td><td><edit var=\"level\" width=50></td></tr></table><br><center><button value=\"Save\" action=\"bypass -h admin_edit_skill_npc ");
  1369. replyMSG.append(npcId);
  1370. replyMSG.append(" ");
  1371. replyMSG.append(skillId);
  1372. replyMSG.append(" $level\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br1><button value=\"Back to SkillList\" action=\"bypass -h admin_show_skilllist_npc ");
  1373. replyMSG.append(npcId);
  1374. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
  1375. }
  1376. replyMSG.append("</body></html>");
  1377. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1378. adminReply.setHtml(replyMSG.toString());
  1379. activeChar.sendPacket(adminReply);
  1380. }
  1381. catch (Exception e)
  1382. {
  1383. activeChar.sendMessage("Could not edit npc skills!");
  1384. _log.warning("Error while editing npc skills (" + npcId + ", " + skillId + "): " + e);
  1385. }
  1386. }
  1387. private void updateNpcSkillData(L2PcInstance activeChar, int npcId, int skillId, int level)
  1388. {
  1389. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1390. {
  1391. L2Skill skillData = SkillTable.getInstance().getInfo(skillId, level);
  1392. if (skillData == null)
  1393. {
  1394. activeChar.sendMessage("Could not update npc skill: not existing skill id with that level!");
  1395. showNpcSkillEdit(activeChar, npcId, skillId);
  1396. return;
  1397. }
  1398. if (skillData.getLevel() != level)
  1399. {
  1400. activeChar.sendMessage("Skill id with requested level doesn't exist! Skill level not changed.");
  1401. showNpcSkillEdit(activeChar, npcId, skillId);
  1402. return;
  1403. }
  1404. int updated = 0;
  1405. if (Config.CUSTOM_NPC_SKILLS_TABLE)
  1406. {
  1407. PreparedStatement statement2 = con.prepareStatement("UPDATE `custom_npcskills` SET `level`=? WHERE `npcid`=? AND `skillid`=?");
  1408. statement2.setInt(1, level);
  1409. statement2.setInt(2, npcId);
  1410. statement2.setInt(3, skillId);
  1411. updated = statement2.executeUpdate();
  1412. statement2.close();
  1413. }
  1414. if (updated == 0)
  1415. {
  1416. PreparedStatement statement = con.prepareStatement("UPDATE `npcskills` SET `level`=? WHERE `npcid`=? AND `skillid`=?");
  1417. statement.setInt(1, level);
  1418. statement.setInt(2, npcId);
  1419. statement.setInt(3, skillId);
  1420. statement.execute();
  1421. statement.close();
  1422. }
  1423. reloadNpcSkillList(npcId);
  1424. showNpcSkillList(activeChar, npcId, 0);
  1425. activeChar.sendMessage("Updated skill id " + skillId + " for npc id " + npcId + " to level " + level + ".");
  1426. }
  1427. catch (Exception e)
  1428. {
  1429. activeChar.sendMessage("Could not update npc skill!");
  1430. _log.warning("Error while updating npc skill (" + npcId + ", " + skillId + ", " + level + "): " + e);
  1431. }
  1432. }
  1433. private void showNpcSkillAdd(L2PcInstance activeChar, int npcId)
  1434. {
  1435. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1436. StringBuffer replyMSG = new StringBuffer("<html><title>NPC Skill Add</title><body><table width=\"100%\"><tr><td>NPC: </td><td>");
  1437. replyMSG.append(npcData.getName());
  1438. replyMSG.append(" (");
  1439. replyMSG.append(npcData.getNpcId());
  1440. replyMSG.append(")</td></tr><tr><td>SkillId: </td><td><edit var=\"skillId\" width=80></td></tr><tr><td>Level: </td><td><edit var=\"level\" width=80></td></tr></table><br><center><button value=\"Add Skill\" action=\"bypass -h admin_add_skill_npc ");
  1441. replyMSG.append(npcData.getNpcId());
  1442. replyMSG.append(" $skillId $level\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br1><button value=\"Back to SkillList\" action=\"bypass -h admin_show_skilllist_npc ");
  1443. replyMSG.append(npcData.getNpcId());
  1444. replyMSG.append("\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  1445. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  1446. adminReply.setHtml(replyMSG.toString());
  1447. activeChar.sendPacket(adminReply);
  1448. }
  1449. private void addNpcSkillData(L2PcInstance activeChar, int npcId, int skillId, int level)
  1450. {
  1451. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1452. {
  1453. // skill check
  1454. L2Skill skillData = SkillTable.getInstance().getInfo(skillId, level);
  1455. if (skillData == null)
  1456. {
  1457. activeChar.sendMessage("Could not add npc skill: not existing skill id with that level!");
  1458. showNpcSkillAdd(activeChar, npcId);
  1459. return;
  1460. }
  1461. if (Config.CUSTOM_NPC_SKILLS_TABLE)
  1462. {
  1463. PreparedStatement statement = con.prepareStatement("INSERT INTO `custom_npcskills`(`npcid`, `skillid`, `level`) VALUES(?,?,?)");
  1464. statement.setInt(1, npcId);
  1465. statement.setInt(2, skillId);
  1466. statement.setInt(3, level);
  1467. statement.execute();
  1468. statement.close();
  1469. }
  1470. else
  1471. {
  1472. PreparedStatement statement = con.prepareStatement("INSERT INTO `npcskills`(`npcid`, `skillid`, `level`) VALUES(?,?,?)");
  1473. statement.setInt(1, npcId);
  1474. statement.setInt(2, skillId);
  1475. statement.setInt(3, level);
  1476. statement.execute();
  1477. statement.close();
  1478. }
  1479. reloadNpcSkillList(npcId);
  1480. showNpcSkillList(activeChar, npcId, 0);
  1481. activeChar.sendMessage("Added skill " + skillId + "-" + level + " to npc id " + npcId + ".");
  1482. }
  1483. catch (Exception e)
  1484. {
  1485. activeChar.sendMessage("Could not add npc skill!");
  1486. _log.warning("Error while adding a npc skill (" + npcId + ", " + skillId + ", " + level + "): " + e);
  1487. }
  1488. }
  1489. private void deleteNpcSkillData(L2PcInstance activeChar, int npcId, int skillId)
  1490. {
  1491. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1492. {
  1493. if (npcId > 0)
  1494. {
  1495. int updated = 0;
  1496. if (Config.CUSTOM_NPC_SKILLS_TABLE)
  1497. {
  1498. PreparedStatement statement = con.prepareStatement("DELETE FROM `custom_npcskills` WHERE `npcid`=? AND `skillid`=?");
  1499. statement.setInt(1, npcId);
  1500. statement.setInt(2, skillId);
  1501. updated = statement.executeUpdate();
  1502. statement.close();
  1503. }
  1504. if (updated == 0)
  1505. {
  1506. PreparedStatement statement2 = con.prepareStatement("DELETE FROM `npcskills` WHERE `npcid`=? AND `skillid`=?");
  1507. statement2.setInt(1, npcId);
  1508. statement2.setInt(2, skillId);
  1509. statement2.execute();
  1510. statement2.close();
  1511. }
  1512. reloadNpcSkillList(npcId);
  1513. showNpcSkillList(activeChar, npcId, 0);
  1514. activeChar.sendMessage("Deleted skill id " + skillId + " from npc id " + npcId + ".");
  1515. }
  1516. }
  1517. catch (Exception e)
  1518. {
  1519. activeChar.sendMessage("Could not delete npc skill!");
  1520. _log.warning("Error while deleting npc skill (" + npcId + ", " + skillId + "): " + e);
  1521. }
  1522. }
  1523. private void reloadNpcSkillList(int npcId)
  1524. {
  1525. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1526. {
  1527. L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
  1528. L2Skill skillData = null;
  1529. if (npcData.getSkills() != null)
  1530. {
  1531. npcData.getSkills().clear();
  1532. }
  1533. // without race
  1534. PreparedStatement statement = con.prepareStatement("SELECT `skillid`, `level` FROM `npcskills` WHERE `npcid`=? AND `skillid` <> 4416");
  1535. statement.setInt(1, npcId);
  1536. ResultSet skillDataList = statement.executeQuery();
  1537. while (skillDataList.next())
  1538. {
  1539. int idval = skillDataList.getInt("skillid");
  1540. int levelval = skillDataList.getInt("level");
  1541. skillData = SkillTable.getInstance().getInfo(idval, levelval);
  1542. if (skillData != null)
  1543. {
  1544. npcData.addSkill(skillData);
  1545. }
  1546. }
  1547. skillDataList.close();
  1548. statement.close();
  1549. if (Config.CUSTOM_NPC_SKILLS_TABLE)
  1550. {
  1551. PreparedStatement statement2 = con.prepareStatement("SELECT `skillid`, `level` FROM `npcskills` WHERE `npcid`=? AND `skillid` <> 4416");
  1552. statement2.setInt(1, npcId);
  1553. ResultSet skillDataList2 = statement2.executeQuery();
  1554. while (skillDataList2.next())
  1555. {
  1556. int idval = skillDataList2.getInt("skillid");
  1557. int levelval = skillDataList2.getInt("level");
  1558. skillData = SkillTable.getInstance().getInfo(idval, levelval);
  1559. if (skillData != null)
  1560. {
  1561. npcData.addSkill(skillData);
  1562. }
  1563. }
  1564. skillDataList2.close();
  1565. statement2.close();
  1566. }
  1567. }
  1568. catch (Exception e)
  1569. {
  1570. _log.warning("Error while reloading npc skill list (" + npcId + "): " + e);
  1571. }
  1572. }
  1573. }