some more progress to inventory system
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
|
||||
|
||||
#include "HYPlayerCharacController.h"
|
||||
#include "HYGameStateBase.h"
|
||||
#include "hwanyoung2Character.h"
|
||||
|
||||
AHYPlayerCharacController::AHYPlayerCharacController()
|
||||
{
|
||||
@ -27,16 +29,33 @@ int32 AHYPlayerCharacController::GetInventoryWeight()
|
||||
|
||||
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)
|
||||
|
Reference in New Issue
Block a user