Added Jelly1 and ItemPurchaseComponent class
Jelly1 is the test item i am creating and i also added a health variable for the temp character
This commit is contained in:
parent
e070b32f0e
commit
7699a088ae
@ -22,6 +22,8 @@ protected:
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
|
||||
FActorComponentTickFunction* ThisTickFunction) override;
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
int32 GoldBalance = 500;
|
||||
};
|
||||
|
@ -35,7 +35,19 @@ public:
|
||||
UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item")
|
||||
FText ItemDescription;
|
||||
|
||||
//The cost of the item
|
||||
UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item")
|
||||
int32 ItemCostPrice;
|
||||
|
||||
//ADD A HEALING ITEM VALUE?
|
||||
|
||||
//reference to the UInventoryComponent script
|
||||
UPROPERTY()
|
||||
class UInventoryComponent* StoredItems;
|
||||
|
||||
//The buy class to purchase the item
|
||||
virtual void Buy(class UItemPurchaseComponent* PurchaseItem) PURE_VIRTUAL(UBaseItem);
|
||||
|
||||
//The use Item class to use the item in the player Inventory
|
||||
virtual void Use(class ATempCharacter* Character) PURE_VIRTUAL(UBaseItem);
|
||||
};
|
||||
|
14
Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp
Normal file
14
Source/the_twilight_abyss/BaseItems/Items/Jelly1.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Jelly1.h"
|
||||
|
||||
void UJelly1::Buy(UItemPurchaseComponent* PurchaseItem)
|
||||
{
|
||||
Super::Buy(PurchaseItem);
|
||||
}
|
||||
|
||||
void UJelly1::Use(ATempCharacter* Character)
|
||||
{
|
||||
Super::Use(Character);
|
||||
}
|
21
Source/the_twilight_abyss/BaseItems/Items/Jelly1.h
Normal file
21
Source/the_twilight_abyss/BaseItems/Items/Jelly1.h
Normal file
@ -0,0 +1,21 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "BaseItem.h"
|
||||
#include "Jelly1.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class THE_TWILIGHT_ABYSS_API UJelly1 : public UBaseItem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
virtual void Buy(class UItemPurchaseComponent* PurchaseItem) override;
|
||||
|
||||
virtual void Use(class ATempCharacter* Character) override;
|
||||
};
|
@ -0,0 +1,35 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "ItemPurchaseComponent.h"
|
||||
|
||||
|
||||
// Sets default values for this component's properties
|
||||
UItemPurchaseComponent::UItemPurchaseComponent()
|
||||
{
|
||||
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
||||
// off to improve performance if you don't need them.
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
// Called when the game starts
|
||||
void UItemPurchaseComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
// ...
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Called every frame
|
||||
void UItemPurchaseComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
// ...
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "ItemPurchaseComponent.generated.h"
|
||||
|
||||
|
||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
class THE_TWILIGHT_ABYSS_API UItemPurchaseComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this component's properties
|
||||
UItemPurchaseComponent();
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
};
|
@ -20,7 +20,7 @@ ATempCharacter::ATempCharacter()
|
||||
void ATempCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
Health = 100;
|
||||
}
|
||||
|
||||
//Binds the input we made in the setup player component to the forward vector
|
||||
@ -28,7 +28,6 @@ void ATempCharacter::ForwardInput(float Axis)
|
||||
{
|
||||
AddMovementInput(GetActorForwardVector() * Axis);
|
||||
}
|
||||
|
||||
//Binds the input we made in the setup player component to the right vector
|
||||
void ATempCharacter::RightMoveInput(float Axis)
|
||||
{
|
||||
|
@ -1,87 +0,0 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "TempCharacter.h"
|
||||
#include "UObject/SoftObjectPath.h"
|
||||
#include "Dialogs/Dialogs.h"
|
||||
#include "Engine/GameViewportClient.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h"
|
||||
#include "the_twilight_abyss/MerchantInteraction/Interaction.h"
|
||||
|
||||
|
||||
// CONSTRUCTOR
|
||||
ATempCharacter::ATempCharacter()
|
||||
{
|
||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ATempCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
//Binds the input we made in the setup player component to the forward vector
|
||||
void ATempCharacter::ForwardInput(float Axis)
|
||||
{
|
||||
AddMovementInput(GetActorForwardVector() * Axis);
|
||||
}
|
||||
|
||||
//Binds the input we made in the setup player component to the right vector
|
||||
void ATempCharacter::RightMoveInput(float Axis)
|
||||
{
|
||||
AddMovementInput(GetActorRightVector() * Axis);
|
||||
}
|
||||
|
||||
|
||||
// Called every frame
|
||||
void ATempCharacter::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
}
|
||||
|
||||
// Called to bind functionality to input
|
||||
void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
PlayerInputComponent->BindAxis(TEXT("Move Forward / Backward"), this, &ATempCharacter::ForwardInput);
|
||||
PlayerInputComponent->BindAxis(TEXT("Move Right / Left"), this, &ATempCharacter::RightMoveInput);
|
||||
PlayerInputComponent->BindAxis(TEXT("Turn Right / Left Mouse"), this, &ATempCharacter::AddControllerYawInput);
|
||||
PlayerInputComponent->BindAxis(TEXT("Look Up / Down Mouse"), this, &ATempCharacter::AddControllerPitchInput);
|
||||
PlayerInputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed);
|
||||
// custom keybind Interact
|
||||
}
|
||||
|
||||
void ATempCharacter::KeyPressed()
|
||||
{
|
||||
LineTraceLogic();
|
||||
}
|
||||
|
||||
void ATempCharacter::LineTraceLogic()
|
||||
{
|
||||
float GlobalTrace = TraceDistance;
|
||||
FHitResult OutHit;
|
||||
FVector Start = GetActorLocation();
|
||||
FVector End = Start + GlobalTrace * GetActorForwardVector();
|
||||
|
||||
FCollisionQueryParams TraceParams;
|
||||
|
||||
TraceParams.AddIgnoredActor(this);
|
||||
|
||||
bool bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams);
|
||||
if (bHit)
|
||||
{
|
||||
if(OutHit.GetActor() == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
|
||||
{
|
||||
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
|
||||
MyInteractable->OnInteract();
|
||||
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
|
||||
}
|
||||
}
|
||||
}
|
@ -35,4 +35,7 @@ public:
|
||||
float TraceDistance = 200;
|
||||
|
||||
void LineTraceLogic();
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category= "Health")
|
||||
float Health;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user