garrison_commandscript
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* ScriptData
|
||||
Name: garrison_commandscript
|
||||
%Complete: 100
|
||||
Comment: All garrison related commands
|
||||
Category: commandscripts
|
||||
EndScriptData */
|
||||
|
||||
#include "ScriptMgr.h"
|
||||
#include "Chat.h"
|
||||
#include "ChatCommand.h"
|
||||
#include "DB2Stores.h"
|
||||
#include "Garrison.h"
|
||||
#include "Player.h"
|
||||
#include "WorldSession.h"
|
||||
#include <GarrisonMgr.h>
|
||||
|
||||
using namespace Trinity::ChatCommands;
|
||||
|
||||
class garrison_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
garrison_commandscript() : CommandScript("garrison_commandscript") { }
|
||||
|
||||
ChatCommandTable GetCommands() const override
|
||||
{
|
||||
static ChatCommandTable garrisonCommandTable =
|
||||
{
|
||||
{ "create", HandleGarrisonCreateCommand, rbac::RBAC_PERM_COMMAND_GM, Console::No },
|
||||
{ "info", HandleGarrisonInfoCommand, rbac::RBAC_PERM_COMMAND_GM, Console::No },
|
||||
};
|
||||
static ChatCommandTable commandTable =
|
||||
{
|
||||
{ "garrison", garrisonCommandTable },
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
static bool HandleGarrisonCreateCommand(ChatHandler* handler, Optional<uint32> siteId)
|
||||
{
|
||||
Player* player = handler->GetPlayer();
|
||||
if (!player)
|
||||
{
|
||||
handler->SendSysMessage("You must be in-game to use this command.");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 garrSiteId = siteId.value_or(2); // Default to Draenor garrison (site 2)
|
||||
|
||||
// Validate GarrSiteLevelEntry exists
|
||||
GarrSiteLevelEntry const* siteLevel = sGarrisonMgr.GetGarrSiteLevelEntry(garrSiteId, 1);
|
||||
if (!siteLevel)
|
||||
{
|
||||
handler->PSendSysMessage("Garrison site %u does not exist.", garrSiteId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if player already has a garrison
|
||||
if (player->GetGarrison())
|
||||
{
|
||||
handler->PSendSysMessage("Player already has a garrison.");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the garrison
|
||||
player->CreateGarrison(garrSiteId);
|
||||
|
||||
if (Garrison* garrison = player->GetGarrison())
|
||||
{
|
||||
handler->PSendSysMessage("Garrison created successfully! Site ID: %u", garrSiteId);
|
||||
|
||||
// Send garrison info to player
|
||||
WorldPackets::Garrison::GetGarrisonInfoResult garrisonInfo;
|
||||
garrisonInfo.FactionIndex = Garrison::GetFaction(player->GetTeam());
|
||||
garrison->BuildInfoPacket(garrisonInfo.Garrisons.emplace_back());
|
||||
garrisonInfo.FollowerSoftCaps = {
|
||||
{ FOLLOWER_TYPE_GARRISON, 20 },
|
||||
{ FOLLOWER_TYPE_SHIPYARD, 6 },
|
||||
{ FOLLOWER_TYPE_CLASS_ORDER, 6 },
|
||||
{ FOLLOWER_TYPE_WAR_CAMPAIGN, 30 },
|
||||
{ FOLLOWER_TYPE_COVENANT, 100 }
|
||||
};
|
||||
player->GetSession()->SendPacket(garrisonInfo.Write());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->PSendSysMessage("Failed to create garrison.");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool HandleGarrisonInfoCommand(ChatHandler* handler)
|
||||
{
|
||||
Player* player = handler->GetPlayer();
|
||||
if (!player)
|
||||
{
|
||||
handler->SendSysMessage("You must be in-game to use this command.");
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto const& garrisons = player->GetGarrisons();
|
||||
if (garrisons.empty())
|
||||
{
|
||||
handler->SendSysMessage("You have no garrisons.");
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->PSendSysMessage("You have %u garrison(s):", uint32(garrisons.size()));
|
||||
for (auto const& [type, garrison] : garrisons)
|
||||
{
|
||||
handler->PSendSysMessage("- Type: %u, Site ID: %u", type,
|
||||
garrison->GetSiteLevel() ? garrison->GetSiteLevel()->GarrSiteID : 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_garrison_commandscript()
|
||||
{
|
||||
new garrison_commandscript();
|
||||
}
|
||||
@@ -58,6 +58,7 @@ void AddSC_tele_commandscript();
|
||||
void AddSC_ticket_commandscript();
|
||||
void AddSC_titles_commandscript();
|
||||
void AddSC_wp_commandscript();
|
||||
void AddSC_garrison_commandscript();
|
||||
|
||||
// The name of this function should match:
|
||||
// void Add${NameOfDirectory}Scripts()
|
||||
@@ -105,4 +106,5 @@ void AddCommandsScripts()
|
||||
AddSC_ticket_commandscript();
|
||||
AddSC_titles_commandscript();
|
||||
AddSC_wp_commandscript();
|
||||
AddSC_garrison_commandscript();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user