Check loot for quest when looting items

This commit is contained in:
郑佩茹
2023-03-21 13:06:00 -06:00
parent aeeb37da78
commit 584658c557
2 changed files with 56 additions and 0 deletions

View File

@@ -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);

View File

@@ -38,6 +38,9 @@ class LootObject
uint32 skillId;
uint32 reqSkillValue;
uint32 reqItem;
private:
static bool IsNeededForQuest(Player* bot, uint32 itemId);
};
class LootTarget