From 584658c5579f5594117a9e1d32fd8c3c75893653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E4=BD=A9=E8=8C=B9?= Date: Tue, 21 Mar 2023 13:06:00 -0600 Subject: [PATCH] Check loot for quest when looting items --- src/LootObjectStack.cpp | 53 +++++++++++++++++++++++++++++++++++++++++ src/LootObjectStack.h | 3 +++ 2 files changed, 56 insertions(+) diff --git a/src/LootObjectStack.cpp b/src/LootObjectStack.cpp index c3ad6bf7..4f417e3c 100644 --- a/src/LootObjectStack.cpp +++ b/src/LootObjectStack.cpp @@ -79,6 +79,28 @@ void LootObject::Refresh(Player* bot, ObjectGuid lootGUID) GameObject* go = botAI->GetGameObject(lootGUID); if (go && go->isSpawned() && go->GetGoState() == GO_STATE_READY) { + + bool isQuestItemOnly = false; + + GameObjectQuestItemList const* items = sObjectMgr->GetGameObjectQuestItemList(go->GetEntry()); + for (int i = 0; i < MAX_GAMEOBJECT_QUEST_ITEMS; i++) + { + if (i >= items->size()) + break; + + auto itemId = uint32((*items)[i]); + + if (IsNeededForQuest(bot, itemId)) + { + this->guid = guid; + return; + } + isQuestItemOnly |= itemId > 0; + } + + if (isQuestItemOnly) + return; + uint32 goId = go->GetEntry(); uint32 lockId = go->GetGOInfo()->GetLockId(); LockEntry const* lockInfo = sLockStore.LookupEntry(lockId); @@ -116,6 +138,37 @@ void LootObject::Refresh(Player* bot, ObjectGuid lootGUID) } } +bool LootObject::IsNeededForQuest(Player* bot, uint32 itemId) +{ + for (int qs = 0; qs < MAX_QUEST_LOG_SIZE; ++qs) + { + uint32 questId = bot->GetQuestSlotQuestId(qs); + if (questId == 0) + continue; + + QuestStatusData& qData = bot->getQuestStatusMap()[questId]; + if (qData.Status != QUEST_STATUS_INCOMPLETE) + continue; + + Quest const* qInfo = sObjectMgr->GetQuestTemplate(questId); + if (!qInfo) + continue; + + for (int i = 0; i < QUEST_ITEM_OBJECTIVES_COUNT; ++i) + { + if (!qInfo->RequiredItemCount[i] || (qInfo->RequiredItemCount[i] - qData.ItemCount[i]) <= 0) + continue; + + if (qInfo->RequiredItemId[i] != itemId) + continue; + + return true; + } + } + + return false; +} + WorldObject* LootObject::GetWorldObject(Player* bot) { Refresh(bot, guid); diff --git a/src/LootObjectStack.h b/src/LootObjectStack.h index 13e2831f..05ba0fb5 100644 --- a/src/LootObjectStack.h +++ b/src/LootObjectStack.h @@ -38,6 +38,9 @@ class LootObject uint32 skillId; uint32 reqSkillValue; uint32 reqItem; + +private: + static bool IsNeededForQuest(Player* bot, uint32 itemId); }; class LootTarget