TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
quest_commandscript Class Reference

Public Member Functions

 quest_commandscript ()
 
std::vector< ChatCommandGetCommands () const override
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

Static Public Member Functions

static bool HandleQuestAdd (ChatHandler *handler, const char *args)
 
static bool HandleQuestRemove (ChatHandler *handler, const char *args)
 
static bool HandleQuestComplete (ChatHandler *handler, const char *args)
 
static bool HandleQuestReward (ChatHandler *handler, char const *args)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()
 

Constructor & Destructor Documentation

quest_commandscript::quest_commandscript ( )
inline
34 : CommandScript("quest_commandscript") { }
CommandScript(const char *name)
Definition: ScriptMgr.cpp:1616

Member Function Documentation

std::vector<ChatCommand> quest_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

37  {
38  static std::vector<ChatCommand> questCommandTable =
39  {
40  { "add", rbac::RBAC_PERM_COMMAND_QUEST_ADD, false, &HandleQuestAdd, "" },
44  };
45  static std::vector<ChatCommand> commandTable =
46  {
47  { "quest", rbac::RBAC_PERM_COMMAND_QUEST, false, NULL, "", questCommandTable },
48  };
49  return commandTable;
50  }
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleQuestComplete(ChatHandler *handler, const char *args)
Definition: cs_quest.cpp:153
static bool HandleQuestReward(ChatHandler *handler, char const *args)
Definition: cs_quest.cpp:251
Definition: RBAC.h:510
Definition: RBAC.h:509
static bool HandleQuestRemove(ChatHandler *handler, const char *args)
Definition: cs_quest.cpp:100
static bool HandleQuestAdd(ChatHandler *handler, const char *args)
Definition: cs_quest.cpp:52

+ Here is the call graph for this function:

