refactor(Scripts/Commands): convert cs_misc to new system (#8939)

This commit is contained in:
IntelligentQuantum 2021-12-21 16:02:21 +03:30 committed by GitHub
parent 7617ae4645
commit 838c88f45a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 2208 additions and 1737 deletions

View File

@ -66,7 +66,8 @@
"cfenv": "cpp",
"typeinfo": "cpp",
"codecvt": "cpp",
"xstring": "cpp"
"xstring": "cpp",
"variant": "cpp"
},
"deno.enable": true,
"deno.path": "deps/deno/bin/deno",

View File

@ -298,7 +298,7 @@ size_t ChatHandler::BuildChatPacket(WorldPacket& data, ChatMsg chatType, Languag
return BuildChatPacket(data, chatType, language, senderGUID, receiverGUID, message, chatTag, senderName, receiverName, achievementId, gmMessage, channelName);
}
Player* ChatHandler::getSelectedPlayer()
Player* ChatHandler::getSelectedPlayer() const
{
if (!m_session)
return nullptr;
@ -310,7 +310,7 @@ Player* ChatHandler::getSelectedPlayer()
return ObjectAccessor::FindConnectedPlayer(selected);
}
Unit* ChatHandler::getSelectedUnit()
Unit* ChatHandler::getSelectedUnit() const
{
if (!m_session)
return nullptr;
@ -321,7 +321,7 @@ Unit* ChatHandler::getSelectedUnit()
return m_session->GetPlayer();
}
WorldObject* ChatHandler::getSelectedObject()
WorldObject* ChatHandler::getSelectedObject() const
{
if (!m_session)
return nullptr;
@ -334,7 +334,7 @@ WorldObject* ChatHandler::getSelectedObject()
return ObjectAccessor::GetUnit(*m_session->GetPlayer(), guid);
}
Creature* ChatHandler::getSelectedCreature()
Creature* ChatHandler::getSelectedCreature() const
{
if (!m_session)
return nullptr;
@ -342,7 +342,7 @@ Creature* ChatHandler::getSelectedCreature()
return ObjectAccessor::GetCreatureOrPetOrVehicle(*m_session->GetPlayer(), m_session->GetPlayer()->GetTarget());
}
Player* ChatHandler::getSelectedPlayerOrSelf()
Player* ChatHandler::getSelectedPlayerOrSelf() const
{
if (!m_session)
return nullptr;
@ -472,7 +472,7 @@ char* ChatHandler::extractKeyFromLink(char* text, char const* const* linkTypes,
return nullptr;
}
GameObject* ChatHandler::GetNearbyGameObject()
GameObject* ChatHandler::GetNearbyGameObject() const
{
if (!m_session)
return nullptr;

View File

@ -90,12 +90,12 @@ public:
bool HasLowerSecurityAccount(WorldSession* target, uint32 account, bool strong = false);
void SendGlobalGMSysMessage(const char* str);
Player* getSelectedPlayer();
Creature* getSelectedCreature();
Unit* getSelectedUnit();
WorldObject* getSelectedObject();
Player* getSelectedPlayer() const;
Creature* getSelectedCreature() const;
Unit* getSelectedUnit() const;
WorldObject* getSelectedObject() const;
// Returns either the selected player or self if there is no selected player
Player* getSelectedPlayerOrSelf();
Player* getSelectedPlayerOrSelf() const;
char* extractKeyFromLink(char* text, char const* linkType, char** something1 = nullptr);
char* extractKeyFromLink(char* text, char const* const* linkTypes, int* found_idx, char** something1 = nullptr);
@ -111,7 +111,7 @@ public:
std::string playerLink(std::string const& name) const { return m_session ? "|cffffffff|Hplayer:" + name + "|h[" + name + "]|h|r" : name; }
std::string GetNameLink(Player* chr) const;
GameObject* GetNearbyGameObject();
GameObject* GetNearbyGameObject() const;
GameObject* GetObjectFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid);
Creature* GetCreatureFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid);
bool HasSentErrorMessage() const { return sentErrorMessage; }

View File

