mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
Script/Commands: imported .instance get/setbossstate commands from TrinityCore
This commit is contained in:
File diff suppressed because one or more lines are too long
3
data/sql/updates/world/2016_08_10_01.sql
Normal file
3
data/sql/updates/world/2016_08_10_01.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
INSERT IGNORE INTO `command` (`name`, `security`, `help`) VALUES
|
||||
('instance setbossstate', 2, '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', 2, '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.');
|
||||
@@ -446,3 +446,25 @@ void InstanceScript::SendEncounterUnit(uint32 type, Unit* unit /*= NULL*/, uint8
|
||||
|
||||
instance->SendToPlayers(&data);
|
||||
}
|
||||
|
||||
std::string InstanceScript::GetBossStateName(uint8 state)
|
||||
{
|
||||
// See enum EncounterState in InstanceScript.h
|
||||
switch (state)
|
||||
{
|
||||
case NOT_STARTED:
|
||||
return "NOT_STARTED";
|
||||
case IN_PROGRESS:
|
||||
return "IN_PROGRESS";
|
||||
case FAIL:
|
||||
return "FAIL";
|
||||
case DONE:
|
||||
return "DONE";
|
||||
case SPECIAL:
|
||||
return "SPECIAL";
|
||||
case TO_BE_DECIDED:
|
||||
return "TO_BE_DECIDED";
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +197,7 @@ class InstanceScript : public ZoneScript
|
||||
|
||||
virtual bool SetBossState(uint32 id, EncounterState state);
|
||||
EncounterState GetBossState(uint32 id) const { return id < bosses.size() ? bosses[id].state : TO_BE_DECIDED; }
|
||||
static std::string GetBossStateName(uint8 state);
|
||||
BossBoundaryMap const* GetBossBoundary(uint32 id) const { return id < bosses.size() ? &bosses[id].boundary : NULL; }
|
||||
BossInfo const* GetBossInfo(uint32 id) const { return &bosses[id]; }
|
||||
|
||||
@@ -216,6 +217,8 @@ class InstanceScript : public ZoneScript
|
||||
|
||||
virtual void FillInitialWorldStates(WorldPacket& /*data*/) {}
|
||||
|
||||
uint32 GetEncounterCount() const { return bosses.size(); }
|
||||
|
||||
protected:
|
||||
void SetBossNumber(uint32 number) { bosses.resize(number); }
|
||||
void LoadDoorData(DoorData const* data);
|
||||
|
||||
@@ -29,6 +29,7 @@ EndScriptData */
|
||||
#include "InstanceScript.h"
|
||||
#include "MapManager.h"
|
||||
#include "Player.h"
|
||||
#include "Language.h"
|
||||
|
||||
class instance_commandscript : public CommandScript
|
||||
{
|
||||
@@ -43,6 +44,8 @@ public:
|
||||
{ "unbind", SEC_ADMINISTRATOR, false, &HandleInstanceUnbindCommand, "", NULL },
|
||||
{ "stats", SEC_ADMINISTRATOR, true, &HandleInstanceStatsCommand, "", NULL },
|
||||
{ "savedata", SEC_ADMINISTRATOR, false, &HandleInstanceSaveDataCommand, "", NULL },
|
||||
{ "setbossstate", SEC_GAMEMASTER, true, &HandleInstanceSetBossStateCommand, "", NULL },
|
||||
{ "getbossstate", SEC_GAMEMASTER, true, &HandleInstanceGetBossStateCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
@@ -176,6 +179,140 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleInstanceSetBossStateCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* param1 = strtok((char*)args, " ");
|
||||
char* param2 = strtok(NULL, " ");
|
||||
char* param3 = strtok(NULL, " ");
|
||||
uint32 encounterId = 0;
|
||||
int32 state = 0;
|
||||
Player* player = NULL;
|
||||
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 = ObjectAccessor::FindPlayerByName(playerName);
|
||||
}
|
||||
|
||||
if (!player)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
InstanceMap* map = player->GetMap()->ToInstanceMap();
|
||||
if (!map)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_NOT_DUNGEON);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!map->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->GetInstanceScript()->GetEncounterCount())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BAD_VALUE);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
map->GetInstanceScript()->SetBossState(encounterId, EncounterState(state));
|
||||
std::string stateName = InstanceScript::GetBossStateName(state);
|
||||
handler->PSendSysMessage(LANG_COMMAND_INST_SET_BOSS_STATE, encounterId, state, stateName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleInstanceGetBossStateCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* param1 = strtok((char*)args, " ");
|
||||
char* param2 = strtok(NULL, " ");
|
||||
uint32 encounterId = 0;
|
||||
Player* player = NULL;
|
||||
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 = ObjectAccessor::FindPlayerByName(playerName);
|
||||
}
|
||||
|
||||
if (!player)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
InstanceMap* map = player->GetMap()->ToInstanceMap();
|
||||
if (!map)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_NOT_DUNGEON);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!map->GetInstanceScript())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_NO_INSTANCE_DATA);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
encounterId = atoi(param1);
|
||||
|
||||
if (encounterId > map->GetInstanceScript()->GetEncounterCount())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_BAD_VALUE);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 state = map->GetInstanceScript()->GetBossState(encounterId);
|
||||
std::string stateName = InstanceScript::GetBossStateName(state);
|
||||
handler->PSendSysMessage(LANG_COMMAND_INST_GET_BOSS_STATE, encounterId, state, stateName.c_str());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_instance_commandscript()
|
||||
|
||||
Reference in New Issue
Block a user