AdminEditNpc.java 60 KB

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