AdminMobGroup.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /*
  2. * Copyright (C) 2004-2015 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 com.l2jserver.gameserver.data.xml.impl.NpcData;
  21. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  22. import com.l2jserver.gameserver.model.L2World;
  23. import com.l2jserver.gameserver.model.MobGroup;
  24. import com.l2jserver.gameserver.model.MobGroupTable;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  30. import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
  31. import com.l2jserver.gameserver.util.Broadcast;
  32. /**
  33. * @author littlecrow Admin commands handler for controllable mobs
  34. */
  35. public class AdminMobGroup implements IAdminCommandHandler
  36. {
  37. private static final String[] ADMIN_COMMANDS =
  38. {
  39. "admin_mobmenu",
  40. "admin_mobgroup_list",
  41. "admin_mobgroup_create",
  42. "admin_mobgroup_remove",
  43. "admin_mobgroup_delete",
  44. "admin_mobgroup_spawn",
  45. "admin_mobgroup_unspawn",
  46. "admin_mobgroup_kill",
  47. "admin_mobgroup_idle",
  48. "admin_mobgroup_attack",
  49. "admin_mobgroup_rnd",
  50. "admin_mobgroup_return",
  51. "admin_mobgroup_follow",
  52. "admin_mobgroup_casting",
  53. "admin_mobgroup_nomove",
  54. "admin_mobgroup_attackgrp",
  55. "admin_mobgroup_invul"
  56. };
  57. @Override
  58. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  59. {
  60. if (command.equals("admin_mobmenu"))
  61. {
  62. showMainPage(activeChar, command);
  63. return true;
  64. }
  65. else if (command.equals("admin_mobgroup_list"))
  66. {
  67. showGroupList(activeChar);
  68. }
  69. else if (command.startsWith("admin_mobgroup_create"))
  70. {
  71. createGroup(command, activeChar);
  72. }
  73. else if (command.startsWith("admin_mobgroup_delete") || command.startsWith("admin_mobgroup_remove"))
  74. {
  75. removeGroup(command, activeChar);
  76. }
  77. else if (command.startsWith("admin_mobgroup_spawn"))
  78. {
  79. spawnGroup(command, activeChar);
  80. }
  81. else if (command.startsWith("admin_mobgroup_unspawn"))
  82. {
  83. unspawnGroup(command, activeChar);
  84. }
  85. else if (command.startsWith("admin_mobgroup_kill"))
  86. {
  87. killGroup(command, activeChar);
  88. }
  89. else if (command.startsWith("admin_mobgroup_attackgrp"))
  90. {
  91. attackGrp(command, activeChar);
  92. }
  93. else if (command.startsWith("admin_mobgroup_attack"))
  94. {
  95. if (activeChar.getTarget() instanceof L2Character)
  96. {
  97. L2Character target = (L2Character) activeChar.getTarget();
  98. attack(command, activeChar, target);
  99. }
  100. }
  101. else if (command.startsWith("admin_mobgroup_rnd"))
  102. {
  103. setNormal(command, activeChar);
  104. }
  105. else if (command.startsWith("admin_mobgroup_idle"))
  106. {
  107. idle(command, activeChar);
  108. }
  109. else if (command.startsWith("admin_mobgroup_return"))
  110. {
  111. returnToChar(command, activeChar);
  112. }
  113. else if (command.startsWith("admin_mobgroup_follow"))
  114. {
  115. follow(command, activeChar, activeChar);
  116. }
  117. else if (command.startsWith("admin_mobgroup_casting"))
  118. {
  119. setCasting(command, activeChar);
  120. }
  121. else if (command.startsWith("admin_mobgroup_nomove"))
  122. {
  123. noMove(command, activeChar);
  124. }
  125. else if (command.startsWith("admin_mobgroup_invul"))
  126. {
  127. invul(command, activeChar);
  128. }
  129. else if (command.startsWith("admin_mobgroup_teleport"))
  130. {
  131. teleportGroup(command, activeChar);
  132. }
  133. showMainPage(activeChar, command);
  134. return true;
  135. }
  136. /**
  137. * @param activeChar
  138. * @param command
  139. */
  140. private void showMainPage(L2PcInstance activeChar, String command)
  141. {
  142. String filename = "mobgroup.htm";
  143. AdminHtml.showAdminHtml(activeChar, filename);
  144. }
  145. private void returnToChar(String command, L2PcInstance activeChar)
  146. {
  147. int groupId;
  148. try
  149. {
  150. groupId = Integer.parseInt(command.split(" ")[1]);
  151. }
  152. catch (Exception e)
  153. {
  154. activeChar.sendMessage("Incorrect command arguments.");
  155. return;
  156. }
  157. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  158. if (group == null)
  159. {
  160. activeChar.sendMessage("Invalid group specified.");
  161. return;
  162. }
  163. group.returnGroup(activeChar);
  164. }
  165. private void idle(String command, L2PcInstance activeChar)
  166. {
  167. int groupId;
  168. try
  169. {
  170. groupId = Integer.parseInt(command.split(" ")[1]);
  171. }
  172. catch (Exception e)
  173. {
  174. activeChar.sendMessage("Incorrect command arguments.");
  175. return;
  176. }
  177. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  178. if (group == null)
  179. {
  180. activeChar.sendMessage("Invalid group specified.");
  181. return;
  182. }
  183. group.setIdleMode();
  184. }
  185. private void setNormal(String command, L2PcInstance activeChar)
  186. {
  187. int groupId;
  188. try
  189. {
  190. groupId = Integer.parseInt(command.split(" ")[1]);
  191. }
  192. catch (Exception e)
  193. {
  194. activeChar.sendMessage("Incorrect command arguments.");
  195. return;
  196. }
  197. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  198. if (group == null)
  199. {
  200. activeChar.sendMessage("Invalid group specified.");
  201. return;
  202. }
  203. group.setAttackRandom();
  204. }
  205. private void attack(String command, L2PcInstance activeChar, L2Character target)
  206. {
  207. int groupId;
  208. try
  209. {
  210. groupId = Integer.parseInt(command.split(" ")[1]);
  211. }
  212. catch (Exception e)
  213. {
  214. activeChar.sendMessage("Incorrect command arguments.");
  215. return;
  216. }
  217. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  218. if (group == null)
  219. {
  220. activeChar.sendMessage("Invalid group specified.");
  221. return;
  222. }
  223. group.setAttackTarget(target);
  224. }
  225. private void follow(String command, L2PcInstance activeChar, L2Character target)
  226. {
  227. int groupId;
  228. try
  229. {
  230. groupId = Integer.parseInt(command.split(" ")[1]);
  231. }
  232. catch (Exception e)
  233. {
  234. activeChar.sendMessage("Incorrect command arguments.");
  235. return;
  236. }
  237. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  238. if (group == null)
  239. {
  240. activeChar.sendMessage("Invalid group specified.");
  241. return;
  242. }
  243. group.setFollowMode(target);
  244. }
  245. private void createGroup(String command, L2PcInstance activeChar)
  246. {
  247. int groupId;
  248. int templateId;
  249. int mobCount;
  250. try
  251. {
  252. String[] cmdParams = command.split(" ");
  253. groupId = Integer.parseInt(cmdParams[1]);
  254. templateId = Integer.parseInt(cmdParams[2]);
  255. mobCount = Integer.parseInt(cmdParams[3]);
  256. }
  257. catch (Exception e)
  258. {
  259. activeChar.sendMessage("Usage: //mobgroup_create <group> <npcid> <count>");
  260. return;
  261. }
  262. if (MobGroupTable.getInstance().getGroup(groupId) != null)
  263. {
  264. activeChar.sendMessage("Mob group " + groupId + " already exists.");
  265. return;
  266. }
  267. L2NpcTemplate template = NpcData.getInstance().getTemplate(templateId);
  268. if (template == null)
  269. {
  270. activeChar.sendMessage("Invalid NPC ID specified.");
  271. return;
  272. }
  273. MobGroup group = new MobGroup(groupId, template, mobCount);
  274. MobGroupTable.getInstance().addGroup(groupId, group);
  275. activeChar.sendMessage("Mob group " + groupId + " created.");
  276. }
  277. private void removeGroup(String command, L2PcInstance activeChar)
  278. {
  279. int groupId;
  280. try
  281. {
  282. groupId = Integer.parseInt(command.split(" ")[1]);
  283. }
  284. catch (Exception e)
  285. {
  286. activeChar.sendMessage("Usage: //mobgroup_remove <groupId>");
  287. return;
  288. }
  289. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  290. if (group == null)
  291. {
  292. activeChar.sendMessage("Invalid group specified.");
  293. return;
  294. }
  295. doAnimation(activeChar);
  296. group.unspawnGroup();
  297. if (MobGroupTable.getInstance().removeGroup(groupId))
  298. {
  299. activeChar.sendMessage("Mob group " + groupId + " unspawned and removed.");
  300. }
  301. }
  302. private void spawnGroup(String command, L2PcInstance activeChar)
  303. {
  304. int groupId;
  305. boolean topos = false;
  306. int posx = 0;
  307. int posy = 0;
  308. int posz = 0;
  309. try
  310. {
  311. String[] cmdParams = command.split(" ");
  312. groupId = Integer.parseInt(cmdParams[1]);
  313. try
  314. { // we try to get a position
  315. posx = Integer.parseInt(cmdParams[2]);
  316. posy = Integer.parseInt(cmdParams[3]);
  317. posz = Integer.parseInt(cmdParams[4]);
  318. topos = true;
  319. }
  320. catch (Exception e)
  321. {
  322. // no position given
  323. }
  324. }
  325. catch (Exception e)
  326. {
  327. activeChar.sendMessage("Usage: //mobgroup_spawn <group> [ x y z ]");
  328. return;
  329. }
  330. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  331. if (group == null)
  332. {
  333. activeChar.sendMessage("Invalid group specified.");
  334. return;
  335. }
  336. doAnimation(activeChar);
  337. if (topos)
  338. {
  339. group.spawnGroup(posx, posy, posz);
  340. }
  341. else
  342. {
  343. group.spawnGroup(activeChar);
  344. }
  345. activeChar.sendMessage("Mob group " + groupId + " spawned.");
  346. }
  347. private void unspawnGroup(String command, L2PcInstance activeChar)
  348. {
  349. int groupId;
  350. try
  351. {
  352. groupId = Integer.parseInt(command.split(" ")[1]);
  353. }
  354. catch (Exception e)
  355. {
  356. activeChar.sendMessage("Usage: //mobgroup_unspawn <groupId>");
  357. return;
  358. }
  359. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  360. if (group == null)
  361. {
  362. activeChar.sendMessage("Invalid group specified.");
  363. return;
  364. }
  365. doAnimation(activeChar);
  366. group.unspawnGroup();
  367. activeChar.sendMessage("Mob group " + groupId + " unspawned.");
  368. }
  369. private void killGroup(String command, L2PcInstance activeChar)
  370. {
  371. int groupId;
  372. try
  373. {
  374. groupId = Integer.parseInt(command.split(" ")[1]);
  375. }
  376. catch (Exception e)
  377. {
  378. activeChar.sendMessage("Usage: //mobgroup_kill <groupId>");
  379. return;
  380. }
  381. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  382. if (group == null)
  383. {
  384. activeChar.sendMessage("Invalid group specified.");
  385. return;
  386. }
  387. doAnimation(activeChar);
  388. group.killGroup(activeChar);
  389. }
  390. private void setCasting(String command, L2PcInstance activeChar)
  391. {
  392. int groupId;
  393. try
  394. {
  395. groupId = Integer.parseInt(command.split(" ")[1]);
  396. }
  397. catch (Exception e)
  398. {
  399. activeChar.sendMessage("Usage: //mobgroup_casting <groupId>");
  400. return;
  401. }
  402. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  403. if (group == null)
  404. {
  405. activeChar.sendMessage("Invalid group specified.");
  406. return;
  407. }
  408. group.setCastMode();
  409. }
  410. private void noMove(String command, L2PcInstance activeChar)
  411. {
  412. int groupId;
  413. String enabled;
  414. try
  415. {
  416. groupId = Integer.parseInt(command.split(" ")[1]);
  417. enabled = command.split(" ")[2];
  418. }
  419. catch (Exception e)
  420. {
  421. activeChar.sendMessage("Usage: //mobgroup_nomove <groupId> <on|off>");
  422. return;
  423. }
  424. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  425. if (group == null)
  426. {
  427. activeChar.sendMessage("Invalid group specified.");
  428. return;
  429. }
  430. if (enabled.equalsIgnoreCase("on") || enabled.equalsIgnoreCase("true"))
  431. {
  432. group.setNoMoveMode(true);
  433. }
  434. else if (enabled.equalsIgnoreCase("off") || enabled.equalsIgnoreCase("false"))
  435. {
  436. group.setNoMoveMode(false);
  437. }
  438. else
  439. {
  440. activeChar.sendMessage("Incorrect command arguments.");
  441. }
  442. }
  443. private void doAnimation(L2PcInstance activeChar)
  444. {
  445. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, 1008, 1, 4000, 0), 1500);
  446. activeChar.sendPacket(new SetupGauge(0, 4000));
  447. }
  448. private void attackGrp(String command, L2PcInstance activeChar)
  449. {
  450. int groupId;
  451. int othGroupId;
  452. try
  453. {
  454. groupId = Integer.parseInt(command.split(" ")[1]);
  455. othGroupId = Integer.parseInt(command.split(" ")[2]);
  456. }
  457. catch (Exception e)
  458. {
  459. activeChar.sendMessage("Usage: //mobgroup_attackgrp <groupId> <TargetGroupId>");
  460. return;
  461. }
  462. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  463. if (group == null)
  464. {
  465. activeChar.sendMessage("Invalid group specified.");
  466. return;
  467. }
  468. MobGroup othGroup = MobGroupTable.getInstance().getGroup(othGroupId);
  469. if (othGroup == null)
  470. {
  471. activeChar.sendMessage("Incorrect target group.");
  472. return;
  473. }
  474. group.setAttackGroup(othGroup);
  475. }
  476. private void invul(String command, L2PcInstance activeChar)
  477. {
  478. int groupId;
  479. String enabled;
  480. try
  481. {
  482. groupId = Integer.parseInt(command.split(" ")[1]);
  483. enabled = command.split(" ")[2];
  484. }
  485. catch (Exception e)
  486. {
  487. activeChar.sendMessage("Usage: //mobgroup_invul <groupId> <on|off>");
  488. return;
  489. }
  490. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  491. if (group == null)
  492. {
  493. activeChar.sendMessage("Invalid group specified.");
  494. return;
  495. }
  496. if (enabled.equalsIgnoreCase("on") || enabled.equalsIgnoreCase("true"))
  497. {
  498. group.setInvul(true);
  499. }
  500. else if (enabled.equalsIgnoreCase("off") || enabled.equalsIgnoreCase("false"))
  501. {
  502. group.setInvul(false);
  503. }
  504. else
  505. {
  506. activeChar.sendMessage("Incorrect command arguments.");
  507. }
  508. }
  509. private void teleportGroup(String command, L2PcInstance activeChar)
  510. {
  511. int groupId;
  512. String targetPlayerStr = null;
  513. L2PcInstance targetPlayer = null;
  514. try
  515. {
  516. groupId = Integer.parseInt(command.split(" ")[1]);
  517. targetPlayerStr = command.split(" ")[2];
  518. if (targetPlayerStr != null)
  519. {
  520. targetPlayer = L2World.getInstance().getPlayer(targetPlayerStr);
  521. }
  522. if (targetPlayer == null)
  523. {
  524. targetPlayer = activeChar;
  525. }
  526. }
  527. catch (Exception e)
  528. {
  529. activeChar.sendMessage("Usage: //mobgroup_teleport <groupId> [playerName]");
  530. return;
  531. }
  532. MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
  533. if (group == null)
  534. {
  535. activeChar.sendMessage("Invalid group specified.");
  536. return;
  537. }
  538. group.teleportGroup(activeChar);
  539. }
  540. private void showGroupList(L2PcInstance activeChar)
  541. {
  542. MobGroup[] mobGroupList = MobGroupTable.getInstance().getGroups();
  543. activeChar.sendMessage("======= <Mob Groups> =======");
  544. for (MobGroup mobGroup : mobGroupList)
  545. {
  546. activeChar.sendMessage(mobGroup.getGroupId() + ": " + mobGroup.getActiveMobCount() + " alive out of " + mobGroup.getMaxMobCount() + " of NPC ID " + mobGroup.getTemplate().getId() + " (" + mobGroup.getStatus() + ")");
  547. }
  548. activeChar.sendPacket(SystemMessageId.FRIEND_LIST_FOOTER);
  549. }
  550. @Override
  551. public String[] getAdminCommandList()
  552. {
  553. return ADMIN_COMMANDS;
  554. }
  555. }