mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Scripts/Commands: Implement commands to set and get boss states during run time
Closes #13186
This commit is contained in:
File diff suppressed because one or more lines are too long
9
sql/updates/auth/2014_10_18_00_auth.sql
Normal file
9
sql/updates/auth/2014_10_18_00_auth.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
DELETE FROM `rbac_permissions` WHERE `id` IN (795, 796);
|
||||
INSERT INTO `rbac_permissions` (`id`, `name`) VALUES
|
||||
(795, 'Command: .instance setbossstate'),
|
||||
(796, 'Command: .instance getbossstate');
|
||||
|
||||
DELETE FROM `rbac_linked_permissions` WHERE `linkedId` IN (795, 796);
|
||||
INSERT INTO `rbac_linked_permissions` (`id`, `linkedId`) VALUES
|
||||
(192, 795),
|
||||
(192, 796);
|
||||
9
sql/updates/world/2014_10_18_02_world.sql
Normal file
9
sql/updates/world/2014_10_18_02_world.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
DELETE FROM `trinity_string` WHERE `entry` IN (5057, 5058);
|
||||
INSERT INTO `trinity_string` (`entry`, `content_default`) VALUES
|
||||
(5057, 'Boss id %i state is now set to %i.'),
|
||||
(5058, 'Boss id %i state is %i.');
|
||||
|
||||
DELETE FROM `command` WHERE `permission` IN (795, 796);
|
||||
INSERT INTO `command` (`name`, `permission`, `help`) VALUES
|
||||
('instance setbossstate', '795', 'Syntax: .instance setbossstate $bossId $encounterState [$Name]\r\nSets the EncounterState for the given boss id to a new value. EncounterStates range from 0 to 5.\r\nIf no character name is provided, the current map will be used as target.'),
|
||||
('instance getbossstate', '796', 'Syntax: .instance getbossstate $bossId [$Name]\r\nGets the current EncounterState for the provided boss id.\r\nIf no character name is provided, the current map will be used as target.');
|
||||
@@ -698,6 +698,8 @@ enum RBACPermissions
|
||||
RBAC_PERM_COMMAND_AHBOT_RELOAD = 792,
|
||||
RBAC_PERM_COMMAND_AHBOT_STATUS = 793,
|
||||
RBAC_PERM_COMMAND_GUILD_INFO = 794,
|
||||
RBAC_PERM_COMMAND_INSTANCE_SET_BOSS_STATE = 795,
|
||||
RBAC_PERM_COMMAND_INSTANCE_GET_BOSS_STATE = 796,
|
||||
|
||||
// custom permissions 1000+
|
||||
RBAC_PERM_MAX
|
||||
|
||||
@@ -241,6 +241,8 @@ class InstanceScript : public ZoneScript
|
||||
|
||||
virtual void FillInitialWorldStates(WorldPacket& /*data*/) { }
|
||||
|
||||
uint32 GetEncounterCount() const { return bosses.size(); }
|
||||
|
||||
protected:
|
||||
void SetHeaders(std::string const& dataHeaders);
|
||||
void SetBossNumber(uint32 number) { bosses.resize(number); }
|
||||
|
||||
@@ -1108,8 +1108,10 @@ enum TrinityStrings
|
||||
LANG_COMMAND_INST_STAT_GROUPSBOUND = 5054,
|
||||
LANG_NOT_DUNGEON = 5055, // Map is not a dungeon.
|
||||
LANG_NO_INSTANCE_DATA = 5056, // Map has no instance data.
|
||||
LANG_COMMAND_INST_SET_BOSS_STATE = 5057,
|
||||
LANG_COMMAND_INST_GET_BOSS_STATE = 5058,
|
||||
|
||||
// Room for more Trinity strings 5057-9999
|
||||
// Room for more Trinity strings 5059-9999
|
||||
|
||||
// Level requirement notifications
|
||||
LANG_SAY_REQ = 6604,
|
||||
|
||||
@@ -40,11 +40,13 @@ public:
|
||||
{
|
||||
static ChatCommand instanceCommandTable[] =
|
||||
{
|
||||
{ "listbinds", rbac::RBAC_PERM_COMMAND_INSTANCE_LISTBINDS, false, &HandleInstanceListBindsCommand, "", NULL },
|
||||
{ "unbind", rbac::RBAC_PERM_COMMAND_INSTANCE_UNBIND, false, &HandleInstanceUnbindCommand, "", NULL },
|
||||
{ "stats", rbac::RBAC_PERM_COMMAND_INSTANCE_STATS, true, &HandleInstanceStatsCommand, "", NULL },
|
||||
{ "savedata", rbac::RBAC_PERM_COMMAND_INSTANCE_SAVEDATA, false, &HandleInstanceSaveDataCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
{ "listbinds", rbac::RBAC_PERM_COMMAND_INSTANCE_LISTBINDS, false, &HandleInstanceListBindsCommand, "", NULL },
|
||||
{ "unbind", rbac::RBAC_PERM_COMMAND_INSTANCE_UNBIND, false, &HandleInstanceUnbindCommand, "", NULL },
|
||||
{ "stats", rbac::RBAC_PERM_COMMAND_INSTANCE_STATS, true, &HandleInstanceStatsCommand, "", NULL },
|
||||
{ "savedata", rbac::RBAC_PERM_COMMAND_INSTANCE_SAVEDATA, false, &HandleInstanceSaveDataCommand, "", NULL },
|
||||
{ "setbossstate", rbac::RBAC_PERM_COMMAND_INSTANCE_SET_BOSS_STATE, true, &HandleInstanceSetBossStateCommand, "", NULL },
|
||||
{ "getbossstate", rbac::RBAC_PERM_COMMAND_INSTANCE_GET_BOSS_STATE, true, &HandleInstanceGetBossStateCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand commandTable[] =
|
||||
@@ -187,6 +189,138 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleInstanceSetBossStateCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* param1 = strtok((char*)args, " ");
|
||||
char* param2 = strtok(nullptr, " ");
|
||||
char* param3 = strtok(nullptr, " ");
|
||||
uint32 encounterId = 0;
|
||||
int32 state = 0;
|
||||
Player* player = nullptr;
|
||||
std::string playerName;
|
||||
|
||||
// Character name must be provided when using this from console.
|
||||
if (!param2 || (!param3 && !handler->GetSession()))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_CMD_SYNTAX);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!param3)
|
||||
player = handler->GetSession()->GetPlayer();
|
||||
else
|
||||
{
|
||||
playerName = param3;
|
||||
if (normalizePlayerName(playerName))
|
||||
player = sObjectAccessor->FindPlayerByName(playerName);
|
||||
}
|
||||
|
||||
if (!player)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Map* map = player->GetMap();
|
||||
if (!map->IsDungeon())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_NOT_DUNGEON);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!map->ToInstanceMap()->GetInstanceScript())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_NO_INSTANCE_DATA);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
encounterId = atoi(param1);
|
||||
state = atoi(param2);
|
||||
|
||||
// Reject improper values.
|
||||
if (state > TO_BE_DECIDED || encounterId > map->ToInstanceMap()->GetInstanceScript()->GetEncounterCount())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BAD_VALUE);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
map->ToInstanceMap()->GetInstanceScript()->SetBossState(encounterId, (EncounterState)state);
|
||||
handler->PSendSysMessage(LANG_COMMAND_INST_SET_BOSS_STATE, encounterId, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleInstanceGetBossStateCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* param1 = strtok((char*)args, " ");
|
||||
char* param2 = strtok(nullptr, " ");
|
||||
uint32 encounterId = 0;
|
||||
Player* player = nullptr;
|
||||
std::string playerName;
|
||||
|
||||
// Character name must be provided when using this from console.
|
||||
if (!param1 || (!param2 && !handler->GetSession()))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_CMD_SYNTAX);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!param2)
|
||||
player = handler->GetSession()->GetPlayer();
|
||||
else
|
||||
{
|
||||
playerName = param2;
|
||||
if (normalizePlayerName(playerName))
|
||||
player = sObjectAccessor->FindPlayerByName(playerName);
|
||||
}
|
||||
|
||||
if (!player)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Map* map = player->GetMap();
|
||||
if (!map->IsDungeon())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_NOT_DUNGEON);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!map->ToInstanceMap()->GetInstanceScript())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_NO_INSTANCE_DATA);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (encounterId > map->ToInstanceMap()->GetInstanceScript()->GetEncounterCount())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BAD_VALUE);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
encounterId = atoi(param1);
|
||||
|
||||
uint8 state = map->ToInstanceMap()->GetInstanceScript()->GetBossState(encounterId);
|
||||
handler->PSendSysMessage(LANG_COMMAND_INST_GET_BOSS_STATE, encounterId, state);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_instance_commandscript()
|
||||
|
||||
Reference in New Issue
Block a user