From aae83576cfd4f1292e2d382a3a4273643749f261 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Wed, 25 Oct 2023 15:53:34 +0200 Subject: [PATCH] Scripts/Commands: dropped now deprecated cs_pet command file as it's meddling with the integrity of pets which should never be allowed in the first place --- src/server/game/Accounts/RBAC.h | 10 +- src/server/scripts/Commands/cs_npc.cpp | 14 +- src/server/scripts/Commands/cs_pet.cpp | 228 ------------------------- 3 files changed, 13 insertions(+), 239 deletions(-) delete mode 100644 src/server/scripts/Commands/cs_pet.cpp diff --git a/src/server/game/Accounts/RBAC.h b/src/server/game/Accounts/RBAC.h index 99d3a56d301..b6ed02c4035 100644 --- a/src/server/game/Accounts/RBAC.h +++ b/src/server/game/Accounts/RBAC.h @@ -376,10 +376,10 @@ enum RBACPermissions RBAC_PERM_COMMAND_GROUP_JOIN = 476, RBAC_PERM_COMMAND_GROUP_LIST = 477, RBAC_PERM_COMMAND_GROUP_SUMMON = 478, - RBAC_PERM_COMMAND_PET = 479, - RBAC_PERM_COMMAND_PET_CREATE = 480, - RBAC_PERM_COMMAND_PET_LEARN = 481, - RBAC_PERM_COMMAND_PET_UNLEARN = 482, + RBAC_PERM_COMMAND_PET = 479, // DEPRECATED: DON'T REUSE + RBAC_PERM_COMMAND_PET_CREATE = 480, // DEPRECATED: DON'T REUSE + RBAC_PERM_COMMAND_PET_LEARN = 481, // DEPRECATED: DON'T REUSE + RBAC_PERM_COMMAND_PET_UNLEARN = 482, // DEPRECATED: DON'T REUSE RBAC_PERM_COMMAND_SEND = 483, RBAC_PERM_COMMAND_SEND_ITEMS = 484, RBAC_PERM_COMMAND_SEND_MAIL = 485, @@ -735,7 +735,7 @@ enum RBACPermissions RBAC_PERM_COMMAND_DEBUG_LOADCELLS = 835, RBAC_PERM_COMMAND_DEBUG_BOUNDARY = 836, RBAC_PERM_COMMAND_NPC_EVADE = 837, - RBAC_PERM_COMMAND_PET_LEVEL = 838, + RBAC_PERM_COMMAND_PET_LEVEL = 838, // DEPRECATED: DON'T REUSE RBAC_PERM_COMMAND_SERVER_SHUTDOWN_FORCE = 839, RBAC_PERM_COMMAND_SERVER_RESTART_FORCE = 840, RBAC_PERM_COMMAND_NEARGRAVEYARD = 841, diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index fe664272387..46c7b850f74 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -1478,8 +1478,8 @@ class npc_commandscript : public CommandScript Creature* creatureTarget = handler->getSelectedCreature(); if (!creatureTarget || creatureTarget->IsPet()) { - handler->PSendSysMessage (LANG_SELECT_CREATURE); - handler->SetSentErrorMessage (true); + handler->PSendSysMessage(LANG_SELECT_CREATURE); + handler->SetSentErrorMessage(true); return false; } @@ -1489,21 +1489,23 @@ class npc_commandscript : public CommandScript if (!cInfo->IsTameable (player->CanTameExoticPets())) { - handler->PSendSysMessage (LANG_CREATURE_NON_TAMEABLE, cInfo->Entry); - handler->SetSentErrorMessage (true); + handler->PSendSysMessage(LANG_CREATURE_NON_TAMEABLE, cInfo->Entry); + handler->SetSentErrorMessage(true); return false; } Optional slot = player->GetUnusedActivePetSlot(); if (!slot.has_value()) { - handler->PSendSysMessage (LANG_CREATURE_NON_TAMEABLE, cInfo->Entry); + handler->PSendSysMessage(LANG_CREATURE_NON_TAMEABLE, cInfo->Entry); + handler->SetSentErrorMessage(true); return false; } if (!player->CreatePlayerPetData(*slot, 0, creatureTarget->GetEntry())) { - handler->PSendSysMessage (LANG_CREATURE_NON_TAMEABLE, cInfo->Entry); + handler->PSendSysMessage(LANG_CREATURE_NON_TAMEABLE, cInfo->Entry); + handler->SetSentErrorMessage(true); return false; } diff --git a/src/server/scripts/Commands/cs_pet.cpp b/src/server/scripts/Commands/cs_pet.cpp deleted file mode 100644 index 9a205b41a65..00000000000 --- a/src/server/scripts/Commands/cs_pet.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/* - * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information - * - * 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 . - */ - -#include "ScriptMgr.h" -#include "CharmInfo.h" -#include "Chat.h" -#include "Language.h" -#include "Log.h" -#include "Map.h" -#include "ObjectMgr.h" -#include "Pet.h" -#include "Player.h" -#include "RBAC.h" -#include "SpellMgr.h" -#include "WorldSession.h" - -inline Pet* GetSelectedPlayerPetOrOwn(ChatHandler* handler) -{ - if (Unit* target = handler->getSelectedUnit()) - { - if (target->GetTypeId() == TYPEID_PLAYER) - return target->ToPlayer()->GetPet(); - if (target->IsPet()) - return target->ToPet(); - return nullptr; - } - Player* player = handler->GetSession()->GetPlayer(); - return player ? player->GetPet() : nullptr; -} - -class pet_commandscript : public CommandScript -{ -public: - pet_commandscript() : CommandScript("pet_commandscript") { } - - std::vector GetCommands() const override - { - static std::vector petCommandTable = - { - { "create", rbac::RBAC_PERM_COMMAND_PET_CREATE, false, &HandlePetCreateCommand, "" }, - { "learn", rbac::RBAC_PERM_COMMAND_PET_LEARN, false, &HandlePetLearnCommand, "" }, - { "unlearn", rbac::RBAC_PERM_COMMAND_PET_UNLEARN, false, &HandlePetUnlearnCommand, "" }, - { "level", rbac::RBAC_PERM_COMMAND_PET_LEVEL, false, &HandlePetLevelCommand, "" }, - }; - - static std::vector commandTable = - { - { "pet", rbac::RBAC_PERM_COMMAND_PET, false, nullptr, "", petCommandTable }, - }; - 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* creatureTemplate = creatureTarget->GetCreatureTemplate(); - // Creatures with family CREATURE_FAMILY_NONE crashes the server - if (!creatureTemplate->family) - { - handler->PSendSysMessage("This creature cannot be tamed. Family id: 0 (CREATURE_FAMILY_NONE)."); - 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->DespawnOrUnsummon(); - creatureTarget->SetHealth(0); // just for nice GM-mode view - - pet->SetGuidValue(UNIT_FIELD_CREATEDBY, player->GetGUID()); - pet->SetFaction(player->GetFaction()); - - if (!pet->InitStatsForLevel(creatureTarget->getLevel())) - { - TC_LOG_ERROR("misc", "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()); - - //pet->SavePetToDB(PET_SAVE_NEW_PET); - - return true; - } - - static bool HandlePetLearnCommand(ChatHandler* handler, char const* args) - { - if (!*args) - return false; - - Pet* pet = GetSelectedPlayerPetOrOwn(handler); - - if (!pet) - { - handler->SendSysMessage(LANG_SELECT_PLAYER_OR_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; - - Pet* pet = GetSelectedPlayerPetOrOwn(handler); - if (!pet) - { - handler->SendSysMessage(LANG_SELECT_PLAYER_OR_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 HandlePetLevelCommand(ChatHandler* handler, char const* args) - { - Pet* pet = GetSelectedPlayerPetOrOwn(handler); - Player* owner = pet ? pet->GetOwner() : nullptr; - if (!pet || !owner) - { - handler->SendSysMessage(LANG_SELECT_PLAYER_OR_PET); - handler->SetSentErrorMessage(true); - return false; - } - - int32 level = args ? atoi(args) : 0; - if (level == 0) - level = owner->getLevel() - pet->getLevel(); - if (level == 0 || level < -STRONG_MAX_LEVEL || level > STRONG_MAX_LEVEL) - { - handler->SendSysMessage(LANG_BAD_VALUE); - handler->SetSentErrorMessage(true); - return false; - } - - int32 newLevel = pet->getLevel() + level; - if (newLevel < 1) - newLevel = 1; - else if (newLevel > owner->getLevel()) - newLevel = owner->getLevel(); - - pet->GivePetLevel(newLevel); - return true; - } -}; - -void AddSC_pet_commandscript() -{ - new pet_commandscript(); -}