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->StoredItems = this;
BaseItem->World = GetWorld(); BaseItem->World = GetWorld();
Items.Add(BaseItem); Items.Add(BaseItem);
BaseItem->SubItemID++; UE_LOG(LogTemp, Display, TEXT("ITEM HAS BEEN ADDED TO INVENTORY"));
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("SUBITEM ID: %d"), BaseItem->SubItemID);
//Refreshes the inventory //Refreshes the inventory
OnInventoryUpdated.Broadcast(); OnInventoryUpdated.Broadcast();
@ -60,13 +57,6 @@ 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;
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); //Items.RemoveSingle(BaseItem);
OnInventoryUpdated.Broadcast(); // Updates UI OnInventoryUpdated.Broadcast(); // Updates UI
return true; return true;
@ -79,3 +69,9 @@ UBaseItem* UInventoryComponent::GetItem(int Index)
return Items[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") UFUNCTION(BlueprintCallable, Category= "Inventory")
class UBaseItem* GetItem(int Index); class UBaseItem* GetItem(int Index);
UFUNCTION()
void RemoveItem(UEatableItems* Item);
}; };

View File

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

View File

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

View File

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