Updated Inventory System

Done it so the items from the inventory now get removed when used instead of one item never being able to be removed
This commit is contained in:
MH261677 2023-01-12 13:56:30 +00:00
parent 9878f0f370
commit 3710f33e74
5 changed files with 22 additions and 27 deletions

View File

@ -40,11 +40,8 @@ bool UInventoryComponent::AddItem(class UBaseItem* BaseItem)
BaseItem->StoredItems = this;
BaseItem->World = GetWorld();
Items.Add(BaseItem);
BaseItem->SubItemID++;
UE_LOG(LogTemp, Display, TEXT("ITEM HAS BEEN ADDED"));
UE_LOG(LogTemp, Display, TEXT("ITEM HAS BEEN ADDED TO INVENTORY"));
//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();
@ -60,13 +57,6 @@ 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;
@ -79,3 +69,9 @@ UBaseItem* UInventoryComponent::GetItem(int Index)
return Items[Index];
}
void UInventoryComponent::RemoveItem(UEatableItems* Item)
{
Items.RemoveSingle(Item);
OnInventoryUpdated.Broadcast();
}

View File

@ -46,4 +46,7 @@ public:
UFUNCTION(BlueprintCallable, Category= "Inventory")
class UBaseItem* GetItem(int Index);
UFUNCTION()
void RemoveItem(UEatableItems* Item);
};

View File

@ -53,14 +53,11 @@ public:
UPROPERTY(EditAnywhere, Category = "Item")
bool isDamageBuffItem;
UPROPERTY(EditAnywhere, Category = "Item")
int ItemID;
UPROPERTY(EditAnywhere, Category = "Item")
int SubItemID;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item")
int32 StackCount;
//reference to the UInventoryComponent script
UPROPERTY()
UPROPERTY(EditAnywhere, Category = "Item")
class UInventoryComponent* StoredItems;
//The buy class to purchase the item

View File

@ -3,14 +3,14 @@
#include "EatableItems.h"
#include "BehaviorTree/BehaviorTreeTypes.h"
#include "the_twilight_abyss/BaseItems/InventoryComponent.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
UEatableItems::UEatableItems()
{
ItemID;
SubItemID;
}
void UEatableItems::Use(ATempCharacter* Character)
@ -21,15 +21,15 @@ void UEatableItems::Use(ATempCharacter* Character)
{
Character->Health += 10;
UE_LOG(LogTemp, Display, TEXT("Healed"));
//delete itself
Character->Inventory->RemoveItem(this);
}
if(isDamageBuffItem == true)
{
// need to add the damage buff functionality here
UE_LOG(LogTemp, Display, TEXT("Damage Buffed"));
}
if(StoredItems)
{
StoredItems->Remove(this);
Character->Inventory->RemoveItem(this);
}
}

View File

@ -12,10 +12,6 @@ class THE_TWILIGHT_ABYSS_API ATempCharacter : public ACharacter
{
GENERATED_BODY()
//Player inventory
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = "true"))
class UInventoryComponent* Inventory; //Using the InventoryComponent class
public:
// Sets default values for this character's properties
ATempCharacter();
@ -31,6 +27,9 @@ public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Inventory, meta = (AllowPrivateAccess = "true"))
class UInventoryComponent* Inventory; //Using the InventoryComponent class
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;