the player can pick up consumable items and use items for different effects; needs optimization in player character base BP class
This commit is contained in:
8
hwanyoung2/Source/hwanyoung2/HYConsumableItem.cpp
Normal file
8
hwanyoung2/Source/hwanyoung2/HYConsumableItem.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "HYConsumableItem.h"
|
||||
|
||||
AHYConsumableItem::AHYConsumableItem()
|
||||
{
|
||||
}
|
25
hwanyoung2/Source/hwanyoung2/HYConsumableItem.h
Normal file
25
hwanyoung2/Source/hwanyoung2/HYConsumableItem.h
Normal file
@ -0,0 +1,25 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "HYManualPickUp.h"
|
||||
#include "HYConsumableItem.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
UCLASS()
|
||||
class HWANYOUNG2_API AHYConsumableItem : public AHYManualPickUp
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AHYConsumableItem();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Pick up and consume")
|
||||
void OnUsed(APlayerController* Controller);
|
||||
|
||||
};
|
@ -39,6 +39,18 @@ bool AHYPlayerCharacController::AddItemToInventoryByID(FName ID)
|
||||
return false;
|
||||
}
|
||||
|
||||
void AHYPlayerCharacController::CraftItem(FInventoryItem ItemA, FInventoryItem ItemB)
|
||||
{
|
||||
for (auto Pair : ItemB.CraftCombinations) {
|
||||
if (Pair.ComponentID == ItemA.ItemID) {
|
||||
if (Pair.bDestroyItemA) Inventory.RemoveSingle(ItemA);
|
||||
if (Pair.bDestroyItemB) Inventory.RemoveSingle(ItemB);
|
||||
AddItemToInventoryByID(Pair.ProductID);
|
||||
ReloadCraftUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AHYPlayerCharacController::Interact()
|
||||
{
|
||||
if (CurrentInteractable) CurrentInteractable->Interact(this);
|
||||
|
@ -25,12 +25,18 @@ public:
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void ReloadInventory();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void ReloadCraftUI();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Utils")
|
||||
int32 GetInventoryWeight();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Utils")
|
||||
bool AddItemToInventoryByID(FName ID);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Utils")
|
||||
void CraftItem(FInventoryItem ItemA, FInventoryItem ItemB);
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
||||
class AHYInteractableActor* CurrentInteractable;
|
||||
|
||||
|
Reference in New Issue
Block a user