Merge pull request #9388 from thomas007788/DeserterCmd

Implement .deserter commands
This commit is contained in:
Nay
2013-03-09 09:45:43 -08:00
4 changed files with 211 additions and 0 deletions
@@ -0,0 +1,11 @@
DELETE FROM `command` WHERE `name` IN
("deserter instance add",
"deserter instance remove",
"deserter bg add",
"deserter bg remove");
INSERT INTO `command` (`name`, `security`, `help`) VALUES
("deserter instance add", 3, "Syntax: .deserter instance add $time \n\n Adds the instance deserter debuff to your target with $time duration."),
("deserter instance remove", 3, "Syntax: .deserter instance remove \n\n Removes the instance deserter debuff from your target."),
("deserter bg add", 3, "Syntax: .deserter bg add $time \n\n Adds the bg deserter debuff to your target with $time duration."),
("deserter bg remove", 3, "Syntax: .deserter bg remove \n\n Removes the bg deserter debuff from your target.");
@@ -52,6 +52,7 @@ void AddSC_cast_commandscript();
void AddSC_character_commandscript();
void AddSC_cheat_commandscript();
void AddSC_debug_commandscript();
void AddSC_deserter_commandscript();
void AddSC_disable_commandscript();
void AddSC_event_commandscript();
void AddSC_gm_commandscript();
@@ -683,6 +684,7 @@ void AddCommandScripts()
AddSC_character_commandscript();
AddSC_cheat_commandscript();
AddSC_debug_commandscript();
AddSC_deserter_commandscript();
AddSC_disable_commandscript();
AddSC_event_commandscript();
AddSC_gm_commandscript();
@@ -18,6 +18,7 @@ set(scripts_STAT_SRCS
Commands/cs_character.cpp
Commands/cs_cheat.cpp
Commands/cs_debug.cpp
Commands/cs_deserter.cpp
Commands/cs_disable.cpp
Commands/cs_event.cpp
Commands/cs_gm.cpp
+197
View File
@@ -0,0 +1,197 @@
/*
* Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
*
* 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 (at your
* option) 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/>.
*/
/**
* @file cs_deserter.cpp
* @brief .deserter related commands
*
* This file contains the CommandScripts for all deserter sub-commands
*/
#include "Chat.h"
#include "Player.h"
#include "Language.h"
enum Spells
{
LFG_SPELL_DUNGEON_DESERTER = 71041,
BG_SPELL_DESERTER = 26013
};
class deserter_commandscript : public CommandScript
{
public:
deserter_commandscript() : CommandScript("deserter_commandscript") { }
/**
* @brief Returns the command structure for the system.
*/
ChatCommand* GetCommands() const
{
static ChatCommand deserterInstanceCommandTable[] =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleDeserterInstanceAdd, "", NULL },
{ "remove", SEC_ADMINISTRATOR, false, &HandleDeserterInstanceRemove, "", NULL },
{ NULL, SEC_PLAYER, false, NULL, "", NULL }
};
static ChatCommand deserterBGCommandTable[] =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleDeserterBGAdd, "", NULL },
{ "remove", SEC_ADMINISTRATOR, false, &HandleDeserterBGRemove, "", NULL },
{ NULL, SEC_PLAYER, false, NULL, "", NULL }
};
static ChatCommand deserterCommandTable[] =
{
{ "instance", SEC_ADMINISTRATOR, false, NULL, "", deserterInstanceCommandTable },
{ "bg", SEC_ADMINISTRATOR, false, NULL, "", deserterBGCommandTable },
{ NULL, SEC_PLAYER, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "deserter", SEC_ADMINISTRATOR, false, NULL, "", deserterCommandTable },
{ NULL, SEC_PLAYER, false, NULL, "", NULL }
};
return commandTable;
}
/**
* @brief Applies the Deserter Debuff to a player
*
* This function applies a Deserter Debuff of the given type (Instance or BG) to the
* selected player, with the provided duration in seconds.
*
* @param handler The ChatHandler, passed by the system.
* @param args The provided duration in seconds.
* @param isInstance provided by the relaying functions, so we don't have
* to write that much code :)
*
* @return true if everything was correct, false if an error occured.
*
* Example Usage:
* @code
* .deserter instance add 3600 (one hour)
* -or-
* .deserter bg add 3600 (one hour)
* @endcode
*/
static bool HandleDeserterAdd(ChatHandler* handler, char const* args, bool isInstance)
{
if (!*args)
return false;
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
char* timeStr = strtok((char*)args, " ");
if (!timeStr)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
uint32 time = atoi(timeStr);
if (!time)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
Aura* aura = player->AddAura(isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER, player);
if (!aura)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
aura->SetDuration(time * IN_MILLISECONDS);
return true;
}
/**
* @brief Removes the Deserter Debuff from a player
*
* This function removes a Deserter Debuff of the given type (Instance or BG) from the
* selected player.
*
* @param handler The ChatHandler, passed by the system.
* @param args Should be nothing.
* @param isInstance provided by the relaying functions, so we don't have
* to write that much code :)
*
* @return true if everything was correct, false if an error occured.
*
* Example Usage:
* @code
* .deserter instance remove
* -or-
* .deserter bg remove
* @endcode
*/
static bool HandleDeserterRemove(ChatHandler* handler, char const* args, bool isInstance)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
player->RemoveAura(isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER);
return true;
}
/// @sa HandleDeserterAdd()
static bool HandleDeserterInstanceAdd(ChatHandler* handler, char const* args)
{
return HandleDeserterAdd(handler, args, true);
}
/// @sa HandleDeserterAdd()
static bool HandleDeserterBGAdd(ChatHandler* handler, char const* args)
{
return HandleDeserterAdd(handler, args, false);
}
/// @sa HandleDeserterRemove()
static bool HandleDeserterInstanceRemove(ChatHandler* handler, char const* args)
{
return HandleDeserterRemove(handler, args, true);
}
/// @sa HandleDeserterRemove()
static bool HandleDeserterBGRemove(ChatHandler* handler, char const* args)
{
return HandleDeserterRemove(handler, args, false);
}
};
void AddSC_deserter_commandscript()
{
new deserter_commandscript();
}