From 168ffc3dbbb75e8b8f73415c2d3dab6a46298e93 Mon Sep 17 00:00:00 2001 From: Tristan Cormier Date: Sat, 28 Jan 2017 01:21:31 -0500 Subject: [PATCH] Fixed a bug where turning in a quest involving multiple rewards would sometimes not reward the items due to a faulty bag space check. Fixes #3. --- src/game/Object/Player.cpp | 78 +++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/src/game/Object/Player.cpp b/src/game/Object/Player.cpp index 58116773..26dff1ce 100644 --- a/src/game/Object/Player.cpp +++ b/src/game/Object/Player.cpp @@ -12318,42 +12318,52 @@ bool Player::CanRewardQuest(Quest const* pQuest, bool msg) const bool Player::CanRewardQuest(Quest const* pQuest, uint32 reward, bool msg) const { - // prevent receive reward with quest items in bank or for not completed quest - if (!CanRewardQuest(pQuest, msg)) - { return false; } + bool result; + uint32 numOptionalRewards; + uint32 numRewards; + uint32 requiredSlots; + InventoryResult iRes; - if (pQuest->GetRewChoiceItemsCount() > 0) - { - if (pQuest->RewChoiceItemId[reward]) - { - ItemPosCountVec dest; - InventoryResult res = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, pQuest->RewChoiceItemId[reward], pQuest->RewChoiceItemCount[reward]); - if (res != EQUIP_ERR_OK) - { - SendEquipError(res, NULL, NULL, pQuest->RewChoiceItemId[reward]); - return false; - } - } - } + requiredSlots = 0; + result = CanRewardQuest(pQuest, msg); + if (result) + { + ItemPosCountVec destActual; + numOptionalRewards = pQuest->GetRewChoiceItemsCount(); + numRewards = pQuest->GetRewItemsCount(); + // Only ONE optional reward can be selected + requiredSlots = numRewards + 1; - if (pQuest->GetRewItemsCount() > 0) - { - for (uint32 i = 0; i < pQuest->GetRewItemsCount(); ++i) - { - if (pQuest->RewItemId[i]) - { - ItemPosCountVec dest; - InventoryResult res = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, pQuest->RewItemId[i], pQuest->RewItemCount[i]); - if (res != EQUIP_ERR_OK) - { - SendEquipError(res, NULL, NULL); - return false; - } - } - } - } - - return true; + if (numRewards > 0 || numOptionalRewards > 0) + { + if (pQuest->RewChoiceItemId[reward]) + { + ItemPosCountVec dest; + iRes = CanStoreNewItem(0, 0, dest, pQuest->RewChoiceItemId[reward], pQuest->RewChoiceItemCount[reward]); + if (iRes != EQUIP_ERR_OK) + goto CANT_EQUIP; + } + for (uint32 i = 0; i < numRewards; ++i) + { + if (pQuest->RewItemId[i]) + { + ItemPosCountVec dest; + iRes = CanStoreNewItem(0, 0, dest, pQuest->RewItemId[i], pQuest->RewItemCount[i]); + if (iRes != EQUIP_ERR_OK) + goto CANT_EQUIP; + } + } + // We use 2586 (Gamemaster's Robes) as the item ID so that we can verify that the slots can be filled for all selected quest rewards + iRes = CanStoreNewItem(0, 0, destActual, 2586, requiredSlots); +CANT_EQUIP: + if (iRes != EQUIP_ERR_OK) + { + SendEquipError(iRes, 0, 0); + result = false; + } + } + } + return result; } void Player::SendPetTameFailure(PetTameFailureReason reason)