AdminEditNpc.java 61 KB

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