/*
* The ManaPlus Client
* Copyright (C) 2012-2014 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
* This program 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 2 of the License, or
* any later version.
*
* This program 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/>.
*/
#include "actions/commands.h"
#include "actormanager.h"
#include "configuration.h"
#include "dropshortcut.h"
#include "emoteshortcut.h"
#include "game.h"
#include "itemshortcut.h"
#include "soundmanager.h"
#include "actions/actiondef.h"
#include "being/attributes.h"
#include "being/localplayer.h"
#include "being/playerinfo.h"
#include "being/playerrelations.h"
#include "gui/dialogsmanager.h"
#include "gui/gui.h"
#include "gui/popupmanager.h"
#include "gui/sdlinput.h"
#include "gui/viewport.h"
#include "gui/popups/popupmenu.h"
#include "gui/windows/skilldialog.h"
#include "gui/windows/socialwindow.h"
#include "gui/windows/statuswindow.h"
#include "gui/windows/tradewindow.h"
#include "gui/windows/questswindow.h"
#include "gui/windows/quitdialog.h"
#include "gui/windows/whoisonline.h"
#include "gui/windows/botcheckerwindow.h"
#include "gui/windows/buyselldialog.h"
#include "gui/windows/chatwindow.h"
#include "gui/windows/debugwindow.h"
#include "gui/windows/didyouknowwindow.h"
#include "gui/windows/equipmentwindow.h"
#include "gui/windows/helpwindow.h"
#include "gui/windows/inventorywindow.h"
#include "gui/windows/killstats.h"
#include "gui/windows/minimap.h"
#include "gui/windows/npcdialog.h"
#include "gui/windows/outfitwindow.h"
#include "gui/windows/setupwindow.h"
#include "gui/windows/shopwindow.h"
#include "gui/windows/shortcutwindow.h"
#include "gui/windows/updaterwindow.h"
#include "gui/widgets/tabs/whispertab.h"
#include "net/adminhandler.h"
#include "net/pethandler.h"
#include "net/net.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
#include "debug.h"
namespace Actions
{
static std::string getNick(const InputEvent &event)
{
std::string args = event.args;
if (args.empty())
{
WhisperTab *const whisper = dynamic_cast<WhisperTab* const>(event.tab);
if (!whisper || whisper->getNick().empty())
{
// TRANSLATORS: change relation
event.tab->chatLog(_("Please specify a name."), ChatMsgType::BY_SERVER);
return std::string();
}
args = whisper->getNick();
}
return args;
}
static void reportRelation(const InputEvent &event,
const PlayerRelation::Relation &rel,
const std::string &str1,
const std::string &str2)
{
if (event.tab)
{
if (player_relations.getRelation(event.args) == rel)
{
// TRANSLATORS: unignore command
event.tab->chatLog(str1, ChatMsgType::BY_SERVER);
}
else
{
// TRANSLATORS: unignore command
event.tab->chatLog(str2, ChatMsgType::BY_SERVER);
}
}
}
static void changeRelation(const InputEvent &event,
const PlayerRelation::Relation relation,
const std::string &relationText)
{
if (!event.tab)
return;
std::string args = getNick(event);
if (args.empty())
return;
if (player_relations.getRelation(args) == relation)
{
// TRANSLATORS: change relation
event.tab->chatLog(strprintf(_("Player already %s!"),
relationText.c_str()), ChatMsgType::BY_SERVER);
return;
}
else
{
player_relations.setRelation(args, relation);
}
reportRelation(event,
relation,
// TRANSLATORS: change relation
strprintf(_("Player successfully %s!"), relationText.c_str()),
// TRANSLATORS: change relation
strprintf(_("Player could not be %s!"), relationText.c_str()));
}
impHandler(chatAnnounce)
{
Net::getAdminHandler()->announce(event.args);
return true;
}
impHandler(chatIgnore)
{
changeRelation(event, PlayerRelation::IGNORED, "ignored");
return true;
}
impHandler(chatUnignore)
{
std::string args = getNick(event);
if (args.empty())
return false;
const PlayerRelation::Relation rel = player_relations.getRelation(args);
if (rel != PlayerRelation::NEUTRAL && rel != PlayerRelation::FRIEND)
{
player_relations.setRelation(args, PlayerRelation::NEUTRAL);
}
else
{
if (event.tab)
{
// TRANSLATORS: unignore command
event.tab->chatLog(_("Player wasn't ignored!"), ChatMsgType::BY_SERVER);
}
return true;
}
reportRelation(event,
PlayerRelation::NEUTRAL,
// TRANSLATORS: unignore command
_("Player no longer ignored!"),
// TRANSLATORS: unignore command
_("Player could not be unignored!"));
return true;
}
impHandler(chatErase)
{
std::string args = getNick(event);
if (args.empty())
return false;
if (player_relations.getRelation(args) == PlayerRelation::ERASED)
{
if (event.tab)
{
// TRANSLATORS: erase command
event.tab->chatLog(_("Player already erased!"), ChatMsgType::BY_SERVER);
}
return true;
}
else
{
player_relations.setRelation(args, PlayerRelation::ERASED);
}
reportRelation(event,
PlayerRelation::ERASED,
// TRANSLATORS: erase command
_("Player no longer erased!"),
// TRANSLATORS: erase command
_("Player could not be erased!"));
return true;
}
impHandler(chatFriend)
{
// TRANSLATORS: adding friend command
changeRelation(event, PlayerRelation::FRIEND, _("friend"));
return true;
}
impHandler(chatDisregard)
{
// TRANSLATORS: disregard command
changeRelation(event, PlayerRelation::DISREGARDED, _("disregarded"));
return true;
}
impHandler(chatNeutral)
{
// TRANSLATORS: neutral command
changeRelation(event, PlayerRelation::NEUTRAL, _("neutral"));
return true;
}
impHandler(chatBlackList)
{
// TRANSLATORS: blacklist command
changeRelation(event, PlayerRelation::BLACKLISTED, _("blacklisted"));
return true;
}
impHandler(chatEnemy)
{
// TRANSLATORS: enemy command
changeRelation(event, PlayerRelation::ENEMY2, _("enemy"));
return true;
}
impHandler0(present)
{
if (chatWindow)
{
chatWindow->doPresent();
return true;
}
return false;
}
impHandler0(printAll)
{
if (actorManager)
{
actorManager->printAllToChat();
return true;
}
return false;
}
impHandler(move)
{
int x = 0;
int y = 0;
if (localPlayer && parse2Int(event.args, x, y))
{
localPlayer->setDestination(x, y);
return true;
}
return false;
}
impHandler(setTarget)
{
if (!actorManager || !localPlayer)
return false;
Being *const target = actorManager->findNearestByName(event.args);
if (target)
localPlayer->setTarget(target);
return true;
}
impHandler(commandOutfit)
{
if (outfitWindow)
{
if (!event.args.empty())
{
const std::string op = event.args.substr(0, 1);
if (op == "n")
{
outfitWindow->wearNextOutfit(true);
}
else if (op == "p")
{
outfitWindow->wearPreviousOutfit(true);
}
else
{
outfitWindow->wearOutfit(atoi(event.args.c_str()) - 1,
false, true);
}
}
else
{
outfitWindow->wearOutfit(atoi(event.args.c_str()) - 1,
false, true);
}
return true;
}
return false;
}
impHandler(commandEmote)
{
if (localPlayer)
{
localPlayer->emote(static_cast<uint8_t>(atoi(event.args.c_str())));
return true;
}
return false;
}
impHandler(commandEmotePet)
{
// need use actual pet id
Net::getPetHandler()->emote(static_cast<uint8_t>(
atoi(event.args.c_str())), 0);
return true;
}
impHandler(awayMessage)
{
if (localPlayer)
{
localPlayer->setAway(event.args);
return true;
}
return false;
}
impHandler(pseudoAway)
{
if (localPlayer)
{
localPlayer->setPseudoAway(event.args);
localPlayer->updateStatus();
return true;
}
return false;
}
impHandler(follow)
{
if (!localPlayer)
return false;
if (!features.getBoolValue("allowFollow"))
return false;
if (!event.args.empty())
{
localPlayer->setFollow(event.args);
}
else if (event.tab && event.tab->getType() == ChatTabType::WHISPER)
{
localPlayer->setFollow(static_cast<WhisperTab*>(event.tab)->getNick());
}
else
{
const Being *const being = localPlayer->getTarget();
if (being != nullptr)
localPlayer->setFollow(being->getName());
}
return true;
}
impHandler(navigate)
{
if (!localPlayer)
return false;
int x = 0;
int y = 0;
if (parse2Int(event.args, x, y))
localPlayer->navigateTo(x, y);
else
localPlayer->navigateClean();
return true;
}
} // namespace Actions