TrinityCore
cs_scene.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "ScriptMgr.h"
19#include "Chat.h"
20#include "ChatCommand.h"
21#include "DB2Stores.h"
22#include "Language.h"
23#include "ObjectMgr.h"
24#include "Player.h"
25#include "RBAC.h"
26#include "WorldSession.h"
27
28using namespace Trinity::ChatCommands;
29
31{
32public:
33 scene_commandscript() : CommandScript("scene_commandscript") { }
34
36 {
37 static ChatCommandTable sceneCommandTable =
38 {
43 };
44 static ChatCommandTable commandTable =
45 {
46 { "scene", sceneCommandTable }
47 };
48 return commandTable;
49 }
50
52 {
53 if (Player* player = handler->GetSession()->GetPlayer())
54 {
55 player->GetSceneMgr().ToggleDebugSceneMode();
56 handler->PSendSysMessage(player->GetSceneMgr().IsInDebugSceneMode() ? LANG_COMMAND_SCENE_DEBUG_ON : LANG_COMMAND_SCENE_DEBUG_OFF);
57 }
58
59 return true;
60 }
61
62 static bool HandlePlaySceneCommand(ChatHandler* handler, uint32 sceneId)
63 {
64 Player* target = handler->getSelectedPlayerOrSelf();
65
66 if (!target)
67 {
69 handler->SetSentErrorMessage(true);
70 return false;
71 }
72
73 if (!sObjectMgr->GetSceneTemplate(sceneId))
74 return false;
75
76 target->GetSceneMgr().PlayScene(sceneId);
77 return true;
78 }
79
80 static bool HandlePlayScenePackageCommand(ChatHandler* handler, uint32 sceneScriptPackageId, Optional<uint32> flags)
81 {
82 Player* target = handler->getSelectedPlayerOrSelf();
83
84 if (!target)
85 {
87 handler->SetSentErrorMessage(true);
88 return false;
89 }
90
91 if (!sSceneScriptPackageStore.HasRecord(sceneScriptPackageId))
92 return false;
93
94 target->GetSceneMgr().PlaySceneByPackageId(sceneScriptPackageId, static_cast<SceneFlag>(flags.value_or(0)));
95 return true;
96 }
97
98 static bool HandleCancelSceneCommand(ChatHandler* handler, uint32 sceneScriptPackageId)
99 {
100 Player* target = handler->getSelectedPlayerOrSelf();
101
102 if (!target)
103 {
105 handler->SetSentErrorMessage(true);
106 return false;
107 }
108
109 if (!sSceneScriptPackageStore.HasRecord(sceneScriptPackageId))
110 return false;
111
112 target->GetSceneMgr().CancelSceneByPackageId(sceneScriptPackageId);
113 return true;
114 }
115};
116
118{
120}
DB2Storage< SceneScriptPackageEntry > sSceneScriptPackageStore("SceneScriptPackage.db2", &SceneScriptPackageLoadInfo::Instance)
uint32_t uint32
Definition: Define.h:142
uint16 flags
Definition: DisableMgr.cpp:49
@ LANG_COMMAND_SCENE_DEBUG_ON
Definition: Language.h:1124
@ LANG_PLAYER_NOT_FOUND
Definition: Language.h:567
@ LANG_COMMAND_SCENE_DEBUG_OFF
Definition: Language.h:1125
#define sObjectMgr
Definition: ObjectMgr.h:1946
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
Role Based Access Control related classes definition.
SceneFlag
Definition: SceneDefines.h:25
Player * getSelectedPlayerOrSelf()
Definition: Chat.cpp:244
WorldSession * GetSession()
Definition: Chat.h:42
void PSendSysMessage(const char *fmt, Args &&... args)
Definition: Chat.h:57
void SetSentErrorMessage(bool val)
Definition: Chat.h:114
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:113
SceneMgr & GetSceneMgr()
Definition: Player.h:2715
void CancelSceneByPackageId(uint32 sceneScriptPackageId)
Definition: SceneMgr.cpp:190
uint32 PlaySceneByPackageId(uint32 sceneScriptPackageId, EnumFlag< SceneFlag > playbackflags, Position const *position=nullptr)
Definition: SceneMgr.cpp:83
uint32 PlayScene(uint32 sceneId, Position const *position=nullptr)
Definition: SceneMgr.cpp:36
Player * GetPlayer() const
static bool HandlePlayScenePackageCommand(ChatHandler *handler, uint32 sceneScriptPackageId, Optional< uint32 > flags)
Definition: cs_scene.cpp:80
static bool HandleDebugSceneCommand(ChatHandler *handler)
Definition: cs_scene.cpp:51
static bool HandlePlaySceneCommand(ChatHandler *handler, uint32 sceneId)
Definition: cs_scene.cpp:62
static bool HandleCancelSceneCommand(ChatHandler *handler, uint32 sceneScriptPackageId)
Definition: cs_scene.cpp:98
ChatCommandTable GetCommands() const override
Definition: cs_scene.cpp:35
void AddSC_scene_commandscript()
Definition: cs_scene.cpp:117
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
@ RBAC_PERM_COMMAND_SCENE_PLAY_PACKAGE
Definition: RBAC.h:718
@ RBAC_PERM_COMMAND_SCENE_DEBUG
Definition: RBAC.h:716
@ RBAC_PERM_COMMAND_SCENE_CANCEL
Definition: RBAC.h:719
@ RBAC_PERM_COMMAND_SCENE_PLAY
Definition: RBAC.h:717