123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633 |
- /*
- * Copyright (C) 2004-2015 L2J DataPack
- *
- * This file is part of L2J DataPack.
- *
- * L2J DataPack is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J DataPack is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package handlers.admincommandhandlers;
- import com.l2jserver.gameserver.data.xml.impl.NpcData;
- import com.l2jserver.gameserver.handler.IAdminCommandHandler;
- import com.l2jserver.gameserver.model.L2World;
- import com.l2jserver.gameserver.model.MobGroup;
- import com.l2jserver.gameserver.model.MobGroupTable;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
- import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
- import com.l2jserver.gameserver.util.Broadcast;
- /**
- * @author littlecrow Admin commands handler for controllable mobs
- */
- public class AdminMobGroup implements IAdminCommandHandler
- {
- private static final String[] ADMIN_COMMANDS =
- {
- "admin_mobmenu",
- "admin_mobgroup_list",
- "admin_mobgroup_create",
- "admin_mobgroup_remove",
- "admin_mobgroup_delete",
- "admin_mobgroup_spawn",
- "admin_mobgroup_unspawn",
- "admin_mobgroup_kill",
- "admin_mobgroup_idle",
- "admin_mobgroup_attack",
- "admin_mobgroup_rnd",
- "admin_mobgroup_return",
- "admin_mobgroup_follow",
- "admin_mobgroup_casting",
- "admin_mobgroup_nomove",
- "admin_mobgroup_attackgrp",
- "admin_mobgroup_invul"
- };
-
- @Override
- public boolean useAdminCommand(String command, L2PcInstance activeChar)
- {
- if (command.equals("admin_mobmenu"))
- {
- showMainPage(activeChar, command);
- return true;
- }
- else if (command.equals("admin_mobgroup_list"))
- {
- showGroupList(activeChar);
- }
- else if (command.startsWith("admin_mobgroup_create"))
- {
- createGroup(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_delete") || command.startsWith("admin_mobgroup_remove"))
- {
- removeGroup(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_spawn"))
- {
- spawnGroup(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_unspawn"))
- {
- unspawnGroup(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_kill"))
- {
- killGroup(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_attackgrp"))
- {
- attackGrp(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_attack"))
- {
- if (activeChar.getTarget() instanceof L2Character)
- {
- L2Character target = (L2Character) activeChar.getTarget();
- attack(command, activeChar, target);
- }
- }
- else if (command.startsWith("admin_mobgroup_rnd"))
- {
- setNormal(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_idle"))
- {
- idle(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_return"))
- {
- returnToChar(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_follow"))
- {
- follow(command, activeChar, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_casting"))
- {
- setCasting(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_nomove"))
- {
- noMove(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_invul"))
- {
- invul(command, activeChar);
- }
- else if (command.startsWith("admin_mobgroup_teleport"))
- {
- teleportGroup(command, activeChar);
- }
- showMainPage(activeChar, command);
- return true;
- }
-
- /**
- * @param activeChar
- * @param command
- */
- private void showMainPage(L2PcInstance activeChar, String command)
- {
- String filename = "mobgroup.htm";
- AdminHtml.showAdminHtml(activeChar, filename);
- }
-
- private void returnToChar(String command, L2PcInstance activeChar)
- {
- int groupId;
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Incorrect command arguments.");
- return;
- }
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
- group.returnGroup(activeChar);
- }
-
- private void idle(String command, L2PcInstance activeChar)
- {
- int groupId;
-
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Incorrect command arguments.");
- return;
- }
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
- group.setIdleMode();
- }
-
- private void setNormal(String command, L2PcInstance activeChar)
- {
- int groupId;
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Incorrect command arguments.");
- return;
- }
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
- group.setAttackRandom();
- }
-
- private void attack(String command, L2PcInstance activeChar, L2Character target)
- {
- int groupId;
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Incorrect command arguments.");
- return;
- }
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
- group.setAttackTarget(target);
- }
-
- private void follow(String command, L2PcInstance activeChar, L2Character target)
- {
- int groupId;
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Incorrect command arguments.");
- return;
- }
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
- group.setFollowMode(target);
- }
-
- private void createGroup(String command, L2PcInstance activeChar)
- {
- int groupId;
- int templateId;
- int mobCount;
-
- try
- {
- String[] cmdParams = command.split(" ");
-
- groupId = Integer.parseInt(cmdParams[1]);
- templateId = Integer.parseInt(cmdParams[2]);
- mobCount = Integer.parseInt(cmdParams[3]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_create <group> <npcid> <count>");
- return;
- }
-
- if (MobGroupTable.getInstance().getGroup(groupId) != null)
- {
- activeChar.sendMessage("Mob group " + groupId + " already exists.");
- return;
- }
-
- L2NpcTemplate template = NpcData.getInstance().getTemplate(templateId);
-
- if (template == null)
- {
- activeChar.sendMessage("Invalid NPC ID specified.");
- return;
- }
-
- MobGroup group = new MobGroup(groupId, template, mobCount);
- MobGroupTable.getInstance().addGroup(groupId, group);
-
- activeChar.sendMessage("Mob group " + groupId + " created.");
- }
-
- private void removeGroup(String command, L2PcInstance activeChar)
- {
- int groupId;
-
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_remove <groupId>");
- return;
- }
-
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
-
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
-
- doAnimation(activeChar);
- group.unspawnGroup();
-
- if (MobGroupTable.getInstance().removeGroup(groupId))
- {
- activeChar.sendMessage("Mob group " + groupId + " unspawned and removed.");
- }
- }
-
- private void spawnGroup(String command, L2PcInstance activeChar)
- {
- int groupId;
- boolean topos = false;
- int posx = 0;
- int posy = 0;
- int posz = 0;
-
- try
- {
- String[] cmdParams = command.split(" ");
- groupId = Integer.parseInt(cmdParams[1]);
-
- try
- { // we try to get a position
- posx = Integer.parseInt(cmdParams[2]);
- posy = Integer.parseInt(cmdParams[3]);
- posz = Integer.parseInt(cmdParams[4]);
- topos = true;
- }
- catch (Exception e)
- {
- // no position given
- }
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_spawn <group> [ x y z ]");
- return;
- }
-
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
-
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
-
- doAnimation(activeChar);
-
- if (topos)
- {
- group.spawnGroup(posx, posy, posz);
- }
- else
- {
- group.spawnGroup(activeChar);
- }
-
- activeChar.sendMessage("Mob group " + groupId + " spawned.");
- }
-
- private void unspawnGroup(String command, L2PcInstance activeChar)
- {
- int groupId;
-
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_unspawn <groupId>");
- return;
- }
-
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
-
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
-
- doAnimation(activeChar);
- group.unspawnGroup();
-
- activeChar.sendMessage("Mob group " + groupId + " unspawned.");
- }
-
- private void killGroup(String command, L2PcInstance activeChar)
- {
- int groupId;
-
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_kill <groupId>");
- return;
- }
-
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
-
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
-
- doAnimation(activeChar);
- group.killGroup(activeChar);
- }
-
- private void setCasting(String command, L2PcInstance activeChar)
- {
- int groupId;
-
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_casting <groupId>");
- return;
- }
-
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
-
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
-
- group.setCastMode();
- }
-
- private void noMove(String command, L2PcInstance activeChar)
- {
- int groupId;
- String enabled;
-
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- enabled = command.split(" ")[2];
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_nomove <groupId> <on|off>");
- return;
- }
-
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
-
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
-
- if (enabled.equalsIgnoreCase("on") || enabled.equalsIgnoreCase("true"))
- {
- group.setNoMoveMode(true);
- }
- else if (enabled.equalsIgnoreCase("off") || enabled.equalsIgnoreCase("false"))
- {
- group.setNoMoveMode(false);
- }
- else
- {
- activeChar.sendMessage("Incorrect command arguments.");
- }
- }
-
- private void doAnimation(L2PcInstance activeChar)
- {
- Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, 1008, 1, 4000, 0), 1500);
- activeChar.sendPacket(new SetupGauge(0, 4000));
- }
-
- private void attackGrp(String command, L2PcInstance activeChar)
- {
- int groupId;
- int othGroupId;
-
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- othGroupId = Integer.parseInt(command.split(" ")[2]);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_attackgrp <groupId> <TargetGroupId>");
- return;
- }
-
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
-
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
-
- MobGroup othGroup = MobGroupTable.getInstance().getGroup(othGroupId);
-
- if (othGroup == null)
- {
- activeChar.sendMessage("Incorrect target group.");
- return;
- }
-
- group.setAttackGroup(othGroup);
- }
-
- private void invul(String command, L2PcInstance activeChar)
- {
- int groupId;
- String enabled;
-
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- enabled = command.split(" ")[2];
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_invul <groupId> <on|off>");
- return;
- }
-
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
-
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
-
- if (enabled.equalsIgnoreCase("on") || enabled.equalsIgnoreCase("true"))
- {
- group.setInvul(true);
- }
- else if (enabled.equalsIgnoreCase("off") || enabled.equalsIgnoreCase("false"))
- {
- group.setInvul(false);
- }
- else
- {
- activeChar.sendMessage("Incorrect command arguments.");
- }
- }
-
- private void teleportGroup(String command, L2PcInstance activeChar)
- {
- int groupId;
- String targetPlayerStr = null;
- L2PcInstance targetPlayer = null;
-
- try
- {
- groupId = Integer.parseInt(command.split(" ")[1]);
- targetPlayerStr = command.split(" ")[2];
-
- if (targetPlayerStr != null)
- {
- targetPlayer = L2World.getInstance().getPlayer(targetPlayerStr);
- }
-
- if (targetPlayer == null)
- {
- targetPlayer = activeChar;
- }
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //mobgroup_teleport <groupId> [playerName]");
- return;
- }
-
- MobGroup group = MobGroupTable.getInstance().getGroup(groupId);
-
- if (group == null)
- {
- activeChar.sendMessage("Invalid group specified.");
- return;
- }
-
- group.teleportGroup(activeChar);
- }
-
- private void showGroupList(L2PcInstance activeChar)
- {
- MobGroup[] mobGroupList = MobGroupTable.getInstance().getGroups();
-
- activeChar.sendMessage("======= <Mob Groups> =======");
-
- for (MobGroup mobGroup : mobGroupList)
- {
- activeChar.sendMessage(mobGroup.getGroupId() + ": " + mobGroup.getActiveMobCount() + " alive out of " + mobGroup.getMaxMobCount() + " of NPC ID " + mobGroup.getTemplate().getId() + " (" + mobGroup.getStatus() + ")");
- }
-
- activeChar.sendPacket(SystemMessageId.FRIEND_LIST_FOOTER);
- }
-
- @Override
- public String[] getAdminCommandList()
- {
- return ADMIN_COMMANDS;
- }
- }
|