some more progress to inventory system
This commit is contained in:
parent
90d6e5af17
commit
b7a583ab27
@ -19,6 +19,11 @@ void AHYInteractableActor::Interact_Implementation(APlayerController* Controller
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FString AHYInteractableActor::GetInteractText() const
|
||||||
|
{
|
||||||
|
return FString();
|
||||||
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
void AHYInteractableActor::BeginPlay()
|
void AHYInteractableActor::BeginPlay()
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,15 @@ public:
|
|||||||
void Interact(APlayerController* Controller);
|
void Interact(APlayerController* Controller);
|
||||||
virtual void Interact_Implementation(APlayerController* Controller);
|
virtual void Interact_Implementation(APlayerController* Controller);
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
FString Name;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
FString Action;
|
||||||
|
|
||||||
|
UFUNCTION(Blueprintcallable, Category = "Pickup")
|
||||||
|
FString GetInteractText() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "HYPlayerCharacController.h"
|
#include "HYPlayerCharacController.h"
|
||||||
|
#include "HYGameStateBase.h"
|
||||||
|
#include "hwanyoung2Character.h"
|
||||||
|
|
||||||
AHYPlayerCharacController::AHYPlayerCharacController()
|
AHYPlayerCharacController::AHYPlayerCharacController()
|
||||||
{
|
{
|
||||||
@ -27,16 +29,33 @@ int32 AHYPlayerCharacController::GetInventoryWeight()
|
|||||||
|
|
||||||
bool AHYPlayerCharacController::AddItemToInventoryByID(FName ID)
|
bool AHYPlayerCharacController::AddItemToInventoryByID(FName ID)
|
||||||
{
|
{
|
||||||
|
AHYGameStateBase* gameState = Cast<AHYGameStateBase>(GetWorld()->GetGameState());
|
||||||
|
UDataTable* itemDB = gameState->GetItemDatabase();
|
||||||
|
FInventoryItem* itemToAdd = itemDB->FindRow<FInventoryItem>(ID, "");
|
||||||
|
|
||||||
|
if (itemToAdd) {
|
||||||
|
if (Inventory.Num() < InventorySlotLimit &&
|
||||||
|
GetInventoryWeight() + itemToAdd->ItemWeight <= InventoryWeightLimit) {
|
||||||
|
Inventory.Add(*itemToAdd);
|
||||||
|
ReloadInventory();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AHYPlayerCharacController::Interact()
|
void AHYPlayerCharacController::Interact()
|
||||||
{
|
{
|
||||||
|
if (CurrentInteractable) CurrentInteractable->Interact(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AHYPlayerCharacController::SetupInputComponent()
|
void AHYPlayerCharacController::SetupInputComponent()
|
||||||
{
|
{
|
||||||
Super::SetupInputComponent();
|
Super::SetupInputComponent();
|
||||||
|
|
||||||
|
InputComponent->BindAction(
|
||||||
|
"Interact", IE_Pressed, this,
|
||||||
|
&AHYPlayerCharacController::Interact);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AHYPlayerCharacController::OnPossess(APawn* InPawn)
|
void AHYPlayerCharacController::OnPossess(APawn* InPawn)
|
||||||
|
@ -19,8 +19,10 @@ class HWANYOUNG2_API AHYPlayerCharacController : public APlayerController
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
#pragma region inventory
|
#pragma region inventory
|
||||||
|
//setting up the controller inventory
|
||||||
AHYPlayerCharacController();
|
AHYPlayerCharacController();
|
||||||
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintImplementableEvent)
|
UFUNCTION(BlueprintImplementableEvent)
|
||||||
void ReloadInventory();
|
void ReloadInventory();
|
||||||
|
|
||||||
|
@ -5,4 +5,7 @@
|
|||||||
|
|
||||||
FInventoryItem::FInventoryItem()
|
FInventoryItem::FInventoryItem()
|
||||||
{
|
{
|
||||||
|
this->ItemName = FText::FromString("No Name");
|
||||||
|
this->ItemWeight = 1;
|
||||||
|
this->ItemDescription = FText::FromString("No Description");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user