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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
|
/*
* This file is part of the AzerothCore 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 Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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/>.
*/
#include "Chat.h"
#include "CommandScript.h"
#include "GameTime.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ReputationMgr.h"
using namespace Acore::ChatCommands;
class quest_commandscript : public CommandScript
{
public:
quest_commandscript() : CommandScript("quest_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable questCommandTable =
{
{ "add", HandleQuestAdd, SEC_GAMEMASTER, Console::Yes },
{ "complete", HandleQuestComplete, SEC_GAMEMASTER, Console::Yes },
{ "remove", HandleQuestRemove, SEC_GAMEMASTER, Console::Yes },
{ "reward", HandleQuestReward, SEC_GAMEMASTER, Console::Yes },
};
static ChatCommandTable commandTable =
{
{ "quest", questCommandTable },
};
return commandTable;
}
static bool HandleQuestAdd(ChatHandler* handler, Quest const* quest, Optional<PlayerIdentifier> playerTarget)
{
if (!playerTarget)
{
playerTarget = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!playerTarget)
{
handler->SendErrorMessage(LANG_PLAYER_NOT_FOUND);
return false;
}
uint32 entry = quest->GetQuestId();
// 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->SendErrorMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, result->second.ItemId);
return false;
}
if (Player* player = playerTarget->GetConnectedPlayer())
{
if (player->IsActiveQuest(entry))
{
handler->SendErrorMessage(LANG_COMMAND_QUEST_ACTIVE, quest->GetTitle().c_str(), entry);
return false;
}
// ok, normal (creature/GO starting) quest
if (player->CanAddQuest(quest, true))
{
player->AddQuestAndCheckCompletion(quest, nullptr);
}
}
else
{
ObjectGuid::LowType guid = playerTarget->GetGUID().GetCounter();
QueryResult result = CharacterDatabase.Query("SELECT 1 FROM character_queststatus WHERE guid = {} AND quest = {}", guid, entry);
if (result)
{
handler->SendErrorMessage(LANG_COMMAND_QUEST_ACTIVE, quest->GetTitle().c_str(), entry);
return false;
}
uint8 index = 0;
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CHAR_QUESTSTATUS);
stmt->SetData(index++, guid);
stmt->SetData(index++, entry);
stmt->SetData(index++, 1);
stmt->SetData(index++, false);
stmt->SetData(index++, 0);
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
{
stmt->SetData(index++, 0);
}
for (uint8 i = 0; i < QUEST_ITEM_OBJECTIVES_COUNT; i++)
{
stmt->SetData(index++, 0);
}
stmt->SetData(index, 0);
CharacterDatabase.Execute(stmt);
}
handler->PSendSysMessage(LANG_COMMAND_QUEST_ADD, quest->GetTitle(), entry);
handler->SetSentErrorMessage(false);
return true;
}
static bool HandleQuestRemove(ChatHandler* handler, Quest const* quest, Optional<PlayerIdentifier> playerTarget)
{
if (!playerTarget)
{
playerTarget = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!playerTarget)
{
handler->SendErrorMessage(LANG_PLAYER_NOT_FOUND);
return false;
}
uint32 entry = quest->GetQuestId();
if (!quest)
{
handler->SendErrorMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
return false;
}
if (Player* player = playerTarget->GetConnectedPlayer())
{
// 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);
}
else
{
ObjectGuid::LowType guid = playerTarget->GetGUID().GetCounter();
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_QUESTSTATUS_REWARDED_BY_QUEST);
stmt->SetData(0, guid);
stmt->SetData(1, entry);
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_QUESTSTATUS_BY_QUEST);
stmt->SetData(0, guid);
stmt->SetData(1, entry);
trans->Append(stmt);
for (uint32 const& requiredItem : quest->RequiredItemId)
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY_AND_OWNER);
stmt->SetData(0, requiredItem);
stmt->SetData(1, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
Field* fields = result->Fetch();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INVENTORY_BY_ITEM);
stmt->SetData(0, fields[0].Get<uint32>());
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE);
stmt->SetData(0, fields[0].Get<uint32>());
trans->Append(stmt);
}
}
CharacterDatabase.CommitTransaction(trans);
}
handler->PSendSysMessage(LANG_COMMAND_QUEST_REMOVED, quest->GetTitle(), entry);
handler->SetSentErrorMessage(false);
return true;
}
static bool HandleQuestComplete(ChatHandler* handler, Quest const* quest, Optional<PlayerIdentifier> playerTarget)
{
if (!playerTarget)
{
playerTarget = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!playerTarget)
{
handler->SendErrorMessage(LANG_PLAYER_NOT_FOUND);
return false;
}
uint32 entry = quest->GetQuestId();
if (Player* player = playerTarget->GetConnectedPlayer())
{
// If player doesn't have the quest
if (player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
{
handler->SendErrorMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
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, ObjectGuid::Empty);
}
}
}
else if (creature < 0)
{
for (uint16 z = 0; z < creatureCount; ++z)
{
player->KillCreditGO(creature);
}
}
}
// player kills
if (quest->HasSpecialFlag(QUEST_SPECIAL_FLAGS_PLAYER_KILL))
{
if (uint32 reqPlayers = quest->GetPlayersSlain())
{
player->KilledPlayerCreditForQuest(reqPlayers, quest);
}
}
// 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, static_cast<float>(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, static_cast<float>(repValue2));
}
}
}
// If the quest requires money
int32 ReqOrRewMoney = quest->GetRewOrReqMoney(player->GetLevel());
if (ReqOrRewMoney < 0)
{
player->ModifyMoney(-ReqOrRewMoney);
}
player->CompleteQuest(entry);
}
else
{
ObjectGuid::LowType guid = playerTarget->GetGUID().GetCounter();
QueryResult result = CharacterDatabase.Query("SELECT 1 FROM character_queststatus WHERE guid = {} AND quest = {}", guid, entry);
if (!result)
{
handler->SendErrorMessage(LANG_COMMAND_QUEST_NOT_FOUND_IN_LOG, quest->GetTitle(), entry);
return false;
}
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
typedef std::pair<uint32, uint32> items;
std::vector<items> questItems;
for (uint8 x = 0; x < QUEST_ITEM_OBJECTIVES_COUNT; ++x)
{
uint32 id = quest->RequiredItemId[x];
uint32 count = quest->RequiredItemCount[x];
if (!id || !count)
{
continue;
}
questItems.emplace_back(id, count);
}
if (!questItems.empty())
{
MailSender sender(MAIL_NORMAL, guid, MAIL_STATIONERY_GM);
// fill mail
MailDraft draft(quest->GetTitle(), std::string());
for (auto const& itr : questItems)
{
if (Item* item = Item::CreateItem(itr.first, itr.second))
{
item->SaveToDB(trans);
draft.AddItem(item);
}
}
draft.SendMailTo(trans, MailReceiver(nullptr, guid), sender);
}
uint8 index = 0;
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CHAR_QUESTSTATUS);
stmt->SetData(index++, guid);
stmt->SetData(index++, entry);
stmt->SetData(index++, 1);
stmt->SetData(index++, quest->HasFlag(QUEST_FLAGS_EXPLORATION));
stmt->SetData(index++, 0);
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
{
stmt->SetData(index++, quest->RequiredNpcOrGoCount[i]);
}
for (uint8 i = 0; i < QUEST_ITEM_OBJECTIVES_COUNT; i++)
{
// Will be updated once they loot the items from the mailbox.
stmt->SetData(index++, 0);
}
stmt->SetData(index, 0);
trans->Append(stmt);
// If the quest requires reputation to complete, set the player rep to the required amount.
if (uint32 repFaction = quest->GetRepObjectiveFaction())
{
uint32 repValue = quest->GetRepObjectiveValue();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_REP_BY_FACTION);
stmt->SetData(0, repFaction);
stmt->SetData(1, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
Field* fields = result->Fetch();
uint32 curRep = fields[0].Get<uint32>();
if (curRep < repValue)
{
if (sFactionStore.LookupEntry(repFaction))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_REP_FACTION_CHANGE);
stmt->SetData(0, repFaction);
stmt->SetData(1, repValue);
stmt->SetData(2, repFaction);
stmt->SetData(3, guid);
trans->Append(stmt);
}
}
}
}
// If the quest requires reputation to complete, set the player rep to the required amount.
if (uint32 repFaction = quest->GetRepObjectiveFaction2())
{
uint32 repValue = quest->GetRepObjectiveValue();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_REP_BY_FACTION);
stmt->SetData(0, repFaction);
stmt->SetData(1, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
Field* fields = result->Fetch();
uint32 curRep = fields[0].Get<uint32>();
if (curRep < repValue)
{
if (sFactionStore.LookupEntry(repFaction))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_REP_FACTION_CHANGE);
stmt->SetData(0, repFaction);
stmt->SetData(1, repValue);
stmt->SetData(2, repFaction);
stmt->SetData(3, guid);
trans->Append(stmt);
}
}
}
}
CharacterDatabase.CommitTransaction(trans);
}
// check if Quest Tracker is enabled
if (sWorld->getBoolConfig(CONFIG_QUEST_ENABLE_QUEST_TRACKER))
{
// prepare Quest Tracker datas
auto stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_QUEST_TRACK_GM_COMPLETE);
stmt->SetData(0, entry);
stmt->SetData(1, playerTarget->GetGUID().GetCounter());
// add to Quest Tracker
CharacterDatabase.Execute(stmt);
}
handler->PSendSysMessage(LANG_COMMAND_QUEST_COMPLETE, quest->GetTitle(), entry);
handler->SetSentErrorMessage(false);
return true;
}
static bool HandleQuestReward(ChatHandler* handler, Quest const* quest, Optional<PlayerIdentifier> playerTarget)
{
if (!playerTarget)
{
playerTarget = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!playerTarget)
{
handler->SendErrorMessage(LANG_PLAYER_NOT_FOUND);
return false;
}
uint32 entry = quest->GetQuestId();
if (Player* player = playerTarget->GetConnectedPlayer())
{
// If player doesn't have the quest
if (player->GetQuestStatus(entry) != QUEST_STATUS_COMPLETE)
{
handler->SendErrorMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
return false;
}
player->RewardQuest(quest, 0, player);
}
else
{
// Achievement criteria updates correctly the next time a quest is rewarded.
// Titles are already awarded correctly the next time they login (only one quest awards title - 11549).
// Rewarded talent points (Death Knights) and spells (e.g Druid forms) are also granted on login.
// No reputation gains - too troublesome to calculate them when the player is offline.
ObjectGuid::LowType guid = playerTarget->GetGUID().GetCounter();
uint8 charLevel = sCharacterCache->GetCharacterLevelByGuid(ObjectGuid(HighGuid::Player, guid));
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
CharacterDatabasePreparedStatement* stmt;
QueryResult result = CharacterDatabase.Query("SELECT 1 FROM character_queststatus WHERE guid = {} AND quest = {} AND status = 1", guid, entry);
if (!result)
{
handler->SendErrorMessage(LANG_COMMAND_QUEST_NOT_COMPLETE);
return false;
}
for (uint32 const& requiredItem : quest->RequiredItemId)
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY_AND_OWNER);
stmt->SetData(0, requiredItem);
stmt->SetData(1, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
Field* fields = result->Fetch();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INVENTORY_BY_ITEM);
stmt->SetData(0, fields[0].Get<uint32>());
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE);
stmt->SetData(0, fields[0].Get<uint32>());
trans->Append(stmt);
}
}
for (uint32 const& sourceItem : quest->ItemDrop)
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY_AND_OWNER);
stmt->SetData(0, sourceItem);
stmt->SetData(1, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
Field* fields = result->Fetch();
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INVENTORY_BY_ITEM);
stmt->SetData(0, fields[0].Get<uint32>());
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE);
stmt->SetData(0, fields[0].Get<uint32>());
trans->Append(stmt);
}
}
typedef std::pair<uint32, uint32> items;
std::vector<items> questRewardItems;
if (quest->GetRewChoiceItemsCount())
{
for (uint32 const& itemId : quest->RewardChoiceItemId)
{
uint8 index = 0;
questRewardItems.emplace_back(itemId, quest->RewardChoiceItemCount[index++]);
}
}
if (quest->GetRewItemsCount())
{
for (uint32 const& itemId : quest->RewardItemId)
{
uint8 index = 0;
questRewardItems.emplace_back(itemId, quest->RewardItemIdCount[index++]);
}
}
if (!questRewardItems.empty())
{
MailSender sender(MAIL_NORMAL, guid, MAIL_STATIONERY_GM);
// fill mail
MailDraft draft(quest->GetTitle(), "This quest has been manually rewarded to you. This mail contains your quest rewards.");
for (auto const& itr : questRewardItems)
{
if (!itr.first || !itr.second)
{
continue;
}
// Skip invalid items.
if (!sObjectMgr->GetItemTemplate(itr.first))
{
continue;
}
if (Item* item = Item::CreateItem(itr.first, itr.second))
{
item->SaveToDB(trans);
draft.AddItem(item);
}
}
draft.SendMailTo(trans, MailReceiver(nullptr, guid), sender);
}
// Send quest giver mail, if any.
if (uint32 mail_template_id = quest->GetRewMailTemplateId())
{
if (quest->GetRewMailSenderEntry() != 0)
{
MailDraft(mail_template_id).SendMailTo(trans, MailReceiver(nullptr, guid), quest->GetRewMailSenderEntry(), MAIL_CHECK_MASK_HAS_BODY, quest->GetRewMailDelaySecs());
}
}
if (quest->IsDaily() || quest->IsDFQuest())
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHARACTER_DAILYQUESTSTATUS);
stmt->SetData(0, guid);
stmt->SetData(1, entry);
stmt->SetData(2, GameTime::GetGameTime().count());
trans->Append(stmt);
}
else if (quest->IsWeekly())
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHARACTER_WEEKLYQUESTSTATUS);
stmt->SetData(0, guid);
stmt->SetData(1, entry);
trans->Append(stmt);
}
else if (quest->IsMonthly())
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHARACTER_MONTHLYQUESTSTATUS);
stmt->SetData(0, guid);
stmt->SetData(1, entry);
trans->Append(stmt);
}
else if (quest->IsSeasonal())
{
// We can't know which event is the quest linked to, so we can't do anything about this.
/* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHARACTER_SEASONALQUESTSTATUS);
stmt->SetData(0, guid);
stmt->SetData(1, entry);
stmt->SetData(2, event_id);
trans->Append(stmt);*/
}
if (uint32 honor = quest->CalculateHonorGain(charLevel))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UDP_CHAR_HONOR_POINTS_ACCUMULATIVE);
stmt->SetData(0, honor);
stmt->SetData(1, guid);
trans->Append(stmt);
}
if (quest->GetRewArenaPoints())
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UDP_CHAR_ARENA_POINTS_ACCUMULATIVE);
stmt->SetData(0, quest->GetRewArenaPoints());
stmt->SetData(1, guid);
trans->Append(stmt);
}
int32 rewMoney = 0;
if (charLevel >= sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
rewMoney = quest->GetRewMoneyMaxLevel();
}
else
{
// Some experience might get lost on level up.
uint32 xp = uint32(quest->XPValue(charLevel) * sWorld->getRate(RATE_XP_QUEST));
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_XP_ACCUMULATIVE);
stmt->SetData(0, xp);
stmt->SetData(1, guid);
trans->Append(stmt);
}
if (int32 rewOrReqMoney = quest->GetRewOrReqMoney(charLevel))
{
rewMoney += rewOrReqMoney;
}
// Only reward money, don't subtract, let's not cause an overflow...
if (rewMoney > 0)
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UDP_CHAR_MONEY_ACCUMULATIVE);
stmt->SetData(0, rewMoney);
stmt->SetData(1, guid);
trans->Append(stmt);
}
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_QUESTSTATUS_REWARDED);
stmt->SetData(0, guid);
stmt->SetData(1, entry);
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_QUESTSTATUS_BY_QUEST);
stmt->SetData(0, guid);
stmt->SetData(1, entry);
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);
}
handler->PSendSysMessage(LANG_COMMAND_QUEST_REWARDED, quest->GetTitle(), entry);
handler->SetSentErrorMessage(false);
return true;
}
};
void AddSC_quest_commandscript()
{
new quest_commandscript();
}
|