Updated Items

Started to create item stacks and fix item not dissapearing bug
This commit is contained in:
MH261677 2022-11-29 15:44:00 +00:00
parent cc9384a9c1
commit 7199ee76a3
5 changed files with 17 additions and 5 deletions

Binary file not shown.

BIN
Content/Levels/MerchantPrototype.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -40,10 +40,11 @@ bool UInventoryComponent::AddItem(class UBaseItem* BaseItem)
BaseItem->StoredItems = this;
BaseItem->World = GetWorld();
Items.Add(BaseItem);
BaseItem->ItemID++;
BaseItem->SubItemID++;
UE_LOG(LogTemp, Display, TEXT("ITEM HAS BEEN ADDED"));
//log the itemid
UE_LOG(LogTemp, Display, TEXT("ITEM ID: %d"), BaseItem->ItemID);
UE_LOG(LogTemp, Display, TEXT("SUBITEM ID: %d"), BaseItem->SubItemID);
//Refreshes the inventory
OnInventoryUpdated.Broadcast();
@ -59,7 +60,14 @@ bool UInventoryComponent::Remove(class UBaseItem* BaseItem)
UE_LOG(LogTemp, Display, TEXT("ItEM HAS BEEN REMOVED"));
BaseItem->StoredItems = nullptr;
BaseItem->World = nullptr;
if(BaseItem->SubItemID < Items.Num())
{
Items.RemoveSingle(BaseItem);
BaseItem->SubItemID --;
UE_LOG(LogTemp, Display, TEXT("ItemRemoved"));
UE_LOG(LogTemp, Display, TEXT("SUBITEM ID: %d"), BaseItem->SubItemID);
}
//Items.RemoveSingle(BaseItem);
OnInventoryUpdated.Broadcast(); // Updates UI
return true;
}

View File

@ -56,6 +56,9 @@ public:
UPROPERTY(EditAnywhere, Category = "Item")
int ItemID;
UPROPERTY(EditAnywhere, Category = "Item")
int SubItemID;
//reference to the UInventoryComponent script
UPROPERTY()
class UInventoryComponent* StoredItems;

View File

@ -10,6 +10,7 @@
UEatableItems::UEatableItems()
{
ItemID;
SubItemID;
}
void UEatableItems::Use(ATempCharacter* Character)