2022-11-14 14:57:02 +00:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "InventoryComponent.h"
|
2022-11-14 17:42:26 +00:00
|
|
|
#include "Items/BaseItem.h"
|
2022-11-15 03:27:44 +00:00
|
|
|
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
|
2022-11-14 14:57:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Sets default values for this component's properties
|
|
|
|
UInventoryComponent::UInventoryComponent()
|
|
|
|
{
|
|
|
|
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
|
|
|
// off to improve performance if you don't need them.
|
|
|
|
PrimaryComponentTick.bCanEverTick = true;
|
|
|
|
|
2022-11-14 17:42:26 +00:00
|
|
|
MaxItemSlots = 10;
|
2022-11-14 14:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Called when the game starts
|
|
|
|
void UInventoryComponent::BeginPlay()
|
|
|
|
{
|
|
|
|
Super::BeginPlay();
|
|
|
|
|
2022-11-14 17:42:26 +00:00
|
|
|
for(auto & BaseItem : DefaultItems)
|
|
|
|
{
|
|
|
|
AddItem(BaseItem);
|
2022-11-18 13:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 17:42:26 +00:00
|
|
|
bool UInventoryComponent::AddItem(class UBaseItem* BaseItem)
|
2022-11-14 14:57:02 +00:00
|
|
|
{
|
2022-11-14 17:42:26 +00:00
|
|
|
//if the items is over the maxinventoryslots then it wont add the item
|
|
|
|
if (Items.Num() >= MaxItemSlots || !BaseItem)
|
|
|
|
{
|
2022-11-18 13:07:44 +00:00
|
|
|
UE_LOG(LogTemp, Display, TEXT("THERE ARE MORE ITEMS THAN THE INVENTORY SLOTS"));
|
2022-11-14 17:42:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
BaseItem->StoredItems = this;
|
|
|
|
BaseItem->World = GetWorld();
|
|
|
|
Items.Add(BaseItem);
|
2022-11-18 13:07:44 +00:00
|
|
|
UE_LOG(LogTemp, Display, TEXT("ITEM HAS BEEN ADDED"));
|
2022-11-14 17:42:26 +00:00
|
|
|
//Update UI
|
|
|
|
OnInventoryUpdated.Broadcast();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-11-14 14:57:02 +00:00
|
|
|
|
2022-11-18 13:07:44 +00:00
|
|
|
bool UInventoryComponent::Remove(class UBaseItem* BaseItem)
|
2022-11-14 17:42:26 +00:00
|
|
|
{
|
|
|
|
if(BaseItem)
|
|
|
|
{
|
2022-11-18 13:07:44 +00:00
|
|
|
UE_LOG(LogTemp, Display, TEXT("ItEM HAS BEEN REMOVED"));
|
2022-11-14 17:42:26 +00:00
|
|
|
BaseItem->StoredItems = nullptr;
|
|
|
|
BaseItem->World = nullptr;
|
|
|
|
Items.RemoveSingle(BaseItem);
|
|
|
|
OnInventoryUpdated.Broadcast(); // Updates UI
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2022-11-14 14:57:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-18 13:07:44 +00:00
|
|
|
UBaseItem* UInventoryComponent::GetItem(int32 Index)
|
|
|
|
{
|
|
|
|
return Items[Index];
|
|
|
|
}
|
|
|
|
|