diff options
| author | ShinDarth <borzifrancesco@gmail.com> | 2016-08-10 20:00:40 +0200 |
|---|---|---|
| committer | ShinDarth <borzifrancesco@gmail.com> | 2016-08-10 20:00:40 +0200 |
| commit | 2ba9f6f17b28dcf8b9214533a13183e6fa57a2db (patch) | |
| tree | 09377f178bc9658e4d4190e38dfcdb5d22661cac /src | |
| parent | f2dfe2b8e362299ba7fb08f92d5a648b14cc1513 (diff) | |
Script/Commands: imported .instance get/setbossstate commands from TrinityCore
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/game/Instances/InstanceScript.cpp | 22 | ||||
| -rw-r--r-- | src/server/game/Instances/InstanceScript.h | 3 | ||||
| -rw-r--r-- | src/server/scripts/Commands/cs_instance.cpp | 137 |
3 files changed, 162 insertions, 0 deletions
diff --git a/src/server/game/Instances/InstanceScript.cpp b/src/server/game/Instances/InstanceScript.cpp index ff3f756222..898e9a3db0 100644 --- a/src/server/game/Instances/InstanceScript.cpp +++ b/src/server/game/Instances/InstanceScript.cpp @@ -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"; + } +} diff --git a/src/server/game/Instances/InstanceScript.h b/src/server/game/Instances/InstanceScript.h index 4fe0d52cc3..d90dd90251 100644 --- a/src/server/game/Instances/InstanceScript.h +++ b/src/server/game/Instances/InstanceScript.h @@ -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); diff --git a/src/server/scripts/Commands/cs_instance.cpp b/src/server/scripts/Commands/cs_instance.cpp index 9c36e5bfb3..183d395e0f 100644 --- a/src/server/scripts/Commands/cs_instance.cpp +++ b/src/server/scripts/Commands/cs_instance.cpp @@ -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() |
