1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
/*
* 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: quest_commandscript
%Complete: 100
Comment: All quest related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "Chat.h"
#include "ChatCommand.h"
#include "DatabaseEnv.h"
#include "DB2Stores.h"
#include "DisableMgr.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "RBAC.h"
#include "ReputationMgr.h"
#include "World.h"
using namespace Trinity::ChatCommands;
class quest_commandscript : public CommandScript
{
public:
quest_commandscript() : CommandScript("quest_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable objectiveCommandTable =
{
{ "complete", HandleQuestObjectiveComplete, rbac::RBAC_PERM_COMMAND_QUEST_OBJECTIVE_COMPLETE, Console::No }
};
static ChatCommandTable questCommandTable =
{
{ "add", HandleQuestAdd, rbac::RBAC_PERM_COMMAND_QUEST_ADD, Console::No },
{ "complete", HandleQuestComplete, rbac::RBAC_PERM_COMMAND_QUEST_COMPLETE, Console::No },
{ "objective", objectiveCommandTable },
{ "remove", HandleQuestRemove, rbac::RBAC_PERM_COMMAND_QUEST_REMOVE, Console::No },
{ "reward", HandleQuestReward, rbac::RBAC_PERM_COMMAND_QUEST_REWARD, Console::No },
};
static ChatCommandTable commandTable =
{
{ "quest", questCommandTable }
};
return commandTable;
}
static bool HandleQuestAdd(ChatHandler* handler, Quest const* quest)
{
Player* player = handler->getSelectedPlayerOrSelf();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
if (DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, quest->GetQuestId(), nullptr))
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, quest->GetQuestId());
handler->SetSentErrorMessage(true);
return false;
}
// check item starting quest (it can work incorrectly if added without item in inventory)
ItemTemplateContainer const& itc = sObjectMgr->GetItemTemplateStore();
auto itr = std::find_if(std::begin(itc), std::end(itc), [quest](ItemTemplateContainer::value_type const& value)
{
return value.second.GetStartQuest() == quest->GetQuestId();
});
if (itr != std::end(itc))
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, quest->GetQuestId(), itr->first);
handler->SetSentErrorMessage(true);
return false;
}
if (player->IsActiveQuest(quest->GetQuestId()))
return false;
// ok, normal (creature/GO starting) quest
if (player->CanAddQuest(quest, true))
player->AddQuestAndCheckCompletion(quest, nullptr);
return true;
}
static bool HandleQuestRemove(ChatHandler* handler, Quest const* quest)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
QuestStatus oldStatus = player->GetQuestStatus(quest->GetQuestId());
if (oldStatus != QUEST_STATUS_NONE)
{
player->RemoveActiveQuest(quest->GetQuestId(), false);
// remove all quest entries for 'entry' from quest log
if (oldStatus != QUEST_STATUS_REWARDED)
{
// we ignore unequippable quest items in this case, its' still be equipped
player->TakeQuestSourceItem(quest->GetQuestId(), false);
if (quest->HasFlag(QUEST_FLAGS_FLAGS_PVP))
{
player->pvpInfo.IsHostile = player->pvpInfo.IsInHostileArea || player->HasPvPForcingQuest();
player->UpdatePvPState();
}
}
player->RemoveRewardedQuest(quest->GetQuestId());
player->DespawnPersonalSummonsForQuest(quest->GetQuestId());
sScriptMgr->OnQuestStatusChange(player, quest->GetQuestId());
sScriptMgr->OnQuestStatusChange(player, quest, oldStatus, QUEST_STATUS_NONE);
handler->SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
return true;
}
else
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, quest->GetQuestId());
handler->SetSentErrorMessage(true);
return false;
}
}
static void CompleteObjective(Player* player, QuestObjective const& obj)
{
switch (obj.Type)
{
case QUEST_OBJECTIVE_ITEM:
{
uint32 curItemCount = player->GetItemCount(obj.ObjectID, true);
ItemPosCountVec dest;
uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, obj.ObjectID, obj.Amount - curItemCount);
if (msg == EQUIP_ERR_OK)
{
Item* item = player->StoreNewItem(dest, obj.ObjectID, true);
player->SendNewItem(item, obj.Amount - curItemCount, true, false);
}
break;
}
case QUEST_OBJECTIVE_CURRENCY:
{
player->ModifyCurrency(obj.ObjectID, obj.Amount, CurrencyGainSource::Cheat);
break;
}
case QUEST_OBJECTIVE_MIN_REPUTATION:
{
uint32 curRep = player->GetReputationMgr().GetReputation(obj.ObjectID);
if (curRep < uint32(obj.Amount))
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(obj.ObjectID))
player->GetReputationMgr().SetReputation(factionEntry, obj.Amount);
break;
}
case QUEST_OBJECTIVE_MAX_REPUTATION:
{
uint32 curRep = player->GetReputationMgr().GetReputation(obj.ObjectID);
if (curRep > uint32(obj.Amount))
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(obj.ObjectID))
player->GetReputationMgr().SetReputation(factionEntry, obj.Amount);
break;
}
case QUEST_OBJECTIVE_MONEY:
{
player->ModifyMoney(obj.Amount);
break;
}
case QUEST_OBJECTIVE_PROGRESS_BAR:
// do nothing
break;
default:
player->UpdateQuestObjectiveProgress(static_cast<QuestObjectiveType>(obj.Type), obj.ObjectID, obj.Amount);
break;
}
}
static bool HandleQuestComplete(ChatHandler* handler, Quest const* quest)
{
Player* player = handler->getSelectedPlayerOrSelf();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// If player doesn't have the quest
if ((player->GetQuestStatus(quest->GetQuestId()) == QUEST_STATUS_NONE && !quest->HasFlag(QUEST_FLAGS_TRACKING_EVENT))
|| DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, quest->GetQuestId(), nullptr))
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, quest->GetQuestId());
handler->SetSentErrorMessage(true);
return false;
}
for (QuestObjective const& obj : quest->Objectives)
CompleteObjective(player, obj);
if (sWorld->getBoolConfig(CONFIG_QUEST_ENABLE_QUEST_TRACKER)) // check if Quest Tracker is enabled
{
// prepare Quest Tracker datas
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_QUEST_TRACK_GM_COMPLETE);
stmt->setUInt32(0, quest->GetQuestId());
stmt->setUInt64(1, player->GetGUID().GetCounter());
// add to Quest Tracker
CharacterDatabase.Execute(stmt);
}
player->CompleteQuest(quest->GetQuestId());
return true;
}
static bool HandleQuestObjectiveComplete(ChatHandler* handler, uint32 objectiveId)
{
Player* player = handler->getSelectedPlayerOrSelf();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
QuestObjective const* obj = sObjectMgr->GetQuestObjective(objectiveId);
if (!obj)
{
handler->SendSysMessage(LANG_COMMAND_QUEST_OBJECTIVE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
CompleteObjective(player, *obj);
return true;
}
static bool HandleQuestReward(ChatHandler* handler, Quest const* quest)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// If player doesn't have the quest
if (player->GetQuestStatus(quest->GetQuestId()) != QUEST_STATUS_COMPLETE
|| DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, quest->GetQuestId(), nullptr))
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, quest->GetQuestId());
handler->SetSentErrorMessage(true);
return false;
}
player->RewardQuest(quest, LootItemType::Item, 0, player);
return true;
}
};
void AddSC_quest_commandscript()
{
new quest_commandscript();
}
|