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

View File

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

View File

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