Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
cs_quest.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/* ScriptData
7Name: quest_commandscript
8%Complete: 100
9Comment: All quest related commands
10Category: commandscripts
11EndScriptData */
12
13#include "Chat.h"
14#include "ObjectMgr.h"
15#include "Player.h"
16#include "ReputationMgr.h"
17#include "ScriptMgr.h"
18
20{
21public:
22 quest_commandscript() : CommandScript("quest_commandscript") { }
23
24 std::vector<ChatCommand> GetCommands() const OVERRIDE
25 {
26 static std::vector<ChatCommand> questCommandTable =
27 {
32 };
33 static std::vector<ChatCommand> commandTable =
34 {
35 { "quest", rbac::RBAC_PERM_COMMAND_QUEST, false, NULL, "", questCommandTable },
36 };
37 return commandTable;
38 }
39
40 static bool HandleQuestAdd(ChatHandler* handler, const char* args)
41 {
42 Player* player = handler->getSelectedPlayer();
43 if (!player)
44 {
46 handler->SetSentErrorMessage(true);
47 return false;
48 }
49
50 // .addquest #entry'
51 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
52 char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
53 if (!cId)
54 return false;
55
56 uint32 entry = atol(cId);
57
58 Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
59
60 if (!quest)
61 {
63 handler->SetSentErrorMessage(true);
64 return false;
65 }
66
67 // check item starting quest (it can work incorrectly if added without item in inventory)
68 ItemTemplateContainer const* itc = sObjectMgr->GetItemTemplateStore();
69 ItemTemplateContainer::const_iterator result = find_if(itc->begin(), itc->end(), Finder<uint32, ItemTemplate>(entry, &ItemTemplate::StartQuest));
70
71 if (result != itc->end())
72 {
73 handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, result->second.ItemId);
74 handler->SetSentErrorMessage(true);
75 return false;
76 }
77
78 // ok, normal (creature/GO starting) quest
79 if (player->CanAddQuest(quest, true))
80 {
81 player->AddQuest(quest, NULL);
82
83 if (player->CanCompleteQuest(entry))
84 player->CompleteQuest(entry);
85 }
86
87 return true;
88 }
89
90 static bool HandleQuestRemove(ChatHandler* handler, const char* args)
91 {
92 Player* player = handler->getSelectedPlayer();
93 if (!player)
94 {
96 handler->SetSentErrorMessage(true);
97 return false;
98 }
99
100 // .removequest #entry'
101 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
102 char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
103 if (!cId)
104 return false;
105
106 uint32 entry = atol(cId);
107
108 Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
109
110 if (!quest)
111 {
113 handler->SetSentErrorMessage(true);
114 return false;
115 }
116
117 // remove all quest entries for 'entry' from quest log
118 for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
119 {
120 uint32 logQuest = player->GetQuestSlotQuestId(slot);
121 if (logQuest == entry)
122 {
123 player->SetQuestSlot(slot, 0);
124
125 // we ignore unequippable quest items in this case, its' still be equipped
126 player->TakeQuestSourceItem(logQuest, false);
127
128 if (quest->HasFlag(QUEST_FLAGS_FLAGS_PVP))
129 {
130 player->pvpInfo.IsHostile = player->pvpInfo.IsInHostileArea || player->HasPvPForcingQuest();
131 player->UpdatePvPState();
132 }
133 }
134 }
135
136 player->RemoveActiveQuest(entry);
137 player->RemoveRewardedQuest(entry);
138
140 return true;
141 }
142
143 static bool HandleQuestComplete(ChatHandler* handler, const char* args)
144 {
145 Player* player = handler->getSelectedPlayer();
146 if (!player)
147 {
149 handler->SetSentErrorMessage(true);
150 return false;
151 }
152
153 // .quest complete #entry
154 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
155 char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
156 if (!cId)
157 return false;
158
159 uint32 entry = atol(cId);
160
161 Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
162
163 // If player doesn't have the quest
164 if (!quest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
165 {
167 handler->SetSentErrorMessage(true);
168 return false;
169 }
170
171 for (QuestObjectiveSet::const_iterator citr = quest->m_questObjectives.begin(); citr != quest->m_questObjectives.end(); ++citr)
172 {
173 QuestObjective const* questObjective = *citr;
174 switch (questObjective->Type)
175 {
177 {
178 if (CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(questObjective->ObjectId))
179 for (uint32 i = 0; i < uint32(questObjective->Amount); i++)
180 player->KilledMonster(creatureInfo, 0);
181
182 break;
183 }
185 {
186 if (CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(questObjective->ObjectId))
187 for (uint32 i = 0; i < uint32(questObjective->Amount); i++)
188 player->KillCreditGO(questObjective->ObjectId, 0);
189
190 break;
191 }
193 {
194 ItemPosCountVec dest;
195 uint32 currentCounter = player->GetItemCount(questObjective->ObjectId, true);
196
197 uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, questObjective->ObjectId, uint32(questObjective->Amount) - currentCounter);
198 if (msg == EQUIP_ERR_OK)
199 {
200 Item* item = player->StoreNewItem(dest, questObjective->ObjectId, true);
201 player->SendNewItem(item, uint32(questObjective->Amount) - currentCounter, true, false);
202 }
203
204 player->SendQuestUpdateAddCredit(quest, questObjective, ObjectGuid(0), currentCounter, uint32(questObjective->Amount) - currentCounter);
205
206 break;
207 }
210 {
211 if (player->GetReputationMgr().GetReputation(questObjective->ObjectId) < questObjective->Amount)
212 if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(questObjective->ObjectId))
213 player->GetReputationMgr().SetReputation(factionEntry, questObjective->Amount);
214
215 break;
216 }
218 {
219 player->ModifyMoney(uint64(questObjective->Amount));
220 break;
221 }
222 default:
223 break;
224 }
225
226 //player->SendQuestUpdateAddCredit();
227 }
228
229 player->CompleteQuest(entry);
230 return true;
231 }
232
233 static bool HandleQuestReward(ChatHandler* handler, char const* args)
234 {
235 Player* player = handler->getSelectedPlayer();
236 if (!player)
237 {
239 handler->SetSentErrorMessage(true);
240 return false;
241 }
242
243 // .quest reward #entry
244 // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
245 char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
246 if (!cId)
247 return false;
248
249 uint32 entry = atol(cId);
250
251 Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
252
253 // If player doesn't have the quest
254 if (!quest || player->GetQuestStatus(entry) != QUEST_STATUS_COMPLETE)
255 {
257 handler->SetSentErrorMessage(true);
258 return false;
259 }
260
261 player->RewardQuest(quest, 0, player);
262 return true;
263 }
264};
265
DBCStorage< FactionEntry > sFactionStore(FactionEntryfmt)
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
std::uint64_t uint64
Definition Define.h:76
@ EQUIP_ERR_OK
Definition Item.h:28
UNORDERED_MAP< uint32, ItemTemplate > ItemTemplateContainer
@ LANG_COMMAND_QUEST_STARTFROMITEM
Definition Language.h:453
@ LANG_COMMAND_QUEST_REMOVED
Definition Language.h:454
@ LANG_NO_CHAR_SELECTED
Definition Language.h:118
@ LANG_COMMAND_QUEST_NOTFOUND
Definition Language.h:452
#define sObjectMgr
Definition ObjectMgr.h:1617
std::vector< ItemPosCount > ItemPosCountVec
Definition Player.h:777
@ QUEST_OBJECTIVE_TYPE_FACTION_REP2
Definition QuestDef.h:200
@ QUEST_OBJECTIVE_TYPE_ITEM
Definition QuestDef.h:194
@ QUEST_OBJECTIVE_TYPE_NPC
Definition QuestDef.h:193
@ QUEST_OBJECTIVE_TYPE_FACTION_REP
Definition QuestDef.h:199
@ QUEST_OBJECTIVE_TYPE_MONEY
Definition QuestDef.h:201
@ QUEST_OBJECTIVE_TYPE_GO
Definition QuestDef.h:195
@ QUEST_FLAGS_FLAGS_PVP
Definition QuestDef.h:128
#define MAX_QUEST_LOG_SIZE
Definition QuestDef.h:22
@ QUEST_STATUS_NONE
Definition QuestDef.h:86
@ QUEST_STATUS_COMPLETE
Definition QuestDef.h:87
@ NULL_BAG
Definition Unit.h:336
@ NULL_SLOT
Definition Unit.h:337
Player * getSelectedPlayer()
Definition Chat.cpp:829
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition Chat.cpp:873
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition Chat.cpp:221
void SetSentErrorMessage(bool val)
Definition Chat.h:114
virtual void SendSysMessage(const char *str)
Definition Chat.cpp:153
CommandScript(const char *name)
Definition Item.h:202
void RewardQuest(Quest const *quest, uint32 reward, Object *questGiver, bool announce=true)
bool HasPvPForcingQuest() const
bool ModifyMoney(int64 amount, bool sendError=true)
Definition Player.cpp:18342
void KilledMonster(CreatureTemplate const *cInfo, uint64 guid)
void UpdatePvPState(bool onlyFFA=false)
Definition Player.cpp:17441
bool CanCompleteQuest(uint32 quest_id)
void AddQuest(Quest const *quest, Object *questGiver)
void KillCreditGO(uint32 entry, uint64 guid=0)
bool CanAddQuest(Quest const *quest, bool msg)
void RemoveRewardedQuest(uint32 quest_id)
void CompleteQuest(uint32 quest_id)
uint32 GetQuestSlotQuestId(uint16 slot) const
uint32 GetItemCount(uint32 item, bool inBankAlso=false, Item *skipItem=NULL) const
void SetQuestSlot(uint16 slot, uint32 quest_id, uint32 timer=0)
void SendQuestUpdateAddCredit(Quest const *quest, QuestObjective const *objective, ObjectGuid guid, uint16 oldCount, uint16 addCount)
InventoryResult CanStoreNewItem(uint8 bag, uint8 slot, ItemPosCountVec &dest, uint32 item, uint32 count, uint32 *no_space_count=NULL) const
PvPInfo pvpInfo
Definition Player.h:2233
bool TakeQuestSourceItem(uint32 questId, bool msg)
QuestStatus GetQuestStatus(uint32 quest_id) const
void RemoveActiveQuest(uint32 quest_id)
Item * StoreNewItem(ItemPosCountVec const &pos, uint32 item, bool update, int32 randomPropertyId=0, AllowedLooterSet const &allowedLooters=AllowedLooterSet())
void SendNewItem(Item *item, uint32 count, bool received, bool created, bool broadcast=false)
Definition Player.cpp:11604
ReputationMgr & GetReputationMgr()
Definition Player.h:2555
bool HasFlag(uint32 flag) const
Definition QuestDef.h:261
QuestObjectiveSet m_questObjectives
Definition QuestDef.h:378
int32 GetReputation(uint32 faction_id) const
bool SetReputation(FactionEntry const *factionEntry, int32 standing)
static bool HandleQuestComplete(ChatHandler *handler, const char *args)
Definition cs_quest.cpp:143
static bool HandleQuestAdd(ChatHandler *handler, const char *args)
Definition cs_quest.cpp:40
std::vector< ChatCommand > GetCommands() const OVERRIDE
Definition cs_quest.cpp:24
static bool HandleQuestRemove(ChatHandler *handler, const char *args)
Definition cs_quest.cpp:90
static bool HandleQuestReward(ChatHandler *handler, char const *args)
Definition cs_quest.cpp:233
void AddSC_quest_commandscript()
Definition cs_quest.cpp:266
@ RBAC_PERM_COMMAND_QUEST_REMOVE
Definition RBAC.h:493
@ RBAC_PERM_COMMAND_QUEST_REWARD
Definition RBAC.h:494
@ RBAC_PERM_COMMAND_QUEST
Definition RBAC.h:490
@ RBAC_PERM_COMMAND_QUEST_COMPLETE
Definition RBAC.h:492
@ RBAC_PERM_COMMAND_QUEST_ADD
Definition RBAC.h:491
Definition Util.h:20
bool IsHostile
Definition Player.h:446
bool IsInHostileArea
Definition Player.h:447
uint32 ObjectId
Definition QuestDef.h:242