@ -38,7 +38,6 @@ struct TalentEntry;
namespace Acore::Hyperlinks
{
struct AchievementLinkData
{
AchievementEntry const* Achievement;
@ -90,7 +89,8 @@ namespace Acore::Hyperlinks
std::string KnownRecipes;
};
namespace LinkTags {
namespace LinkTags
{
/************************** LINK TAGS ***************************************************\
|* Link tags must abide by the following: *|
@ -247,9 +247,9 @@ namespace Acore::Hyperlinks
std::string_view const data;
std::string_view const text;
};
HyperlinkInfo AC_GAME_API ParseSingleHyperlink(std::string_view str);
bool AC_GAME_API CheckAllLinks(std::string_view str);
}
#endif

View File

@ -18,11 +18,11 @@
#include "ScriptMgr.h"
#include "ScriptMgrMacros.h"
void ScriptMgr::OnHandleDevCommand(Player* player, std::string& argstr)
void ScriptMgr::OnHandleDevCommand(Player* player, bool& enable)
{
ExecuteScript<CommandSC>([&](CommandSC* script)
{
script->OnHandleDevCommand(player, argstr);
script->OnHandleDevCommand(player, enable);
});
}

View File

@ -1842,7 +1842,7 @@ public:
bool IsDatabaseBound() const { return false; }
virtual void OnHandleDevCommand(Player* /*player*/, std::string& /*argstr*/) { }
virtual void OnHandleDevCommand(Player* /*player*/, bool& /*enable*/) { }
/**
* @brief This hook runs execute chat command
@ -2464,7 +2464,7 @@ public: /* MiscScript */
public: /* CommandSC */
void OnHandleDevCommand(Player* player, std::string& argstr);
void OnHandleDevCommand(Player* player, bool& enable);
bool CanExecuteCommand(ChatHandler& handler, std::string_view cmdStr);
public: /* DatabaseScript */

View File

@ -0,0 +1,161 @@
/*
* This file is part of the AzerothCore 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 Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
constexpr std::array<std::string_view, MAX_ITEM_QUALITY> itemQualityToString =
{
"poor",
"normal",
"uncommon",
"rare",
"epic",
"legendary",
"artifact",
"all"
};
using namespace Acore::ChatCommands;
class bg_commandscript : public CommandScript
{
public:
bg_commandscript() : CommandScript("bg_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable commandTable =
{
{ "bags clear", HandleBagsClearCommand, SEC_GAMEMASTER, Console::No },
};
return commandTable;
}
static bool HandleBagsClearCommand(ChatHandler* handler, std::string_view args)
{
if (args.empty())
{
return false;
}
Player* player = handler->GetSession()->GetPlayer();
if (!player)
{
return false;
}
uint8 itemQuality = MAX_ITEM_QUALITY;
for (uint8 i = ITEM_QUALITY_POOR; i < MAX_ITEM_QUALITY; ++i)
{
if (args == itemQualityToString[i])
{
itemQuality = i;
break;
}
}
if (itemQuality == MAX_ITEM_QUALITY)
{
return false;
}
std::array<uint32, MAX_ITEM_QUALITY> removedItems = { };
// in inventory
for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
{
if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
if (ItemTemplate const* itemTemplate = item->GetTemplate())
{
if (itemTemplate->Quality <= itemQuality)
{
player->DestroyItem(INVENTORY_SLOT_BAG_0, i, true);
++removedItems[itemTemplate->Quality];
}
}
}
}
// in inventory bags
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
{
if (Bag* bag = player->GetBagByPos(i))
{
for (uint32 j = 0; j < bag->GetBagSize(); j++)
{
if (Item* item = bag->GetItemByPos(j))
{
if (ItemTemplate const* itemTemplate = item->GetTemplate())
{
if (itemTemplate->Quality <= itemQuality)
{
player->DestroyItem(i, j, true);
++removedItems[itemTemplate->Quality];
}
}
}
}
}
}
std::ostringstream str;
str << "Removed ";
if (itemQuality == ITEM_QUALITY_HEIRLOOM)
{
str << "all";
}
else
{
bool initialize = true;
for (uint8 i = ITEM_QUALITY_POOR; i < MAX_ITEM_QUALITY; ++i)
{
if (uint32 itemCount = removedItems[i])
{
std::string_view itemQualityString = itemQualityToString[i];
if (!initialize)
{
str << ", ";
}
str << "|c";
str << std::hex << ItemQualityColors[i] << std::dec;
str << itemCount << " " << itemQualityString << "|r";
initialize = false;
}
}
}
str << " items from your bags.";
handler->SendSysMessage(str.str().c_str());
return true;
};
};
void AddSC_bag_commandscript()
{
new bg_commandscript();
}

View File

@ -0,0 +1,128 @@
/*
* This file is part of the AzerothCore 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 Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Log.h"
#include "Player.h"
#include "WorldSession.h"
using namespace Acore::ChatCommands;
class gear_commandscript : public CommandScript
{
public:
gear_commandscript() : CommandScript("gear_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable gearCommandTable =
{
{ "repair", HandleGearRepairCommand, SEC_GAMEMASTER, Console::No },
{ "stats", HandleGearStatsCommand, SEC_PLAYER, Console::No }
};
static ChatCommandTable commandTable =
{
{ "gear", gearCommandTable }
};
return commandTable;
}
static bool HandleGearRepairCommand(ChatHandler* handler, Optional<PlayerIdentifier> target)
{
if (!target)
{
target = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!target || !target->IsConnected())
{
return false;
}
// check online security
if (handler->HasLowerSecurity(target->GetConnectedPlayer()))
{
return false;
}
// Repair items
target->GetConnectedPlayer()->DurabilityRepairAll(false, 0, false);
std::string nameLink = handler->playerLink(target->GetName());
handler->PSendSysMessage(LANG_YOU_REPAIR_ITEMS, nameLink.c_str());
if (handler->needReportToTarget(target->GetConnectedPlayer()))
{
ChatHandler(target->GetConnectedPlayer()->GetSession()).PSendSysMessage(LANG_YOUR_ITEMS_REPAIRED, nameLink.c_str());
}
return true;
}
static bool HandleGearStatsCommand(ChatHandler* handler)
{
Player* player = handler->getSelectedPlayerOrSelf();
if (!player)
{
return false;
}
handler->PSendSysMessage("Character: %s", player->GetPlayerName().c_str());
handler->PSendSysMessage("Current equipment average item level: |cff00ffff%u|r", (int16)player->GetAverageItemLevel());
if (sWorld->getIntConfig(CONFIG_MIN_LEVEL_STAT_SAVE))
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_STATS);
stmt->setUInt32(0, player->GetGUID().GetCounter());
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
Field* fields = result->Fetch();
uint32 MaxHealth = fields[0].GetUInt32();
uint32 Strength = fields[1].GetUInt32();
uint32 Agility = fields[2].GetUInt32();
uint32 Stamina = fields[3].GetUInt32();
uint32 Intellect = fields[4].GetUInt32();
uint32 Spirit = fields[5].GetUInt32();
uint32 Armor = fields[6].GetUInt32();
uint32 AttackPower = fields[7].GetUInt32();
uint32 SpellPower = fields[8].GetUInt32();
uint32 Resilience = fields[9].GetUInt32();
handler->PSendSysMessage("Health: |cff00ffff%u|r - Stamina: |cff00ffff%u|r", MaxHealth, Stamina);
handler->PSendSysMessage("Strength: |cff00ffff%u|r - Agility: |cff00ffff%u|r", Strength, Agility);
handler->PSendSysMessage("Intellect: |cff00ffff%u|r - Spirit: |cff00ffff%u|r", Intellect, Spirit);
handler->PSendSysMessage("AttackPower: |cff00ffff%u|r - SpellPower: |cff00ffff%u|r", AttackPower, SpellPower);
handler->PSendSysMessage("Armor: |cff00ffff%u|r - Resilience: |cff00ffff%u|r", Armor, Resilience);
}
}
return true;
}
};
void AddSC_gear_commandscript()
{
new gear_commandscript();
}

View File

@ -0,0 +1,268 @@
/*
* This file is part of the AzerothCore 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 Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "ScriptMgr.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "GroupMgr.h"
#include "Language.h"
#include "LFG.h"
#include "ObjectAccessor.h"
#include "Player.h"
using namespace Acore::ChatCommands;
class group_commandscript : public CommandScript
{
public:
group_commandscript() : CommandScript("group_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable groupCommandTable =
{
{ "list", HandleGroupListCommand, SEC_GAMEMASTER, Console::No },
{ "join", HandleGroupJoinCommand, SEC_GAMEMASTER, Console::No },
{ "remove", HandleGroupRemoveCommand, SEC_GAMEMASTER, Console::No },
{ "disband", HandleGroupDisbandCommand, SEC_GAMEMASTER, Console::No },
{ "leader", HandleGroupLeaderCommand, SEC_GAMEMASTER, Console::No }
};
static ChatCommandTable commandTable =
{
{ "group", groupCommandTable }
};
return commandTable;
}
static bool HandleGroupLeaderCommand(ChatHandler* handler, Optional<PlayerIdentifier> target)
{
if (!target)
{
target = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!target)
{
return false;
}
Player* player = nullptr;
Group* group = nullptr;
ObjectGuid guid;
if (handler->GetPlayerGroupAndGUIDByName(target->GetName().c_str(), player, group, guid))
{
if (group && group->GetLeaderGUID() != guid)
{
group->ChangeLeader(guid);
group->SendUpdate();
}
}
return true;
}
static bool HandleGroupDisbandCommand(ChatHandler* handler, Optional<PlayerIdentifier> target)
{
if (!target)
{
target = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!target || !target->IsConnected())
{
return false;
}
Player* player = nullptr;
Group* group = nullptr;
ObjectGuid guid;
if (handler->GetPlayerGroupAndGUIDByName(target->GetName().c_str(), player, group, guid))
{
if (group)
{
group->Disband();
}
}
return true;
}
static bool HandleGroupRemoveCommand(ChatHandler* handler, Optional<PlayerIdentifier> target)
{
if (!target)
{
target = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!target || !target->IsConnected())
{
return false;
}
Player* player = nullptr;
Group* group = nullptr;
ObjectGuid guid;
if (handler->GetPlayerGroupAndGUIDByName(target->GetName().c_str(), player, group, guid, true))
{
if (group)
{
group->RemoveMember(guid);
}
}
return true;
}
static bool HandleGroupJoinCommand(ChatHandler* handler, std::string const& playerInGroup, std::string const& playerName)
{
if (playerInGroup.empty() || playerName.empty())
{
return false;
}
Player* playerSource = nullptr;
Group* groupSource = nullptr;
ObjectGuid guidSource;
ObjectGuid guidTarget;
if (handler->GetPlayerGroupAndGUIDByName(playerInGroup.c_str(), playerSource, groupSource, guidSource, true))
{
if (groupSource)
{
Group* groupTarget = nullptr;
Player* playerTarget = nullptr;
if (handler->GetPlayerGroupAndGUIDByName(playerName.c_str(), playerTarget, groupTarget, guidTarget, true))
{
if (!groupTarget && playerTarget->GetGroup() != groupSource)
{
if (!groupSource->IsFull())
{
groupSource->AddMember(playerTarget);
groupSource->BroadcastGroupUpdate();
handler->PSendSysMessage(LANG_GROUP_PLAYER_JOINED, playerTarget->GetName().c_str(), playerSource->GetName().c_str());
return true;
}
else
{
// group is full
handler->PSendSysMessage(LANG_GROUP_FULL);
return true;
}
}
else
{
// group is full or target player already in a group
handler->PSendSysMessage(LANG_GROUP_ALREADY_IN_GROUP, playerTarget->GetName().c_str());
return true;
}
}
}
else
{
// specified source player is not in a group
handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, playerSource->GetName().c_str());
return true;
}
}
return true;
}
static bool HandleGroupListCommand(ChatHandler* handler, Optional<PlayerIdentifier> target)
{
if (!target)
{
target = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!target)
{
return false;
}
Group* groupTarget = nullptr;
if (target->IsConnected())
{
groupTarget = target->GetConnectedPlayer()->GetGroup();
}
if (!groupTarget)
{
if (ObjectGuid groupGUID = sCharacterCache->GetCharacterGroupGuidByGuid(target->GetGUID()))
{
groupTarget = sGroupMgr->GetGroupByGUID(groupGUID.GetCounter());
}
}
if (!groupTarget)
{
handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, target->GetName().c_str());
return true;
}
handler->PSendSysMessage(LANG_GROUP_TYPE, (groupTarget->isRaidGroup() ? "raid" : "party"));
for (auto const& slot : groupTarget->GetMemberSlots())
{
std::string flags;
if (slot.flags & MEMBER_FLAG_ASSISTANT)
{
flags = "Assistant";
}
if (slot.flags & MEMBER_FLAG_MAINTANK)
{
if (!flags.empty())
{
flags.append(", ");
}
flags.append("MainTank");
}
if (slot.flags & MEMBER_FLAG_MAINASSIST)
{
if (!flags.empty())
{
flags.append(", ");
}
flags.append("MainAssist");
}
if (flags.empty())
{
flags = "None";
}
}
return true;
}
};
void AddSC_group_commandscript()
{
new group_commandscript();
}

View File

@ -0,0 +1,187 @@
/*
* This file is part of the AzerothCore 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 Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Player.h"
#include "WorldSession.h"
constexpr std::array<const char*, MAX_ITEM_SUBCLASS_CONTAINER> bagSpecsToString =
{
"normal",
"soul",
"herb",
"enchanting",
"engineering",
"gem",
"mining",
"leatherworking",
"inscription"
};
constexpr std::array<uint32, MAX_ITEM_SUBCLASS_CONTAINER> bagSpecsColors =
{
0xfff0de18, // YELLOW - Normal
0xffa335ee, // PURPLE - Souls
0xff1eff00, // GREEN - Herb
0xffe37166, // PINK - Enchanting
0xffa68b30, // BROWN - Engineering
0xff0070dd, // BLUE - Gem
0xffc1c8c9, // GREY - Mining
0xfff5a925, // ORANGE - Leatherworking
0xff54504f // DARK GREY - Inscription
};
//constexpr std::array<const char*, MAX_ITEM_SUBCLASS_CONTAINER> bagSpecsColorToString =
//{
// "normal",
// "soul",
// "herb",
// "enchanting",
// "engineering",
// "gem",
// "mining",
// "leatherworking",
// "inscription"
//};
using namespace Acore::ChatCommands;
class inventory_commandscript : public CommandScript
{
public:
inventory_commandscript() : CommandScript("inventory_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable inventoryCommandTable =
{
{ "count", HandleInventoryCountCommand, SEC_MODERATOR, Console::No }
};
static ChatCommandTable commandTable =
{
{ "inventory", inventoryCommandTable }
};
return commandTable;
}
static bool HandleInventoryCountCommand(ChatHandler* handler, Optional<PlayerIdentifier> player)
{
if (!player)
{
player = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!player)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
Player* target = player->GetConnectedPlayer();
if (!target)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
std::array<uint32, MAX_ITEM_SUBCLASS_CONTAINER> freeSlotsInBags = { };
uint32 freeSlotsForBags = 0;
bool haveFreeSlot = false;
// Check backpack
for (uint8 slot = INVENTORY_SLOT_ITEM_START; slot < INVENTORY_SLOT_ITEM_END; ++slot)
{
if (!target->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
{
haveFreeSlot = true;
++freeSlotsInBags[ITEM_SUBCLASS_CONTAINER];
}
}
// Check bags
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
{
if (Bag* bag = target->GetBagByPos(i))
{
if (ItemTemplate const* bagTemplate = bag->GetTemplate())
{
if (bagTemplate->Class == ITEM_CLASS_CONTAINER || bagTemplate->Class == ITEM_CLASS_QUIVER)
{
haveFreeSlot = true;
freeSlotsInBags[bagTemplate->SubClass] += bag->GetFreeSlots();
}
}
}
else
{
++freeSlotsForBags;
}
}
std::ostringstream str;
if (haveFreeSlot)
{
str << "Player " << target->GetName() << " have ";
bool initialize = true;
for (uint8 i = ITEM_SUBCLASS_CONTAINER; i < MAX_ITEM_SUBCLASS_CONTAINER; ++i)
{
if (uint32 freeSlots = freeSlotsInBags[i])
{
std::string bagSpecString = bagSpecsToString[i];
if (!initialize)
{
str << ", ";
}
str << "|c";
str << std::hex << bagSpecsColors[i] << std::dec;
str << freeSlots << " in " << bagSpecString << " bags|r";
initialize = false;
}
}
}
else
{
str << "Player " << target->GetName() << " does not have free slots in their bags";
}
if (freeSlotsForBags)
{
str << " and also has " << freeSlotsForBags << " free slots for bags";
}
str << ".";
handler->SendSysMessage(str.str().c_str());
return true;
}
};
void AddSC_inventory_commandscript()
{
new inventory_commandscript();
}

View File

@ -140,7 +140,8 @@ public:
return false;
}
do {
do
{
Field* fields = disposedItems->Fetch();
uint32 id = fields[0].GetUInt32();
uint32 itemId = fields[1].GetUInt32();
@ -161,7 +162,6 @@ public:
// TODO - move item to other slot
static bool HandleItemMoveCommand(ChatHandler* handler, uint8 srcSlot, uint8 dstSlot)
{
if (srcSlot == dstSlot)
return true;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,210 @@
/*
* This file is part of the AzerothCore 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 Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Pet.h"
#include "Player.h"
#include "SpellMgr.h"
#include "SpellInfo.h"
#include "WorldSession.h"
using namespace Acore::ChatCommands;
class pet_commandscript : public CommandScript
{
public:
pet_commandscript() : CommandScript("pet_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable petCommandTable =
{
{ "create", HandlePetCreateCommand, SEC_GAMEMASTER, Console::No },
{ "learn", HandlePetLearnCommand, SEC_GAMEMASTER, Console::No },
{ "unlearn", HandlePetUnlearnCommand, SEC_GAMEMASTER, Console::No }
};
static ChatCommandTable commandTable =
{
{ "pet", petCommandTable }
};
return commandTable;
}
static bool HandlePetCreateCommand(ChatHandler* handler)
{
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->SetGuidValue(UNIT_FIELD_CREATEDBY, player->GetGUID());
pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, player->GetFaction());
if (!pet->InitStatsForLevel(creatureTarget->getLevel()))
{
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());
player->SetMinion(pet, true);
pet->SavePetToDB(PET_SAVE_AS_CURRENT, false);
player->PetSpellInitialize();
return true;
}
static bool HandlePetLearnCommand(ChatHandler* handler, SpellInfo const* spell)
{
if (!spell)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!SpellMgr::IsSpellValid(spell))
{
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id);
handler->SetSentErrorMessage(true);
return false;
}
Pet* pet = handler->GetSession()->GetPlayer()->GetPet();
if (!pet)
{
handler->PSendSysMessage("You have no pet");
handler->SetSentErrorMessage(true);
return false;
}
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell->Id);
uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell->Id);
if (bounds.first != bounds.second || spellDifficultyId)
{
handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell->Id);
handler->SetSentErrorMessage(true);
return false;
}
// Check if pet already has it
if (pet->HasSpell(spell->Id))
{
handler->PSendSysMessage("Pet already has spell: %u", spell->Id);
handler->SetSentErrorMessage(true);
return false;
}
pet->learnSpell(spell->Id);
handler->PSendSysMessage("Pet has learned spell %u", spell->Id);
return true;
}
static bool HandlePetUnlearnCommand(ChatHandler* handler, SpellInfo const* spell)
{
if (!spell)
{
handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!SpellMgr::IsSpellValid(spell))
{
handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id);
handler->SetSentErrorMessage(true);
return false;
}
Pet* pet = handler->GetSession()->GetPlayer()->GetPet();
if (!pet)
{
handler->PSendSysMessage("You have no pet");
handler->SetSentErrorMessage(true);
return false;
}
if (pet->HasSpell(spell->Id))
{
pet->removeSpell(spell->Id, false);
}
else
{
handler->PSendSysMessage("Pet doesn't have that spell");
}
return true;
}
};
void AddSC_pet_commandscript()
{
new pet_commandscript();
}

View File

@ -19,6 +19,7 @@
void AddSC_account_commandscript();
void AddSC_achievement_commandscript();
void AddSC_arena_commandscript();
void AddSC_bag_commandscript();
void AddSC_ban_commandscript();
void AddSC_bf_commandscript();
void AddSC_cast_commandscript();
@ -28,12 +29,15 @@ void AddSC_debug_commandscript();
void AddSC_deserter_commandscript();
void AddSC_disable_commandscript();
void AddSC_event_commandscript();
void AddSC_gear_commandscript();
void AddSC_gm_commandscript();
void AddSC_go_commandscript();
void AddSC_gobject_commandscript();
void AddSC_group_commandscript();
void AddSC_guild_commandscript();
void AddSC_honor_commandscript();
void AddSC_instance_commandscript();
void AddSC_inventory_commandscript();
void AddSC_learn_commandscript();
void AddSC_lfg_commandscript();
void AddSC_list_commandscript();
@ -43,16 +47,18 @@ void AddSC_misc_commandscript();
void AddSC_mmaps_commandscript();
void AddSC_modify_commandscript();
void AddSC_npc_commandscript();
void AddSC_pet_commandscript();
void AddSC_player_commandscript();
void AddSC_quest_commandscript();
void AddSC_reload_commandscript();
void AddSC_reset_commandscript();
void AddSC_send_commandscript();
void AddSC_server_commandscript();
void AddSC_spectator_commandscript();
void AddSC_tele_commandscript();
void AddSC_ticket_commandscript();
void AddSC_titles_commandscript();
void AddSC_wp_commandscript();
void AddSC_player_commandscript();
void AddSC_cache_commandscript();
void AddSC_item_commandscript();
@ -63,6 +69,7 @@ void AddCommandsScripts()
AddSC_account_commandscript();
AddSC_achievement_commandscript();
AddSC_arena_commandscript();
AddSC_bag_commandscript();
AddSC_ban_commandscript();
AddSC_bf_commandscript();
AddSC_cast_commandscript();
@ -72,12 +79,15 @@ void AddCommandsScripts()
AddSC_deserter_commandscript();
AddSC_disable_commandscript();
AddSC_event_commandscript();
AddSC_gear_commandscript();
AddSC_gm_commandscript();
AddSC_go_commandscript();
AddSC_gobject_commandscript();
AddSC_group_commandscript();
AddSC_guild_commandscript();
AddSC_honor_commandscript();
AddSC_instance_commandscript();
AddSC_inventory_commandscript();
AddSC_learn_commandscript();
AddSC_lfg_commandscript();
AddSC_list_commandscript();
@ -87,16 +97,18 @@ void AddCommandsScripts()
AddSC_mmaps_commandscript();
AddSC_modify_commandscript();
AddSC_npc_commandscript();
AddSC_pet_commandscript();
AddSC_player_commandscript();
AddSC_quest_commandscript();
AddSC_reload_commandscript();
AddSC_reset_commandscript();
AddSC_send_commandscript();
AddSC_server_commandscript();
AddSC_spectator_commandscript();
AddSC_tele_commandscript();
AddSC_ticket_commandscript();
AddSC_titles_commandscript();
AddSC_wp_commandscript();
AddSC_player_commandscript();
AddSC_cache_commandscript();
AddSC_item_commandscript();
}

View File

@ -0,0 +1,220 @@
/*
* This file is part of the AzerothCore 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 Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "ScriptMgr.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "Item.h"
#include "Language.h"
#include "Mail.h"
#include "ObjectMgr.h"
#include "Pet.h"
#include "Player.h"
#include "WorldSession.h"
#include "Tokenize.h"
using namespace Acore::ChatCommands;
class send_commandscript : public CommandScript
{
public:
send_commandscript() : CommandScript("send_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable sendCommandTable =
{
{ "items", HandleSendItemsCommand, SEC_GAMEMASTER, Console::Yes },
{ "mail", HandleSendMailCommand, SEC_GAMEMASTER, Console::Yes },
{ "message", HandleSendMessageCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "money", HandleSendMoneyCommand, SEC_GAMEMASTER, Console::Yes }
};
static ChatCommandTable commandTable =
{
{ "send", sendCommandTable }
};
return commandTable;
}
static bool HandleSendItemsCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, QuotedString subject, QuotedString text, Tail items)
{
if (!target)
{
target = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!target)
{
return false;
}
// extract items
std::vector<std::pair<uint32, uint32>> itemList;
for (auto const& itemString : Acore::Tokenize(items, ' ', true))
{
auto itemTokens = Acore::Tokenize(itemString, ':', false);
if (itemTokens.size() != 2)
{
handler->SendSysMessage(Acore::StringFormatFmt("> Incorrect item list format for '{}'", itemString));
continue;
}
uint32 itemID = *Acore::StringTo<uint32>(itemTokens.at(0));
uint32 itemCount = *Acore::StringTo<uint32>(itemTokens.at(1));
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemID);
if (!itemTemplate)
{
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemID);
handler->SetSentErrorMessage(true);
return false;
}
if (!itemCount || (itemTemplate->MaxCount > 0 && itemCount > uint32(itemTemplate->MaxCount)))
{
handler->PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, itemCount, itemID);
handler->SetSentErrorMessage(true);
return false;
}
while (itemCount > itemTemplate->GetMaxStackSize())
{
itemList.emplace_back(itemID, itemTemplate->GetMaxStackSize());
itemCount -= itemTemplate->GetMaxStackSize();
}
itemList.emplace_back(itemID, itemCount);
if (itemList.size() > MAX_MAIL_ITEMS)
{
handler->PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
handler->SetSentErrorMessage(true);
return false;
}
}
// If the message is sent from console, set it as sent by the target itself, like the other Customer Support mails.
ObjectGuid::LowType senderGuid = handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : target->GetGUID().GetCounter();
// fill mail
MailDraft draft(subject, text);
MailSender sender(MAIL_NORMAL, senderGuid, MAIL_STATIONERY_GM);
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
for (auto const& [itemID, itemCount] : itemList)
{
if (Item* item = Item::CreateItem(itemID, itemCount, handler->GetSession() ? handler->GetSession()->GetPlayer() : 0))
{
item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
draft.AddItem(item);
}
}
draft.SendMailTo(trans, MailReceiver(target->GetConnectedPlayer(), target->GetGUID().GetCounter()), sender);
CharacterDatabase.CommitTransaction(trans);
handler->PSendSysMessage(LANG_MAIL_SENT, handler->playerLink(target->GetName()).c_str());
return true;
}
static bool HandleSendMailCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, QuotedString subject, QuotedString text)
{
if (!target)
{
target = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!target)
{
return false;
}
ObjectGuid::LowType senderGuid = handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : target->GetGUID().GetCounter();
// If the message is sent from console, set it as sent by the target itself, like the other Customer Support mails.
MailSender sender(MAIL_NORMAL, senderGuid, MAIL_STATIONERY_GM);
MailDraft draft(subject, text);
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
draft.SendMailTo(trans, MailReceiver(target->GetConnectedPlayer(), target->GetGUID().GetCounter()), sender);
CharacterDatabase.CommitTransaction(trans);
handler->PSendSysMessage(LANG_MAIL_SENT, handler->playerLink(target->GetName()).c_str());
return true;
}
static bool HandleSendMessageCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, Tail message)
{
if (!target)
{
target = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!target || !target->IsConnected())
{
return false;
}
Player* player = target->GetConnectedPlayer();
std::string msg = std::string{ message };
/// - Send the message
// Use SendAreaTriggerMessage for fastest delivery.
player->GetSession()->SendAreaTriggerMessage("%s", msg.c_str());
player->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
// Confirmation message
handler->PSendSysMessage(LANG_SENDMESSAGE, handler->playerLink(target->GetName()).c_str(), msg.c_str());
return true;
}
static bool HandleSendMoneyCommand(ChatHandler* handler, Optional<PlayerIdentifier> target, QuotedString subject, QuotedString text, uint32 money)
{
if (!target)
{
target = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!target)
{
return false;
}
// from console show not existed sender
MailSender sender(MAIL_NORMAL, handler->GetSession() ? handler->GetSession()->GetPlayer()->GetGUID().GetCounter() : 0, MAIL_STATIONERY_GM);
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
MailDraft(subject, text)
.AddMoney(money)
.SendMailTo(trans, MailReceiver(target->GetConnectedPlayer(), target->GetGUID().GetCounter()), sender);
CharacterDatabase.CommitTransaction(trans);
handler->PSendSysMessage(LANG_MAIL_SENT, handler->playerLink(target->GetName()).c_str());
return true;
}
};
void AddSC_send_commandscript()
{
new send_commandscript();
}