Skip to content

Commit

Permalink
fix: duplicating quest items
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed May 25, 2022
1 parent b9247f6 commit 2b7c2d9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Code/client/Games/Skyrim/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ void* TP_MAKE_THISCALL(HookPickUpObject, Actor, TESObjectREFR* apObject, int32_t
Inventory::Entry item{};
modSystem.GetServerModId(apObject->baseForm->formID, item.BaseId);
item.Count = aCount;

if (apObject->GetExtraDataList())
apThis->GetItemFromExtraData(item, apObject->GetExtraDataList());

Expand Down
22 changes: 16 additions & 6 deletions Code/client/Games/Skyrim/TESObjectREFR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ Inventory TESObjectREFR::GetEquippedItems() const noexcept
return inventory;
}

bool TESObjectREFR::IsItemInInventory(uint32_t aFormID) const noexcept
{
Inventory inventory = GetInventory([aFormID](TESForm& aForm) { return aForm.formID == aFormID; });
return !inventory.Entries.empty();
}

void TESObjectREFR::SetInventory(const Inventory& aInventory) noexcept
{
spdlog::debug("Setting inventory for {:X}", formID);
Expand Down Expand Up @@ -518,14 +524,18 @@ void TESObjectREFR::AddOrRemoveItem(const Inventory::Entry& arEntry) noexcept
RemoveItem(pObject, -arEntry.Count, ITEM_REMOVE_REASON::kRemove, pExtraDataList, nullptr);
}

// TODO(cosideci): this needs to be tested. This just creates a copy of the "quest object".
// Might cause issues when delivering quests.
// Maybe make it so that the quest leader gets the ref, and the other party members get the copy?
if (arEntry.IsQuestItem)
// TODO(cosideci): this is still flawed. Adding the refr to the quest leader is hard.
// It is still recommended that the quest leader loots all quest items.
if (arEntry.IsQuestItem && arEntry.Count > 0)
{
if (IsItemInInventory(objectId))
return;

Actor* pActor = Cast<Actor>(this);
if (pActor && pActor->GetExtension()->IsRemotePlayer())
PlayerCharacter::Get()->AddOrRemoveItem(arEntry);
if (!pActor || !pActor->GetExtension()->IsRemotePlayer())
return;

PlayerCharacter::Get()->AddOrRemoveItem(arEntry);
}
}

Expand Down
4 changes: 3 additions & 1 deletion Code/client/Games/Skyrim/TESObjectREFR.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ struct TESObjectREFR : TESForm
Inventory GetArmor() const noexcept;
Inventory GetWornArmor() const noexcept;
Inventory GetEquippedItems() const noexcept;
void SetInventory(const Inventory& acContainer) noexcept;

bool IsItemInInventory(uint32_t aFormID) const noexcept;

void SetInventory(const Inventory& acContainer) noexcept;
void AddOrRemoveItem(const Inventory::Entry& arEntry) noexcept;

BSHandleRefObject handleRefObject;
Expand Down

0 comments on commit 2b7c2d9

Please sign in to comment.