Illusion-UE5/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.cpp

60 lines
1.4 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "HYPlayerCharacController.h"
#include "HYGameStateBase.h"
#include "hwanyoung2Character.h"
AHYPlayerCharacController::AHYPlayerCharacController()
{
//this is hardcoding the limits:
InventorySlotLimit = 50;
InventoryWeightLimit = 500;
}
int32 AHYPlayerCharacController::GetInventoryWeight()
{
int32 TotalWeight = 0;
for (auto& Item : Inventory) {
TotalWeight += 1; //hard coding for now
}
return TotalWeight;
}
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;
}
void AHYPlayerCharacController::Interact()
{
if (CurrentInteractable) CurrentInteractable->Interact(this);
}
void AHYPlayerCharacController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction(
"Interact", IE_Pressed, this,
&AHYPlayerCharacController::Interact);
}
void AHYPlayerCharacController::OnPossess(APawn* InPawn)
{
}