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,6 +20,7 @@
#include "Player.h"
#include "ScriptMgr.h"
#include "Transmogrification.h"
#include "Log.h"
using namespace Acore::ChatCommands;
@@ -32,8 +33,8 @@ public:
{
static ChatCommandTable addCollectionTable =
{
{ "set", HandleAddTransmogItemSet, SEC_MODERATOR, Console::No },
{ "", HandleAddTransmogItem, SEC_MODERATOR, Console::No },
{"set", HandleAddTransmogItemSet, SEC_MODERATOR, Console::Yes},
{"", HandleAddTransmogItem, SEC_MODERATOR, Console::Yes},
};
static ChatCommandTable transmogTable =
@@ -82,9 +83,14 @@ public:
}
if (!player)
{
player = PlayerIdentifier::FromTargetOrSelf(handler);
if (!player || !player->IsConnected())
}
if (!player)
{
return false;
}
Player *target = player->GetConnectedPlayer();
@@ -103,14 +109,30 @@ public:
}
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;
tempStream << std::hex << ItemQualityColors[itemTemplate->Quality];
std::string itemQuality = tempStream.str();
std::string itemName = itemTemplate->Name1;
std::string nameLink = handler->playerLink(target->GetName());
bool isNotConsoleAndIsPlayerOnline = handler->GetSession() && target->GetSession();
if (sTransmogrification->AddCollectedAppearance(accountId, itemId))
{
if (isNotConsoleAndIsPlayerOnline)
{
std::string nameLink = handler->playerLink(target->GetName());
if (!(target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value))
{
@@ -121,14 +143,19 @@ public:
{
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);
}
else
{
if (isNotConsoleAndIsPlayerOnline)
{
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;
}
@@ -146,9 +173,14 @@ public:
}
if (!player)
{
player = PlayerIdentifier::FromTargetOrSelf(handler);
if (!player || !player->IsConnected())
}
if (!player)
{
return false;
}
Player *target = player->GetConnectedPlayer();
ItemSetEntry const *set = sItemSetStore.LookupEntry(uint32(itemSetId));
@@ -162,8 +194,20 @@ public:
bool added = false;
uint32 error = 0;
uint32 accountId = target->GetSession()->GetAccountId();
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)
{
itemId = set->itemId[i];
@@ -199,6 +243,10 @@ public:
return true;
}
bool isNotConsoleAndIsPlayerOnline = handler->GetSession() && target->GetSession();
if (isNotConsoleAndIsPlayerOnline)
{
int locale = handler->GetSessionDbcLocale();
std::string setName = set->name[locale];
std::string nameLink = handler->playerLink(target->GetName());
@@ -219,6 +267,7 @@ public:
{
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;
}