loot source for item drops

Added support for Items to have a loot source attached to them when dropped or rolled.  This fixes the issue where achievements would give the item before it appeared in the achievement window.
This commit is contained in:
EmosewaMC
2022-04-23 20:35:34 -07:00
parent ceab229a63
commit 7a051afd97
29 changed files with 65 additions and 62 deletions

View File

@@ -217,7 +217,7 @@ void CharacterComponent::HandleLevelUp()
switch (reward->rewardType)
{
case 0:
inventoryComponent->AddItem(reward->value, reward->count, eInventoryType::INVALID, {}, 0LL, true, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_LEVEL_REWARD);
inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LOOT_SOURCE_LEVEL_REWARD);
break;
case 4:
{

View File

@@ -141,6 +141,7 @@ const EquipmentMap& InventoryComponent::GetEquippedItems() const
void InventoryComponent::AddItem(
const LOT lot,
const uint32_t count,
eLootSourceType lootSourceType,
eInventoryType inventoryType,
const std::vector<LDFBaseData*>& config,
const LWOOBJID parent,
@@ -150,8 +151,7 @@ void InventoryComponent::AddItem(
const eInventoryType inventorySourceType,
const int32_t sourceType,
const bool bound,
int32_t preferredSlot,
eLootSourceType lootSourceType)
int32_t preferredSlot)
{
if (count == 0)
{
@@ -181,7 +181,7 @@ void InventoryComponent::AddItem(
if (!config.empty() || bound)
{
const auto slot = inventory->FindEmptySlot();
const auto slot = preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot) ? preferredSlot : inventory->FindEmptySlot();
if (slot == -1)
{
@@ -224,7 +224,7 @@ void InventoryComponent::AddItem(
left -= delta;
existing->SetCount(existing->GetCount() + delta, false, true, showFlyingLoot);
existing->SetCount(existing->GetCount() + delta, false, true, showFlyingLoot, lootSourceType);
if (isModMoveAndEquip)
{
@@ -255,9 +255,6 @@ void InventoryComponent::AddItem(
if (slot == -1)
{
// if (inventoryType == eInventoryType::VAULT_ITEMS || inventoryType == eInventoryType::VAULT_MODELS) {
// }
auto* player = dynamic_cast<Player*>(GetParent());
if (player == nullptr)
@@ -372,7 +369,7 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in
left -= delta;
AddItem(lot, delta, inventory, {}, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, false, preferredSlot, eLootSourceType::LOOT_SOURCE_NONE);
AddItem(lot, delta, eLootSourceType::LOOT_SOURCE_NONE, inventory, {}, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, false, preferredSlot);
item->SetCount(item->GetCount() - delta, false, false);
@@ -390,7 +387,7 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in
const auto delta = std::min<uint32_t>(item->GetCount(), count);
AddItem(lot, delta, inventory, config, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, item->GetBound(), preferredSlot, eLootSourceType::LOOT_SOURCE_NONE);
AddItem(lot, delta, eLootSourceType::LOOT_SOURCE_NONE, inventory, config, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, item->GetBound(), preferredSlot);
item->SetCount(item->GetCount() - delta, false, false);
}

View File

@@ -87,10 +87,12 @@ public:
* @param sourceType the source of the item, used to determine if the item is dropped or mailed if the inventory is full
* @param bound whether this item is bound
* @param preferredSlot the preferred slot to store this item
* @param lootSourceType The source of the loot. Defaults to none.
*/
void AddItem(
LOT lot,
uint32_t count,
eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE,
eInventoryType inventoryType = INVALID,
const std::vector<LDFBaseData*>& config = {},
LWOOBJID parent = LWOOBJID_EMPTY,
@@ -100,8 +102,7 @@ public:
eInventoryType inventorySourceType = INVALID,
int32_t sourceType = 0,
bool bound = false,
int32_t preferredSlot = -1,
eLootSourceType lootSourceType = eLootSourceType::LOOT_SOURCE_NONE
int32_t preferredSlot = -1
);
/**

View File

@@ -615,7 +615,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position)
GameMessages::SendRegisterPetDBID(m_Tamer, petSubKey, tamer->GetSystemAddress());
inventoryComponent->AddItem(m_Parent->GetLOT(), 1, MODELS, {}, LWOOBJID_EMPTY, true, false, petSubKey, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_ACTIVITY);
inventoryComponent->AddItem(m_Parent->GetLOT(), 1, eLootSourceType::LOOT_SOURCE_ACTIVITY, eInventoryType::MODELS, {}, LWOOBJID_EMPTY, true, false, petSubKey);
auto* item = inventoryComponent->FindItemBySubKey(petSubKey, MODELS);
if (item == nullptr)

View File

@@ -491,7 +491,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
settings.push_back(propertyObjectID);
settings.push_back(modelType);
inventoryComponent->AddItem(6662, 1, HIDDEN, settings, LWOOBJID_EMPTY, false, false, spawnerId, INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION);
inventoryComponent->AddItem(6662, 1, eLootSourceType::LOOT_SOURCE_DELETION, eInventoryType::HIDDEN, settings, LWOOBJID_EMPTY, false, false, spawnerId);
auto* item = inventoryComponent->FindItemBySubKey(spawnerId);
if (item == nullptr) {
@@ -526,7 +526,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
return;
}
inventoryComponent->AddItem(model->GetLOT(), 1, INVALID, {}, LWOOBJID_EMPTY, false, false, 0LL, eInventoryType::INVALID, 0, false, -1, eLootSourceType::LOOT_SOURCE_DELETION);
inventoryComponent->AddItem(model->GetLOT(), 1, eLootSourceType::LOOT_SOURCE_DELETION, INVALID, {}, LWOOBJID_EMPTY, false);
auto* item = inventoryComponent->FindItemByLot(model->GetLOT());