static bool quest_commandscript::HandleQuestAdd ( ChatHandler handler,
const char *  args 
)
inlinestatic
53  {
54  Player* player = handler->getSelectedPlayerOrSelf();
55  if (!player)
56  {
58  handler->SetSentErrorMessage(true);
59  return false;
60  }
61 
62  // .addquest #entry'
63  // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
64  char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
65  if (!cId)
66  return false;
67 
68  uint32 entry = atoul(cId);
69 
70  Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
71 
72  if (!quest)
73  {
75  handler->SetSentErrorMessage(true);
76  return false;
77  }
78 
79  // check item starting quest (it can work incorrectly if added without item in inventory)
80  ItemTemplateContainer const* itc = sObjectMgr->GetItemTemplateStore();
81  ItemTemplateContainer::const_iterator result = std::find_if(itc->begin(), itc->end(), [quest](ItemTemplateContainer::value_type const& value)
82  {
83  return value.second.GetStartQuest() == quest->GetQuestId();
84  });
85 
86  if (result != itc->end())
87  {
88  handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, result->second.GetId());
89  handler->SetSentErrorMessage(true);
90  return false;
91  }
92 
93  // ok, normal (creature/GO starting) quest
94  if (player->CanAddQuest(quest, true))
95  player->AddQuestAndCheckCompletion(quest, NULL);
96 
97  return true;
98  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: QuestDef.h:279
arena_t NULL
Definition: jemalloc_internal.h:624
Player * getSelectedPlayerOrSelf()
Definition: Chat.cpp:623
Definition: Language.h:140
#define sObjectMgr
Definition: ObjectMgr.h:1567
unsigned long atoul(char const *str)
Definition: Common.h:90
uint32 GetQuestId() const
Definition: QuestDef.h:304
uint32_t uint32
Definition: Define.h:150
Definition: Language.h:474
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
const FieldDescriptor value
Definition: descriptor.h:1522
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641
std::unordered_map< uint32, ItemTemplate > ItemTemplateContainer
Definition: ItemTemplate.h:769
Definition: Language.h:475

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool quest_commandscript::HandleQuestComplete ( ChatHandler handler,
const char *  args 
)
inlinestatic
154  {
155  Player* player = handler->getSelectedPlayerOrSelf();
156  if (!player)
157  {
159  handler->SetSentErrorMessage(true);
160  return false;
161  }
162 
163  // .quest complete #entry
164  // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
165  char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
166  if (!cId)
167  return false;
168 
169  uint32 entry = atoul(cId);
170 
171  Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
172 
173  // If player doesn't have the quest
174  if (!quest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
175  {
177  handler->SetSentErrorMessage(true);
178  return false;
179  }
180 
181  for (uint32 i = 0; i < quest->Objectives.size(); ++i)
182  {
183  QuestObjective const& obj = quest->Objectives[i];
184 
185  switch (obj.Type)
186  {
188  {
189  uint32 curItemCount = player->GetItemCount(obj.ObjectID, true);
190  ItemPosCountVec dest;
191  uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, obj.ObjectID, obj.Amount - curItemCount);
192  if (msg == EQUIP_ERR_OK)
193  {
194  Item* item = player->StoreNewItem(dest, obj.ObjectID, true);
195  player->SendNewItem(item, obj.Amount - curItemCount, true, false);
196  }
197  break;
198  }
200  {
201  if (CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(obj.ObjectID))
202  for (uint16 z = 0; z < obj.Amount; ++z)
203  player->KilledMonster(creatureInfo, ObjectGuid::Empty);
204  break;
205  }
207  {
208  for (uint16 z = 0; z < obj.Amount; ++z)
209  player->KillCreditGO(obj.ObjectID);
210  break;
211  }
213  {
214  uint32 curRep = player->GetReputationMgr().GetReputation(obj.ObjectID);
215  if (curRep < uint32(obj.Amount))
216  if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(obj.ObjectID))
217  player->GetReputationMgr().SetReputation(factionEntry, obj.Amount);
218  break;
219  }
221  {
222  uint32 curRep = player->GetReputationMgr().GetReputation(obj.ObjectID);
223  if (curRep > uint32(obj.Amount))
224  if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(obj.ObjectID))
225  player->GetReputationMgr().SetReputation(factionEntry, obj.Amount);
226  break;
227  }
229  {
230  player->ModifyMoney(obj.Amount);
231  break;
232  }
233  }
234  }
235 
236  if (sWorld->getBoolConfig(CONFIG_QUEST_ENABLE_QUEST_TRACKER)) // check if Quest Tracker is enabled
237  {
238  // prepare Quest Tracker datas
240  stmt->setUInt32(0, quest->GetQuestId());
241  stmt->setUInt64(1, player->GetGUID().GetCounter());
242 
243  // add to Quest Tracker
245  }
246 
247  player->CompleteQuest(entry);
248  return true;
249  }
Definition: QuestDef.h:226
Definition: CharacterDatabase.h:577
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Definition: QuestDef.h:221
Definition: QuestDef.h:279
Definition: Unit.h:379
Definition: QuestDef.h:261
Player * getSelectedPlayerOrSelf()
Definition: Chat.cpp:623
#define sWorld
Definition: World.h:887
Definition: Language.h:140
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: PreparedStatement.h:74
Definition: QuestDef.h:110
uint8 Type
Definition: QuestDef.h:264
Definition: World.h:165
Definition: QuestDef.h:228
Definition: Item.h:48
Definition: Unit.h:378
unsigned long atoul(char const *str)
Definition: Common.h:90
Definition: QuestDef.h:220
uint32 GetQuestId() const
Definition: QuestDef.h:304
G3D::int16 z
Definition: Vector3int16.h:46
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: QuestDef.h:227
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
int32 ObjectID
Definition: QuestDef.h:266
Definition: DBCStructure.h:405
Definition: Language.h:474
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
uint8_t uint8
Definition: Define.h:152
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
DBCStorage< FactionEntry > sFactionStore(Factionfmt)
uint32_t uint32
Definition: g3dmath.h:168
Definition: QuestDef.h:222
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641
int32 Amount
Definition: QuestDef.h:267
Definition: Creature.h:79
QuestObjectives Objectives
Definition: QuestDef.h:454

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool quest_commandscript::HandleQuestRemove ( ChatHandler handler,
const char *  args 
)
inlinestatic
101  {
102  Player* player = handler->getSelectedPlayer();
103  if (!player)
104  {
106  handler->SetSentErrorMessage(true);
107  return false;
108  }
109 
110  // .removequest #entry'
111  // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
112  char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
113  if (!cId)
114  return false;
115 
116  uint32 entry = atoul(cId);
117 
118  Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
119 
120  if (!quest)
121  {
123  handler->SetSentErrorMessage(true);
124  return false;
125  }
126 
127  // remove all quest entries for 'entry' from quest log
128  for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
129  {
130  uint32 logQuest = player->GetQuestSlotQuestId(slot);
131  if (logQuest == entry)
132  {
133  player->SetQuestSlot(slot, 0);
134 
135  // we ignore unequippable quest items in this case, its' still be equipped
136  player->TakeQuestSourceItem(logQuest, false);
137 
138  if (quest->HasFlag(QUEST_FLAGS_FLAGS_PVP))
139  {
140  player->pvpInfo.IsHostile = player->pvpInfo.IsInHostileArea || player->HasPvPForcingQuest();
141  player->UpdatePvPState();
142  }
143  }
144  }
145 
146  player->RemoveActiveQuest(entry, false);
147  player->RemoveRewardedQuest(entry);
148 
150  return true;
151  }
Definition: Language.h:476
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: QuestDef.h:279
#define MAX_QUEST_LOG_SIZE
Definition: QuestDef.h:43
Definition: Language.h:140
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: QuestDef.h:155
unsigned long atoul(char const *str)
Definition: Common.h:90
uint32_t uint32
Definition: Define.h:150
Player * getSelectedPlayer()
Definition: Chat.cpp:579
Definition: Language.h:474
bool HasFlag(uint32 flag) const
Definition: QuestDef.h:297
uint8_t uint8
Definition: Define.h:152
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool quest_commandscript::HandleQuestReward ( ChatHandler handler,
char const args 
)
inlinestatic
252  {
253  Player* player = handler->getSelectedPlayer();
254  if (!player)
255  {
257  handler->SetSentErrorMessage(true);
258  return false;
259  }
260 
261  // .quest reward #entry
262  // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r
263  char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
264  if (!cId)
265  return false;
266 
267  uint32 entry = atoul(cId);
268 
269  Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
270 
271  // If player doesn't have the quest
272  if (!quest || player->GetQuestStatus(entry) != QUEST_STATUS_COMPLETE)
273  {
275  handler->SetSentErrorMessage(true);
276  return false;
277  }
278 
279  player->RewardQuest(quest, 0, player);
280  return true;
281  }
Definition: QuestDef.h:111
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: QuestDef.h:279
Definition: Language.h:140
#define sObjectMgr
Definition: ObjectMgr.h:1567
unsigned long atoul(char const *str)
Definition: Common.h:90
uint32_t uint32
Definition: Define.h:150
Player * getSelectedPlayer()
Definition: Chat.cpp:579
Definition: Language.h:474
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: