the player character can automatically pick up souls
This commit is contained in:
parent
d91704b9a7
commit
e8cacbe1c7
44
hwanyoung2/Source/hwanyoung2/HYAutomaticPickUp.cpp
Normal file
44
hwanyoung2/Source/hwanyoung2/HYAutomaticPickUp.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "HYAutomaticPickUp.h"
|
||||||
|
#include "HYPlayerCharacController.h"
|
||||||
|
|
||||||
|
// Sets default values
|
||||||
|
AHYAutomaticPickUp::AHYAutomaticPickUp()
|
||||||
|
{
|
||||||
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||||
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>("PickupMesh");
|
||||||
|
RootComponent = Cast<USceneComponent>(PickupMesh);
|
||||||
|
|
||||||
|
ItemID = FName("No ID");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AHYAutomaticPickUp::Collect_Implementation(APlayerController* Controller)
|
||||||
|
{
|
||||||
|
AHYPlayerCharacController* IController = Cast<AHYPlayerCharacController>(Controller);
|
||||||
|
if (IController->AddItemToInventoryByID(ItemID))
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
FName AHYAutomaticPickUp::GetItemID()
|
||||||
|
{
|
||||||
|
return ItemID;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the game starts or when spawned
|
||||||
|
void AHYAutomaticPickUp::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called every frame
|
||||||
|
void AHYAutomaticPickUp::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
38
hwanyoung2/Source/hwanyoung2/HYAutomaticPickUp.h
Normal file
38
hwanyoung2/Source/hwanyoung2/HYAutomaticPickUp.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/Actor.h"
|
||||||
|
#include "HYAutomaticPickUp.generated.h"
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class HWANYOUNG2_API AHYAutomaticPickUp : public AActor
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Sets default values for this actor's properties
|
||||||
|
AHYAutomaticPickUp();
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintNativeEvent)
|
||||||
|
void Collect(APlayerController* Controller);
|
||||||
|
virtual void Collect_Implementation(APlayerController* Controller);
|
||||||
|
|
||||||
|
FName GetItemID();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Called when the game starts or when spawned
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
UStaticMeshComponent* PickupMesh;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FName ItemID;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Called every frame
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
|
};
|
18
hwanyoung2/Source/hwanyoung2/HYMoneyAutoPickUp.cpp
Normal file
18
hwanyoung2/Source/hwanyoung2/HYMoneyAutoPickUp.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "HYMoneyAutoPickUp.h"
|
||||||
|
#include "HYPlayerCharacController.h"
|
||||||
|
|
||||||
|
AHYMoneyAutoPickUp::AHYMoneyAutoPickUp()
|
||||||
|
{
|
||||||
|
Super::ItemID = FName("Lost soul");
|
||||||
|
Value = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AHYMoneyAutoPickUp::Collect_Implementation(APlayerController* Controller)
|
||||||
|
{
|
||||||
|
AHYPlayerCharacController* IController = Cast<AHYPlayerCharacController>(Controller);
|
||||||
|
IController->Currency += Value;
|
||||||
|
Destroy();
|
||||||
|
}
|
26
hwanyoung2/Source/hwanyoung2/HYMoneyAutoPickUp.h
Normal file
26
hwanyoung2/Source/hwanyoung2/HYMoneyAutoPickUp.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "HYAutomaticPickUp.h"
|
||||||
|
#include "HYMoneyAutoPickUp.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class HWANYOUNG2_API AHYMoneyAutoPickUp : public AHYAutomaticPickUp
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
AHYMoneyAutoPickUp();
|
||||||
|
|
||||||
|
void Collect_Implementation(APlayerController* Controller) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
int32 Value;
|
||||||
|
|
||||||
|
};
|
@ -43,6 +43,9 @@ public:
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
int32 InventoryWeightLimit;
|
int32 InventoryWeightLimit;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
int32 Currency;
|
||||||
|
|
||||||
//interacts with the Interactable objects
|
//interacts with the Interactable objects
|
||||||
UFUNCTION(BlueprintCallable, Category = "Utils")
|
UFUNCTION(BlueprintCallable, Category = "Utils")
|
||||||
void Interact();
|
void Interact();
|
||||||
|
@ -7,5 +7,6 @@ FInventoryItem::FInventoryItem()
|
|||||||
{
|
{
|
||||||
this->ItemName = FText::FromString("No Name");
|
this->ItemName = FText::FromString("No Name");
|
||||||
this->ItemWeight = 1;
|
this->ItemWeight = 1;
|
||||||
|
this->ItemValue = 1;
|
||||||
this->ItemDescription = FText::FromString("No Description");
|
this->ItemDescription = FText::FromString("No Description");
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,10 @@ public:
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
int32 ItemWeight;
|
int32 ItemWeight;
|
||||||
|
|
||||||
|
//value of the item
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
int32 ItemValue;
|
||||||
|
|
||||||
//is the item only available through drops?
|
//is the item only available through drops?
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
bool OnlyDropped;
|
bool OnlyDropped;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "EnhancedInputSubsystems.h"
|
#include "EnhancedInputSubsystems.h"
|
||||||
#include "HYInteractableActor.h"
|
#include "HYInteractableActor.h"
|
||||||
#include "InventoryItem.h"
|
#include "InventoryItem.h"
|
||||||
|
#include "HYAutomaticPickUp.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -97,12 +98,29 @@ void Ahwanyoung2Character::CheckForInteractables()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Ahwanyoung2Character::CollectAutoPickups()
|
||||||
|
{
|
||||||
|
// Stores all the overlapping actors in an array
|
||||||
|
TArray<AActor*> CollectedActors;
|
||||||
|
CollectionSphere->GetOverlappingActors(CollectedActors);
|
||||||
|
|
||||||
|
AHYPlayerCharacController* IController = Cast<AHYPlayerCharacController>(GetController());
|
||||||
|
|
||||||
|
for (int32 indCollect = 0; indCollect < CollectedActors.Num(); ++indCollect) {
|
||||||
|
AHYAutomaticPickUp* const Pickup = Cast<AHYAutomaticPickUp>(CollectedActors[indCollect]);
|
||||||
|
if (Pickup && !Pickup->IsPendingKill()) {
|
||||||
|
Pickup->Collect(IController);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Ahwanyoung2Character::Tick(float DeltaTime)
|
void Ahwanyoung2Character::Tick(float DeltaTime)
|
||||||
{
|
{
|
||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
CheckForInteractables();
|
CheckForInteractables();
|
||||||
|
CollectAutoPickups();
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -201,6 +219,10 @@ void Ahwanyoung2Character::Initialize()
|
|||||||
|
|
||||||
// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
|
// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
|
||||||
// are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++)
|
// are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++)
|
||||||
|
|
||||||
|
CollectionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("CollectionSphere"));
|
||||||
|
CollectionSphere->SetupAttachment(RootComponent);
|
||||||
|
CollectionSphere->SetSphereRadius(200.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "InputAction.h"
|
#include "InputAction.h"
|
||||||
#include "hwanyoung2.h"
|
#include "hwanyoung2.h"
|
||||||
|
#include "Components/SphereComponent.h"
|
||||||
#include "hwanyoung2Character.generated.h"
|
#include "hwanyoung2Character.generated.h"
|
||||||
|
|
||||||
|
|
||||||
@ -103,6 +104,8 @@ protected:
|
|||||||
/** Called for checking for the closest Interactable in sight and in range*/
|
/** Called for checking for the closest Interactable in sight and in range*/
|
||||||
void CheckForInteractables();
|
void CheckForInteractables();
|
||||||
|
|
||||||
|
/** Called for collecting automatic pick-upable interactables*/
|
||||||
|
void CollectAutoPickups();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// APawn interface
|
// APawn interface
|
||||||
|
Loading…
Reference in New Issue
Block a user