feat: make commands available for console and for player offline

This commit is contained in:
Helias
2022-05-26 17:52:42 +02:00
parent 8dfdd17975
commit 2ea7c9c8fb

View File

@@ -20,39 +20,40 @@
#include "Player.h" #include "Player.h"
#include "ScriptMgr.h" #include "ScriptMgr.h"
#include "Transmogrification.h" #include "Transmogrification.h"
#include "Log.h"
using namespace Acore::ChatCommands; using namespace Acore::ChatCommands;
class transmog_commandscript : public CommandScript class transmog_commandscript : public CommandScript
{ {
public: public:
transmog_commandscript() : CommandScript("transmog_commandscript") { } transmog_commandscript() : CommandScript("transmog_commandscript") {}
ChatCommandTable GetCommands() const override ChatCommandTable GetCommands() const override
{ {
static ChatCommandTable addCollectionTable = static ChatCommandTable addCollectionTable =
{ {
{ "set", HandleAddTransmogItemSet, SEC_MODERATOR, Console::No }, {"set", HandleAddTransmogItemSet, SEC_MODERATOR, Console::Yes},
{ "", HandleAddTransmogItem, SEC_MODERATOR, Console::No }, {"", HandleAddTransmogItem, SEC_MODERATOR, Console::Yes},
}; };
static ChatCommandTable transmogTable = static ChatCommandTable transmogTable =
{ {
{ "add", addCollectionTable }, {"add", addCollectionTable},
{ "", HandleDisableTransMogVisual, SEC_PLAYER, Console::No }, {"", HandleDisableTransMogVisual, SEC_PLAYER, Console::No},
}; };
static ChatCommandTable commandTable = static ChatCommandTable commandTable =
{ {
{ "transmog", transmogTable }, {"transmog", transmogTable},
}; };
return commandTable; return commandTable;
} }
static bool HandleDisableTransMogVisual(ChatHandler* handler, bool hide) static bool HandleDisableTransMogVisual(ChatHandler *handler, bool hide)
{ {
Player* player = handler->GetPlayer(); Player *player = handler->GetPlayer();
if (hide) if (hide)
{ {
@@ -69,7 +70,7 @@ public:
return true; return true;
} }
static bool HandleAddTransmogItem(ChatHandler* handler, Optional<PlayerIdentifier> player, ItemTemplate const* itemTemplate) static bool HandleAddTransmogItem(ChatHandler *handler, Optional<PlayerIdentifier> player, ItemTemplate const *itemTemplate)
{ {
if (!sTransmogrification->GetUseCollectionSystem()) if (!sTransmogrification->GetUseCollectionSystem())
return true; return true;
@@ -82,11 +83,16 @@ public:
} }
if (!player) if (!player)
{
player = PlayerIdentifier::FromTargetOrSelf(handler); player = PlayerIdentifier::FromTargetOrSelf(handler);
if (!player || !player->IsConnected()) }
return false;
Player* target = player->GetConnectedPlayer(); if (!player)
{
return false;
}
Player *target = player->GetConnectedPlayer();
if (!sTransmogrification->GetTrackUnusableItems() && !sTransmogrification->SuitableForTransmogrification(target, itemTemplate)) if (!sTransmogrification->GetTrackUnusableItems() && !sTransmogrification->SuitableForTransmogrification(target, itemTemplate))
{ {
@@ -103,37 +109,58 @@ public:
} }
uint32 itemId = itemTemplate->ItemId; uint32 itemId = itemTemplate->ItemId;
uint32 accountId = target->GetSession()->GetAccountId(); uint32 accountId;
auto guid = player->GetGUID().GetCounter();
if (QueryResult result = CharacterDatabase.Query("SELECT `account` FROM `characters` WHERE `guid` = {}", guid))
{
Field *fields = result->Fetch();
accountId = fields[0].Get<uint32>();
}
else
{
return false;
}
std::stringstream tempStream; std::stringstream tempStream;
tempStream << std::hex << ItemQualityColors[itemTemplate->Quality]; tempStream << std::hex << ItemQualityColors[itemTemplate->Quality];
std::string itemQuality = tempStream.str(); std::string itemQuality = tempStream.str();
std::string itemName = itemTemplate->Name1; std::string itemName = itemTemplate->Name1;
std::string nameLink = handler->playerLink(target->GetName());
bool isNotConsoleAndIsPlayerOnline = handler->GetSession() && target->GetSession();
if (sTransmogrification->AddCollectedAppearance(accountId, itemId)) if (sTransmogrification->AddCollectedAppearance(accountId, itemId))
{ {
if (isNotConsoleAndIsPlayerOnline)
if (!(target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value))
{ {
ChatHandler(target->GetSession()).PSendSysMessage(R"(|c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r has been added to your appearance collection.)", itemQuality.c_str(), itemId, itemName.c_str()); std::string nameLink = handler->playerLink(target->GetName());
}
if (target != handler->GetPlayer()) if (!(target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value))
{ {
handler->PSendSysMessage(R"(|c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r has been added to the appearance collection of Player %s.)", itemQuality.c_str(), itemId, itemName.c_str(), nameLink); ChatHandler(target->GetSession()).PSendSysMessage(R"(|c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r has been added to your appearance collection.)", itemQuality.c_str(), itemId, itemName.c_str());
}
if (target != handler->GetPlayer())
{
handler->PSendSysMessage(R"(|c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r has been added to the appearance collection of Player %s.)", itemQuality.c_str(), itemId, itemName.c_str(), nameLink);
}
} }
CharacterDatabase.Execute("INSERT INTO custom_unlocked_appearances (account_id, item_template_id) VALUES ({}, {})", accountId, itemId); CharacterDatabase.Execute("INSERT INTO custom_unlocked_appearances (account_id, item_template_id) VALUES ({}, {})", accountId, itemId);
} }
else else
{ {
handler->PSendSysMessage(R"(Player %s already has item |c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r in the appearance collection.)", nameLink, itemQuality.c_str(), itemId, itemName.c_str()); if (isNotConsoleAndIsPlayerOnline)
handler->SetSentErrorMessage(true); {
std::string nameLink = handler->playerLink(target->GetName());
handler->PSendSysMessage(R"(Player %s already has item |c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r in the appearance collection.)", nameLink, itemQuality.c_str(), itemId, itemName.c_str());
handler->SetSentErrorMessage(true);
}
} }
return true; return true;
} }
static bool HandleAddTransmogItemSet(ChatHandler* handler, Optional<PlayerIdentifier> player, Variant<Hyperlink<itemset>, uint32> itemSetId) static bool HandleAddTransmogItemSet(ChatHandler *handler, Optional<PlayerIdentifier> player, Variant<Hyperlink<itemset>, uint32> itemSetId)
{ {
if (!sTransmogrification->GetUseCollectionSystem()) if (!sTransmogrification->GetUseCollectionSystem())
return true; return true;
@@ -146,12 +173,17 @@ public:
} }
if (!player) if (!player)
{
player = PlayerIdentifier::FromTargetOrSelf(handler); player = PlayerIdentifier::FromTargetOrSelf(handler);
if (!player || !player->IsConnected()) }
return false;
Player* target = player->GetConnectedPlayer(); if (!player)
ItemSetEntry const* set = sItemSetStore.LookupEntry(uint32(itemSetId)); {
return false;
}
Player *target = player->GetConnectedPlayer();
ItemSetEntry const *set = sItemSetStore.LookupEntry(uint32(itemSetId));
if (!set) if (!set)
{ {
@@ -162,14 +194,26 @@ public:
bool added = false; bool added = false;
uint32 error = 0; uint32 error = 0;
uint32 accountId = target->GetSession()->GetAccountId();
uint32 itemId; uint32 itemId;
uint32 accountId;
auto guid = player->GetGUID().GetCounter();
if (QueryResult result = CharacterDatabase.Query("SELECT `account` FROM `characters` WHERE `guid` = {}", guid))
{
Field *fields = result->Fetch();
accountId = fields[0].Get<uint32>();
}
else
{
return false;
}
for (uint32 i = 0; i < MAX_ITEM_SET_ITEMS; ++i) for (uint32 i = 0; i < MAX_ITEM_SET_ITEMS; ++i)
{ {
itemId = set->itemId[i]; itemId = set->itemId[i];
if (itemId) if (itemId)
{ {
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId); ItemTemplate const *itemTemplate = sObjectMgr->GetItemTemplate(itemId);
if (itemTemplate) if (itemTemplate)
{ {
if (!sTransmogrification->GetTrackUnusableItems() && !sTransmogrification->SuitableForTransmogrification(target, itemTemplate)) if (!sTransmogrification->GetTrackUnusableItems() && !sTransmogrification->SuitableForTransmogrification(target, itemTemplate))
@@ -199,25 +243,30 @@ public:
return true; return true;
} }
int locale = handler->GetSessionDbcLocale(); bool isNotConsoleAndIsPlayerOnline = handler->GetSession() && target->GetSession();
std::string setName = set->name[locale];
std::string nameLink = handler->playerLink(target->GetName());
if (!added) if (isNotConsoleAndIsPlayerOnline)
{ {
handler->PSendSysMessage("Player %s already has ItemSet |cffffffff|Hitemset:%d|h[%s %s]|h|r in the appearance collection.", nameLink, uint32(itemSetId), setName.c_str(), localeNames[locale]); int locale = handler->GetSessionDbcLocale();
handler->SetSentErrorMessage(true); std::string setName = set->name[locale];
return true; std::string nameLink = handler->playerLink(target->GetName());
}
if (!(target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value)) if (!added)
{ {
ChatHandler(target->GetSession()).PSendSysMessage("ItemSet |cffffffff|Hitemset:%d|h[%s %s]|h|r has been added to your appearance collection.", uint32(itemSetId), setName.c_str(), localeNames[locale]); handler->PSendSysMessage("Player %s already has ItemSet |cffffffff|Hitemset:%d|h[%s %s]|h|r in the appearance collection.", nameLink, uint32(itemSetId), setName.c_str(), localeNames[locale]);
} handler->SetSentErrorMessage(true);
return true;
}
if (target != handler->GetPlayer()) if (!(target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value))
{ {
handler->PSendSysMessage("ItemSet |cffffffff|Hitemset:%d|h[%s %s]|h|r has been added to the appearance collection of Player %s.", uint32(itemSetId), setName.c_str(), localeNames[locale], nameLink); ChatHandler(target->GetSession()).PSendSysMessage("ItemSet |cffffffff|Hitemset:%d|h[%s %s]|h|r has been added to your appearance collection.", uint32(itemSetId), setName.c_str(), localeNames[locale]);
}
if (target != handler->GetPlayer())
{
handler->PSendSysMessage("ItemSet |cffffffff|Hitemset:%d|h[%s %s]|h|r has been added to the appearance collection of Player %s.", uint32(itemSetId), setName.c_str(), localeNames[locale], nameLink);
}
} }
return true; return true;