mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 09:44:45 +01:00
Core/RBAC: Move pet commands to RBAC (using individual permissions)
- Pet commands moved from cs_misc.cpp to own file
This commit is contained in:
@@ -44,13 +44,6 @@ public:
|
||||
|
||||
ChatCommand* GetCommands() const OVERRIDE
|
||||
{
|
||||
static ChatCommand petCommandTable[] =
|
||||
{
|
||||
{ "create", RBAC_PERM_GAMEMASTER_COMMANDS, false, &HandleCreatePetCommand, "", NULL },
|
||||
{ "learn", RBAC_PERM_GAMEMASTER_COMMANDS, false, &HandlePetLearnCommand, "", NULL },
|
||||
{ "unlearn", RBAC_PERM_GAMEMASTER_COMMANDS, false, &HandlePetUnlearnCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand sendCommandTable[] =
|
||||
{
|
||||
{ "items", RBAC_PERM_ADMINISTRATOR_COMMANDS, true, &HandleSendItemsCommand, "", NULL },
|
||||
@@ -94,7 +87,6 @@ public:
|
||||
{ "pinfo", RBAC_PERM_GAMEMASTER_COMMANDS, true, &HandlePInfoCommand, "", NULL },
|
||||
{ "respawn", RBAC_PERM_ADMINISTRATOR_COMMANDS, false, &HandleRespawnCommand, "", NULL },
|
||||
{ "send", RBAC_PERM_MODERATOR_COMMANDS, true, NULL, "", sendCommandTable },
|
||||
{ "pet", RBAC_PERM_GAMEMASTER_COMMANDS, false, NULL, "", petCommandTable },
|
||||
{ "mute", RBAC_PERM_MODERATOR_COMMANDS, true, &HandleMuteCommand, "", NULL },
|
||||
{ "unmute", RBAC_PERM_MODERATOR_COMMANDS, true, &HandleUnmuteCommand, "", NULL },
|
||||
{ "movegens", RBAC_PERM_ADMINISTRATOR_COMMANDS, false, &HandleMovegensCommand, "", NULL },
|
||||
@@ -2491,145 +2483,6 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleCreatePetCommand(ChatHandler* handler, char const* /*args*/)
|
||||
{
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
Creature* creatureTarget = handler->getSelectedCreature();
|
||||
|
||||
if (!creatureTarget || creatureTarget->IsPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_SELECT_CREATURE);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
CreatureTemplate const* creatrueTemplate = sObjectMgr->GetCreatureTemplate(creatureTarget->GetEntry());
|
||||
// Creatures with family 0 crashes the server
|
||||
if (!creatrueTemplate->family)
|
||||
{
|
||||
handler->PSendSysMessage("This creature cannot be tamed. (family id: 0).");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player->GetPetGUID())
|
||||
{
|
||||
handler->PSendSysMessage("You already have a pet");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Everything looks OK, create new pet
|
||||
Pet* pet = new Pet(player, HUNTER_PET);
|
||||
if (!pet->CreateBaseAtCreature(creatureTarget))
|
||||
{
|
||||
delete pet;
|
||||
handler->PSendSysMessage("Error 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
creatureTarget->setDeathState(JUST_DIED);
|
||||
creatureTarget->RemoveCorpse();
|
||||
creatureTarget->SetHealth(0); // just for nice GM-mode view
|
||||
|
||||
pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, player->GetGUID());
|
||||
pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, player->getFaction());
|
||||
|
||||
if (!pet->InitStatsForLevel(creatureTarget->getLevel()))
|
||||
{
|
||||
TC_LOG_ERROR(LOG_FILTER_GENERAL, "InitStatsForLevel() in EffectTameCreature failed! Pet deleted.");
|
||||
handler->PSendSysMessage("Error 2");
|
||||
delete pet;
|
||||
return false;
|
||||
}
|
||||
|
||||
// prepare visual effect for levelup
|
||||
pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel()-1);
|
||||
|
||||
pet->GetCharmInfo()->SetPetNumber(sObjectMgr->GeneratePetNumber(), true);
|
||||
// this enables pet details window (Shift+P)
|
||||
pet->InitPetCreateSpells();
|
||||
pet->SetFullHealth();
|
||||
|
||||
pet->GetMap()->AddToMap(pet->ToCreature());
|
||||
|
||||
// visual effect for levelup
|
||||
pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel());
|
||||
|
||||
player->SetMinion(pet, true);
|
||||
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
|
||||
player->PetSpellInitialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePetLearnCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
Pet* pet = player->GetPet();
|
||||
|
||||
if (!pet)
|
||||
{
|
||||
handler->PSendSysMessage("You have no pet");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
|
||||
|
||||
if (!spellId || !sSpellMgr->GetSpellInfo(spellId))
|
||||
return false;
|
||||
|
||||
// Check if pet already has it
|
||||
if (pet->HasSpell(spellId))
|
||||
{
|
||||
handler->PSendSysMessage("Pet already has spell: %u", spellId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if spell is valid
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||
if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
pet->learnSpell(spellId);
|
||||
|
||||
handler->PSendSysMessage("Pet has learned spell %u", spellId);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePetUnlearnCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
Pet* pet = player->GetPet();
|
||||
if (!pet)
|
||||
{
|
||||
handler->PSendSysMessage("You have no pet");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
|
||||
|
||||
if (pet->HasSpell(spellId))
|
||||
pet->removeSpell(spellId, false);
|
||||
else
|
||||
handler->PSendSysMessage("Pet doesn't have that spell");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleFreezeCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
std::string name;
|
||||
|
||||
190
src/server/scripts/Commands/cs_pet.cpp
Normal file
190
src/server/scripts/Commands/cs_pet.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "Chat.h"
|
||||
#include "Language.h"
|
||||
#include "Pet.h"
|
||||
#include "Player.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "ScriptMgr.h"
|
||||
|
||||
class pet_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
pet_commandscript() : CommandScript("pet_commandscript") { }
|
||||
|
||||
ChatCommand* GetCommands() const OVERRIDE
|
||||
{
|
||||
static ChatCommand petCommandTable[] =
|
||||
{
|
||||
{ "create", RBAC_PERM_COMMAND_PET_CREATE, false, &HandlePetCreateCommand, "", NULL },
|
||||
{ "learn", RBAC_PERM_COMMAND_PET_LEARN, false, &HandlePetLearnCommand, "", NULL },
|
||||
{ "unlearn", RBAC_PERM_COMMAND_PET_UNLEARN, false, &HandlePetUnlearnCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "pet", RBAC_PERM_COMMAND_PET, false, NULL, "", petCommandTable },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
static bool HandlePetCreateCommand(ChatHandler* handler, char const* /*args*/)
|
||||
{
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
Creature* creatureTarget = handler->getSelectedCreature();
|
||||
|
||||
if (!creatureTarget || creatureTarget->IsPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_SELECT_CREATURE);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
CreatureTemplate const* creatrueTemplate = sObjectMgr->GetCreatureTemplate(creatureTarget->GetEntry());
|
||||
// Creatures with family 0 crashes the server
|
||||
if (!creatrueTemplate->family)
|
||||
{
|
||||
handler->PSendSysMessage("This creature cannot be tamed. (family id: 0).");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player->GetPetGUID())
|
||||
{
|
||||
handler->PSendSysMessage("You already have a pet");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Everything looks OK, create new pet
|
||||
Pet* pet = new Pet(player, HUNTER_PET);
|
||||
if (!pet->CreateBaseAtCreature(creatureTarget))
|
||||
{
|
||||
delete pet;
|
||||
handler->PSendSysMessage("Error 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
creatureTarget->setDeathState(JUST_DIED);
|
||||
creatureTarget->RemoveCorpse();
|
||||
creatureTarget->SetHealth(0); // just for nice GM-mode view
|
||||
|
||||
pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, player->GetGUID());
|
||||
pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, player->getFaction());
|
||||
|
||||
if (!pet->InitStatsForLevel(creatureTarget->getLevel()))
|
||||
{
|
||||
TC_LOG_ERROR(LOG_FILTER_GENERAL, "InitStatsForLevel() in EffectTameCreature failed! Pet deleted.");
|
||||
handler->PSendSysMessage("Error 2");
|
||||
delete pet;
|
||||
return false;
|
||||
}
|
||||
|
||||
// prepare visual effect for levelup
|
||||
pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel()-1);
|
||||
|
||||
pet->GetCharmInfo()->SetPetNumber(sObjectMgr->GeneratePetNumber(), true);
|
||||
// this enables pet details window (Shift+P)
|
||||
pet->InitPetCreateSpells();
|
||||
pet->SetFullHealth();
|
||||
|
||||
pet->GetMap()->AddToMap(pet->ToCreature());
|
||||
|
||||
// visual effect for levelup
|
||||
pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel());
|
||||
|
||||
player->SetMinion(pet, true);
|
||||
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
|
||||
player->PetSpellInitialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePetLearnCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
Pet* pet = player->GetPet();
|
||||
|
||||
if (!pet)
|
||||
{
|
||||
handler->PSendSysMessage("You have no pet");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
|
||||
|
||||
if (!spellId || !sSpellMgr->GetSpellInfo(spellId))
|
||||
return false;
|
||||
|
||||
// Check if pet already has it
|
||||
if (pet->HasSpell(spellId))
|
||||
{
|
||||
handler->PSendSysMessage("Pet already has spell: %u", spellId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if spell is valid
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||
if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
pet->learnSpell(spellId);
|
||||
|
||||
handler->PSendSysMessage("Pet has learned spell %u", spellId);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePetUnlearnCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
Pet* pet = player->GetPet();
|
||||
if (!pet)
|
||||
{
|
||||
handler->PSendSysMessage("You have no pet");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
|
||||
|
||||
if (pet->HasSpell(spellId))
|
||||
pet->removeSpell(spellId, false);
|
||||
else
|
||||
handler->PSendSysMessage("Pet doesn't have that spell");
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_pet_commandscript()
|
||||
{
|
||||
new pet_commandscript();
|
||||
}
|
||||
Reference in New Issue
Block a user