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
|
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/
/* ScriptData
Name: quest_commandscript
%Complete: 100
Comment: All quest related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ReputationMgr.h"
#include "ScriptMgr.h"
class quest_commandscript : public CommandScript
{
public:
quest_commandscript() : CommandScript("quest_commandscript") { }
std::vector<ChatCommand> GetCommands() const override
{
static std::vector<ChatCommand> questCommandTable =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleQuestAdd, "" },
{ "complete", SEC_ADMINISTRATOR, false, &HandleQuestComplete, "" },
{ "remove", SEC_ADMINISTRATOR, false, &HandleQuestRemove, "" },
{ "reward", SEC_ADMINISTRATOR, false, &HandleQuestReward, "" },
{ nullptr, SEC_PLAYER, false, nullptr, "" }
};
static std::vector<ChatCommand> commandTable =
{
{ "quest", SEC_ADMINISTRATOR, false, nullptr, "", questCommandTable },
{ nullptr, SEC_PLAYER, false, nullptr, "" }
};
return commandTable;
}
static bool HandleQuestAdd(ChatHandler* handler, const char* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// .addquest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
if (!cId)
return false;
uint32 entry = atol(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
if (!quest)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
// check item starting quest (it can work incorrectly if added without item in inventory)
ItemTemplateContainer const* itc = sObjectMgr->GetItemTemplateStore();
ItemTemplateContainer::const_iterator result = find_if(itc->begin(), itc->end(), Finder<uint32, ItemTemplate>(entry, &ItemTemplate::StartQuest));
if (result != itc->end())
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, result->second.ItemId);
handler->SetSentErrorMessage(true);
return false;
}
// ok, normal (creature/GO starting) quest
if (player->CanAddQuest(quest, true))
player->AddQuestAndCheckCompletion(quest, nullptr);
return true;
}
static bool HandleQuestRemove(ChatHandler* handler, const char* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// .removequest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
if (!cId)
return false;
uint32 entry = atol(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
if (!quest)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
// remove all quest entries for 'entry' from quest log
for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
{
uint32 logQuest = player->GetQuestSlotQuestId(slot);
if (logQuest == entry)
{
player->SetQuestSlot(slot, 0);
// we ignore unequippable quest items in this case, its' still be equipped
player->TakeQuestSourceItem(logQuest, false);
if (quest->HasFlag(QUEST_FLAGS_FLAGS_PVP))
{
player->pvpInfo.IsHostile = player->pvpInfo.IsInHostileArea || player->HasPvPForcingQuest();
player->UpdatePvPState();
}
}
}
player->RemoveRewardedQuest(entry);
player->RemoveActiveQuest(entry, false);
handler->SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
return true;
}
static bool HandleQuestComplete(ChatHandler* handler, const char* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// .quest complete #entry
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
if (!cId)
return false;
uint32 entry = atol(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
// If player doesn't have the quest
if (!quest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
// Add quest items for quests that require items
for (uint8 x = 0; x < QUEST_ITEM_OBJECTIVES_COUNT; ++x)
{
uint32 id = quest->RequiredItemId[x];
uint32 count = quest->RequiredItemCount[x];
if (!id || !count)
continue;
uint32 curItemCount = player->GetItemCount(id, true);
ItemPosCountVec dest;
uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, id, count-curItemCount);
if (msg == EQUIP_ERR_OK)
{
Item* item = player->StoreNewItem(dest, id, true);
player->SendNewItem(item, count-curItemCount, true, false);
}
}
// All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
{
int32 creature = quest->RequiredNpcOrGo[i];
uint32 creatureCount = quest->RequiredNpcOrGoCount[i];
if (creature > 0)
{
if (CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(creature))
for (uint16 z = 0; z < creatureCount; ++z)
player->KilledMonster(creatureInfo, 0);
}
else if (creature < 0)
for (uint16 z = 0; z < creatureCount; ++z)
player->KillCreditGO(creature, 0);
}
// If the quest requires reputation to complete
if (uint32 repFaction = quest->GetRepObjectiveFaction())
{
uint32 repValue = quest->GetRepObjectiveValue();
uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
if (curRep < repValue)
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(repFaction))
player->GetReputationMgr().SetReputation(factionEntry, repValue);
}
// If the quest requires a SECOND reputation to complete
if (uint32 repFaction = quest->GetRepObjectiveFaction2())
{
uint32 repValue2 = quest->GetRepObjectiveValue2();
uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
if (curRep < repValue2)
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(repFaction))
player->GetReputationMgr().SetReputation(factionEntry, repValue2);
}
// If the quest requires money
int32 ReqOrRewMoney = quest->GetRewOrReqMoney();
if (ReqOrRewMoney < 0)
player->ModifyMoney(-ReqOrRewMoney);
player->CompleteQuest(entry);
return true;
}
static bool HandleQuestReward(ChatHandler* handler, char const* args)
{
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
// .quest reward #entry
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
if (!cId)
return false;
uint32 entry = atol(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
// If player doesn't have the quest
if (!quest || player->GetQuestStatus(entry) != QUEST_STATUS_COMPLETE)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
player->RewardQuest(quest, 0, player);
return true;
}
};
void AddSC_quest_commandscript()
{
new quest_commandscript();
}
|